diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java index 3698b6d000e6..d57d4ed8ac43 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java @@ -507,6 +507,57 @@ public Map postProcessModels(Map objs) { return postProcessModelsEnum(objs); } + @Override + public Map postProcessModelsEnum(Map objs) { + objs = super.postProcessModelsEnum(objs); + + List models = (List) objs.get("models"); + for (Object _mo : models) { + Map mo = (Map) _mo; + CodegenModel cm = (CodegenModel) mo.get("model"); + + // For enum var names prepend with this model's name to help prevent namespace collision + if (Boolean.TRUE.equals(cm.isEnum) && cm.allowableValues != null) { + String prefix = toEnumVarName(cm.name, "string") + "_"; + cm.allowableValues = prefixAllowableValues(cm.allowableValues, prefix); + } + // Also prepend var names used for defining inline enums with inline enum's name + if (Boolean.TRUE.equals(cm.hasEnums)) { + for (CodegenProperty param : cm.vars) { + if (Boolean.TRUE.equals(param.isEnum) && param.allowableValues != null) { + String prefix = toEnumVarName(param.name, "string") + "_"; + param.allowableValues = prefixAllowableValues(param.allowableValues, prefix); + // Form datatype for this field: use ClassNameFieldName syntax + param.dataType = cm.classname + param.nameInCamelCase; + if (Boolean.TRUE.equals(param.isListContainer)) { + // Special case: slice of enums, use []ClassNameFieldName + param.datatypeWithEnum = "[]" + param.dataType; + } else if (Boolean.TRUE.equals(param.isMapContainer)) { + // Special case: map of enums, use map[string]ClassNameFieldName + param.datatypeWithEnum = "map[string]" + param.dataType; + } else { + param.datatypeWithEnum = param.dataType; + } + } + } + } + } + return objs; + } + + public Map prefixAllowableValues(Map allowableValues, String prefix) { + if (allowableValues.get("enumVars") != null) { + List> enumVars = (List>) allowableValues.get("enumVars"); + for (Map enumVar : enumVars) { + String enumName = (String) enumVar.get("name"); + if (enumName != null) { + enumVar.put("name", prefix + enumName); + } + } + } + return allowableValues; + } + @Override public Map postProcessSupportingFileData(Map objs) { generateYAMLSpecFile(objs); @@ -542,10 +593,10 @@ public Map createMapping(String key, String value) { @Override public String toEnumValue(String value, String datatype) { - if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) { - return value; + if ("string".equals(datatype)) { + return "\"" + escapeText(value) + "\""; } else { - return escapeText(value); + return value; } } @@ -561,7 +612,7 @@ public String toEnumVarName(String name, String datatype) { } // number - if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) { + if (datatype.startsWith("float") || datatype.startsWith("int") || datatype.startsWith("uint")) { String varName = name; varName = varName.replaceAll("-", "MINUS_"); varName = varName.replaceAll("\\+", "PLUS_"); @@ -582,7 +633,7 @@ public String toEnumVarName(String name, String datatype) { if (isReservedWord(enumName)) { // reserved word return escapeReservedWord(enumName); } else if (enumName.matches("\\d.*")) { // starts with a number - return "_" + enumName; + return "NUM_" + enumName; } else { return enumName; } diff --git a/modules/openapi-generator/src/main/resources/go-gin-server/model.mustache b/modules/openapi-generator/src/main/resources/go-gin-server/model.mustache index 38408680231c..eb9dccb63c65 100644 --- a/modules/openapi-generator/src/main/resources/go-gin-server/model.mustache +++ b/modules/openapi-generator/src/main/resources/go-gin-server/model.mustache @@ -11,7 +11,7 @@ type {{{name}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/form const ( {{#allowableValues}} {{#enumVars}} - {{name}} {{{classname}}} = "{{{value}}}" + {{name}} {{{classname}}} = {{{value}}} {{/enumVars}} {{/allowableValues}} ){{/isEnum}}{{^isEnum}}{{#description}} @@ -19,6 +19,31 @@ const ( type {{classname}} struct { {{#vars}}{{#description}} // {{{description}}}{{/description}} - {{name}} {{#isNullable}}*{{/isNullable}}{{{dataType}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}` + {{name}} {{#isNullable}}*{{/isNullable}}{{#isEnum}}{{datatypeWithEnum}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}` {{/vars}} -}{{/isEnum}}{{/model}}{{/models}} +}{{/isEnum}} +{{! Define any inline enums from above}} +{{#hasEnums}} +{{#vars}} +{{#isEnum}} + +{{#description}} +// {{datatype}} : {{{description}}} +{{/description}} +type {{datatype}} {{#items}}{{baseType}}{{/items}}{{^items}}{{baseType}}{{/items}} + +// List of {{datatype}} +const ( + {{#allowableValues}} + {{#enumVars}} + {{^-first}} + {{/-first}} + {{name}} {{datatype}} = {{{value}}} + {{/enumVars}} + {{/allowableValues}} +) +{{/isEnum}} +{{/vars}} +{{/hasEnums}} +{{/model}} +{{/models}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/go-server/model.mustache b/modules/openapi-generator/src/main/resources/go-server/model.mustache index 38408680231c..eb9dccb63c65 100644 --- a/modules/openapi-generator/src/main/resources/go-server/model.mustache +++ b/modules/openapi-generator/src/main/resources/go-server/model.mustache @@ -11,7 +11,7 @@ type {{{name}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/form const ( {{#allowableValues}} {{#enumVars}} - {{name}} {{{classname}}} = "{{{value}}}" + {{name}} {{{classname}}} = {{{value}}} {{/enumVars}} {{/allowableValues}} ){{/isEnum}}{{^isEnum}}{{#description}} @@ -19,6 +19,31 @@ const ( type {{classname}} struct { {{#vars}}{{#description}} // {{{description}}}{{/description}} - {{name}} {{#isNullable}}*{{/isNullable}}{{{dataType}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}` + {{name}} {{#isNullable}}*{{/isNullable}}{{#isEnum}}{{datatypeWithEnum}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}` {{/vars}} -}{{/isEnum}}{{/model}}{{/models}} +}{{/isEnum}} +{{! Define any inline enums from above}} +{{#hasEnums}} +{{#vars}} +{{#isEnum}} + +{{#description}} +// {{datatype}} : {{{description}}} +{{/description}} +type {{datatype}} {{#items}}{{baseType}}{{/items}}{{^items}}{{baseType}}{{/items}} + +// List of {{datatype}} +const ( + {{#allowableValues}} + {{#enumVars}} + {{^-first}} + {{/-first}} + {{name}} {{datatype}} = {{{value}}} + {{/enumVars}} + {{/allowableValues}} +) +{{/isEnum}} +{{/vars}} +{{/hasEnums}} +{{/model}} +{{/models}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/go/model.mustache b/modules/openapi-generator/src/main/resources/go/model.mustache index 1a9f8d1c5aaf..e6714b17c402 100644 --- a/modules/openapi-generator/src/main/resources/go/model.mustache +++ b/modules/openapi-generator/src/main/resources/go/model.mustache @@ -23,7 +23,7 @@ const ( {{#enumVars}} {{^-first}} {{/-first}} - {{name}} {{{classname}}} = "{{{value}}}" + {{name}} {{{classname}}} = {{{value}}} {{/enumVars}} {{/allowableValues}} ){{/isEnum}}{{^isEnum}}{{#description}} @@ -35,9 +35,32 @@ type {{classname}} struct { {{#description}} // {{{description}}} {{/description}} - {{name}} {{#isNullable}}*{{/isNullable}}{{{dataType}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}` + {{name}} {{#isNullable}}*{{/isNullable}}{{#isEnum}}{{datatypeWithEnum}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}` {{/vars}} } {{/isEnum}} +{{! Define any inline enums from above}} +{{#hasEnums}} +{{#vars}} +{{#isEnum}} + +{{#description}} +// {{datatype}} : {{{description}}} +{{/description}} +type {{datatype}} {{#items}}{{baseType}}{{/items}}{{^items}}{{baseType}}{{/items}} + +// List of {{datatype}} +const ( + {{#allowableValues}} + {{#enumVars}} + {{^-first}} + {{/-first}} + {{name}} {{datatype}} = {{{value}}} + {{/enumVars}} + {{/allowableValues}} +) +{{/isEnum}} +{{/vars}} +{{/hasEnums}} {{/model}} -{{/models}} +{{/models}} \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/docs/EnumArrays.md b/samples/client/petstore/go/go-petstore/docs/EnumArrays.md index 9eca8b290325..6145b34e6aeb 100644 --- a/samples/client/petstore/go/go-petstore/docs/EnumArrays.md +++ b/samples/client/petstore/go/go-petstore/docs/EnumArrays.md @@ -3,8 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**JustSymbol** | **string** | | [optional] -**ArrayEnum** | **[]string** | | [optional] +**JustSymbol** | **EnumArraysJustSymbol** | | [optional] +**ArrayEnum** | **EnumArraysArrayEnum** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/go/go-petstore/docs/EnumTest.md b/samples/client/petstore/go/go-petstore/docs/EnumTest.md index 85eab0e1d402..fc8e5dbb81ff 100644 --- a/samples/client/petstore/go/go-petstore/docs/EnumTest.md +++ b/samples/client/petstore/go/go-petstore/docs/EnumTest.md @@ -3,10 +3,10 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**EnumString** | **string** | | [optional] -**EnumStringRequired** | **string** | | -**EnumInteger** | **int32** | | [optional] -**EnumNumber** | **float64** | | [optional] +**EnumString** | **EnumTestEnumString** | | [optional] +**EnumStringRequired** | **EnumTestEnumStringRequired** | | +**EnumInteger** | **EnumTestEnumInteger** | | [optional] +**EnumNumber** | **EnumTestEnumNumber** | | [optional] **OuterEnum** | [**OuterEnum**](OuterEnum.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/go/go-petstore/docs/MapTest.md b/samples/client/petstore/go/go-petstore/docs/MapTest.md index 49381ec4b857..d7f04b0c8233 100644 --- a/samples/client/petstore/go/go-petstore/docs/MapTest.md +++ b/samples/client/petstore/go/go-petstore/docs/MapTest.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **MapMapOfString** | [**map[string]map[string]string**](map.md) | | [optional] -**MapOfEnumString** | **map[string]string** | | [optional] +**MapOfEnumString** | **MapTestMapOfEnumString** | | [optional] **DirectMap** | **map[string]bool** | | [optional] **IndirectMap** | **map[string]bool** | | [optional] diff --git a/samples/client/petstore/go/go-petstore/docs/Order.md b/samples/client/petstore/go/go-petstore/docs/Order.md index befa9151a18a..c872ed504849 100644 --- a/samples/client/petstore/go/go-petstore/docs/Order.md +++ b/samples/client/petstore/go/go-petstore/docs/Order.md @@ -7,7 +7,7 @@ Name | Type | Description | Notes **PetId** | **int64** | | [optional] **Quantity** | **int32** | | [optional] **ShipDate** | [**time.Time**](time.Time.md) | | [optional] -**Status** | **string** | Order Status | [optional] +**Status** | **OrderStatus** | Order Status | [optional] **Complete** | **bool** | | [optional] [default to false] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/go/go-petstore/docs/Pet.md b/samples/client/petstore/go/go-petstore/docs/Pet.md index 049c82eb5a03..16bb4d6e9c5c 100644 --- a/samples/client/petstore/go/go-petstore/docs/Pet.md +++ b/samples/client/petstore/go/go-petstore/docs/Pet.md @@ -8,7 +8,7 @@ Name | Type | Description | Notes **Name** | **string** | | **PhotoUrls** | **[]string** | | **Tags** | [**[]Tag**](Tag.md) | | [optional] -**Status** | **string** | pet status in the store | [optional] +**Status** | **PetStatus** | pet status in the store | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/go/go-petstore/model_enum_arrays.go b/samples/client/petstore/go/go-petstore/model_enum_arrays.go index ab4dce92ebbc..833d10b68d47 100644 --- a/samples/client/petstore/go/go-petstore/model_enum_arrays.go +++ b/samples/client/petstore/go/go-petstore/model_enum_arrays.go @@ -10,6 +10,22 @@ package petstore type EnumArrays struct { - JustSymbol string `json:"just_symbol,omitempty"` - ArrayEnum []string `json:"array_enum,omitempty"` + JustSymbol EnumArraysJustSymbol `json:"just_symbol,omitempty"` + ArrayEnum []EnumArraysArrayEnum `json:"array_enum,omitempty"` } + +type EnumArraysJustSymbol string + +// List of EnumArraysJustSymbol +const ( + JUST_SYMBOL_GREATER_THAN_OR_EQUAL_TO EnumArraysJustSymbol = ">=" + JUST_SYMBOL_DOLLAR EnumArraysJustSymbol = "$" +) + +type EnumArraysArrayEnum string + +// List of EnumArraysArrayEnum +const ( + ARRAY_ENUM_FISH EnumArraysArrayEnum = "fish" + ARRAY_ENUM_CRAB EnumArraysArrayEnum = "crab" +) diff --git a/samples/client/petstore/go/go-petstore/model_enum_class.go b/samples/client/petstore/go/go-petstore/model_enum_class.go index 534ce4328817..e94b84dfca6e 100644 --- a/samples/client/petstore/go/go-petstore/model_enum_class.go +++ b/samples/client/petstore/go/go-petstore/model_enum_class.go @@ -12,7 +12,7 @@ type EnumClass string // List of EnumClass const ( - ABC EnumClass = "_abc" - EFG EnumClass = "-efg" - XYZ EnumClass = "(xyz)" + ENUM_CLASS_ABC EnumClass = "_abc" + ENUM_CLASS_EFG EnumClass = "-efg" + ENUM_CLASS_XYZ EnumClass = "(xyz)" ) \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/model_enum_test_.go b/samples/client/petstore/go/go-petstore/model_enum_test_.go index f85f31501a01..3787858c444b 100644 --- a/samples/client/petstore/go/go-petstore/model_enum_test_.go +++ b/samples/client/petstore/go/go-petstore/model_enum_test_.go @@ -10,9 +10,43 @@ package petstore type EnumTest struct { - EnumString string `json:"enum_string,omitempty"` - EnumStringRequired string `json:"enum_string_required"` - EnumInteger int32 `json:"enum_integer,omitempty"` - EnumNumber float64 `json:"enum_number,omitempty"` + EnumString EnumTestEnumString `json:"enum_string,omitempty"` + EnumStringRequired EnumTestEnumStringRequired `json:"enum_string_required"` + EnumInteger EnumTestEnumInteger `json:"enum_integer,omitempty"` + EnumNumber EnumTestEnumNumber `json:"enum_number,omitempty"` OuterEnum OuterEnum `json:"outerEnum,omitempty"` } + +type EnumTestEnumString string + +// List of EnumTestEnumString +const ( + ENUM_STRING_UPPER EnumTestEnumString = "UPPER" + ENUM_STRING_LOWER EnumTestEnumString = "lower" + ENUM_STRING_EMPTY EnumTestEnumString = "" +) + +type EnumTestEnumStringRequired string + +// List of EnumTestEnumStringRequired +const ( + ENUM_STRING_REQUIRED_UPPER EnumTestEnumStringRequired = "UPPER" + ENUM_STRING_REQUIRED_LOWER EnumTestEnumStringRequired = "lower" + ENUM_STRING_REQUIRED_EMPTY EnumTestEnumStringRequired = "" +) + +type EnumTestEnumInteger int32 + +// List of EnumTestEnumInteger +const ( + ENUM_INTEGER_1 EnumTestEnumInteger = 1 + ENUM_INTEGER_MINUS_1 EnumTestEnumInteger = -1 +) + +type EnumTestEnumNumber float64 + +// List of EnumTestEnumNumber +const ( + ENUM_NUMBER_1_DOT_1 EnumTestEnumNumber = 1.1 + ENUM_NUMBER_MINUS_1_DOT_2 EnumTestEnumNumber = -1.2 +) diff --git a/samples/client/petstore/go/go-petstore/model_map_test_.go b/samples/client/petstore/go/go-petstore/model_map_test_.go index 830e760fe314..8de771c11b11 100644 --- a/samples/client/petstore/go/go-petstore/model_map_test_.go +++ b/samples/client/petstore/go/go-petstore/model_map_test_.go @@ -11,7 +11,15 @@ package petstore type MapTest struct { MapMapOfString map[string]map[string]string `json:"map_map_of_string,omitempty"` - MapOfEnumString map[string]string `json:"map_of_enum_string,omitempty"` + MapOfEnumString map[string]MapTestMapOfEnumString `json:"map_of_enum_string,omitempty"` DirectMap map[string]bool `json:"direct_map,omitempty"` IndirectMap map[string]bool `json:"indirect_map,omitempty"` } + +type MapTestMapOfEnumString string + +// List of MapTestMapOfEnumString +const ( + MAP_OF_ENUM_STRING_UPPER MapTestMapOfEnumString = "UPPER" + MAP_OF_ENUM_STRING_LOWER MapTestMapOfEnumString = "lower" +) diff --git a/samples/client/petstore/go/go-petstore/model_order.go b/samples/client/petstore/go/go-petstore/model_order.go index c81d67ae0fa4..c343cf3b47e4 100644 --- a/samples/client/petstore/go/go-petstore/model_order.go +++ b/samples/client/petstore/go/go-petstore/model_order.go @@ -18,6 +18,16 @@ type Order struct { Quantity int32 `json:"quantity,omitempty"` ShipDate time.Time `json:"shipDate,omitempty"` // Order Status - Status string `json:"status,omitempty"` + Status OrderStatus `json:"status,omitempty"` Complete bool `json:"complete,omitempty"` } + +// OrderStatus : Order Status +type OrderStatus string + +// List of OrderStatus +const ( + STATUS_PLACED OrderStatus = "placed" + STATUS_APPROVED OrderStatus = "approved" + STATUS_DELIVERED OrderStatus = "delivered" +) diff --git a/samples/client/petstore/go/go-petstore/model_outer_enum.go b/samples/client/petstore/go/go-petstore/model_outer_enum.go index 903d31e82690..3ec2a3131c31 100644 --- a/samples/client/petstore/go/go-petstore/model_outer_enum.go +++ b/samples/client/petstore/go/go-petstore/model_outer_enum.go @@ -12,7 +12,7 @@ type OuterEnum string // List of OuterEnum const ( - PLACED OuterEnum = "placed" - APPROVED OuterEnum = "approved" - DELIVERED OuterEnum = "delivered" + OUTER_ENUM_PLACED OuterEnum = "placed" + OUTER_ENUM_APPROVED OuterEnum = "approved" + OUTER_ENUM_DELIVERED OuterEnum = "delivered" ) \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/model_pet.go b/samples/client/petstore/go/go-petstore/model_pet.go index 4930dbb92e8e..16646391fc9e 100644 --- a/samples/client/petstore/go/go-petstore/model_pet.go +++ b/samples/client/petstore/go/go-petstore/model_pet.go @@ -16,5 +16,15 @@ type Pet struct { PhotoUrls []string `json:"photoUrls"` Tags []Tag `json:"tags,omitempty"` // pet status in the store - Status string `json:"status,omitempty"` + Status PetStatus `json:"status,omitempty"` } + +// PetStatus : pet status in the store +type PetStatus string + +// List of PetStatus +const ( + STATUS_AVAILABLE PetStatus = "available" + STATUS_PENDING PetStatus = "pending" + STATUS_SOLD PetStatus = "sold" +) diff --git a/samples/server/petstore/go-api-server/go/model_order.go b/samples/server/petstore/go-api-server/go/model_order.go index a9d8dbb79579..ca056a34aaeb 100644 --- a/samples/server/petstore/go-api-server/go/model_order.go +++ b/samples/server/petstore/go-api-server/go/model_order.go @@ -25,7 +25,17 @@ type Order struct { ShipDate time.Time `json:"shipDate,omitempty"` // Order Status - Status string `json:"status,omitempty"` + Status OrderStatus `json:"status,omitempty"` Complete bool `json:"complete,omitempty"` } + +// OrderStatus : Order Status +type OrderStatus string + +// List of OrderStatus +const ( + STATUS_PLACED OrderStatus = "placed" + STATUS_APPROVED OrderStatus = "approved" + STATUS_DELIVERED OrderStatus = "delivered" +) diff --git a/samples/server/petstore/go-api-server/go/model_pet.go b/samples/server/petstore/go-api-server/go/model_pet.go index fb206487ab08..c2e6f6ac8863 100644 --- a/samples/server/petstore/go-api-server/go/model_pet.go +++ b/samples/server/petstore/go-api-server/go/model_pet.go @@ -23,5 +23,15 @@ type Pet struct { Tags []Tag `json:"tags,omitempty"` // pet status in the store - Status string `json:"status,omitempty"` + Status PetStatus `json:"status,omitempty"` } + +// PetStatus : pet status in the store +type PetStatus string + +// List of PetStatus +const ( + STATUS_AVAILABLE PetStatus = "available" + STATUS_PENDING PetStatus = "pending" + STATUS_SOLD PetStatus = "sold" +) diff --git a/samples/server/petstore/go-gin-api-server/go/model_order.go b/samples/server/petstore/go-gin-api-server/go/model_order.go index a9d8dbb79579..ca056a34aaeb 100644 --- a/samples/server/petstore/go-gin-api-server/go/model_order.go +++ b/samples/server/petstore/go-gin-api-server/go/model_order.go @@ -25,7 +25,17 @@ type Order struct { ShipDate time.Time `json:"shipDate,omitempty"` // Order Status - Status string `json:"status,omitempty"` + Status OrderStatus `json:"status,omitempty"` Complete bool `json:"complete,omitempty"` } + +// OrderStatus : Order Status +type OrderStatus string + +// List of OrderStatus +const ( + STATUS_PLACED OrderStatus = "placed" + STATUS_APPROVED OrderStatus = "approved" + STATUS_DELIVERED OrderStatus = "delivered" +) diff --git a/samples/server/petstore/go-gin-api-server/go/model_pet.go b/samples/server/petstore/go-gin-api-server/go/model_pet.go index fb206487ab08..c2e6f6ac8863 100644 --- a/samples/server/petstore/go-gin-api-server/go/model_pet.go +++ b/samples/server/petstore/go-gin-api-server/go/model_pet.go @@ -23,5 +23,15 @@ type Pet struct { Tags []Tag `json:"tags,omitempty"` // pet status in the store - Status string `json:"status,omitempty"` + Status PetStatus `json:"status,omitempty"` } + +// PetStatus : pet status in the store +type PetStatus string + +// List of PetStatus +const ( + STATUS_AVAILABLE PetStatus = "available" + STATUS_PENDING PetStatus = "pending" + STATUS_SOLD PetStatus = "sold" +)