Skip to content

Commit 5e8e78e

Browse files
committed
Fix context import order
1 parent f9ae84d commit 5e8e78e

27 files changed

+868
-477
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package {{packageName}}
33

44
{{#operations}}
55
import (
6+
"context"
67
"io/ioutil"
78
"net/http"
89
"net/url"
910
"strings"
10-
"context"
1111
{{#imports}} "{{import}}"
1212
{{/imports}}
1313
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package {{packageName}}
33

44
import (
55
"bytes"
6+
"context"
67
"encoding/json"
78
"encoding/xml"
89
"errors"
@@ -20,7 +21,6 @@ import (
2021
"time"
2122
"unicode/utf8"
2223

23-
"context"
2424
"golang.org/x/oauth2"
2525
)
2626

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
2222
Class | Method | HTTP request | Description
2323
------------ | ------------- | ------------- | -------------
2424
*AnotherFakeApi* | [**TestSpecialTags**](docs/AnotherFakeApi.md#testspecialtags) | **Patch** /another-fake/dummy | To test special tags
25-
*DefaultApi* | [**TestBodyWithQueryParams**](docs/DefaultApi.md#testbodywithqueryparams) | **Put** /fake/body-with-query-params |
2625
*FakeApi* | [**FakeOuterBooleanSerialize**](docs/FakeApi.md#fakeouterbooleanserialize) | **Post** /fake/outer/boolean |
2726
*FakeApi* | [**FakeOuterCompositeSerialize**](docs/FakeApi.md#fakeoutercompositeserialize) | **Post** /fake/outer/composite |
2827
*FakeApi* | [**FakeOuterNumberSerialize**](docs/FakeApi.md#fakeouternumberserialize) | **Post** /fake/outer/number |
2928
*FakeApi* | [**FakeOuterStringSerialize**](docs/FakeApi.md#fakeouterstringserialize) | **Post** /fake/outer/string |
29+
*FakeApi* | [**TestBodyWithQueryParams**](docs/FakeApi.md#testbodywithqueryparams) | **Put** /fake/body-with-query-params |
3030
*FakeApi* | [**TestClientModel**](docs/FakeApi.md#testclientmodel) | **Patch** /fake | To test \"client\" model
3131
*FakeApi* | [**TestEndpointParameters**](docs/FakeApi.md#testendpointparameters) | **Post** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
3232
*FakeApi* | [**TestEnumParameters**](docs/FakeApi.md#testenumparameters) | **Get** /fake | To test enum parameters

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

Lines changed: 25 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"
110111
enum:
111112
- "available"
112113
- "pending"
113114
- "sold"
114-
default: "available"
115115
collectionFormat: "csv"
116116
x-exportParamName: "Status"
117117
responses:
@@ -216,12 +216,14 @@ paths:
216216
required: false
217217
type: "string"
218218
x-exportParamName: "Name"
219+
x-optionalDataType: "String"
219220
- name: "status"
220221
in: "formData"
221222
description: "Updated status of the pet"
222223
required: false
223224
type: "string"
224225
x-exportParamName: "Status"
226+
x-optionalDataType: "String"
225227
responses:
226228
405:
227229
description: "Invalid input"
@@ -244,6 +246,7 @@ paths:
244246
required: false
245247
type: "string"
246248
x-exportParamName: "ApiKey"
249+
x-optionalDataType: "String"
247250
- name: "petId"
248251
in: "path"
249252
description: "Pet id to delete"
@@ -283,6 +286,7 @@ paths:
283286
required: false
284287
type: "string"
285288
x-exportParamName: "AdditionalMetadata"
289+
x-optionalDataType: "String"
286290
- name: "file"
287291
in: "formData"
288292
description: "file to upload"
@@ -635,10 +639,10 @@ paths:
635639
type: "array"
636640
items:
637641
type: "string"
642+
default: "$"
638643
enum:
639644
- ">"
640645
- "$"
641-
default: "$"
642646
x-exportParamName: "EnumFormStringArray"
643647
- name: "enum_form_string"
644648
in: "formData"
@@ -651,17 +655,18 @@ paths:
651655
- "-efg"
652656
- "(xyz)"
653657
x-exportParamName: "EnumFormString"
658+
x-optionalDataType: "String"
654659
- name: "enum_header_string_array"
655660
in: "header"
656661
description: "Header parameter enum test (string array)"
657662
required: false
658663
type: "array"
659664
items:
660665
type: "string"
666+
default: "$"
661667
enum:
662668
- ">"
663669
- "$"
664-
default: "$"
665670
x-exportParamName: "EnumHeaderStringArray"
666671
- name: "enum_header_string"
667672
in: "header"
@@ -674,17 +679,18 @@ paths:
674679
- "-efg"
675680
- "(xyz)"
676681
x-exportParamName: "EnumHeaderString"
682+
x-optionalDataType: "String"
677683
- name: "enum_query_string_array"
678684
in: "query"
679685
description: "Query parameter enum test (string array)"
680686
required: false
681687
type: "array"
682688
items:
683689
type: "string"
690+
default: "$"
684691
enum:
685692
- ">"
686693
- "$"
687-
default: "$"
688694
x-exportParamName: "EnumQueryStringArray"
689695
- name: "enum_query_string"
690696
in: "query"
@@ -697,6 +703,7 @@ paths:
697703
- "-efg"
698704
- "(xyz)"
699705
x-exportParamName: "EnumQueryString"
706+
x-optionalDataType: "String"
700707
- name: "enum_query_integer"
701708
in: "query"
702709
description: "Query parameter enum test (double)"
@@ -707,6 +714,7 @@ paths:
707714
- 1
708715
- -2
709716
x-exportParamName: "EnumQueryInteger"
717+
x-optionalDataType: "Int32"
710718
- name: "enum_query_double"
711719
in: "formData"
712720
description: "Query parameter enum test (double)"
@@ -717,6 +725,7 @@ paths:
717725
- 1.1
718726
- -1.2
719727
x-exportParamName: "EnumQueryDouble"
728+
x-optionalDataType: "Float64"
720729
responses:
721730
400:
722731
description: "Invalid request"
@@ -745,6 +754,7 @@ paths:
745754
maximum: 100
746755
minimum: 10
747756
x-exportParamName: "Integer"
757+
x-optionalDataType: "Int32"
748758
- name: "int32"
749759
in: "formData"
750760
description: "None"
@@ -754,13 +764,15 @@ paths:
754764
minimum: 20
755765
format: "int32"
756766
x-exportParamName: "Int32_"
767+
x-optionalDataType: "Int32"
757768
- name: "int64"
758769
in: "formData"
759770
description: "None"
760771
required: false
761772
type: "integer"
762773
format: "int64"
763774
x-exportParamName: "Int64_"
775+
x-optionalDataType: "Int64"
764776
- name: "number"
765777
in: "formData"
766778
description: "None"
@@ -777,6 +789,7 @@ paths:
777789
maximum: 987.6
778790
format: "float"
779791
x-exportParamName: "Float"
792+
x-optionalDataType: "Float32"
780793
- name: "double"
781794
in: "formData"
782795
description: "None"
@@ -793,6 +806,7 @@ paths:
793806
type: "string"
794807
pattern: "/[a-z]/i"
795808
x-exportParamName: "String_"
809+
x-optionalDataType: "String"
796810
- name: "pattern_without_delimiter"
797811
in: "formData"
798812
description: "None"
@@ -814,20 +828,23 @@ paths:
814828
type: "string"
815829
format: "binary"
816830
x-exportParamName: "Binary"
831+
x-optionalDataType: "String"
817832
- name: "date"
818833
in: "formData"
819834
description: "None"
820835
required: false
821836
type: "string"
822837
format: "date"
823838
x-exportParamName: "Date"
839+
x-optionalDataType: "String"
824840
- name: "dateTime"
825841
in: "formData"
826842
description: "None"
827843
required: false
828844
type: "string"
829845
format: "date-time"
830846
x-exportParamName: "DateTime"
847+
x-optionalDataType: "Time"
831848
- name: "password"
832849
in: "formData"
833850
description: "None"
@@ -837,12 +854,14 @@ paths:
837854
minLength: 10
838855
format: "password"
839856
x-exportParamName: "Password"
857+
x-optionalDataType: "String"
840858
- name: "callback"
841859
in: "formData"
842860
description: "None"
843861
required: false
844862
type: "string"
845863
x-exportParamName: "Callback"
864+
x-optionalDataType: "String"
846865
responses:
847866
400:
848867
description: "Invalid username supplied"
@@ -998,6 +1017,8 @@ paths:
9981017
description: "successful operation"
9991018
/fake/body-with-query-params:
10001019
put:
1020+
tags:
1021+
- "fake"
10011022
operationId: "testBodyWithQueryParams"
10021023
consumes:
10031024
- "application/json"

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
package petstore
1212

1313
import (
14+
"context"
1415
"io/ioutil"
1516
"net/http"
1617
"net/url"
1718
"strings"
18-
"golang.org/x/net/context"
1919
)
2020

2121
// Linger please
@@ -25,11 +25,14 @@ var (
2525

2626
type AnotherFakeApiService service
2727

28-
/* AnotherFakeApiService To test special tags
28+
/*
29+
AnotherFakeApiService To test special tags
2930
To test special tags
30-
* @param ctx context.Context for authentication, logging, tracing, etc.
31-
@param body client model
32-
@return Client*/
31+
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
32+
* @param body client model
33+
34+
@return Client
35+
*/
3336
func (a *AnotherFakeApiService) TestSpecialTags(ctx context.Context, body Client) (Client, *http.Response, error) {
3437
var (
3538
localVarHttpMethod = strings.ToUpper("Patch")
@@ -76,6 +79,7 @@ func (a *AnotherFakeApiService) TestSpecialTags(ctx context.Context, body Client
7679
}
7780

7881
localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
82+
localVarHttpResponse.Body.Close()
7983
if err != nil {
8084
return localVarReturnValue, localVarHttpResponse, err
8185
}

0 commit comments

Comments
 (0)