tro*_*r19 5 enums swagger swagger-codegen angular
我想从 SpringBoot Rest 服务在 Angular 应用程序中生成模型,为此我使用 ng-swagger-gen 插件。但不知何故,枚举仅作为内联字符串值生成,而不是作为 Enum 类生成,因此每次我必须自己键入字符串值或在 Typescript 中创建 Enum 对象时。
@Data
public class DummyClass {
private DummyEnum dummyEnum;
}
public enum DummyEnum {
One,
Two,
Three
}
Run Code Online (Sandbox Code Playgroud)
并且只生成 1 个代表模型的文件:
export interface DummyClass {
dummyEnum?: 'One' | 'Two' | 'Three';
}
Run Code Online (Sandbox Code Playgroud)
swagger 定义如下所示:
"definitions": {
"DummyClass": {
"type": "object",
"properties": {
"dummyEnum": {
"type": "string",
"enum": [
"One",
"Two",
"Three"
]
}
},
"title": "DummyClass"
}
}
Run Code Online (Sandbox Code Playgroud)
相反,当我手动将定义更改为此时,一切看起来都不错,生成了 2 个文件,1 个类和 1 个枚举
"definitions": {
"DummyClass": {
"type": "object",
"properties": {
"dummyEnum": {
"$ref": "#/definitions/DummyEnum"
}
}
},
"DummyEnum": {
"type": "string",
"enum": [
"One",
"Two",
"Three"
]
}
}
Run Code Online (Sandbox Code Playgroud)
在打字稿中:
import { DummyEnum } from './dummy-enum';
export interface DummyClass {
dummyEnum?: DummyEnum;
}
Run Code Online (Sandbox Code Playgroud)
你能建议什么是正确的方法吗?我迫切需要我的 Angular 应用程序中的枚举类,但我希望生成它们而不是手动创建。似乎 ng-swagger-gen 插件工作正常,但 Springfox Swagger2 以某种方式将 Enums 视为第二类对象,因此未将它们包含在定义部分中。
谢谢
| 归档时间: |
|
| 查看次数: |
487 次 |
| 最近记录: |