@ts-rest/open-api
Advanced tools
Comparing version 3.27.0-rc.0 to 3.27.0
# @ts-rest/open-api | ||
## 3.27.0-rc.0 | ||
## 3.27.0 | ||
### Minor Changes | ||
- b85118a: Add support for headers (using Zod) in open-api generation, from PR #318 | ||
### Patch Changes | ||
- 55411ad: Upgrade zod to 3.21.4 | ||
Upgrade @anatine/zod-openapi to 2.0.1 | ||
## 3.26.4 | ||
## 3.26.3 | ||
## 3.26.2 | ||
@@ -6,0 +19,0 @@ |
22
index.js
@@ -60,2 +60,21 @@ 'use strict'; | ||
}; | ||
const getHeaderParameters = (zodObject) => { | ||
const isZodObj = core.isZodObject(zodObject); | ||
if (!isZodObj) { | ||
return []; | ||
} | ||
const zodShape = core.extractZodObjectShape(zodObject); | ||
return Object.entries(zodShape).map(([key, value]) => { | ||
const schema = getOpenApiSchemaFromZod(value); | ||
const isRequired = !value.isOptional(); | ||
return { | ||
name: key, | ||
in: 'header', | ||
...(isRequired && { required: true }), | ||
...({ | ||
schema: schema, | ||
}), | ||
}; | ||
}); | ||
}; | ||
const getQueryParametersFromZod = (zodObject, jsonQuery = false) => { | ||
@@ -110,2 +129,3 @@ const isZodObj = core.isZodObject(zodObject); | ||
const pathParams = getPathParameters(path.path, path.route.pathParams); | ||
const headerParams = getHeaderParameters(path.route.headers); | ||
const querySchema = getQueryParametersFromZod(path.route.query, !!options.jsonQuery); | ||
@@ -139,3 +159,3 @@ const bodySchema = ((_a = path.route) === null || _a === void 0 ? void 0 : _a.method) !== 'GET' | ||
tags: path.paths, | ||
parameters: [...pathParams, ...querySchema], | ||
parameters: [...pathParams, ...headerParams, ...querySchema], | ||
...(options.setOperationId ? { operationId: path.id } : {}), | ||
@@ -142,0 +162,0 @@ ...(bodySchema |
{ | ||
"name": "@ts-rest/open-api", | ||
"version": "3.27.0-rc.0", | ||
"version": "3.27.0", | ||
"dependencies": { | ||
@@ -9,4 +9,4 @@ "@anatine/zod-openapi": "^1.12.0", | ||
"peerDependencies": { | ||
"zod": "^3.0.0", | ||
"@ts-rest/core": "3.27.0-rc.0" | ||
"zod": "^3.21.0", | ||
"@ts-rest/core": "3.27.0" | ||
}, | ||
@@ -13,0 +13,0 @@ "typedoc": { |
@@ -55,3 +55,3 @@ # ts-rest | ||
Fulfil the contract on your sever, with a type-safe router: | ||
Fulfil the contract on your server, with a type-safe router: | ||
@@ -125,2 +125,3 @@ ```typescript | ||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/baryla"><img src="https://avatars.githubusercontent.com/u/10336085?v=4?s=100" width="100px;" alt="Adrian Barylski"/><br /><sub><b>Adrian Barylski</b></sub></a><br /><a href="https://github.com/ts-rest/ts-rest/commits?author=baryla" title="Code">๐ป</a> <a href="https://github.com/ts-rest/ts-rest/commits?author=baryla" title="Documentation">๐</a> <a href="https://github.com/ts-rest/ts-rest/commits?author=baryla" title="Tests">โ ๏ธ</a></td> | ||
<td align="center" valign="top" width="14.28%"><a href="https://nad.dev"><img src="https://avatars.githubusercontent.com/u/6670753?v=4?s=100" width="100px;" alt="Neil A. Dobson"/><br /><sub><b>Neil A. Dobson</b></sub></a><br /><a href="https://github.com/ts-rest/ts-rest/commits?author=neildobson-au" title="Code">๐ป</a></td> | ||
</tr> | ||
@@ -127,0 +128,0 @@ </tbody> |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
26404
376
1
149