Closed
Description
An invalid Typescript type is generated in contexts where all of the following criteria are met:
- The schema is a composed schema with an
allOf
specification - The
allOf
contains at least two type specifications - One of the
allOf
types contains an array property ofenum
values - That array contains an enum value with a hyphen (
-
)
I suspect the issue to be the following code snippet:
swagger-typescript-api/src/typeFormatters.js
Lines 31 to 37 in acc770b
Since
checkAndRenameModelName
will find a hyphen in the described situation, Lodash's startCase
function and whitespace removal is executed on the whole subtype, causing distortions in the output as shown below (undesired casing, missing punctuation and missing spacing). It might be a sufficient fix to just remove the checkAndRenameModelName
there.
Swagger specification for reproduction
openapi: 3.0.1
info:
title: Test
version: test
paths: {}
components:
schemas:
Test:
type: object
allOf:
- type: object
properties:
x:
type: array
items:
type: string
enum:
- A-B
- type: object
properties:
y:
type: string
Generated code
export type Test = XAB & { y?: string };