Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,11 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
iterator.remove();
}

// this will only import "fmt" if there are items in pathParams
// this will only import "fmt" and "strings" if there are items in pathParams
for (CodegenOperation operation : operations) {
if (operation.pathParams != null && operation.pathParams.size() > 0) {
imports.add(createMapping("import", "fmt"));
imports.add(createMapping("import", "strings"));
break; //just need to import once
}
}
Expand Down
3 changes: 1 addition & 2 deletions modules/openapi-generator/src/main/resources/go/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"net/http"
"net/url"
"strings"
{{#imports}} "{{import}}"
{{/imports}}
)
Expand Down Expand Up @@ -66,7 +65,7 @@ type {{{nickname}}}Opts struct {
{{/hasOptionalParams}}
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) {
var (
localVarHttpMethod = strings.ToUpper("{{httpMethod}}")
localVarHttpMethod = http.Method{{httpMethod}}
localVarPostBody interface{}
localVarFormFileName string
localVarFileName string
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.0-SNAPSHOT
4.0.1-SNAPSHOT
48 changes: 39 additions & 9 deletions samples/client/petstore/go/go-petstore-withXml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
## Installation

Install the following dependencies:
```

```shell
go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context
go get github.com/antihax/optional
```

Put the package under your project folder and add the following in import:

```golang
import "./petstore"
```
Expand Down Expand Up @@ -70,18 +72,27 @@ Class | Method | HTTP request | Description

## Documentation For Models

- [AdditionalPropertiesAnyType](docs/AdditionalPropertiesAnyType.md)
- [AdditionalPropertiesArray](docs/AdditionalPropertiesArray.md)
- [AdditionalPropertiesBoolean](docs/AdditionalPropertiesBoolean.md)
- [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
- [AdditionalPropertiesInteger](docs/AdditionalPropertiesInteger.md)
- [AdditionalPropertiesNumber](docs/AdditionalPropertiesNumber.md)
- [AdditionalPropertiesObject](docs/AdditionalPropertiesObject.md)
- [AdditionalPropertiesString](docs/AdditionalPropertiesString.md)
- [Animal](docs/Animal.md)
- [ApiResponse](docs/ApiResponse.md)
- [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
- [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
- [ArrayTest](docs/ArrayTest.md)
- [Capitalization](docs/Capitalization.md)
- [Cat](docs/Cat.md)
- [CatAllOf](docs/CatAllOf.md)
- [Category](docs/Category.md)
- [ClassModel](docs/ClassModel.md)
- [Client](docs/Client.md)
- [Dog](docs/Dog.md)
- [DogAllOf](docs/DogAllOf.md)
- [EnumArrays](docs/EnumArrays.md)
- [EnumClass](docs/EnumClass.md)
- [EnumTest](docs/EnumTest.md)
Expand Down Expand Up @@ -111,40 +122,56 @@ Class | Method | HTTP request | Description

## Documentation For Authorization



## api_key
- **Type**: API key

- **Type**: API key

Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
r, err := client.Service.Operation(auth, args)
```


## api_key_query
- **Type**: API key

- **Type**: API key

Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
r, err := client.Service.Operation(auth, args)
```


## http_basic_test

- **Type**: HTTP basic authentication

Example

```golang
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
UserName: "username",
Password: "password",
UserName: "username",
Password: "password",
})
r, err := client.Service.Operation(auth, args)
```


## petstore_auth


- **Type**: OAuth
- **Flow**: implicit
- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog
Expand All @@ -153,12 +180,14 @@ r, err := client.Service.Operation(auth, args)
- **read:pets**: read your pets

Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```

Or via OAuth2 module to automatically refresh tokens and perform user authentication.

```golang
import "golang.org/x/oauth2"

Expand All @@ -169,6 +198,7 @@ auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource)
r, err := client.Service.Operation(auth, args)
```


## Author


Expand Down
41 changes: 28 additions & 13 deletions samples/client/petstore/go/go-petstore-withXml/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ paths:
description: Pet object that needs to be added to the store
required: true
responses:
200:
content: {}
description: successful operation
405:
content: {}
description: Invalid input
Expand All @@ -56,6 +59,9 @@ paths:
description: Pet object that needs to be added to the store
required: true
responses:
200:
content: {}
description: successful operation
400:
content: {}
description: Invalid ID supplied
Expand Down Expand Up @@ -120,7 +126,8 @@ paths:
/pet/findByTags:
get:
deprecated: true
description: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
description: Multiple tags can be provided with comma separated strings. Use
tag1, tag2, tag3 for testing.
operationId: findPetsByTags
parameters:
- description: Tags to filter by
Expand Down Expand Up @@ -173,6 +180,9 @@ paths:
format: int64
type: integer
responses:
200:
content: {}
description: successful operation
400:
content: {}
description: Invalid pet value
Expand Down Expand Up @@ -332,7 +342,8 @@ paths:
x-codegen-request-body-name: body
/store/order/{order_id}:
delete:
description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
description: For valid response try integer IDs with value < 1000. Anything
above 1000 or nonintegers will generate API errors
operationId: deleteOrder
parameters:
- description: ID of the order that needs to be deleted
Expand All @@ -352,7 +363,8 @@ paths:
tags:
- store
get:
description: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
description: For valid response try integer IDs with value <= 5 or > 10. Other
values will generated exceptions
operationId: getOrderById
parameters:
- description: ID of pet that needs to be fetched
Expand Down Expand Up @@ -1072,7 +1084,8 @@ paths:
x-codegen-request-body-name: body
/fake/body-with-file-schema:
put:
description: For this test, the body for this request much reference a schema named `File`.
description: For this test, the body for this request much reference a schema
named `File`.
operationId: testBodyWithFileSchema
requestBody:
content:
Expand Down Expand Up @@ -1350,17 +1363,11 @@ components:
Dog:
allOf:
- $ref: '#/components/schemas/Animal'
- properties:
breed:
type: string
type: object
- $ref: '#/components/schemas/Dog_allOf'
Cat:
allOf:
- $ref: '#/components/schemas/Animal'
- properties:
declawed:
type: boolean
type: object
- $ref: '#/components/schemas/Cat_allOf'
Animal:
discriminator:
propertyName: className
Expand Down Expand Up @@ -2009,6 +2016,14 @@ components:
xml:
namespace: http://a.com/schema
prefix: pre
Dog_allOf:
properties:
breed:
type: string
Cat_allOf:
properties:
declawed:
type: boolean
securitySchemes:
petstore_auth:
flows:
Expand All @@ -2028,4 +2043,4 @@ components:
type: apiKey
http_basic_test:
scheme: basic
type: http
type: http

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading