Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [GO] The Enum field is not generated. #18924

Closed
4 of 6 tasks
jishupei opened this issue Jun 14, 2024 · 3 comments
Closed
4 of 6 tasks

[BUG] [GO] The Enum field is not generated. #18924

jishupei opened this issue Jun 14, 2024 · 3 comments

Comments

@jishupei
Copy link

jishupei commented Jun 14, 2024

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • 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.

@wing328
Copy link
Member

wing328 commented Jun 17, 2024

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)

@jishupei
Copy link
Author

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)

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.

@wing328
Copy link
Member

wing328 commented Jun 17, 2024

you can use docker instead: https://hub.docker.com/r/openapitools/openapi-generator-cli

@wing328 wing328 closed this as completed Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants