Skip to content

Commit 179bd2a

Browse files
authored
Merge pull request #9472 from kostyay/fix_issue9471_opts_struct_name_collision
[GO] Issue 9471 - opts struct name collision when operation has multiple tags
2 parents 778e1bc + 0f8bd0d commit 179bd2a

File tree

24 files changed

+165
-152
lines changed

24 files changed

+165
-152
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
{{>partial_header}}
23
package {{packageName}}
34

@@ -25,19 +26,19 @@ type {{classname}}Service service
2526
{{notes}}{{/notes}}
2627
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
2728
{{#allParams}}{{#required}} * @param {{paramName}}{{#description}} {{.}}{{/description}}
28-
{{/required}}{{/allParams}}{{#hasOptionalParams}} * @param optional nil or *{{{nickname}}}Opts - Optional Parameters:
29+
{{/required}}{{/allParams}}{{#hasOptionalParams}} * @param optional nil or *{{{classname}}}{{{nickname}}}Opts - Optional Parameters:
2930
{{#allParams}}{{^required}} * @param "{{vendorExtensions.x-exportParamName}}" ({{#isPrimitiveType}}optional.{{vendorExtensions.x-optionalDataType}}{{/isPrimitiveType}}{{^isPrimitiveType}}optional.Interface of {{dataType}}{{/isPrimitiveType}}) - {{#description}} {{.}}{{/description}}
3031
{{/required}}{{/allParams}}{{/hasOptionalParams}}
3132
{{#returnType}}@return {{{returnType}}}{{/returnType}}
3233
*/
3334
{{#hasOptionalParams}}
3435

35-
type {{{nickname}}}Opts struct { {{#allParams}}{{^required}}
36+
type {{{classname}}}{{{nickname}}}Opts struct { {{#allParams}}{{^required}}
3637
{{#isPrimitiveType}} {{vendorExtensions.x-exportParamName}} optional.{{vendorExtensions.x-optionalDataType}}{{/isPrimitiveType}}{{^isPrimitiveType}} {{vendorExtensions.x-exportParamName}} optional.Interface{{/isPrimitiveType}}{{/required}}{{/allParams}}
3738
}
3839

3940
{{/hasOptionalParams}}
40-
func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}}, {{/hasParams}}{{#allParams}}{{#required}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}localVarOptionals *{{{nickname}}}Opts{{/hasOptionalParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}*http.Response, error) {
41+
func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}}, {{/hasParams}}{{#allParams}}{{#required}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}localVarOptionals *{{{classname}}}{{{nickname}}}Opts{{/hasOptionalParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}*http.Response, error) {
4142
var (
4243
localVarHttpMethod = strings.ToUpper("{{httpMethod}}")
4344
localVarPostBody interface{}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ Name | Type | Description | Notes
2222
------------- | ------------- | ------------- | -------------
2323
**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc.{{/-last}}{{/allParams}}{{#allParams}}{{#required}}
2424
**{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}{{/required}}{{/allParams}}{{#hasOptionalParams}}
25-
**optional** | ***{{{nickname}}}Opts** | optional parameters | nil if no parameters
25+
**optional** | ***{{{classname}}}{{{nickname}}}Opts** | optional parameters | nil if no parameters
2626

2727
### Optional Parameters
28-
Optional parameters are passed through a pointer to a {{{nickname}}}Opts struct
28+
Optional parameters are passed through a pointer to a {{{classname}}}{{{nickname}}}Opts struct
2929
{{#allParams}}{{#-last}}
3030
Name | Type | Description | Notes
3131
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}{{#allParams}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.3-SNAPSHOT
1+
2.4.6-SNAPSHOT

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

Lines changed: 26 additions & 26 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"
110111
enum:
111112
- "available"
112113
- "pending"
113114
- "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: "$"
642643
enum:
643644
- ">"
644645
- "$"
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: "$"
666667
enum:
667668
- ">"
668669
- "$"
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: "$"
690691
enum:
691692
- ">"
692693
- "$"
693-
default: "$"
694694
x-exportParamName: "EnumQueryStringArray"
695695
- name: "enum_query_string"
696696
in: "query"
@@ -1108,12 +1108,12 @@ definitions:
11081108
xml:
11091109
name: "Order"
11101110
example:
1111-
id: 0
11121111
petId: 6
1113-
complete: false
1114-
status: "placed"
11151112
quantity: 1
1113+
id: 0
11161114
shipDate: "2000-01-23T04:56:07.000+00:00"
1115+
complete: false
1116+
status: "placed"
11171117
Category:
11181118
type: "object"
11191119
properties:
@@ -1125,8 +1125,8 @@ definitions:
11251125
xml:
11261126
name: "Category"
11271127
example:
1128-
id: 6
11291128
name: "name"
1129+
id: 6
11301130
User:
11311131
type: "object"
11321132
properties:
@@ -1153,14 +1153,14 @@ definitions:
11531153
xml:
11541154
name: "User"
11551155
example:
1156-
id: 0
1156+
firstName: "firstName"
11571157
lastName: "lastName"
1158+
password: "password"
1159+
userStatus: 6
11581160
phone: "phone"
1159-
username: "username"
1161+
id: 0
11601162
email: "email"
1161-
userStatus: 6
1162-
firstName: "firstName"
1163-
password: "password"
1163+
username: "username"
11641164
Tag:
11651165
type: "object"
11661166
properties:
@@ -1172,8 +1172,8 @@ definitions:
11721172
xml:
11731173
name: "Tag"
11741174
example:
1175-
id: 1
11761175
name: "name"
1176+
id: 1
11771177
Pet:
11781178
type: "object"
11791179
required:
@@ -1213,20 +1213,20 @@ definitions:
12131213
xml:
12141214
name: "Pet"
12151215
example:
1216-
tags:
1217-
- id: 1
1218-
name: "name"
1219-
- id: 1
1220-
name: "name"
1216+
photoUrls:
1217+
- "photoUrls"
1218+
- "photoUrls"
1219+
name: "doggie"
12211220
id: 0
12221221
category:
1223-
id: 6
12241222
name: "name"
1223+
id: 6
1224+
tags:
1225+
- name: "name"
1226+
id: 1
1227+
- name: "name"
1228+
id: 1
12251229
status: "available"
1226-
name: "doggie"
1227-
photoUrls:
1228-
- "photoUrls"
1229-
- "photoUrls"
12301230
ApiResponse:
12311231
type: "object"
12321232
properties:
@@ -1238,9 +1238,9 @@ definitions:
12381238
message:
12391239
type: "string"
12401240
example:
1241-
message: "message"
12421241
code: 0
12431242
type: "type"
1243+
message: "message"
12441244
$special[model.name]:
12451245
properties:
12461246
$special[property.name]:
@@ -1574,8 +1574,8 @@ definitions:
15741574
my_boolean:
15751575
$ref: "#/definitions/OuterBoolean"
15761576
example:
1577-
my_number: {}
15781577
my_string: {}
1578+
my_number: {}
15791579
my_boolean: {}
15801580
OuterNumber:
15811581
type: "number"

samples/client/petstore/go/go-petstore-withXml/api_another_fake.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/*
23
* Swagger Petstore
34
*

samples/client/petstore/go/go-petstore-withXml/api_fake.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/*
23
* Swagger Petstore
34
*
@@ -30,17 +31,17 @@ type FakeApiService service
3031
FakeApiService
3132
Test serialization of outer boolean types
3233
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
33-
* @param optional nil or *FakeOuterBooleanSerializeOpts - Optional Parameters:
34+
* @param optional nil or *FakeApiFakeOuterBooleanSerializeOpts - Optional Parameters:
3435
* @param "Body" (optional.Interface of OuterBoolean) - Input boolean as post body
3536
3637
@return OuterBoolean
3738
*/
3839

39-
type FakeOuterBooleanSerializeOpts struct {
40+
type FakeApiFakeOuterBooleanSerializeOpts struct {
4041
Body optional.Interface
4142
}
4243

43-
func (a *FakeApiService) FakeOuterBooleanSerialize(ctx context.Context, localVarOptionals *FakeOuterBooleanSerializeOpts) (OuterBoolean, *http.Response, error) {
44+
func (a *FakeApiService) FakeOuterBooleanSerialize(ctx context.Context, localVarOptionals *FakeApiFakeOuterBooleanSerializeOpts) (OuterBoolean, *http.Response, error) {
4445
var (
4546
localVarHttpMethod = strings.ToUpper("Post")
4647
localVarPostBody interface{}
@@ -133,17 +134,17 @@ func (a *FakeApiService) FakeOuterBooleanSerialize(ctx context.Context, localVar
133134
FakeApiService
134135
Test serialization of object with outer number type
135136
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
136-
* @param optional nil or *FakeOuterCompositeSerializeOpts - Optional Parameters:
137+
* @param optional nil or *FakeApiFakeOuterCompositeSerializeOpts - Optional Parameters:
137138
* @param "Body" (optional.Interface of OuterComposite) - Input composite as post body
138139
139140
@return OuterComposite
140141
*/
141142

142-
type FakeOuterCompositeSerializeOpts struct {
143+
type FakeApiFakeOuterCompositeSerializeOpts struct {
143144
Body optional.Interface
144145
}
145146

146-
func (a *FakeApiService) FakeOuterCompositeSerialize(ctx context.Context, localVarOptionals *FakeOuterCompositeSerializeOpts) (OuterComposite, *http.Response, error) {
147+
func (a *FakeApiService) FakeOuterCompositeSerialize(ctx context.Context, localVarOptionals *FakeApiFakeOuterCompositeSerializeOpts) (OuterComposite, *http.Response, error) {
147148
var (
148149
localVarHttpMethod = strings.ToUpper("Post")
149150
localVarPostBody interface{}
@@ -236,17 +237,17 @@ func (a *FakeApiService) FakeOuterCompositeSerialize(ctx context.Context, localV
236237
FakeApiService
237238
Test serialization of outer number types
238239
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
239-
* @param optional nil or *FakeOuterNumberSerializeOpts - Optional Parameters:
240+
* @param optional nil or *FakeApiFakeOuterNumberSerializeOpts - Optional Parameters:
240241
* @param "Body" (optional.Interface of OuterNumber) - Input number as post body
241242
242243
@return OuterNumber
243244
*/
244245

245-
type FakeOuterNumberSerializeOpts struct {
246+
type FakeApiFakeOuterNumberSerializeOpts struct {
246247
Body optional.Interface
247248
}
248249

249-
func (a *FakeApiService) FakeOuterNumberSerialize(ctx context.Context, localVarOptionals *FakeOuterNumberSerializeOpts) (OuterNumber, *http.Response, error) {
250+
func (a *FakeApiService) FakeOuterNumberSerialize(ctx context.Context, localVarOptionals *FakeApiFakeOuterNumberSerializeOpts) (OuterNumber, *http.Response, error) {
250251
var (
251252
localVarHttpMethod = strings.ToUpper("Post")
252253
localVarPostBody interface{}
@@ -339,17 +340,17 @@ func (a *FakeApiService) FakeOuterNumberSerialize(ctx context.Context, localVarO
339340
FakeApiService
340341
Test serialization of outer string types
341342
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
342-
* @param optional nil or *FakeOuterStringSerializeOpts - Optional Parameters:
343+
* @param optional nil or *FakeApiFakeOuterStringSerializeOpts - Optional Parameters:
343344
* @param "Body" (optional.Interface of OuterString) - Input string as post body
344345
345346
@return OuterString
346347
*/
347348

348-
type FakeOuterStringSerializeOpts struct {
349+
type FakeApiFakeOuterStringSerializeOpts struct {
349350
Body optional.Interface
350351
}
351352

352-
func (a *FakeApiService) FakeOuterStringSerialize(ctx context.Context, localVarOptionals *FakeOuterStringSerializeOpts) (OuterString, *http.Response, error) {
353+
func (a *FakeApiService) FakeOuterStringSerialize(ctx context.Context, localVarOptionals *FakeApiFakeOuterStringSerializeOpts) (OuterString, *http.Response, error) {
353354
var (
354355
localVarHttpMethod = strings.ToUpper("Post")
355356
localVarPostBody interface{}
@@ -609,7 +610,7 @@ Fake endpoint for testing various parameters 假端點 偽のエンドポイン
609610
* @param double None
610611
* @param patternWithoutDelimiter None
611612
* @param byte_ None
612-
* @param optional nil or *TestEndpointParametersOpts - Optional Parameters:
613+
* @param optional nil or *FakeApiTestEndpointParametersOpts - Optional Parameters:
613614
* @param "Integer" (optional.Int32) - None
614615
* @param "Int32_" (optional.Int32) - None
615616
* @param "Int64_" (optional.Int64) - None
@@ -624,7 +625,7 @@ Fake endpoint for testing various parameters 假端點 偽のエンドポイン
624625
625626
*/
626627

627-
type TestEndpointParametersOpts struct {
628+
type FakeApiTestEndpointParametersOpts struct {
628629
Integer optional.Int32
629630
Int32_ optional.Int32
630631
Int64_ optional.Int64
@@ -637,7 +638,7 @@ type TestEndpointParametersOpts struct {
637638
Callback optional.String
638639
}
639640

640-
func (a *FakeApiService) TestEndpointParameters(ctx context.Context, number float32, double float64, patternWithoutDelimiter string, byte_ string, localVarOptionals *TestEndpointParametersOpts) (*http.Response, error) {
641+
func (a *FakeApiService) TestEndpointParameters(ctx context.Context, number float32, double float64, patternWithoutDelimiter string, byte_ string, localVarOptionals *FakeApiTestEndpointParametersOpts) (*http.Response, error) {
641642
var (
642643
localVarHttpMethod = strings.ToUpper("Post")
643644
localVarPostBody interface{}
@@ -749,7 +750,7 @@ func (a *FakeApiService) TestEndpointParameters(ctx context.Context, number floa
749750
FakeApiService To test enum parameters
750751
To test enum parameters
751752
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
752-
* @param optional nil or *TestEnumParametersOpts - Optional Parameters:
753+
* @param optional nil or *FakeApiTestEnumParametersOpts - Optional Parameters:
753754
* @param "EnumFormStringArray" (optional.Interface of []string) - Form parameter enum test (string array)
754755
* @param "EnumFormString" (optional.String) - Form parameter enum test (string)
755756
* @param "EnumHeaderStringArray" (optional.Interface of []string) - Header parameter enum test (string array)
@@ -762,7 +763,7 @@ To test enum parameters
762763
763764
*/
764765

765-
type TestEnumParametersOpts struct {
766+
type FakeApiTestEnumParametersOpts struct {
766767
EnumFormStringArray optional.Interface
767768
EnumFormString optional.String
768769
EnumHeaderStringArray optional.Interface
@@ -773,7 +774,7 @@ type TestEnumParametersOpts struct {
773774
EnumQueryDouble optional.Float64
774775
}
775776

776-
func (a *FakeApiService) TestEnumParameters(ctx context.Context, localVarOptionals *TestEnumParametersOpts) (*http.Response, error) {
777+
func (a *FakeApiService) TestEnumParameters(ctx context.Context, localVarOptionals *FakeApiTestEnumParametersOpts) (*http.Response, error) {
777778
var (
778779
localVarHttpMethod = strings.ToUpper("Get")
779780
localVarPostBody interface{}

samples/client/petstore/go/go-petstore-withXml/api_fake_classname_tags123.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/*
23
* Swagger Petstore
34
*

0 commit comments

Comments
 (0)