astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)
openapi-zod-client.vercel.app
717 stars 80 forks source link

feat: add exportAllNamedSchemas option to allow exporting duplicate schemas with different names. #268

Closed codingmatty closed 5 months ago

codingmatty commented 5 months ago

This PR provides a new option, exportAllNamedSchemas, to override that behavior and export all named schemas even if they are the same type.

The default behavior was causing the same schema name to be used in multiple places and the semantics did not make sense.

Example:

This portion of schema with a complexity of 0 would result in a single username: z.string() schema set to both username and password query parameters, as well as any other parameters that are schema.type: string

  /user/login:
    get:
      tags:
        - user
      summary: Logs user into the system
      description: ""
      operationId: loginUser
      parameters:
        - name: username
          in: query
          description: The user name for login
          required: false
          schema:
            type: string
        - name: password
          in: query
          description: The password for login in clear text
          required: false
          schema:
            type: string

Result:

"parameters": [
    {
        "name": "username",
        "schema": "username",
        "type": "Query",
    },
    {
        "name": "password",
        "schema": "username",
        "type": "Query",
    },
],
vercel[bot] commented 5 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
openapi-zod-client ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 24, 2024 10:41pm