Skip to content

Commit

Permalink
updated go client model template to get enums value right and updated…
Browse files Browse the repository at this point in the history
… go samples.
  • Loading branch information
HugoMario committed Feb 19, 2021
1 parent 3afe17b commit 164d45f
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 46 deletions.
4 changes: 1 addition & 3 deletions modules/swagger-codegen/src/main/resources/go/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ type {{{classname}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{
const (
{{#allowableValues}}
{{#enumVars}}
{{^-first}}
{{/-first}}
{{name}}_{{{classname}}} {{{classname}}} = "{{{value}}}"

This comment has been minimized.

Copy link
@hemanthk76in

hemanthk76in Jun 8, 2021

May I know the reason why this is removed? This is triggering a enum conflict regressing the previous behavior.

This comment has been minimized.

Copy link
@aethanol

aethanol Feb 28, 2023

Contributor

I am encountering the same bug

This comment has been minimized.

Copy link
@aaryan-srivastava-glean

aaryan-srivastava-glean Mar 12, 2024

I am still encountering this bug

{{name}} {{{classname}}} = {{{value}}}
{{/enumVars}}
{{/allowableValues}}
){{/isEnum}}{{^isEnum}}{{#description}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.16-SNAPSHOT
2.4.19-SNAPSHOT
3 changes: 3 additions & 0 deletions samples/client/petstore/go/go-petstore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Class | Method | HTTP request | Description
- [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
- [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
- [ArrayTest](docs/ArrayTest.md)
- [Boolean](docs/Boolean.md)
- [Capitalization](docs/Capitalization.md)
- [Cat](docs/Cat.md)
- [Category](docs/Category.md)
Expand All @@ -74,6 +75,7 @@ Class | Method | HTTP request | Description
- [EnumTest](docs/EnumTest.md)
- [FormatTest](docs/FormatTest.md)
- [HasOnlyReadOnly](docs/HasOnlyReadOnly.md)
- [Ints](docs/Ints.md)
- [List](docs/List.md)
- [MapTest](docs/MapTest.md)
- [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
Expand All @@ -82,6 +84,7 @@ Class | Method | HTTP request | Description
- [ModelReturn](docs/ModelReturn.md)
- [Name](docs/Name.md)
- [NumberOnly](docs/NumberOnly.md)
- [Numbers](docs/Numbers.md)
- [Order](docs/Order.md)
- [OuterBoolean](docs/OuterBoolean.md)
- [OuterComposite](docs/OuterComposite.md)
Expand Down
34 changes: 30 additions & 4 deletions samples/client/petstore/go/go-petstore/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ paths:
type: "array"
items:
type: "string"
default: "available"
enum:
- "available"
- "pending"
- "sold"
default: "available"
collectionFormat: "csv"
x-exportParamName: "Status"
responses:
Expand Down Expand Up @@ -639,10 +639,10 @@ paths:
type: "array"
items:
type: "string"
default: "$"
enum:
- ">"
- "$"
default: "$"
x-exportParamName: "EnumFormStringArray"
- name: "enum_form_string"
in: "formData"
Expand All @@ -663,10 +663,10 @@ paths:
type: "array"
items:
type: "string"
default: "$"
enum:
- ">"
- "$"
default: "$"
x-exportParamName: "EnumHeaderStringArray"
- name: "enum_header_string"
in: "header"
Expand All @@ -687,10 +687,10 @@ paths:
type: "array"
items:
type: "string"
default: "$"
enum:
- ">"
- "$"
default: "$"
x-exportParamName: "EnumQueryStringArray"
- name: "enum_query_string"
in: "query"
Expand Down Expand Up @@ -1583,6 +1583,32 @@ definitions:
type: "string"
OuterBoolean:
type: "boolean"
Boolean:
type: "boolean"
description: "True or False indicator"
enum:
- "true"
- "false"
Ints:
type: "integer"
format: "int32"
description: "True or False indicator"
enum:
- "0"
- "1"
- "2"
- "3"
- "4"
- "5"
- "6"
Numbers:
type: "number"
description: "some number"
enum:
- "7"
- "8"
- "9"
- "10"
externalDocs:
description: "Find out more about Swagger"
url: "http://swagger.io"
9 changes: 9 additions & 0 deletions samples/client/petstore/go/go-petstore/docs/Boolean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Boolean

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


9 changes: 9 additions & 0 deletions samples/client/petstore/go/go-petstore/docs/Ints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ints

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


9 changes: 9 additions & 0 deletions samples/client/petstore/go/go-petstore/docs/Numbers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Numbers

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


19 changes: 19 additions & 0 deletions samples/client/petstore/go/go-petstore/model_boolean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Swagger Petstore
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* API version: 1.0.0
* Contact: [email protected]
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/

package petstore
// Boolean : True or False indicator
type Boolean bool

// List of Boolean
const (
TRUE Boolean = true
FALSE Boolean = false
)
6 changes: 3 additions & 3 deletions samples/client/petstore/go/go-petstore/model_enum_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type EnumClass string

// List of EnumClass
const (
ABC_EnumClass EnumClass = "_abc"
EFG_EnumClass EnumClass = "-efg"
XYZ_EnumClass EnumClass = "(xyz)"
ABC EnumClass = "_abc"
EFG EnumClass = "-efg"
XYZ EnumClass = "(xyz)"
)
24 changes: 24 additions & 0 deletions samples/client/petstore/go/go-petstore/model_ints.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Swagger Petstore
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* API version: 1.0.0
* Contact: [email protected]
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/

package petstore
// Ints : True or False indicator
type Ints int32

// List of Ints
const (
_0 Ints = 0
_1 Ints = 1
_2 Ints = 2
_3 Ints = 3
_4 Ints = 4
_5 Ints = 5
_6 Ints = 6
)
21 changes: 21 additions & 0 deletions samples/client/petstore/go/go-petstore/model_numbers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Swagger Petstore
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* API version: 1.0.0
* Contact: [email protected]
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/

package petstore
// Numbers : some number
type Numbers float32

// List of Numbers
const (
_7 Numbers = 7
_8 Numbers = 8
_9 Numbers = 9
_10 Numbers = 10
)
6 changes: 3 additions & 3 deletions samples/client/petstore/go/go-petstore/model_outer_enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type OuterEnum string

// List of OuterEnum
const (
PLACED_OuterEnum OuterEnum = "placed"
APPROVED_OuterEnum OuterEnum = "approved"
DELIVERED_OuterEnum OuterEnum = "delivered"
PLACED OuterEnum = "placed"
APPROVED OuterEnum = "approved"
DELIVERED OuterEnum = "delivered"
)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.6-SNAPSHOT
2.4.19-SNAPSHOT
14 changes: 14 additions & 0 deletions samples/server/petstore/go-api-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.10 AS build
WORKDIR /go/src
COPY go ./go
COPY main.go .

ENV CGO_ENABLED=0
RUN go get -d -v ./...

RUN go build -a -installsuffix cgo -o swagger .

FROM scratch AS runtime
COPY --from=build /go/src/swagger ./
EXPOSE 8080/tcp
ENTRYPOINT ["./swagger"]
Loading

0 comments on commit 164d45f

Please sign in to comment.