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

Generate the client from multiple versions #350

Open
christophergoltz opened this issue Mar 27, 2024 · 1 comment
Open

Generate the client from multiple versions #350

christophergoltz opened this issue Mar 27, 2024 · 1 comment
Assignees
Labels
enhancement New feature, bug fix, or request

Comments

@christophergoltz
Copy link

Is your feature request related to a problem? Please describe.
I have a V1 and a V2 specification of the same Api. If I now want to generate a client, I have to do this for each version and also maintain the interface and dependency injection twice.

Describe the solution you'd like
Generate a client that contains both versions. For example, the method name could contain the required version.

.refitter File

{
    "openApiPaths": [
        "PetstoreV1.yaml",
        "PetstoreV2.yaml",
    ]
}

Generated Interface:

Pet UpdatePetV1 (long? id, string name, List<string> photoUrls, List<Tag> tags, string status);

Pet UpdatePetV2 (long? id, string name, List<string> photoUrls, List<Tag> tags, string status);

Additional context

OpenAPI - PetstoreV1
openapi: 3.0.3
info:
  title: Swagger Petstore - OpenAPI
  version: 1.0.0
servers:
  - url: https://petstore.swagger.io/api/v1
tags:
  - name: pet
    description: Everything about your Pets
paths:
  /pet:
    put:
      tags:
        - pet
      summary: Update an existing pet
      description: Update an existing pet by Id
      operationId: updatePet
      requestBody:
        description: Update an existent pet in the store
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
          application/xml:
            schema:
              $ref: '#/components/schemas/Pet'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Pet'
        required: true
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'          
            application/xml:
              schema:
                $ref: '#/components/schemas/Pet'
        '400':
          description: Invalid ID supplied
        '404':
          description: Pet not found
        '422':
          description: Validation exception
      security:
        - petstore_auth:
            - write:pets
            - read:pets
components:
  schemas:
    Tag:
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
      xml:
        name: tag
    Pet:
      required:
        - name
        - photoUrls
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 10
        name:
          type: string
          example: doggie
        photoUrls:
          type: array
          xml:
            wrapped: true
          items:
            type: string
            xml:
              name: photoUrl
        tags:
          type: array
          xml:
            wrapped: true
          items:
            $ref: '#/components/schemas/Tag'
        status:
          type: string
          description: pet status in the store
          enum:
            - available
            - pending
            - sold
      xml:
        name: pet
    ApiResponse:
      type: object
      properties:
        code:
          type: integer
          format: int32
        type:
          type: string
        message:
          type: string
      xml:
        name: '##default'
  securitySchemes:
    petstore_auth:
      type: oauth2
      flows:
        implicit:
          authorizationUrl: https://petstore3.swagger.io/oauth/authorize
          scopes:
            write:pets: modify pets in your account
            read:pets: read your pets
    api_key:
      type: apiKey
      name: api_key
      in: header
OpenAPI - PetstoreV2
openapi: 3.0.3
info:
  title: Swagger Petstore - OpenAPI
  version: 2.0.0
servers:
  - url: https://petstore.swagger.io/api/v2
tags:
  - name: pet
    description: Everything about your Pets
paths:
  /pet:
    put:
      tags:
        - pet
      summary: Update an existing pet
      description: Update an existing pet by Id
      operationId: updatePet
      requestBody:
        description: Update an existent pet in the store
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
          application/xml:
            schema:
              $ref: '#/components/schemas/Pet'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Pet'
        required: true
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'          
            application/xml:
              schema:
                $ref: '#/components/schemas/Pet'
      security:
        - petstore_auth:
            - write:pets
            - read:pets
components:
  schemas:
    Tag:
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
      xml:
        name: tag
    Pet:
      required:
        - name
        - photoUrls
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 10
        name:
          type: string
          example: doggie
        photoUrls:
          type: array
          xml:
            wrapped: true
          items:
            type: string
            xml:
              name: photoUrl
        tags:
          type: array
          xml:
            wrapped: true
          items:
            $ref: '#/components/schemas/Tag'
        status:
          type: string
          description: pet status in the store
          enum:
            - available
            - pending
            - sold
      xml:
        name: pet
    ApiResponse:
      type: object
      properties:
        code:
          type: integer
          format: int32
        type:
          type: string
        message:
          type: string
      xml:
        name: '##default'
  securitySchemes:
    petstore_auth:
      type: oauth2
      flows:
        implicit:
          authorizationUrl: https://petstore3.swagger.io/oauth/authorize
          scopes:
            write:pets: modify pets in your account
            read:pets: read your pets
@christophergoltz christophergoltz added the enhancement New feature, bug fix, or request label Mar 27, 2024
@christianhelle
Copy link
Owner

@christophergoltz thanks for taking the time to suggest this.

It's a non-trivial thing to implement because there are quite a few things to consider. So far, here are the first things that come to mind:

  • Duplicate operation IDs
  • Duplicate components schemas
  • Specifying a base URL if the servers: - url doesn't specify the full base URL

I'll think a bit more about this over the Easter holiday

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, bug fix, or request
Projects
None yet
Development

No branches or pull requests

2 participants