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
2 changes: 1 addition & 1 deletion bin/go-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/go -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l go -o samples/client/petstore/go/go-petstore -DpackageName=petstore "
ags="$@ generate -t modules/swagger-codegen/src/main/resources/go -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l go -o samples/client/petstore/go/go-petstore -DpackageName=petstore "

java $JAVA_OPTS -jar $executable $ags
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public GoClientCodegen() {

setReservedWordsLowerCase(
Arrays.asList(
// data type
"string", "bool", "uint", "uint8", "uint16", "uint32", "uint64",
"int", "int8", "int16", "int32", "int64", "float32", "float64",
"complex64", "complex128", "rune", "byte", "uintptr",

"break", "default", "func", "interface", "select",
"case", "defer", "go", "map", "struct",
"chan", "else", "goto", "package", "switch",
Expand Down Expand Up @@ -91,6 +96,7 @@ public GoClientCodegen() {
typeMapping.put("double", "float64");
typeMapping.put("boolean", "bool");
typeMapping.put("string", "string");
typeMapping.put("UUID", "string");
typeMapping.put("date", "time.Time");
typeMapping.put("DateTime", "time.Time");
typeMapping.put("password", "string");
Expand Down Expand Up @@ -192,9 +198,13 @@ public String toVarName(String name) {
name = camelize(name);

// for reserved word or word starting with number, append _
if(isReservedWord(name) || name.matches("^\\d.*"))
if (isReservedWord(name))
name = escapeReservedWord(name);

// for reserved word or word starting with number, append _
if (name.matches("^\\d.*"))
name = "Var" + name;

return name;
}

Expand Down Expand Up @@ -230,10 +240,16 @@ public String toModelFilename(String name) {

// model name cannot use reserved keyword, e.g. return
if (isReservedWord(name)) {
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name));
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + ("model_" + name));
name = "model_" + name; // e.g. return => ModelReturn (after camelize)
}

// model name starts with number
if (name.matches("^\\d.*")) {
LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + ("model_" + name));
name = "model_" + name; // e.g. 200Response => Model200Response (after camelize)
}

return underscore(name);
}

Expand Down
18 changes: 13 additions & 5 deletions modules/swagger-codegen/src/main/resources/go/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,21 @@ func (a {{{classname}}}) {{{nickname}}}({{#allParams}}{{paramName}} {{{dataType}
}{{#hasHeaderParams}}

{{#headerParams}} // header params "{{baseName}}"
localVarHeaderParams["{{baseName}}"] = {{paramName}}
{{/headerParams}}{{/hasHeaderParams}}{{#hasFormParams}}
{{#formParams}}{{#isFile}}
localVarHeaderParams["{{baseName}}"] = a.Configuration.APIClient.ParameterToString({{paramName}}, "")
{{/headerParams}}{{/hasHeaderParams}}
{{#hasFormParams}}
{{#formParams}}
{{#isFile}}
fbs, _ := ioutil.ReadAll(file)
localVarFileBytes = fbs
localVarFileName = file.Name(){{/isFile}}
{{^isFile}} localVarFormParams["{{paramName}}"] = {{paramName}}{{/isFile}}{{/formParams}}{{/hasFormParams}}{{#hasBodyParam}}
localVarFileName = file.Name()
{{/isFile}}
{{^isFile}}
localVarFormParams["{{paramName}}"] = a.Configuration.APIClient.ParameterToString({{paramName}}, "")
{{/isFile}}
{{/formParams}}
{{/hasFormParams}}
{{#hasBodyParam}}
{{#bodyParams}} // body params
localVarPostBody = &{{paramName}}
{{/bodyParams}}{{/hasBodyParam}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,8 @@ paths:
description: Invalid username supplied
'404':
description: User not found

security:
- http_basic_test: []
securityDefinitions:
petstore_auth:
type: oauth2
Expand All @@ -784,6 +785,8 @@ securityDefinitions:
type: apiKey
name: api_key
in: header
http_basic_test:
type: basic
definitions:
Order:
type: object
Expand Down
34 changes: 32 additions & 2 deletions samples/client/petstore/go/go-petstore/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Go API client for petstore

This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\

## Overview
This API client was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [swagger-spec](https://github.com/swagger-api/swagger-spec) from a remote server, you can easily generate an API client.

- API version: 1.0.0
- Package version: 1.0.0
- Build date: 2016-08-10T15:46:53.636+08:00
- Build date: 2016-08-11T12:21:56.063+08:00
- Build package: class io.swagger.codegen.languages.GoClientCodegen

## Installation
Expand All @@ -22,6 +22,9 @@ All URIs are relative to *http://petstore.swagger.io/v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*FakeApi* | [**TestClientModel**](docs/FakeApi.md#testclientmodel) | **Patch** /fake | To test \"client\" model
*FakeApi* | [**TestEndpointParameters**](docs/FakeApi.md#testendpointparameters) | **Post** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
*FakeApi* | [**TestEnumParameters**](docs/FakeApi.md#testenumparameters) | **Get** /fake | To test enum parameters
*PetApi* | [**AddPet**](docs/PetApi.md#addpet) | **Post** /pet | Add a new pet to the store
*PetApi* | [**DeletePet**](docs/PetApi.md#deletepet) | **Delete** /pet/{petId} | Deletes a pet
*PetApi* | [**FindPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **Get** /pet/findByStatus | Finds Pets by status
Expand All @@ -46,10 +49,33 @@ Class | Method | HTTP request | Description

## Documentation For Models

- [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
- [Animal](docs/Animal.md)
- [AnimalFarm](docs/AnimalFarm.md)
- [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
- [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
- [ArrayTest](docs/ArrayTest.md)
- [Cat](docs/Cat.md)
- [Category](docs/Category.md)
- [Client](docs/Client.md)
- [Dog](docs/Dog.md)
- [EnumArrays](docs/EnumArrays.md)
- [EnumClass](docs/EnumClass.md)
- [EnumTest](docs/EnumTest.md)
- [FormatTest](docs/FormatTest.md)
- [HasOnlyReadOnly](docs/HasOnlyReadOnly.md)
- [List](docs/List.md)
- [MapTest](docs/MapTest.md)
- [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
- [Model200Response](docs/Model200Response.md)
- [ModelApiResponse](docs/ModelApiResponse.md)
- [ModelReturn](docs/ModelReturn.md)
- [Name](docs/Name.md)
- [NumberOnly](docs/NumberOnly.md)
- [Order](docs/Order.md)
- [Pet](docs/Pet.md)
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [SpecialModelName](docs/SpecialModelName.md)
- [Tag](docs/Tag.md)
- [User](docs/User.md)

Expand All @@ -72,6 +98,10 @@ Class | Method | HTTP request | Description
- **write:pets**: modify pets in your account
- **read:pets**: read your pets

## http_basic_test

- **Type**: HTTP basic authentication


## Author

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/go/go-petstore/api_client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Swagger Petstore
*
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/go/go-petstore/api_response.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Swagger Petstore
*
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/go/go-petstore/category.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Swagger Petstore
*
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/go/go-petstore/configuration.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Swagger Petstore
*
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Swagger Petstore
*
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/go/go-petstore/order.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Swagger Petstore
*
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/go/go-petstore/pet.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Swagger Petstore
*
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
Expand Down
15 changes: 9 additions & 6 deletions samples/client/petstore/go/go-petstore/pet_api.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Swagger Petstore
*
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
Expand Down Expand Up @@ -165,7 +165,8 @@ func (a PetApi) DeletePet(petId int64, apiKey string) (*APIResponse, error) {
}

// header params "api_key"
localVarHeaderParams["api_key"] = apiKey
localVarHeaderParams["api_key"] = a.Configuration.APIClient.ParameterToString(apiKey, "")



localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
Expand Down Expand Up @@ -233,6 +234,7 @@ func (a PetApi) FindPetsByStatus(status []string) ([]Pet, *APIResponse, error) {
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}

var successPayload = new([]Pet)
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
if err != nil {
Expand Down Expand Up @@ -299,6 +301,7 @@ func (a PetApi) FindPetsByTags(tags []string) ([]Pet, *APIResponse, error) {
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}

var successPayload = new([]Pet)
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
if err != nil {
Expand Down Expand Up @@ -356,6 +359,7 @@ func (a PetApi) GetPetById(petId int64) (*Pet, *APIResponse, error) {
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}

var successPayload = new(Pet)
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
if err != nil {
Expand Down Expand Up @@ -478,9 +482,9 @@ func (a PetApi) UpdatePetWithForm(petId int64, name string, status string) (*API
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}
localVarFormParams["name"] = a.Configuration.APIClient.ParameterToString(name, "")
localVarFormParams["status"] = a.Configuration.APIClient.ParameterToString(status, "")

localVarFormParams["name"] = name
localVarFormParams["status"] = status

localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
if err != nil {
Expand Down Expand Up @@ -541,8 +545,7 @@ func (a PetApi) UploadFile(petId int64, additionalMetadata string, file *os.File
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}

localVarFormParams["additionalMetadata"] = additionalMetadata
localVarFormParams["additionalMetadata"] = a.Configuration.APIClient.ParameterToString(additionalMetadata, "")
fbs, _ := ioutil.ReadAll(file)
localVarFileBytes = fbs
localVarFileName = file.Name()
Expand Down
5 changes: 4 additions & 1 deletion samples/client/petstore/go/go-petstore/store_api.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Swagger Petstore
*
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
Expand Down Expand Up @@ -95,6 +95,7 @@ func (a StoreApi) DeleteOrder(orderId string) (*APIResponse, error) {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}


localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
if err != nil {
return NewAPIResponse(localVarHttpResponse.RawResponse), err
Expand Down Expand Up @@ -148,6 +149,7 @@ func (a StoreApi) GetInventory() (*map[string]int32, *APIResponse, error) {
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}

var successPayload = new(map[string]int32)
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
if err != nil {
Expand Down Expand Up @@ -202,6 +204,7 @@ func (a StoreApi) GetOrderById(orderId int64) (*Order, *APIResponse, error) {
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}

var successPayload = new(Order)
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/go/go-petstore/tag.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Swagger Petstore
*
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/go/go-petstore/user.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Swagger Petstore
*
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
Expand Down
Loading