[BUG] [GO] The Enum field is not generated.
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [ ] Have you tested with the latest master to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?
- [x] What's the actual output vs expected output?
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When I use the following JSON to generate code, the fields with enum types in the model do not generate the corresponding enums. The generated code is as follows:
type CommonErrorType struct {
// 错误码
Code string `json:"code"`
// 解决方案链接
Links *string `json:"links,omitempty"`
// 错误描述
Message string `json:"message"`
AdditionalProperties map[string]interface{}
}
The enum values for code are not reflected in the model.
openapi-generator version
openapi-generator-cli-6.6.0.jar
OpenAPI declaration file content or url
{
"openapi": "3.0.3",
"info": {
"title": "test",
"description": "test",
"contact": {
"name": "test",
"url": "https://test/support/home.htm"
},
"version": "1.0"
},
"servers": [
{
"url": "https://openapi.com",
"description": "Production server"
},
{
"url": "https://openapidev.com",
"description": "Sandbox server"
}
],
"paths": {
"/card/template/query" : {
"get" : {
"tags" : [ "card.template" ],
"summary" : "query",
"description" : "query",
"operationId" : "card.template.query",
"responses" : {
"200" : {
"description" : "common response",
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/CardTemplateQueryResponseModel"
}
}
}
},
"default" : {
"description" : "error",
"content" : {
"application/json" : {
"schema" : {
"anyOf" : [ {
"$ref" : "#/components/schemas/CommonErrorType"
}, {
"$ref" : "#/components/schemas/CardTemplateQueryErrorResponseModel"
} ]
}
}
}
}
},
"parameters" : [ {
"name" : "template_id",
"in" : "query",
"description" : "id",
"schema" : {
"type" : "string",
"example" : "20160718000000001"
}
} ]
}
}
},
"components": {
"schemas": {
"CardTemplateQueryErrorResponseModel" : {
"required" : [ "code", "message" ],
"type" : "object",
"properties" : {
"code" : {
"type" : "string",
"description" : "code",
"enum" : [ "INVALID_PARAMETER", "SYSTEM_ERROR", "TEMPLATE_NOT_EXIT" ]
},
"links" : {
"type" : "string",
"description" : "links"
},
"message" : {
"type" : "string",
"description" : "message"
}
}
},
"CardTemplateQueryResponseModel" : {
"type" : "object",
"properties" : {
"access_version" : {
"type" : "string",
"description" : "access_version",
"example" : "basic"
},
"biz_no_prefix" : {
"type" : "string",
"description" : "biz_no_prefix",
"example" : "prex"
}
}
},
"CommonErrorType" : {
"required" : [ "code", "message" ],
"type" : "object",
"properties" : {
"code" : {
"type" : "string",
"description" : "code",
"enum" : [ "invalid-parameter", "upload-fail", "invalid-file-extension" ]
},
"links" : {
"type" : "string",
"description" : "links"
},
"message" : {
"type" : "string",
"description" : "message"
}
}
}
}
}
}
Generation Details
Steps to reproduce
java -jar bin/openapi-generator-cli-6.6.0.jar generate
-g go
-i template/oas_full.json
-o source
--global-property skipFormModel=false,modelTests=false,apiTests=false,modelDocs=false
Related issues/PRs
Suggest a fix
generate the correct enum classes.
https://github.com/openapitools/openapi-generator/blob/master/docs/customization.md#inline-schema-naming
RESOLVE_INLINE_ENUMS=true will refactor inline enum definitions into $ref
you can enable this in inline schema mapping option to refactor inline enum into $ref (which will be generated as enum class)
https://github.com/openapitools/openapi-generator/blob/master/docs/customization.md#inline-schema-naming
RESOLVE_INLINE_ENUMS=true will refactor inline enum definitions into $refyou can enable this in inline schema mapping option to refactor inline enum into $ref (which will be generated as enum class)
This parameter doesn't seem to work in version 6.6.0. However, I can't upgrade to version 7.6.0 because my system can only use JDK 1.8.
you can use docker instead: https://hub.docker.com/r/openapitools/openapi-generator-cli