Azure / autorest.csharp

Extension for AutoRest (https://github.com/Azure/autorest) that generates C# code
MIT License
141 stars 166 forks source link

Duplicate object schemas with ... name detected when using oneOf/anyOf/allOf property #4086

Open leonidumanskiy opened 9 months ago

leonidumanskiy commented 9 months ago

Example schema:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pet:
    get:
      summary: Returns a pet
      operationId: getPet
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pet"
components:
  schemas:
    Pet:
      properties:
        owner:
          anyOf:
          - $ref: "#/components/schemas/PetOwner"
      required:
        - owner
    PetOwner:
      properties:
        name:
          type: string
      required:
        - name

Although there are no duplicate schema names, it will still result in the following error:

> autorest --input-file=schema.yaml --csharp
...
error   | Duplicate object schemas with 'PetOwner' name  detected.

The issue seems to be coming from combining schema name (Pet) and property name (owner) resulting in auto-generated property schema PetOwner that collides with the existing schema.

The error is quite ambiguous and does not indicate where the issue is coming from.

ArcturusZhang commented 9 months ago

Hi @leonidumanskiy sorry but openapi v3 is not fully supported in our current implementation of the generator, namely the anyOf and oneOf part. Therefore it is possible that the generator could have funny behavior when it gets the input of those. The swagger part of the generator is in maintenance model right now therefore we do not have a plan to support that.

If possible, your case looks like a discriminator case, please refine your swagger to define it in a way of regular discriminator and I believe the generator could support now.