Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ts-rest/open-api

Package Overview
Dependencies
Maintainers
1
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-rest/open-api - npm Package Compare versions

Comparing version 1.3.0 to 2.0.1

16

CHANGELOG.md
# @ts-rest/open-api
## 2.0.1
### Patch Changes
- 119aed6: Bump versions to 2.0.1
## 2.0.0
### Major Changes
- 4792b26: Change contract to support multiple responses, for different statuses
### Patch Changes
- 4792b26: Add error handling support to express
## 1.3.0

@@ -4,0 +20,0 @@

6

package.json
{
"name": "@ts-rest/open-api",
"version": "1.3.0",
"version": "2.0.1",
"type": "commonjs",

@@ -9,4 +9,4 @@ "main": "./src/index.js",

"peerDependencies": {
"@ts-rest/core": "1.3.0",
"zod": "^3.17.10",
"@ts-rest/core": "2.0.1",
"zod": "^3.18.0",
"openapi3-ts": "^2.0.2",

@@ -13,0 +13,0 @@ "zod-to-json-schema": "^3.17.1",

@@ -22,2 +22,11 @@ "use strict";

};
const isZodObject = (body) => {
return (body === null || body === void 0 ? void 0 : body.safeParse) !== undefined;
};
const getResponseSchemaFromZod = (response) => isZodObject(response)
? (0, zod_to_json_schema_1.default)(response, {
name: 'zodObject',
target: 'openApi3',
}).definitions['zodObject']
: undefined;
const generateOpenApi = (router, options) => {

@@ -32,5 +41,2 @@ const paths = getPathsFromRouter(router);

};
const isZodObject = (body) => {
return (body === null || body === void 0 ? void 0 : body.safeParse) !== undefined;
};
const pathObject = paths.reduce((acc, path) => {

@@ -40,14 +46,17 @@ var _a, _b;

.match(/{[^}]+}/g)) === null || _a === void 0 ? void 0 : _a.map((param) => param.slice(1, -1));
const bodySchema = ((_b = path.route) === null || _b === void 0 ? void 0 : _b.__type) === 'AppRouteMutation' && isZodObject(path.route.body)
? (0, zod_to_json_schema_1.default)(path.route.body, {
name: 'zodObject',
target: 'openApi3',
}).definitions['zodObject']
: undefined;
const responseSchema = isZodObject(path.route.response)
? (0, zod_to_json_schema_1.default)(path.route.response, {
name: 'zodObject',
target: 'openApi3',
}).definitions['zodObject']
: undefined;
const bodySchema = ((_b = path.route) === null || _b === void 0 ? void 0 : _b.__tsType) === 'AppRouteMutation' &&
getResponseSchemaFromZod(path.route.responses);
const responses = Object.keys(path.route.responses).reduce((acc, key) => {
const keyAsNumber = Number(key);
const responseSchema = getResponseSchemaFromZod(path.route.responses[keyAsNumber]);
return Object.assign(Object.assign({}, acc), { [keyAsNumber]: Object.assign({ description: `${keyAsNumber}` }, (responseSchema
? {
content: {
'application/json': {
schema: responseSchema,
},
},
}
: {})) });
}, {});
const newPath = Object.assign(Object.assign({ description: path.route.description, summary: path.route.summary, deprecated: path.route.deprecated, tags: path.paths, parameters: paramsFromPath === null || paramsFromPath === void 0 ? void 0 : paramsFromPath.map((param) => ({

@@ -68,13 +77,3 @@ name: param,

}
: {})), { responses: {
200: Object.assign({ description: 'Success' }, (responseSchema
? {
content: {
'application/json': {
schema: responseSchema,
},
},
}
: {})),
} });
: {})), { responses });
acc[path.path] = Object.assign(Object.assign({}, acc[path.path]), { [mapMethod[path.route.method]]: newPath });

@@ -81,0 +80,0 @@ return acc;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc