Skip to content

Commit cd01ba9

Browse files
authored
Update go samples with more tests, improve code format (#22593)
* update go samples with more tests * fix indention
1 parent 97af5d1 commit cd01ba9

File tree

10 files changed

+464
-17
lines changed

10 files changed

+464
-17
lines changed

modules/openapi-generator/src/main/resources/go/api.mustache

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,16 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class
217217
parameterAddToHeaderOrQuery(localVarQueryParams, "{{{baseName}}}", r.{{paramName}}, "{{style}}", "{{collectionFormat}}")
218218
{{/isCollectionFormatMulti}}
219219
{{#defaultValue}}} else {
220-
{{#isArray}}
221-
var defaultValue {{{dataType}}} = {{{dataType}}}{{{.}}}
222-
parameterAddToHeaderOrQuery(localVarQueryParams, "{{{baseName}}}", defaultValue, "{{style}}", "{{collectionFormat}}")
223-
r.{{paramName}} = &defaultValue
224-
{{/isArray}}
225-
{{^isArray}}
226-
var defaultValue {{{dataType}}} = {{{.}}}
227-
parameterAddToHeaderOrQuery(localVarQueryParams, "{{{baseName}}}", defaultValue, "{{style}}", "{{collectionFormat}}")
228-
r.{{paramName}} = &defaultValue
229-
{{/isArray}}
220+
{{#isArray}}
221+
var defaultValue {{{dataType}}} = {{{dataType}}}{{{.}}}
222+
parameterAddToHeaderOrQuery(localVarQueryParams, "{{{baseName}}}", defaultValue, "{{style}}", "{{collectionFormat}}")
223+
r.{{paramName}} = &defaultValue
224+
{{/isArray}}
225+
{{^isArray}}
226+
var defaultValue {{{dataType}}} = {{{.}}}
227+
parameterAddToHeaderOrQuery(localVarQueryParams, "{{{baseName}}}", defaultValue, "{{style}}", "{{collectionFormat}}")
228+
r.{{paramName}} = &defaultValue
229+
{{/isArray}}
230230
{{/defaultValue}}}
231231
{{/required}}
232232
{{/queryParams}}

modules/openapi-generator/src/test/resources/3_0/go/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,40 @@ paths:
13081308
application/json:
13091309
schema:
13101310
type: object
1311+
/fake/query-array-with-default-values:
1312+
post:
1313+
tags:
1314+
- fake
1315+
summary: to test query array with default values
1316+
operationId: query_array_with_default_values
1317+
requestBody:
1318+
content:
1319+
application/json:
1320+
schema:
1321+
type: string
1322+
parameters:
1323+
- name: "arrayparam"
1324+
in: query
1325+
schema:
1326+
type: array
1327+
items:
1328+
type: string
1329+
default: ["test1", "test2"]
1330+
- name: "enumarrayparam"
1331+
in: query
1332+
schema:
1333+
type: array
1334+
items:
1335+
$ref: "#/components/schemas/ExampleEnum"
1336+
default: ["example1"]
1337+
- name: "stringparam"
1338+
in: query
1339+
schema:
1340+
type: string
1341+
default: "test3"
1342+
responses:
1343+
200:
1344+
description: Ok
13111345
servers:
13121346
- url: 'http://localhost/v2'
13131347
- url: 'http://{server}.swagger.io:{port}/v2'
@@ -2306,3 +2340,8 @@ components:
23062340
- type: array
23072341
items:
23082342
type: string
2343+
ExampleEnum:
2344+
type: string
2345+
enum:
2346+
- example1
2347+
- example2

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

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/openapi3/client/petstore/go/go-petstore/.openapi-generator/FILES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ docs/DuplicatedPropParent.md
3838
docs/EnumArrays.md
3939
docs/EnumClass.md
4040
docs/EnumTest.md
41+
docs/ExampleEnum.md
4142
docs/FakeAPI.md
4243
docs/FakeClassnameTags123API.md
4344
docs/File.md
@@ -123,6 +124,7 @@ model_duplicated_prop_parent.go
123124
model_enum_arrays.go
124125
model_enum_class.go
125126
model_enum_test_.go
127+
model_example_enum.go
126128
model_file.go
127129
model_file_schema_test_class.go
128130
model_filter_any.go

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Class | Method | HTTP request | Description
8888
*FakeAPI* | [**FakeOuterNumberSerialize**](docs/FakeAPI.md#fakeouternumberserialize) | **Post** /fake/outer/number |
8989
*FakeAPI* | [**FakeOuterStringSerialize**](docs/FakeAPI.md#fakeouterstringserialize) | **Post** /fake/outer/string |
9090
*FakeAPI* | [**GetParameterNameMapping**](docs/FakeAPI.md#getparameternamemapping) | **Get** /fake/parameter-name-mapping | parameter name mapping test
91+
*FakeAPI* | [**QueryArrayWithDefaultValues**](docs/FakeAPI.md#queryarraywithdefaultvalues) | **Post** /fake/query-array-with-default-values | to test query array with default values
9192
*FakeAPI* | [**TestAdditionalPropertiesReference**](docs/FakeAPI.md#testadditionalpropertiesreference) | **Post** /fake/additionalProperties-reference | test referenced additionalProperties
9293
*FakeAPI* | [**TestBodyWithFileSchema**](docs/FakeAPI.md#testbodywithfileschema) | **Put** /fake/body-with-file-schema |
9394
*FakeAPI* | [**TestBodyWithQueryParams**](docs/FakeAPI.md#testbodywithqueryparams) | **Put** /fake/body-with-query-params |
@@ -154,6 +155,7 @@ Class | Method | HTTP request | Description
154155
- [EnumArrays](docs/EnumArrays.md)
155156
- [EnumClass](docs/EnumClass.md)
156157
- [EnumTest](docs/EnumTest.md)
158+
- [ExampleEnum](docs/ExampleEnum.md)
157159
- [File](docs/File.md)
158160
- [FileSchemaTestClass](docs/FileSchemaTestClass.md)
159161
- [FilterAny](docs/FilterAny.md)

samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,52 @@ paths:
12671267
schema:
12681268
type: object
12691269
description: success
1270+
/fake/query-array-with-default-values:
1271+
post:
1272+
operationId: query_array_with_default_values
1273+
parameters:
1274+
- explode: true
1275+
in: query
1276+
name: arrayparam
1277+
required: false
1278+
schema:
1279+
default:
1280+
- test1
1281+
- test2
1282+
items:
1283+
type: string
1284+
type: array
1285+
style: form
1286+
- explode: true
1287+
in: query
1288+
name: enumarrayparam
1289+
required: false
1290+
schema:
1291+
default:
1292+
- example1
1293+
items:
1294+
$ref: "#/components/schemas/ExampleEnum"
1295+
type: array
1296+
style: form
1297+
- explode: true
1298+
in: query
1299+
name: stringparam
1300+
required: false
1301+
schema:
1302+
default: test3
1303+
type: string
1304+
style: form
1305+
requestBody:
1306+
content:
1307+
application/json:
1308+
schema:
1309+
type: string
1310+
responses:
1311+
"200":
1312+
description: Ok
1313+
summary: to test query array with default values
1314+
tags:
1315+
- fake
12701316
components:
12711317
requestBodies:
12721318
UserArray:
@@ -2286,6 +2332,11 @@ components:
22862332
- items:
22872333
type: string
22882334
type: array
2335+
ExampleEnum:
2336+
enum:
2337+
- example1
2338+
- example2
2339+
type: string
22892340
_foo_get_default_response:
22902341
example:
22912342
string:

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

Lines changed: 164 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ExampleEnum
2+
3+
## Enum
4+
5+
6+
* `EXAMPLE1` (value: `"example1"`)
7+
8+
* `EXAMPLE2` (value: `"example2"`)
9+
10+
11+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
12+
13+

0 commit comments

Comments
 (0)