-
Thank you for developing this wonderful tool. When I installed Orval in my project and generated the code, I got an error that there were duplicate type definitions. In cases where the shape of a deprecated property differs from that of a new property only in the nesting level but shares a similar name, defining the name in PascalCase creates duplicate type definitions. I have prepared a repository to reproduce the error: https://github.com/ykokw/orval-duplicate-identifier-repro In src/petstore.schemas.ts, there are duplicate type definitions for While it is important to be mindful of naming API properties, is there a way within Orval to resolve such duplicate type definition errors? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hmmm since it gets created as a Type if you have two types called Pet i don't see how it can know. I suggest better naming conventions in your API. You can also try to use the |
Beta Was this translation helpful? Give feedback.
-
I considered removing deprecated properties from the list of properties to automatic generation as a workaround. In orval.config.ts, I set the following transformer to input.override.transformer to filter out deprecated properties from the request body and component properties. const filterDeprecated = (schema) =>
Object.fromEntries(
Object.entries(schema || {}).filter(
([_, schemaContent]) => schemaContent.deprecated !== true
)
);
const transformComponentsSchemas = (schemas) =>
Object.entries(schemas).reduce(
(acc, [componentName, component]) => ({
...acc,
[componentName]: {
...component,
properties: filterDeprecated(component.properties),
},
}),
{}
);
const transformRequestBodyContent = (requestBodyContent) =>
Object.entries(requestBodyContent || {}).reduce(
(acc, [contentType, content]) => ({
...acc,
[contentType]: {
...content,
schema: {
...content.schema,
properties: filterDeprecated(content.schema.properties),
},
},
}),
{}
);
const transformPathItem = (pathItem) =>
Object.entries(pathItem).reduce(
(pathItemAcc, [verb, operation]) => ({
...pathItemAcc,
[verb]: {
...operation,
requestBody: {
...operation.requestBody,
content: transformRequestBodyContent(
(operation.requestBody || {}).content
),
},
},
}),
{}
);
/**
* Transformer function for orval.
*
* @param {OpenAPIObject} inputSchema
* @return {OpenAPIObject}
*/
module.exports = (inputSchema) => ({
...inputSchema,
paths: Object.entries(inputSchema.paths).reduce((acc, [path, pathItem]) => {
return {
...acc,
[path]: transformPathItem(pathItem),
};
}, {}),
components: {
...inputSchema.components,
schemas: transformComponentsSchemas(inputSchema.components.schemas),
},
}); The result is available here: ykokw/orval-duplicate-identifier-repro#1 |
Beta Was this translation helpful? Give feedback.
I considered removing deprecated properties from the list of properties to automatic generation as a workaround.
In orval.config.ts, I set the following transformer to input.override.transformer to filter out deprecated properties from the request body and component properties.
(In my own reproduction repository, there were only duplicate errors occurring with the request body and Pet properties, but it seems necessary to handle it for responses as well if needed.)