orval icon indicating copy to clipboard operation
orval copied to clipboard

Error: Duplicate schema names detected

Open SamyZog opened this issue 11 months ago • 11 comments

Trying to generate swagger client from openapi 3.0.3 Orval v7.3.0 (also tried v7.2.0)

When generating i get an error

Error: Duplicate schema names detected:
  1x PatchedPayoutRequestListAdminDTOReimbursability
  1x PayoutRequestListAdminDTOReimbursability
  1x PayoutRequestRetrieveAdminDTOReimbursability
  1x PayoutRequestRetrieveUserDTOReimbursability
  1x PayoutRequestSetReimbursabilityDTOReimbursability

The schema is valid, I have ran it through the swagger editor and all is clean.

this is my config

export default defineConfig({
  newTechService: {
    hooks: {
      afterAllFilesWrite: "eslint --fix src/api",
    },
    output: {
      mode: "tags-split",
      target: "./src/api/query",
      schemas: "./src/api/model",
      client: "react-query",
      httpClient: "axios",
      urlEncodeParameters: false,
      clean: true,
      tslint: true,
      override: {
        fetch: {
          includeHttpResponseReturnType: false,
        },
        query: {
          signal: true,
          useInfinite: false,
        },
        mutator: {
          path: "./src/api/custom-instance/axios-instance.ts",
          name: "customInstance",
        },
        components: {
          schemas: {
            suffix: "DTO",
          },
          responses: {
            suffix: "Response",
          },
          parameters: {
            suffix: "Params",
          },
          requestBodies: {
            suffix: "Body",
          },
        },
      },
    },
    input: {
      target: ...
    },
  },
});

SamyZog avatar Dec 03 '24 09:12 SamyZog

The same issue here

nitoba avatar Dec 07 '24 13:12 nitoba

@SamyZog Could you provide the schema specification so I can try to replicate this?

AllieJonsson avatar Dec 20 '24 22:12 AllieJonsson

@AllieJonsson This happens for me if i have a field name defined twice in both snake_case and camelCase on the same pydantic model class (later used in an endpoint).

Luiz-N avatar Jan 21 '25 16:01 Luiz-N

If index files are not needed, a temporary workaround is to disable indexFiles. This error only happens when indexFiles is true. https://github.com/orval-labs/orval/blob/b3592ac52f678756eb27182707ceae883e37727a/packages/core/src/writers/schemas.ts#L130-L156

vandreleal avatar Feb 17 '25 13:02 vandreleal

That workaround works if the two colliding properties are of the same type, but if they are different, e.g.

calling_code:
  type: number
  enum: [1, 2, 3]
callingCode:
  type: string
  enum: ['+33', '+420', '+33']

the generated models will be

interface Pet {
  calling_code: PetCallingCode;
  callingCode: PetCallingCode;
}

...

export type PetCallingCode = (typeof PetCallingCode)[keyof typeof PetCallingCode];
export const PetCallingCode = {
  '+33': '+33',
  '+420': '+420',
} as const;

which is wrong.

What is the reason to have properties with the same (when Pascal-cased) name in the model? If only one of them is used, it is probably advisable to either remove them from the schema or filter them out in the input transformer when generating

AllieJonsson avatar Mar 02 '25 08:03 AllieJonsson

Perhaps this issue was fixed in #1958? so i'll close this.

soartec-lab avatar Mar 17 '25 13:03 soartec-lab

Just encountered this problem on @7.7.0

PrinceLoren avatar Mar 17 '25 14:03 PrinceLoren

Perhaps this issue was fixed in #1958? so i'll close this.

@soartec-lab that only fixed the error message 😅

AllieJonsson avatar Mar 17 '25 16:03 AllieJonsson

Same issue with Orval 7.7.0 (and v6 too).

The issue occurs only if output:schemas is set. When I comment this setting, Orval processes my openapi.yaml file. However, in my <project_name>.schemas.ts file, I have duplicate types. For instance :

export type POSTprofilesBody = {
  first_name?: string;
  last_name?: string;
  email?: string;
};

export type POSTprofilesBody = {
  '*'?: POSTprofilesBody;
};

I need to manually delete the second one to get it working.

vdsbenoit avatar Mar 17 '25 17:03 vdsbenoit

I found out it comes from a request that have a "*" root key. For instance :

requestBody:
  required: false
  content:
    application/json:
      schema:
        type: object
        properties:
          '*':
            type: object
            description: ''
            example: []
            properties:
              email:
                type: string
                description: ''
                example: [email protected]
              name:
                type: string
                description: ''
                example: vega

It looks like this in the swagger ui

Image

This kind of layout is generated by Laravel when a bulk request is possible.

I'm not sure whether this use case should be supported by Orval or if I should change some config in the export of my Laravel API.

vdsbenoit avatar Mar 20 '25 16:03 vdsbenoit

I fixed it on my side by patching the OpenAPI specification file. With the example from my previous comment, it would look like this after the patch is applied :

requestBody:
  required: false
  content:
    application/json:
      schema:
        type: object
        description: ''
        example: []
        properties:
          email:
            type: string
            description: ''
            example: [email protected]
          name:
            type: string
            description: ''
            example: vega

vdsbenoit avatar Apr 07 '25 13:04 vdsbenoit

past 1 year and still not fixed

RAIbrahim360 avatar Sep 26 '25 19:09 RAIbrahim360

@RAIbrahim360 PR is welcome. This is an open source project and all volunteer contributions....

melloware avatar Sep 26 '25 20:09 melloware