Skip to content

Commit 164d45f

Browse files
committed
updated go client model template to get enums value right and updated go samples.
1 parent 3afe17b commit 164d45f

File tree

16 files changed

+178
-46
lines changed

16 files changed

+178
-46
lines changed

modules/swagger-codegen/src/main/resources/go/model.mustache

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ type {{{classname}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{
1111
const (
1212
{{#allowableValues}}
1313
{{#enumVars}}
14-
{{^-first}}
15-
{{/-first}}
16-
{{name}}_{{{classname}}} {{{classname}}} = "{{{value}}}"
14+
{{name}} {{{classname}}} = {{{value}}}
1715
{{/enumVars}}
1816
{{/allowableValues}}
1917
){{/isEnum}}{{^isEnum}}{{#description}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.16-SNAPSHOT
1+
2.4.19-SNAPSHOT

samples/client/petstore/go/go-petstore/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Class | Method | HTTP request | Description
6363
- [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
6464
- [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
6565
- [ArrayTest](docs/ArrayTest.md)
66+
- [Boolean](docs/Boolean.md)
6667
- [Capitalization](docs/Capitalization.md)
6768
- [Cat](docs/Cat.md)
6869
- [Category](docs/Category.md)
@@ -74,6 +75,7 @@ Class | Method | HTTP request | Description
7475
- [EnumTest](docs/EnumTest.md)
7576
- [FormatTest](docs/FormatTest.md)
7677
- [HasOnlyReadOnly](docs/HasOnlyReadOnly.md)
78+
- [Ints](docs/Ints.md)
7779
- [List](docs/List.md)
7880
- [MapTest](docs/MapTest.md)
7981
- [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
@@ -82,6 +84,7 @@ Class | Method | HTTP request | Description
8284
- [ModelReturn](docs/ModelReturn.md)
8385
- [Name](docs/Name.md)
8486
- [NumberOnly](docs/NumberOnly.md)
87+
- [Numbers](docs/Numbers.md)
8588
- [Order](docs/Order.md)
8689
- [OuterBoolean](docs/OuterBoolean.md)
8790
- [OuterComposite](docs/OuterComposite.md)

samples/client/petstore/go/go-petstore/api/swagger.yaml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ paths:
107107
type: "array"
108108
items:
109109
type: "string"
110-
default: "available"
111110
enum:
112111
- "available"
113112
- "pending"
114113
- "sold"
114+
default: "available"
115115
collectionFormat: "csv"
116116
x-exportParamName: "Status"
117117
responses:
@@ -639,10 +639,10 @@ paths:
639639
type: "array"
640640
items:
641641
type: "string"
642-
default: "$"
643642
enum:
644643
- ">"
645644
- "$"
645+
default: "$"
646646
x-exportParamName: "EnumFormStringArray"
647647
- name: "enum_form_string"
648648
in: "formData"
@@ -663,10 +663,10 @@ paths:
663663
type: "array"
664664
items:
665665
type: "string"
666-
default: "$"
667666
enum:
668667
- ">"
669668
- "$"
669+
default: "$"
670670
x-exportParamName: "EnumHeaderStringArray"
671671
- name: "enum_header_string"
672672
in: "header"
@@ -687,10 +687,10 @@ paths:
687687
type: "array"
688688
items:
689689
type: "string"
690-
default: "$"
691690
enum:
692691
- ">"
693692
- "$"
693+
default: "$"
694694
x-exportParamName: "EnumQueryStringArray"
695695
- name: "enum_query_string"
696696
in: "query"
@@ -1583,6 +1583,32 @@ definitions:
15831583
type: "string"
15841584
OuterBoolean:
15851585
type: "boolean"
1586+
Boolean:
1587+
type: "boolean"
1588+
description: "True or False indicator"
1589+
enum:
1590+
- "true"
1591+
- "false"
1592+
Ints:
1593+
type: "integer"
1594+
format: "int32"
1595+
description: "True or False indicator"
1596+
enum:
1597+
- "0"
1598+
- "1"
1599+
- "2"
1600+
- "3"
1601+
- "4"
1602+
- "5"
1603+
- "6"
1604+
Numbers:
1605+
type: "number"
1606+
description: "some number"
1607+
enum:
1608+
- "7"
1609+
- "8"
1610+
- "9"
1611+
- "10"
15861612
externalDocs:
15871613
description: "Find out more about Swagger"
15881614
url: "http://swagger.io"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Boolean
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
7+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
8+
9+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Ints
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
7+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
8+
9+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Numbers
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
7+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
8+
9+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Swagger Petstore
3+
*
4+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
5+
*
6+
* API version: 1.0.0
7+
* Contact: [email protected]
8+
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
9+
*/
10+
11+
package petstore
12+
// Boolean : True or False indicator
13+
type Boolean bool
14+
15+
// List of Boolean
16+
const (
17+
TRUE Boolean = true
18+
FALSE Boolean = false
19+
)

samples/client/petstore/go/go-petstore/model_enum_class.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type EnumClass string
1414

1515
// List of EnumClass
1616
const (
17-
ABC_EnumClass EnumClass = "_abc"
18-
EFG_EnumClass EnumClass = "-efg"
19-
XYZ_EnumClass EnumClass = "(xyz)"
17+
ABC EnumClass = "_abc"
18+
EFG EnumClass = "-efg"
19+
XYZ EnumClass = "(xyz)"
2020
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Swagger Petstore
3+
*
4+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
5+
*
6+
* API version: 1.0.0
7+
* Contact: [email protected]
8+
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
9+
*/
10+
11+
package petstore
12+
// Ints : True or False indicator
13+
type Ints int32
14+
15+
// List of Ints
16+
const (
17+
_0 Ints = 0
18+
_1 Ints = 1
19+
_2 Ints = 2
20+
_3 Ints = 3
21+
_4 Ints = 4
22+
_5 Ints = 5
23+
_6 Ints = 6
24+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Swagger Petstore
3+
*
4+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
5+
*
6+
* API version: 1.0.0
7+
* Contact: [email protected]
8+
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
9+
*/
10+
11+
package petstore
12+
// Numbers : some number
13+
type Numbers float32
14+
15+
// List of Numbers
16+
const (
17+
_7 Numbers = 7
18+
_8 Numbers = 8
19+
_9 Numbers = 9
20+
_10 Numbers = 10
21+
)

samples/client/petstore/go/go-petstore/model_outer_enum.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type OuterEnum string
1414

1515
// List of OuterEnum
1616
const (
17-
PLACED_OuterEnum OuterEnum = "placed"
18-
APPROVED_OuterEnum OuterEnum = "approved"
19-
DELIVERED_OuterEnum OuterEnum = "delivered"
17+
PLACED OuterEnum = "placed"
18+
APPROVED OuterEnum = "approved"
19+
DELIVERED OuterEnum = "delivered"
2020
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.6-SNAPSHOT
1+
2.4.19-SNAPSHOT
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM golang:1.10 AS build
2+
WORKDIR /go/src
3+
COPY go ./go
4+
COPY main.go .
5+
6+
ENV CGO_ENABLED=0
7+
RUN go get -d -v ./...
8+
9+
RUN go build -a -installsuffix cgo -o swagger .
10+
11+
FROM scratch AS runtime
12+
COPY --from=build /go/src/swagger ./
13+
EXPOSE 8080/tcp
14+
ENTRYPOINT ["./swagger"]

0 commit comments

Comments
 (0)