【发布时间】:2020-12-03 10:58:38
【问题描述】:
在包含 oneOf 关键字的 openapi 3.3 规范上使用 openapi-generator-cli 生成 golang 代码导致损坏且无法编译的代码。
Openapi-generator-cli docker-hub:
Digest:sha256:829f0b601005c28950ed55c65d853f2caead265730782b2c7c48812bf8135222
鉴于此架构:
"schemas": {
"Foo": {
"type": "object",
"properties": {
"Bar": {
"oneOf": [
{"$ref": "#/components/schemas/FooBar"},
{"$ref": "#/components/schemas/BarFoo"}
]
}
}
},
"FooBar": {
"type": "object",
"title": "FooBar",
"properties": {
"example": {
"type": "string"
}
}
},
"BarFoo": {
"type": "object",
"title": "BarFoo",
"properties": {
"example": {
"type": "string"
}
}
}
}
结果是:
type Foo struct {
Bar *OneOfFooBarBarFoo `json:"Bar,omitempty"`
}
我已经读到对此的支持是有限的,应该会产生 interface{},我会对这样的结果感到满意。 我运行的命令是:
openapi-generator-cli generate \
-i "/swagger.json" \
-g go \
--global-property models,supportingFiles=utils.go,modelDocs=false \
--additional-properties \
--minimal-update \
-p enumClassPrefix=true \
--enable-post-process-file \
--additional-properties packageName="Some Name" \
-o "/Some_Location"
有人知道这个问题的解决方案吗?我试图找到答案,但大多数已知问题似乎已经敲定
【问题讨论】:
标签: go openapi openapi-generator