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

@asteasolutions/zod-to-openapi

Package Overview
Dependencies
Maintainers
3
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asteasolutions/zod-to-openapi - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

1

dist/index.d.ts
export * from './zod-extensions';
export { OpenAPIGenerator } from './openapi-generator';
export { OpenAPIRegistry, RouteConfig, ResponseConfig, } from './openapi-registry';
export * as OpenAPI from 'openapi3-ts';

@@ -13,7 +13,19 @@ "use strict";

}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpenAPIRegistry = exports.OpenAPIGenerator = void 0;
exports.OpenAPI = exports.OpenAPIRegistry = exports.OpenAPIGenerator = void 0;
__exportStar(require("./zod-extensions"), exports);

@@ -24,1 +36,2 @@ var openapi_generator_1 = require("./openapi-generator");

Object.defineProperty(exports, "OpenAPIRegistry", { enumerable: true, get: function () { return openapi_registry_1.OpenAPIRegistry; } });
exports.OpenAPI = __importStar(require("openapi3-ts"));

@@ -10,2 +10,3 @@ import { OpenAPIObject, InfoObject, ServerObject, SecurityRequirementObject, TagObject, ExternalDocumentationObject, ComponentsObject } from 'openapi3-ts';

externalDocs?: ExternalDocumentationObject;
[key: string]: unknown;
}

@@ -39,2 +40,8 @@ export declare class OpenAPIGenerator {

private getBodyContent;
private getZodStringCheck;
/**
* Attempts to map Zod strings to known formats
* https://json-schema.org/understanding-json-schema/reference/string.html#built-in-formats
*/
private mapStringFormat;
private toOpenAPISchema;

@@ -41,0 +48,0 @@ private isOptionalSchema;

@@ -287,2 +287,23 @@ "use strict";

}
getZodStringCheck(zodString, kind) {
return zodString._def.checks.find((check) => {
return check.kind === kind;
});
}
/**
* Attempts to map Zod strings to known formats
* https://json-schema.org/understanding-json-schema/reference/string.html#built-in-formats
*/
mapStringFormat(zodString) {
if (zodString.isUUID) {
return 'uuid';
}
if (zodString.isEmail) {
return 'email';
}
if (zodString.isURL) {
return 'uri';
}
return undefined;
}
toOpenAPISchema(zodSchema, isNullable) {

@@ -294,5 +315,8 @@ var _a, _b, _c, _d, _e;

if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodString')) {
const regexCheck = this.getZodStringCheck(zodSchema, 'regex');
return {
type: 'string',
nullable: isNullable ? true : undefined,
format: this.mapStringFormat(zodSchema),
pattern: regexCheck === null || regexCheck === void 0 ? void 0 : regexCheck.regex.source,
};

@@ -302,3 +326,3 @@ }

return {
type: 'number',
type: zodSchema.isInt ? 'integer' : 'number',
minimum: (_a = zodSchema.minValue) !== null && _a !== void 0 ? _a : undefined,

@@ -305,0 +329,0 @@ maximum: (_b = zodSchema.maxValue) !== null && _b !== void 0 ? _b : undefined,

@@ -52,3 +52,15 @@ "use strict";

};
const zodPick = zod.ZodObject.prototype.pick;
zod.ZodObject.prototype.pick = function (...args) {
const result = zodPick.apply(this, args);
result._def.openapi = undefined;
return result;
};
const zodOmit = zod.ZodObject.prototype.omit;
zod.ZodObject.prototype.omit = function (...args) {
const result = zodOmit.apply(this, args);
result._def.openapi = undefined;
return result;
};
}
exports.extendZodWithOpenApi = extendZodWithOpenApi;

2

package.json
{
"name": "@asteasolutions/zod-to-openapi",
"version": "2.0.0",
"version": "2.1.0",
"description": "Builds OpenAPI schemas from Zod schemas",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -45,8 +45,11 @@ # Zod to OpenAPI

},
responses: {
200: {
mediaType: 'application/json',
schema: UserSchema.openapi({
description: 'Object with user data',
}),
description: 'Object with user data.',
content: {
'application/json': {
schema: UserSchema,
},
},
},

@@ -361,3 +364,5 @@ },

- `ZodString`
- adding `format` for `.uuid()`, `.email()` and `.url()` and `pattern` for `.regex()` is also supported
- `ZodNumber`
- including `z.number().int()` being inferred as `type: 'integer'`
- `ZodBoolean`

@@ -364,0 +369,0 @@ - `ZodDefault`

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