christianhelle / refitter

Refit Client API Generator for OpenAPI
https://refitter.github.io
MIT License
157 stars 36 forks source link

Generate the client from multiple versions #350

Open christophergoltz opened 3 months ago

christophergoltz commented 3 months ago

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 ```yaml 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 ```yaml 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 ```
christianhelle commented 3 months ago

@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:

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