Skip to content

Make toJsonSchema method compatible with OpenAPI spec / @fastify/swagger for enums / unions #1328

Closed

Description

@stanjns

Request a feature

Make output of toJsonSchema method on enums/unions compatible with OpenAPI spec and make the output look the same to other popular tools like zod-to-json-schema for zod.

🤷 Motivation

Make it easier to use arktype as a validator in fastify or other backend frameworks for documentation.

I am trying to migrate from zod as a validator for my API written in fastify. Everything expect swagger is working properly but since the json schema generated for enums/unions is different between zod/typebox and arktype I couldn't get enums to work properly on swagger.

💡 Solution

Change how we generate JSON schema for enums/unions in arktype to match other popular tools.

💡 Code

This repo contains an example of not working path parameters enums for v param - for zod v is 0 | 1 but for arktype it's only 0 -> the enum is displayed properly.

I tried both literal string union "'0' | '1'" and type.enumerated and the output was the same.

repo

This issue tho might be not fully related to arktype becuase the generated JSON schema is totally valid it just doesn't work well with open api spec or @fastify/swagger itself but it's a big blocker when it comes to migration as the documentation is a really important part and currently there are no other libraries than @fastify/swagger for fastify ecosystem.

Activity

  1. moved this from To do to Implemented in arktypeioon Feb 28, 2025
  2. moved this from Implemented to Planned in arktypeioon Feb 28, 2025
  3. moved this from Planned to Implemented in arktypeioon Apr 7, 2025
  4. ssalbdivad commented on Apr 7, 2025

    @ssalbdivad
    Member

    Fixed in 2.1.19 🎉

  5. moved this from Implemented to Done (merged or closed) in arktypeioon Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done (merged or closed)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions