asteasolutions / zod-to-openapi

A library that generates OpenAPI (Swagger) docs from Zod schemas
MIT License
916 stars 57 forks source link

Add a tag to a schema #216

Closed damianobarbati closed 6 months ago

damianobarbati commented 6 months ago

In order to use the x-tagGroups of redoc, I need to provide a tag to every operation and schema I want to list in the sidebar.

All good with operations, but how can I provide a tag when I use the .openapi('UserSchema')?

AGalabov commented 6 months ago

Hello @damianobarbati thank you for using our library. Would you be able to provide an example of a schema in the OpenAPI specification of what you are trying to achieve with schema tags? Any JSON/YAML version would suffice. Since I cannot find anything for schemas (only operations) in the specs, if you can also give me a reference to the definition of such a tag it would be great.

damianobarbati commented 6 months ago

@AGalabov sure, here an example:

servers:
  - url: https://api-cesc.cryopdp.com/
x-tagGroups:
  - name: API reference
    tags:
      - Auth
      - User
      - Shipment
      - Password reset
      - API Key
  - name: Schemas
    tags:
      - metric
      - last_metric
      - user
      - shipment
components:
  schemas:
    metric:
      type: object
      properties:
        id:
          type: string
          format: uuid
        created_at:
          type: string
          format: date-time
....
        is_out_of_threshold:
          type: boolean
      required:
        - id
        - tracker_id
        - shipment_id
        - type
        - value
        - unit
        - is_out_of_threshold
      additionalProperties: false
    last_metric:
      type: object
      nullable: true
      properties:
        id:
          type: string
          format: uuid
        measured_at:
          type: string
          minLength: 1
          format: date-time
...       
      required:
        - measured_at
        - battery
        - temperature
        - humidity
        - position
      additionalProperties: false
    user:
      type: object
      nullable: true
      properties:
        id:
          type: string
          minLength: 1
          format: uuid
....
Screenshot 2024-03-22 at 10 10 07

But I think it's a redoc/redocly problem and their x-tags management, and I managed to solve this manipulating the final document. Closing this!