Automatic addition of the suffix `Schema` to the object names in `schemas.gen.ts` causes conflicts with `types.gen.ts`
Description
Automatic addition of the suffix Schema to the object names in schemas.gen.ts causes conflicts with types.gen.ts
In the openapi specs we have:
{
"WarningAction":
{
"type": "string",
"enum":
[
"set_value_to_null_once",
"set_value_to_null",
"set_value_to_null_for_field",
"hide"
],
"title": "WarningAction",
"description": "Warning Actions are a subset of Alert Actions"
},
"WarningActionSchema":
{
"properties":
{
"text":
{
"type": "string",
"title": "Text"
},
"info":
{
"type": "string",
"title": "Info"
},
"action":
{
"$ref": "#/components/schemas/WarningAction"
},
"url":
{
"anyOf":
[
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Url"
}
},
"type": "object",
"required":
[
"text",
"info",
"action"
],
"title": "WarningActionSchema"
},
}
But heyapi creates:
schemas.gen.ts:
export const WarningActionSchema = {
type: 'string',
enum: ['set_value_to_null_once', 'set_value_to_null', 'set_value_to_null_for_field', 'hide'],
title: 'WarningAction',
description: `Warning Actions are a subset of Alert Actions`
} as const;
export const WarningActionSchemaSchema = {
properties: {
text: {
type: 'string',
title: 'Text'
},
info: {
type: 'string',
title: 'Info'
},
action: {
'$ref': '#/components/schemas/WarningAction'
},
url: {
anyOf: [
{
type: 'string'
},
{
type: 'null'
}
],
title: 'Url'
}
},
type: 'object',
required: ['text', 'info', 'action'],
title: 'WarningActionSchema'
} as const;
And in types.gen.ts:
export type WarningAction = 'set_value_to_null_once' | 'set_value_to_null' | 'set_value_to_null_for_field' | 'hide';
export type WarningActionSchema = {
text: string;
info: string;
action: WarningAction;
url?: (string | null);
};
Which causes a conflict because WarningActionSchema has a conflict between the 2 files.
OpenAPI specification (optional)
openapi: 3.0.0 info: title: Warning Actions API version: 1.0.0 description: API to handle warning actions servers:
- url: 'https://example.com/api' paths: /warningActions: get: summary: Get warning actions operationId: getWarningActions responses: '200': description: Successful response content: application/json: schema: $ref: '#/components/schemas/WarningActionSchema' components: schemas: WarningAction: type: string enum: - set_value_to_null_once - set_value_to_null - set_value_to_null_for_field - hide title: WarningAction description: Warning Actions are a subset of Alert Actions WarningActionSchema: type: object properties: text: type: string title: Text info: type: string title: Info action: $ref: '#/components/schemas/WarningAction' url: anyOf: - type: string - type: 'null' title: Url required: - text - info - action title: WarningActionSchema
System information (optional)
No response
Also manually setting the schema name pattern can fix the issue, but I think openapi-ts should detect these conflicts and use a proper suffix or prefix automatically.
export default defineConfig({
client: '@hey-api/client-axios',
input: 'openapi.yaml',
output: {
format: 'prettier',
path: './src/client',
},
types: {
dates: 'types+transform',
enums: 'javascript',
},
schemas: {
name: (name) => `_${name}`, // [!code ++]
},
});
@seperman How would you choose to resolve this conflict if you were asked to resolve it manually?
This will be fixed by removing the index.ts barrel file, the complexity of maintaining a conflict-free index file is not worth it.
Fixed as mentioned above. Might revisit it one day if people complain!