I want to generate models in Angular application from SpringBoot Rest services and for this purpose I use ng-swagger-gen plugin. But somehow, the Enums are generated only as inline String values and not the Enum class so everytime I must either type string value or create the Enum object in Typescript by myself.
@Data
public class DummyClass {
private DummyEnum dummyEnum;
}
public enum DummyEnum {
One,
Two,
Three
}
And only 1 file representaing the model is generated:
export interface DummyClass {
dummyEnum?: 'One' | 'Two' | 'Three';
}
The swagger definition looks like this:
"definitions": {
"DummyClass": {
"type": "object",
"properties": {
"dummyEnum": {
"type": "string",
"enum": [
"One",
"Two",
"Three"
]
}
},
"title": "DummyClass"
}
}
Instead when I manually change the definition to this, everything looks OK, there are 2 files generated, 1 class and 1 enum
"definitions": {
"DummyClass": {
"type": "object",
"properties": {
"dummyEnum": {
"$ref": "#/definitions/DummyEnum"
}
}
},
"DummyEnum": {
"type": "string",
"enum": [
"One",
"Two",
"Three"
]
}
}
And in Typescript:
import { DummyEnum } from './dummy-enum';
export interface DummyClass {
dummyEnum?: DummyEnum;
}
Could you please advice whats the correct approach? I desperately needs the enum classes in my Angular Application, but I want to them to be generated and not created manually. Seems like ng-swagger-gen plugin is working correctly but somehow Springfox Swagger2 considered Enums as second class object and therefore not included them into the definitions part.
Thanks