orval
orval copied to clipboard
Error: Duplicate schema names detected
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: ...
},
},
});
The same issue here
@SamyZog Could you provide the schema specification so I can try to replicate this?
@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).
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
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
Perhaps this issue was fixed in #1958? so i'll close this.
Just encountered this problem on @7.7.0
Perhaps this issue was fixed in #1958? so i'll close this.
@soartec-lab that only fixed the error message 😅
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.
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
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.
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
past 1 year and still not fixed
@RAIbrahim360 PR is welcome. This is an open source project and all volunteer contributions....