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.1.0 to 1.2.0

11

dist/openapi-generator.js

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

description: metadata === null || metadata === void 0 ? void 0 : metadata.description,
required: true,
required: !bodySchema.isOptional(),
content: {

@@ -310,2 +310,11 @@ // TODO: Maybe should be coming from metadata

}
if (zodSchema instanceof zod_1.ZodDefault) {
const innerSchema = zodSchema._def.innerType;
return this.toOpenAPISchema(innerSchema, isNullable, hasOpenAPIType);
}
if (zodSchema instanceof zod_1.ZodEffects &&
zodSchema._def.effect.type === 'refinement') {
const innerSchema = zodSchema._def.schema;
return this.toOpenAPISchema(innerSchema, isNullable, hasOpenAPIType);
}
if (zodSchema instanceof zod_1.ZodLiteral) {

@@ -312,0 +321,0 @@ return {

2

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

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

@@ -11,6 +11,9 @@ # Zod to OpenAPI

4. [Defining schemas](#defining-schemas)
6. [Defining routes](#defining-routes)
7. [A full example](#a-full-example)
8. [Adding it as part of your build](#adding-it-as-part-of-your-build)
3. [Technologies](#technologies)
5. [Defining routes](#defining-routes)
6. [A full example](#a-full-example)
7. [Adding it as part of your build](#adding-it-as-part-of-your-build)
3. [Zod schema types](#zod-schema-types)
1. [Supported types](#supported-types)
2. [Unsupported types](#unsupported-types)
4. [Technologies](#technologies)

@@ -48,3 +51,3 @@ We keep a changelog as part of the [GitHub releases](https://github.com/asteasolutions/zod-to-openapi/releases).

}),
}
},
},

@@ -201,3 +204,3 @@ });

params: z.object({
id: z.string().openapi({ example: '1212121' })
id: z.string().openapi({ example: '1212121' }),
}),

@@ -254,3 +257,2 @@ },

#### Defining route parameters

@@ -282,2 +284,3 @@

```
The YAML equivalent would be:

@@ -344,2 +347,31 @@

## Zod schema types
### Supported types
The list of all supported types as of now is:
- `ZodString`
- `ZodNumber`
- `ZodBoolean`
- `ZodDefault`
- `ZodEffects` - only for `.refine()`
- `ZodLiteral`
- `ZodEnum`
- `ZodNativeEnum`
- `ZodObject`
- `ZodArray`
- `ZodUnion`
- `ZodIntersection`
- `ZodRecord`
- `ZodUnknown`
### Unsupported types
In case you try to create an OpenAPI schema from a zod schema that is not one of the aforementioned types then you'd receive an `UnknownZodTypeError`.
You can still register such schemas on your own by providing a `type` via the `.openapi` method. In case you think that the desired behavior can be achieved automatically do not hesitate to reach out to us by describing your case via Github Issues.
**Note:** The `ZodEffects` schema from the `.transform` method is an example for a zod schema that cannot be automatically generated since the result of the transformation resides only as a type definition and is not an actual zod specific object.
## Technologies

@@ -346,0 +378,0 @@

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