Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvement to Go client generator, move test case #430

Merged
merged 5 commits into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions modules/openapi-generator/src/main/resources/go/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ var (
type {{classname}}Service service
{{#operation}}

/*
{{{classname}}}Service{{#summary}} {{.}}{{/summary}}
/*
{{{classname}}}Service{{#summary}} {{{.}}}{{/summary}}
{{#notes}}
{{notes}}
{{/notes}}
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
{{#allParams}}
{{#required}}
* @param {{paramName}}{{#description}} {{.}}{{/description}}
* @param {{paramName}}{{#description}} {{{.}}}{{/description}}
{{/required}}
{{/allParams}}
{{#hasOptionalParams}}
Expand Down Expand Up @@ -243,8 +243,12 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
} else {
key = auth.Key
}
{{#isKeyInHeader}}localVarHeaderParams["{{keyParamName}}"] = key{{/isKeyInHeader}}
{{#isKeyInQuery}}localVarQueryParams.Add("{{keyParamName}}", key){{/isKeyInQuery}}
{{#isKeyInHeader}}
localVarHeaderParams["{{keyParamName}}"] = key
{{/isKeyInHeader}}
{{#isKeyInQuery}}
localVarQueryParams.Add("{{keyParamName}}", key)
{{/isKeyInQuery}}
}
}

Expand All @@ -270,7 +274,7 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
if localVarHttpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err == nil {
if err == nil {
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, err
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,43 +272,6 @@ paths:
- petstore_auth:
- 'write:pets'
- 'read:pets'
'/pet/{petId}/uploadImageWithRequiredFile':
post:
tags:
- pet
summary: uploads an image
description: ''
operationId: uploadFileWithRequiredFile
consumes:
- multipart/form-data
produces:
- application/json
parameters:
- name: petId
in: path
description: ID of pet to update
required: true
type: integer
format: int64
- name: additionalMetadata
in: formData
description: Additional data to pass to server
required: false
type: string
- name: file
in: formData
description: file to upload
required: true
type: file
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/ApiResponse'
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
/store/inventory:
get:
tags:
Expand Down Expand Up @@ -984,6 +947,43 @@ paths:
description: successful operation
schema:
$ref: '#/definitions/Client'
'/fake/{petId}/uploadImageWithRequiredFile':
post:
tags:
- pet
summary: uploads an image (required)
description: ''
operationId: uploadFileWithRequiredFile
consumes:
- multipart/form-data
produces:
- application/json
parameters:
- name: petId
in: path
description: ID of pet to update
required: true
type: integer
format: int64
- name: additionalMetadata
in: formData
description: Additional data to pass to server
required: false
type: string
- name: file
in: formData
description: file to upload
required: true
type: file
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/ApiResponse'
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
securityDefinitions:
petstore_auth:
type: oauth2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ paths:
description: Status values that need to be considered for filter
required: true
style: form
explode: false
schema:
type: array
items:
Expand Down Expand Up @@ -111,6 +112,7 @@ paths:
description: Tags to filter by
required: true
style: form
explode: false
schema:
type: array
items:
Expand Down Expand Up @@ -265,47 +267,6 @@ paths:
description: file to upload
type: string
format: binary
'/pet/{petId}/uploadImageWithRequiredFile':
post:
tags:
- pet
summary: uploads an image
description: ''
operationId: uploadFileWithRequiredFile
parameters:
- name: petId
in: path
description: ID of pet to update
required: true
schema:
type: integer
format: int64
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
additionalMetadata:
description: Additional data to pass to server
type: string
file:
description: file to upload
type: string
format: binary
required:
- file
/store/inventory:
get:
tags:
Expand Down Expand Up @@ -612,6 +573,7 @@ paths:
parameters:
- name: enum_header_string_array
in: header
explode: true
description: Header parameter enum test (string array)
schema:
type: array
Expand Down Expand Up @@ -950,6 +912,47 @@ paths:
$ref: '#/components/schemas/Client'
requestBody:
$ref: '#/components/requestBodies/Client'
'/fake/{petId}/uploadImageWithRequiredFile':
post:
tags:
- pet
summary: uploads an image (required)
description: ''
operationId: uploadFileWithRequiredFile
parameters:
- name: petId
in: path
description: ID of pet to update
required: true
schema:
type: integer
format: int64
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
additionalMetadata:
description: Additional data to pass to server
type: string
file:
description: file to upload
type: string
format: binary
required:
- file
components:
requestBodies:
UserArray:
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.3-SNAPSHOT
3.1.0-SNAPSHOT
2 changes: 2 additions & 0 deletions samples/client/petstore/go/go-petstore-withXml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Class | Method | HTTP request | Description
*PetApi* | [**UpdatePet**](docs/PetApi.md#updatepet) | **Put** /pet | Update an existing pet
*PetApi* | [**UpdatePetWithForm**](docs/PetApi.md#updatepetwithform) | **Post** /pet/{petId} | Updates a pet in the store with form data
*PetApi* | [**UploadFile**](docs/PetApi.md#uploadfile) | **Post** /pet/{petId}/uploadImage | uploads an image
*PetApi* | [**UploadFileWithRequiredFile**](docs/PetApi.md#uploadfilewithrequiredfile) | **Post** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required)
*StoreApi* | [**DeleteOrder**](docs/StoreApi.md#deleteorder) | **Delete** /store/order/{order_id} | Delete purchase order by ID
*StoreApi* | [**GetInventory**](docs/StoreApi.md#getinventory) | **Get** /store/inventory | Returns pet inventories by status
*StoreApi* | [**GetOrderById**](docs/StoreApi.md#getorderbyid) | **Get** /store/order/{order_id} | Find purchase order by ID
Expand Down Expand Up @@ -97,6 +98,7 @@ Class | Method | HTTP request | Description
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [Return](docs/Return.md)
- [SpecialModelName](docs/SpecialModelName.md)
- [StringBooleanMap](docs/StringBooleanMap.md)
- [Tag](docs/Tag.md)
- [User](docs/User.md)

Expand Down
62 changes: 58 additions & 4 deletions samples/client/petstore/go/go-petstore-withXml/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,46 @@ paths:
summary: To test special tags
tags:
- $another-fake?
/fake/{petId}/uploadImageWithRequiredFile:
post:
operationId: uploadFileWithRequiredFile
parameters:
- description: ID of pet to update
in: path
name: petId
required: true
schema:
format: int64
type: integer
requestBody:
content:
multipart/form-data:
schema:
properties:
additionalMetadata:
description: Additional data to pass to server
type: string
file:
description: file to upload
format: binary
type: string
required:
- file
required: true
responses:
200:
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
description: successful operation
security:
- petstore_auth:
- write:pets
- read:pets
summary: uploads an image (required)
tags:
- pet
components:
schemas:
Category:
Expand Down Expand Up @@ -1276,14 +1316,18 @@ components:
type: array
type: object
OuterComposite:
example: {}
example:
my_string: my_string
my_number: 0.80082819046101150206595775671303272247314453125
my_boolean: true
properties:
my_number:
$ref: '#/components/schemas/OuterNumber'
type: number
my_string:
$ref: '#/components/schemas/OuterString'
type: string
my_boolean:
$ref: '#/components/schemas/OuterBoolean'
type: boolean
x-codegen-body-parameter-name: boolean_post_body
type: object
format_test:
properties:
Expand Down Expand Up @@ -1381,6 +1425,10 @@ components:
required:
- className
type: object
StringBooleanMap:
additionalProperties:
type: boolean
type: object
Cat:
allOf:
- $ref: '#/components/schemas/Animal'
Expand All @@ -1403,6 +1451,12 @@ components:
- lower
type: string
type: object
direct_map:
additionalProperties:
type: boolean
type: object
indirect_map:
$ref: '#/components/schemas/StringBooleanMap'
type: object
Tag:
example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (

type AnotherFakeApiService service

/*
/*
AnotherFakeApiService To test special tags
To test special tags
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
Expand Down Expand Up @@ -85,7 +85,7 @@ func (a *AnotherFakeApiService) TestSpecialTags(ctx context.Context, client Clie
if localVarHttpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err == nil {
if err == nil {
return localVarReturnValue, localVarHttpResponse, err
}
}
Expand Down
Loading