Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The null example for a nullable field is ignored. #283

Open
BenoitClaveau opened this issue Dec 12, 2024 · 1 comment
Open

The null example for a nullable field is ignored. #283

BenoitClaveau opened this issue Dec 12, 2024 · 1 comment

Comments

@BenoitClaveau
Copy link

The openapi({ example: null }} is not take into account.

const UserSchema = z
    .object({
        id: z.string().openapi({ example: "1212121" })
    })
    .openapi("User");

const UserInputSchema = z
    .object({
        name: z.string().openapi({ example: "John Doe" }),
        age: z.number().nullish().openapi({ example: null }) // <-- null
    })
    .openapi("User");

registry.registerPath({
    method: "post",
    path: "/users",
    summary: "Create a user",
    request: {
        body: {
            description: "Retrosynthesis request",
            content: {
                "application/json": {
                    schema: UserInputSchema
                }
            }
        }
    },
    responses: {
        200: {
            description: "Object with user data.",
            content: {
                "application/json": {
                    schema: UserSchema
                }
            }
        }
    }
});

Will generate:

  /users:
    post:
      summary: Create a user
      requestBody:
        description: Retrosynthesis request
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/User"
                - properties:
                    name:
                      type: string
                      example: John Doe
                    age:
                      type:
                        - number
                        - "null"
                  required:
                    - name
      responses:
        "200":
          description: Object with user data.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/User"

The field "age" do not contains example like the field "name".

I expect to have this

 /users:
    post:
      summary: Create a user
      requestBody:
        description: Retrosynthesis request
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/User"
                - properties:
                    name:
                      type: string
                      example: John Doe
                    age:
                      type:
                        - number
                        - "null"
                       example: null
                  required:
                    - name
      responses:
        "200":
          description: Object with user data.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/User"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@BenoitClaveau and others