A library that generates OpenAPI (Swagger) docs from Zod schemas

Overview

Zod to OpenAPI

A library that uses zod schemas to generate an Open API Swagger documentation.

  1. Purpose and quick example
  2. Usage
    1. Installation
    2. The openapi method
    3. The Registry
    4. Defining schemas
    5. Defining routes
    6. A full example
    7. Adding it as part of your build
  3. Technologies

We keep a changelog as part of the GitHub releases.

Purpose and quick example

We at Astea Solutions made this library because we use zod for validation in our APIs and are tired of the duplication to also support a separate OpenAPI definition that must be kept in sync. Using zod-to-openapi, we generate OpenAPI definitions directly from our zod schemas, this having single source of truth.

Simply put, it turns this:

const UserSchema = registry.register(
  'User',
  z.object({
    id: z.string().openapi({ example: '1212121' }),
    name: z.string().openapi({ example: 'John Doe' }),
    age: z.number().openapi({ example: 42 }),
  })
);

registry.registerPath({
  method: 'get',
  path: '/users/{id}',
  summary: 'Get a single user',
  request: {
    params: z.object({ id: z.string() }),
  },
  responses: {
    200: {
      mediaType: 'application/json',
      schema: UserSchema.openapi({
        description: 'Object with user data',
      }),
    }
  },
});

into this:

components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: string
          example: '1212121'
        name:
          type: string
          example: John Doe
        age:
          type: number
          example: 42
      required:
        - id
        - name
        - age

/users/{id}:
  get:
    summary: Get a single user
    parameters:
      - in: path
        name: id
        schema:
          type: string
        required: true
    responses:
      '200':
        description: Object with user data
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/User'

and you can still use UserSchema and the request.params object to validate the input of your API.

Usage

Installation

npm install @asteasolutions/zod-to-openapi
# or
yarn add @asteasolutions/zod-to-openapi

The openapi method

To keep openapi definitions natural, we add an openapi method to all Zod objects. For this to work, you need to call extendZodWithOpenApi once in your project.

Note: This should be done only once in a common-entrypoint file of your project (for example an index.ts/app.ts). If you're using tree-shaking with Webpack, mark that file as having side-effects.

import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
import { z } from 'zod';

extendZodWithOpenApi(z);

// We can now use `.openapi()` to specify OpenAPI metadata
z.string().openapi({ description: 'Some string' });

The Registry

The OpenAPIRegistry is used to track definitions which are later generated using the OpenAPIGenerator class.

import {
  OpenAPIRegistry,
  OpenAPIGenerator,
} from '@asteasolutions/zod-to-openapi';

const registry = new OpenAPIRegistry();

// Register definitions here

const generator = new OpenAPIGenerator(registry.definitions);

return generator.generateComponents();

generateComponents will generate only the /components section of an OpenAPI document (e.g. only schemas and parameters), not generating actual routes.

Defining schemas

An OpenAPI schema should be registered using the register method of an OpenAPIRegistry instance.

const UserSchema = registry.register(
  'User',
  z.object({
    id: z.string().openapi({ example: '1212121' }),
    name: z.string().openapi({ example: 'John Doe' }),
    age: z.number().openapi({ example: 42 }),
  })
);

If run now, generateComponents will generate the following structure:

components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: string
          example: '1212121'
        name:
          type: string
          example: John Doe
        age:
          type: number
          example: 42
      required:
        - id
        - name
        - age

The key for the schema in the output is the first argument passed to .register (in this case - User).

Note that generateComponents does not return YAML but a JS object - you can then serialize that object into YAML or JSON depending on your use-case.

The resulting schema can then be referenced by using $ref: #/components/schemas/User in an existing OpenAPI JSON. This will be done automatically for Routes defined through the registry.

Defining routes

Registering a path

An OpenAPI path is registered using the registerPath method of an OpenAPIRegistry instance.

registry.registerPath({
  method: 'get',
  path: '/users/{id}',
  description: 'Get user data by its id',
  summary: 'Get a single user',
  request: {
    params: z.object({
      id: z.string().openapi({ example: '1212121' })
    }),
  },
  responses: {
    200: {
      mediaType: 'application/json',
      schema: UserSchema.openapi({
        description: 'Object with user data.',
      }),
    },
    204: z.void(),
  },
});

The YAML equivalent of the schema above would be:

'/users/{id}':
  get:
    description: Get user data by its id
    summary: Get a single user
    parameters:
      - in: path
        name: id
        schema:
          type: string
          example: '1212121'
        required: true
    responses:
      '200':
        description: Object with user data.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/User'
      '204':
        description: No content - successful operation

The library specific properties for registerPath are method, path, request and responses. Everything else gets directly appended to the path definition.

  • method - One of get, post, put, delete and patch;
  • path - a string - being the path of the endpoint;
  • request - an optional object with optional body, params, query and headers keys,
    • query, params - being instances of ZodObject
    • body - being any zod instance
    • headers - an array of zod instances
  • responses - an object where the key is the status code or default and the value is either:
    • an instance of ZodVoid - meaning a no content response
    • an object with mediaType (a string like application/json) and a schema of any zod type

Defining route parameters

If you don't want to inline all parameter definitions, you can define them separately with registerParameter and then reference them:

const UserIdParam = registry.registerParameter(
  'UserId',
  z.string().openapi({
    param: {
      name: 'id',
      in: 'path',
    },
    example: '1212121',
  })
);

registry.registerPath({
  ...
  request: {
    params: z.object({
      id: UserIdParam
    }),
  },
  responses: ...
});

The YAML equivalent would be:

components:
  parameters:
    UserId:
      in: path
      name: id
      schema:
        type: string
        example: '1212121'
      required: true

'/users/{id}':
  get:
    ...
    parameters:
      - $ref: '#/components/parameters/UserId'
    responses: ...

Note: In order to define properties that apply to the parameter itself, use the param property of .openapi. Any properties provided outside of param would be applied to the schema for this parameter.

Generating the full document

A full OpenAPI document can be generated using the generateDocument method of an OpenAPIGenerator instance. It takes one argument - the document config. It may look something like this:

return generator.generateDocument({
  openapi: '3.0.0',
  info: {
    version: '1.0.0',
    title: 'My API',
    description: 'This is the API',
  },
  servers: [{ url: 'v1' }],
});

A full example

A full example code can be found here. And the YAML representation of its result - here

Adding it as part of your build

In a file inside your project you can have a file like so:

export const registry = new OpenAPIRegistry();

export function generateOpenAPI() {
  const config = {...}; // your config comes here

  return new OpenAPIGenerator(schemas.definitions).generateDocument(config);
}

You then use the exported registry object to register all schemas, parameters and routes where appropriate.

Then you can create a script that executes the exported generateOpenAPI function. This script can be executed as a part of your build step so that it can write the result to some file like openapi-docs.json.

Technologies

Comments
  • Followed the example and failed

    Followed the example and failed

    Hi. I followed the example and got the following error:

    UnknownZodTypeError {
      message: 'Unknown zod object type, please specify `type` and other OpenAPI props using `ZodSchema.openapi`.',
      data: {
        currentSchema: {
          shape: [Function: shape],
          unknownKeys: 'strip',
          catchall: [ZodNever],
          typeName: 'ZodObject',
          openapi: [Object]
        },
        schemaName: 'User'
      }
    }
    

    when trying to use registry.registerParameter, registry.register, registry.registerPath in NextJS api route.

    My package.json:

    "dependencies": {
        "@asteasolutions/zod-to-openapi": "^1.2.1",
    }
    

    My code:

    import { extendZodWithOpenApi, OpenAPIGenerator, OpenAPIRegistry } from '@asteasolutions/zod-to-openapi';
    import { NextApiRequest, NextApiResponse } from 'next';
    import { z } from 'zod';
    
    function getOpenApiDocumentation() {
      extendZodWithOpenApi(z);
      const registry = new OpenAPIRegistry();
    
      const UserIdSchema = registry.registerParameter(
        "UserId",
        z.string().openapi({
          param: {
            name: "id",
            in: "path",
          },
          example: "1212121",
        })
      );
      const UserSchema = registry.register(
        "User",
        z.object({
          id: z.string().openapi({
            example: "1212121",
          }),
          name: z.string().openapi({
            example: "John Doe",
          }),
          age: z.number().openapi({
            example: 42,
          }),
        })
      );
    
      registry.registerPath({
        method: "get",
        path: "/users/{id}",
        description: "Get user data by its id",
        summary: "Get a single user",
        request: {
          params: z.object({ id: UserIdSchema }),
        },
        responses: {
          200: {
            mediaType: "application/json",
            schema: UserSchema.openapi({
              description: "Object with user data.",
            }),
          },
          204: z
            .void()
            .openapi({ description: "No content - successful operation" }),
        },
      });
    
      const generator = new OpenAPIGenerator(registry.definitions);
    
      return generator.generateDocument({
        openapi: "3.0.0",
        info: {
          version: "1.0.0",
          title: "My API",
          description: "This is the API",
        },
        servers: [{ url: "localhost:3000/api" }],
      });
    }
    
    export default (req: NextApiRequest, res: NextApiResponse) => {
      return new Promise<void>((resolve, reject) => {
        try {
          const openApiDocumentation = getOpenApiDocumentation();
          res.status(200).json(openApiDocumentation);
          resolve();
        } catch (e) {
          console.error(e);
          reject();
        }
        resolve();
      });
    };
    

    What am I doing wrong?

    opened by nazarEnzo 8
  • Breaking Change

    Breaking Change

    Oops I accidentally shipped a breaking change, though Zod shipped the breaking change first ๐Ÿค”

    https://github.com/asteasolutions/zod-to-openapi/pull/78/files#diff-d8192a426c76954f6ca5af42fd2975758ff8e25940d33c3959c5317b4dabfb77R24

    What should we do about it. If a consumer has lib check enabled and pulls the latest version of this library with an older version of Zod it'll complain.

    opened by samchungy 5
  • Can't define header parameters.

    Can't define header parameters.

    Hi, I've recently discovered this library and I found it very useful, it brings a lot of value!

    I'm struggling a little bit with header parameters, for some reason I am not able to define header parameters correctly when registering a path with registerPath function (from OpenAPIRegistry instance).

    opened by ciprian-andrei-extlm 5
  • Support zod preprocessed schemas

    Support zod preprocessed schemas

    Since an OpenAPI request's underlying params and query values can only be string, it's very common having to resort to z.preprocess(...) to convert them to the desired type.

    This PR adds support for z.preprocess(...), similarly to the recent addition of support for refine(...).

    opened by nktpro 5
  • Request body only allows 'application/json'

    Request body only allows 'application/json'

    Currently we only allow request bodies with media type application/json

    I would like to use application/x-www-form-urlencoded. Unfortunately these are still quite common, including in the OAuth spec.

    application/json is hard-coded here: https://github.com/asteasolutions/zod-to-openapi/blob/5fc40ede62ec4891a899469d941f20eb11ea26a2/src/openapi-generator.ts#L423-L425

    I'm not sure how to modify the existing openapi extension to stay consistent with the current design.

    opened by ryan-mars 5
  • feat: add ability to define securitySchemes under components

    feat: add ability to define securitySchemes under components

    Hi, there is a small change that I missed when using this package: having to define my securitySchemes (as of v3 of open api)

    I hope you too find it useful and it'll get merged shortly.

    Any feedback would be appreciated!

    Thanks

    opened by viktor-ku 5
  • openapi3 response anyOf schema definitions

    openapi3 response anyOf schema definitions

    Looking at the documentation and source code, I couldn't figure out if zod-to-openapi supports anyOf when defining response schemas.

    Example yaml copied from swagger website:

    paths:
      /pets:
        patch:
          requestBody:
            content:
              application/json:
                schema:
                  oneOf:
                    - $ref: '#/components/schemas/Cat'
                    - $ref: '#/components/schemas/Dog'
          responses:
            '200':
              description: Updated
    

    As you can see there are 2 possible response schemas. However, if I understand correctly, ResponseConfig.content[mediaType].schema only supports a single schema at a time. Am I missing something?

    opened by botiapa 4
  • Support for native numeric enums

    Support for native numeric enums

    Hi,

    first thank you for this awesome library!

    I have a problem with native numeric enums, they are rendered as strings, e.g. when I do the following:

    enum Test {
      First = 1,
      Second = 2
    }
    
    export const testSchema = z.object({
      test1: z.nativeEnum(Test),
      test2: z.nativeEnum(Test).openapi({example: Test.First}),
    });
    

    Then it is emitted as:

    {
      "test1": { "type": "string", "enum": ["First", "Second", 1, 2] },
      "test2": { "type": "string", "enum": ["First", "Second", 1, 2], "example": 1 }
    }
    

    Swagger UI renders this as

    {
      "test1": "First",
      "test2": "1"
    }
    

    Is there a simple fix or workaround for this?

    opened by heivo 4
  • How to use the schema in request.Body

    How to use the schema in request.Body

    Hi. Sorry for the simple question. Can you please tell me how I can do the same thing as in the yaml file:

    ...
    requestBody:
       required: true
       content:
         application/json:
             schema:
                 $ref: "#/components/schemas/Address"
    ...
    

    I tried to connect the scheme in the same way as in responses section but got an error.

    registry.registerPath({
     ...
      requestBody: {
        content: {
          "application/json": {
            schema: Schemes.AddressSchema.openapi({
              description: "Object with Address data.",
            }),
          },
        },
      },
      responses: {
        200: {
          mediaType: "application/json",
          schema: Schemes.AddressSchema.openapi({
            description: "Object with Address data.",
          }),
        },
    })
    

    Thank you!

    opened by nazarEnzo 4
  • Support for z.refine

    Support for z.refine

    Seeing the following error. I don't think z.refine() is supported

    UnknownZodTypeError {
      message: 'Unknown zod object type, please specify `type` and other OpenAPI props using `ZodSchema.openapi`.',
      data: {
        currentSchema: {
          schema: [ZodObject],
          typeName: 'ZodEffects',
          effect: [Object],
          openapi: [Object]
        },
        schemaName: 'Object'
      }
    }```
    opened by blade2005 4
  • [request]: Support for `x-tagGroups`

    [request]: Support for `x-tagGroups`

    Description

    Hi ๐Ÿ‘‹ ! Awesome project here. It would be nice to have x-tagGroups support or some recommendations for how to possibly extend zod-to-openapi

    Seen at http://redocly.github.io/redoc -> http://redocly.github.io/redoc/openapi.yaml

    The spec yaml:

    x-tagGroups:
      - name: General
        tags:
          - pet
          - store
      - name: User Management
        tags:
          - user
      - name: Models
        tags:
          - pet_model
          - store_model
    

    What it looks like in ReDoc UI:

    CleanShot 2022-12-03 at 11 29 08@2x

    opened by thiskevinwang 3
  • Why are request headers defined as an array instead of a ZodObject?

    Why are request headers defined as an array instead of a ZodObject?

    First of all, great job with this project. I don't see why it isn't more adopted in the larger community.

    I'm struggling to understand why the request.headers configuration is defined as a Zodtype[], while params and query are defined as AnyZodObject.

    My understanding behind this decision is because there are often non-user defined headers that are passed through with a request directly from the browser (cache-control, content-security-policy, etc..).

    However, playing around with request.body revealed that you are actually able to pass in un-specified keys unless you add z.object({...}).strict() to the request.body specification.

    If that is the case, could request.headers also accept an AnyZodObject?

    I'm building an Express middleware which accepts a RouteConfig object and:

    1. Registers this as a route in the OpenAPI documentation.
    2. Provides validation on the request object (body/params/query/headers), and rejects the response if an input is malformed.
    3. Once the route returns a response, the response is also validated against the schema.

    I'm trying to build a strongly typed end-to-end system, and the usage of zod-to-openapi as an input to the validation middleware allows stronger consistency. I've attached a gist of the middleware here. (It is ofc a work in progress). https://gist.github.com/adamgarcia4/7b5644bb6bb5d3daabf5f8377c5b66b4

    I first wanted to ask the above question, as well as showcase how I'm using your package.

    export interface RouteConfig extends OperationObject {
        method: Method;
        path: string;
        request?: {
            body?: ZodRequestBody;
            params?: AnyZodObject;
            query?: AnyZodObject;
            headers?: ZodType<unknown>[];
        };
        responses: {
            [statusCode: string]: ResponseConfig;
        };
    }
    
    opened by adamgarcia4 6
  • Unknown zod object type

    Unknown zod object type

    When generating document, the generator logic can not find openapi data for this zod config:

    z.string()
    	.openapi({
    		param: {
    			name: 'fruits',
    			in: 'query',
    		},
    		example: 'apple,banana,orange',
    	})
    	.transform((fruits) => fruits.split(',').map(fruit => fruitMap[fruit])) // Splitting to array and mapping to allowed fruits
    	.refine((fruits) => !fruits.some((fruit) => !fruit)); // Empty strings not allowed
    

    Error thrown:

    UnknownZodTypeError {
      message: 'Unknown zod object type, please specify 'type' and other OpenAPI props using 'ZodSchema.openapi'.',
      data: {
        currentSchema: { schema: [ZodString], typeName: 'ZodEffects', effect: [Object] },
        schemaName: undefined
      }
    }
    

    I can't move move openapi configuration to the end because the type is changed with transform.

    opened by Mikkoun 2
Releases(v4.0.0)
  • v4.0.0(Dec 20, 2022)

    What's Changed

    Zod introduced a breaking change to one of its models in its latest version. See this comment

    Because of that we are updating our peer dependency to ^3.20.2.

    Full Changelog: https://github.com/asteasolutions/zod-to-openapi/compare/v3.4.0...v4.0.0

    Source code(tar.gz)
    Source code(zip)
  • v3.4.0(Dec 15, 2022)

  • v3.3.0(Dec 5, 2022)

    What's Changed

    • Fixed exclusive minimum and maximum checks for numbers

    Examples

    The following schema z.number().gt(0) would have the following result

    { type: 'number', minimum: 0, exclusiveMinimum: true } // for OpenApi 3.0.0
    { type: 'number', exclusiveMinimum: 0 } // for OpenApi 3.1.0 and higher
    

    Similarly, for the schema z.number().lt(10) the result would be

    { type: 'number', maximum: 10, exclusiveMaximum: true } // for OpenApi 3.0.0
    { type: 'number', exclusiveMaximum: 10 } // for OpenApi 3.1.0 and higher
    

    Full Changelog: https://github.com/asteasolutions/zod-to-openapi/compare/v3.2.0...v3.3.0

    Source code(tar.gz)
    Source code(zip)
  • v3.2.0(Dec 4, 2022)

    What's Changed

    • added support for branded types [closes #72]

    Full Changelog: https://github.com/asteasolutions/zod-to-openapi/compare/v3.1.0...v3.2.0

    Source code(tar.gz)
    Source code(zip)
  • v3.1.0(Nov 22, 2022)

    What's Changed

    • Added additionalProperties: false to strict objects. Removed additionalProperties: true from regular objects since this is the OpenApi default
    • Fix referencing schema with unrecognized type

    Full Changelog: https://github.com/asteasolutions/zod-to-openapi/compare/v3.0.1...v3.1.0

    Source code(tar.gz)
    Source code(zip)
  • v3.0.1(Nov 21, 2022)

    What's Changed

    • Fixed a Typescript 4.9
    • Fixed Route types to support strict objects

    Full Changelog: https://github.com/asteasolutions/zod-to-openapi/compare/v3.0.0...v3.0.1

    Source code(tar.gz)
    Source code(zip)
  • v3.0.0(Nov 7, 2022)

    Summary

    • Added support for Open API 3.1.0
    • Add typing for examples and default metadata
    • Added discriminator key to ZodDiscriminatedUnion schemas
    • Added support for ZodDate type
    • Added support for object inheritance when it's more than one level deep
    • Added support for default
    • Added support for minLength/maxLength on string type
    • Exposed a function getOpenApiMetadata that exposes all provided metada

    Full Changelog: v2.3.0...v3.0.0

    Migrating to v3.0.0

    The v3.0.0 release comes out with support for OpenApi v3.1.0. This new version comes with some breaking changes around null values. Check the OpenApi changelog for more information.

    How it affects @asteasolutions/zod-to-openapi

    Schema generation

    The generator constructor now takes 2 arguments - the second one being the version OpenApi target version. This version would be used when generating the schemas provided as the first argument.

    So if you had something like this:

    const generator = new OpenAPIGenerator(registry.definitions);
    

    it should become:

    const generator = new OpenAPIGenerator(registry.definitions, '3.0.0'); // Where 3.0.0 can be replaced with your desired version
    

    Additionally the openapi version used to be passed in the config object of generateDocument. It should not be passed anymore since the version provided in the constructor is the one that would be used.

    Types

    We've updated our underlying library for OpenApi object types. As a result the .openapi method would not accept "random" keys that are not OpenApi specific. All additional keys must now follow the format x-{some-string}. This is expected since it better suites the OpenApi specification and if you used it with different keys it might have been incorrect to start with.

    We've also separated the internal metadata provided to zod objects. That means that you cannot use .openapi to provide a refId or extendedFrom manually. That was never the intended behavior to start with. Those are meant for internal usage only and any changes to them might break the inner workings of the library.

    Note: If for some reason you want to modify such properties manually, you can use the internal_openapi method added for every zod schema at your own risk.

    Source code(tar.gz)
    Source code(zip)
  • v2.3.0(Oct 12, 2022)

    • Added support for numeric enums
    • Added webhooks support (for OpenAPI 3.1)

    Full Changelog: https://github.com/asteasolutions/zod-to-openapi/compare/v2.2.0...v2.3.0

    Source code(tar.gz)
    Source code(zip)
  • v2.2.0(Oct 11, 2022)

  • v2.1.0(Oct 8, 2022)

    • Added support for integers
    • Introduced string pattern and formats
    • Allow for root level specification extensions
    • Exported all OpenAPI types
    • Treat omit/pick as new objects

    Full Changelog: https://github.com/asteasolutions/zod-to-openapi/compare/v2.0.0...v2.1.0

    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Oct 3, 2022)

    Summary

    1. Multiple response bodies (#31) for different media types can now be used when specifying an endpoint.
    2. Multiple request bodies (#31) for different media types can now be used when specifying an endpoint.
    3. Request and response bodies can now be described using pure OpenAPI format and not only zod schema.

    Migrating to v2.0.0

    Responses

    The responses of an endpoint used to be described as a single object per status code. Inside this object a mediaType property was specified. The current structure allows for multiple mediaTypes to be passed by following the standard OpenAPI format. To do that a new content key was introduced explicitly for each status code and inside of it, any mediaType string can be used as a key. The value could either be a plain OpenAPI object definition or a zod schema.

    Additionally since there can now be multiple response schemas per status code it did not make sense to keep the functionality where a description specified using the .openapi method was used. Instead the status code response description is moved to the top level following the OpenAPI specification.

    So for example a path that looked like this:

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

    should now be migrated to the following structure:

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

    Request bodies

    The mediaType of the requestBodyof an endpoint used to be hardcoded to application/json. The previous format used to be to provide a zod schema as the value for request.body. The current structure allows for multiple mediaTypes to be used by following the standard OpenAPI format. To do that a new content key was introduced and inside of it, any mediaType string can be used as a key. The value could either be a plain OpenAPI object definition or a zod schema.

    So for example a path that looked like this:

    registry.registerPath({
      ...
      request: {
        body: UserSchema,
      },
      responses: { ... }
    });
    

    should now be migrated to the following structure:

    registry.registerPath({
      ...
      request: {
        body: {
          content: {
            'application/json': {
              schema: UserSchema,
            },
          },
        },
      },
      responses: {...},
    });
    
    Source code(tar.gz)
    Source code(zip)
  • v1.4.1(Sep 27, 2022)

  • v1.4.0(Sep 15, 2022)

  • v1.3.0(Aug 4, 2022)

    • https://github.com/asteasolutions/zod-to-openapi/pull/28 & https://github.com/asteasolutions/zod-to-openapi/pull/25 Add method OpenAPIRegistry#registerComponent that is able to register non-Zod components. This includes headers, security schemes, etc.
    • https://github.com/asteasolutions/zod-to-openapi/pull/28 Add ability to set response headers during route definition
    • https://github.com/asteasolutions/zod-to-openapi/pull/28 & https://github.com/asteasolutions/zod-to-openapi/issues/27 Support for discriminatedUnion

    Full Changelog: https://github.com/asteasolutions/zod-to-openapi/compare/v1.2.3...v1.3.0

    Source code(tar.gz)
    Source code(zip)
  • v1.2.3(Jul 1, 2022)

    • https://github.com/asteasolutions/zod-to-openapi/pull/24 Allow all 3.x, >3.14 versions of Zod as peer dependencies

    Full Changelog: https://github.com/asteasolutions/zod-to-openapi/compare/v1.2.2...v1.2.3

    Source code(tar.gz)
    Source code(zip)
  • v1.2.2(Jun 19, 2022)

    Fixed an issue where in a Next.js server the library would not be able to properly detect types. This would also possibly fix other use-cases where node CJS modules are mixed with ES modules. See https://github.com/asteasolutions/zod-to-openapi/issues/17 for more context.

    Source code(tar.gz)
    Source code(zip)
  • v1.2.1(May 31, 2022)

    • Added support for optional zod schemas when using .default and .refine.
    • Made the type provided using .openapi take precedence when generating a schema.
    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(May 26, 2022)

    Added

    • https://github.com/asteasolutions/zod-to-openapi/issues/11 Support for optional request bodies
    • https://github.com/asteasolutions/zod-to-openapi/issues/12 Support for .default()
    • https://github.com/asteasolutions/zod-to-openapi/issues/13 Support for .refine()
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0-rc.1(Apr 21, 2022)

Owner
Astea Solutions
Astea Solutions
Command line utility to split OpenAPI documents into smaller, self contained, service oriented documents and prepare StackQL provider interfaces

openapi-doc-util Command line utility to split OpenAPI documents into smaller, self contained, service oriented documents and prepare StackQL provider

StackQL Studios 9 Sep 29, 2022
Simple validator for Steuerliche Identifikationsnummer (German personal tax number) according to the official docs (see readme).

simple-de-taxid-validator Important Code of this validator is taken (with small changes like optimization or removing not needed elements) from THIS R

Wojciech 3 Feb 24, 2022
jQuery Validation Plugin library sources

jQuery Validation Plugin - Form validation made easy The jQuery Validation Plugin provides drop-in validation for your existing forms, while making al

null 10.3k Jan 3, 2023
Lightweight JavaScript form validation library inspired by CodeIgniter.

validate.js validate.js is a lightweight JavaScript form validation library inspired by CodeIgniter. Features Validate form fields from over a dozen r

Rick Harrison 2.6k Dec 15, 2022
Micro check library

is.js This is a general-purpose check library. No dependencies AMD, Node & browser ready Usage: Node.js: npm install is_js Bower: bower install is_js

aras 9.2k Dec 27, 2022
FieldVal - multipurpose validation library. Supports both sync and async validation.

FieldVal-JS The FieldVal-JS library allows you to easily validate data and provide readable and structured error reports. Documentation and Examples D

null 137 Sep 24, 2022
jQuery Validation Plugin library sources

jQuery Validation Plugin - Form validation made easy The jQuery Validation Plugin provides drop-in validation for your existing forms, while making al

null 10.3k Jan 3, 2023
jQuery library to validate html forms. compatible with bootstrap v4 and bootstrap v3

jQuery form validation jQuery form validation is a library that helps you to validate your HTML form, it's completable with both Bootstrap 3 and Boots

Bassam Nabriss 33 Jun 10, 2021
The most powerful data validation library for JS

joi The most powerful schema description language and data validator for JavaScript. Installation npm install joi Visit the joi.dev Developer Portal f

Sideway Inc. 19.6k Jan 4, 2023
Lightweight and powerfull library for declarative form validation

Formurai is a lightweight and powerfull library for declarative form validation Features Setup Usage Options Methods Rules Examples Roadmap Features ?

Illia 49 May 13, 2022
Jquery.Circle.js - Circle is a Javascript global-menu library for jQuery.

Circle About Circle is a Javascript global-menu library for jQuery. Read more at the website: http://uc.gpgkd906.com/ Installation Just include the Ja

้™ˆ็€š 3 Jul 19, 2021
A simple credit cards validation library in JavaScript

creditcard.js A simple credit cards validation library in JavaScript. Project website: https://contaazul.github.io/creditcard.js Install creditcard.js

ContaAzul 323 Jan 7, 2023
v8n โ˜‘๏ธ ultimate JavaScript validation library

The ultimate JavaScript validation library you've ever needed. Dead simple fluent API. Customizable. Reusable. Installation - Documentation - API Intr

Bruno C. Couto 4.1k Dec 30, 2022
A lightweight NodeJS library for strict mime-type validation on streams

A lightweight NodeJS library for strict mime-type validation on streams. It gets a ReadableStream and decets the mime-type using its Magic number and validates it using the provided allowed and forbidden lists; If it's allowed it will pass it to the created WritableStreams and if it's not it will throw an error.

CEO of Death Star 9 Apr 3, 2022
A library for validate a string using regular expressions.

Fogex Form Regex Quickly and easily check if the content is valid. Installation npm install fogex or yarn add fogex Usage import fogex from 'fogex';

null 5 May 5, 2022
A simple library to validate Mexican CURPs (Personal ID)

Validate CURP A simple and lightweight library to validate Mexican CURPs (Personal ID). Install NodeJS Use NPM: $ npm install --save validate-curp Or

Manuel de la Torre 15 Nov 24, 2022
Themis is a validation and processing library that helps you always make sure your data is correct.

Dataffy Themis - The advanced validation library Themis is a validation and processing library that helps you always make sure your data is correct. ยท

Dataffy 14 Oct 27, 2022
Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.

Introduction Swagger UI allows anyone โ€” be it your development team or your end consumers โ€” to visualize and interact with the APIโ€™s resources without

Swagger 23.2k Dec 28, 2022
Prisma 2+ generator to emit Zod schemas from your Prisma schema

Prisma Zod Generator Automatically generate Zod schemas from your Prisma Schema, and use them to validate your API endpoints or any other use you have

Omar Dulaimi 212 Dec 27, 2022
OpenAPI (Swagger) module for Nest framework (node.js) :earth_americas:

A progressive Node.js framework for building efficient and scalable server-side applications. Description OpenAPI (Swagger) module for Nest. Installat

nestjs 1.3k Jan 6, 2023