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
5
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 1.2.0 to 1.2.1

3

dist/openapi-generator.d.ts

@@ -36,6 +36,7 @@ import { OpenAPIObject, InfoObject, ServerObject, SecurityRequirementObject, TagObject, ExternalDocumentationObject, ComponentsObject } from 'openapi3-ts';

private toOpenAPISchema;
private isOptionalSchema;
private toOpenAPIObjectSchema;
private flattenUnionTypes;
private flattenIntersectionTypes;
private unwrapOptional;
private unwrapChained;
private buildSchemaMetadata;

@@ -42,0 +43,0 @@ private buildParameterMetadata;

@@ -180,3 +180,3 @@ "use strict";

generateSimpleSchema(zodSchema) {
const innerSchema = this.unwrapOptional(zodSchema);
const innerSchema = this.unwrapChained(zodSchema);
const metadata = zodSchema._def.openapi

@@ -191,3 +191,7 @@ ? zodSchema._def.openapi

}
const result = this.toOpenAPISchema(innerSchema, zodSchema.isNullable(), !!(metadata === null || metadata === void 0 ? void 0 : metadata.type));
const result = (metadata === null || metadata === void 0 ? void 0 : metadata.type)
? {
type: metadata === null || metadata === void 0 ? void 0 : metadata.type,
}
: this.toOpenAPISchema(innerSchema, zodSchema.isNullable());
return metadata

@@ -286,3 +290,3 @@ ? this.applySchemaMetadata(result, metadata)

}
toOpenAPISchema(zodSchema, isNullable, hasOpenAPIType) {
toOpenAPISchema(zodSchema, isNullable) {
var _a, _b, _c, _d, _e;

@@ -314,3 +318,3 @@ if (zodSchema instanceof zod_1.ZodNull) {

const innerSchema = zodSchema._def.innerType;
return this.toOpenAPISchema(innerSchema, isNullable, hasOpenAPIType);
return this.generateInnerSchema(innerSchema);
}

@@ -320,3 +324,3 @@ if (zodSchema instanceof zod_1.ZodEffects &&

const innerSchema = zodSchema._def.schema;
return this.toOpenAPISchema(innerSchema, isNullable, hasOpenAPIType);
return this.generateInnerSchema(innerSchema);
}

@@ -379,3 +383,3 @@ if (zodSchema instanceof zod_1.ZodLiteral) {

}
if (zodSchema instanceof zod_1.ZodUnknown || hasOpenAPIType) {
if (zodSchema instanceof zod_1.ZodUnknown) {
return {};

@@ -389,2 +393,11 @@ }

}
isOptionalSchema(zodSchema) {
if (zodSchema instanceof zod_1.ZodEffects) {
return this.isOptionalSchema(zodSchema._def.schema);
}
if (zodSchema instanceof zod_1.ZodDefault) {
return this.isOptionalSchema(zodSchema._def.innerType);
}
return zodSchema.isOptional();
}
toOpenAPIObjectSchema(zodSchema, isNullable) {

@@ -394,3 +407,3 @@ const propTypes = zodSchema._def.shape();

const requiredProperties = Object.entries(propTypes)
.filter(([_key, type]) => !type.isOptional())
.filter(([_key, type]) => !this.isOptionalSchema(type))
.map(([key, _type]) => key);

@@ -420,6 +433,13 @@ return {

}
unwrapOptional(schema) {
while (schema instanceof zod_1.ZodOptional || schema instanceof zod_1.ZodNullable) {
schema = schema.unwrap();
unwrapChained(schema) {
if (schema instanceof zod_1.ZodOptional || schema instanceof zod_1.ZodNullable) {
return this.unwrapChained(schema.unwrap());
}
if (schema instanceof zod_1.ZodDefault) {
return this.unwrapChained(schema._def.innerType);
}
if (schema instanceof zod_1.ZodEffects &&
schema._def.effect.type === 'refinement') {
return this.unwrapChained(schema._def.schema);
}
return schema;

@@ -435,3 +455,3 @@ }

getMetadata(zodSchema) {
const innerSchema = this.unwrapOptional(zodSchema);
const innerSchema = this.unwrapChained(zodSchema);
const metadata = zodSchema._def.openapi

@@ -438,0 +458,0 @@ ? zodSchema._def.openapi

{
"name": "@asteasolutions/zod-to-openapi",
"version": "1.2.0",
"version": "1.2.1",
"description": "Builds OpenAPI schemas from Zod schemas",

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

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