diff --git a/packages/openapi-ts-tests/main/test/2.0.x.test.ts b/packages/openapi-ts-tests/main/test/2.0.x.test.ts index 672641f6f..00e3a1d08 100644 --- a/packages/openapi-ts-tests/main/test/2.0.x.test.ts +++ b/packages/openapi-ts-tests/main/test/2.0.x.test.ts @@ -287,6 +287,30 @@ describe(`OpenAPI ${version}`, () => { }), description: 'handles read-only and write-only types', }, + { + config: createConfig({ + input: 'transforms-schemas-name.yaml', + output: 'transforms-schemas-name', + parser: { + transforms: { + schemas: { + name: (name: string) => { + // Strip version markers: User_v1_0_0_User → User + let clean = name.replace(/([A-Za-z\d]+)_v\d+_\d+_\d+_([A-Za-z\d]*)/g, (_, p1, p2) => + p2.startsWith(p1) ? p2 : p1 + p2, + ); + // Deduplicate prefixes: Foo_Foo → Foo + const m = clean.match(/^([A-Za-z\d]+)_\1([A-Za-z\d]*)$/); + if (m) clean = m[1] + m[2]; + return clean; + }, + }, + }, + }, + plugins: ['@hey-api/typescript'], + }), + description: 'handles schema name transforms', + }, { config: createConfig({ input: 'schema-unknown.yaml', diff --git a/specs/2.0.x/transforms-schemas-name.yaml b/specs/2.0.x/transforms-schemas-name.yaml new file mode 100644 index 000000000..3383e4f8a --- /dev/null +++ b/specs/2.0.x/transforms-schemas-name.yaml @@ -0,0 +1,71 @@ +swagger: '2.0' +info: + title: Schema Name Transform Test (Swagger 2.0) + version: 1.0.0 +paths: + /users: + get: + summary: Get users + produces: + - application/json + responses: + '200': + description: Success + schema: + $ref: '#/definitions/User_v1_0_0_User' + /posts: + post: + summary: Create post + consumes: + - application/json + produces: + - application/json + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/Post_v2_1_3_Post' + responses: + '201': + description: Created + schema: + $ref: '#/definitions/Post_v2_1_3_Post' +definitions: + User_v1_0_0_User: + type: object + properties: + id: + type: string + name: + type: string + profile: + $ref: '#/definitions/UserProfile_v1_0_0_UserProfile' + UserProfile_v1_0_0_UserProfile: + type: object + properties: + bio: + type: string + avatar: + type: string + Post_v2_1_3_Post: + type: object + properties: + id: + type: string + title: + type: string + author: + $ref: '#/definitions/User_v1_0_0_User' + comments: + type: array + items: + $ref: '#/definitions/Comment_v1_5_2_Comment' + Comment_v1_5_2_Comment: + type: object + properties: + id: + type: string + text: + type: string + author: + $ref: '#/definitions/User_v1_0_0_User'