Fix data type shadowing

This commit is contained in:
antihax 2018-04-29 12:16:17 -07:00
parent d8165b0cfb
commit 622a75b2ce
16 changed files with 209 additions and 173 deletions

View File

@ -35,6 +35,21 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
"array")
);
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",
"const", "fallthrough", "if", "range", "type",
"continue", "for", "import", "return", "var", "error", "nil")
// Added "error" as it's used so frequently that it may as well be a keyword
);
languageSpecificPrimitives = new HashSet<String>(
Arrays.asList(
"string",
@ -123,9 +138,11 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
// pet_id => PetId
name = camelize(name);
// for reserved word or word starting with number, append _
if (isReservedWord(name))
// for reserved word append _
if (isReservedWord(name)) {
LOGGER.warn(name + " (reserved word) cannot be used as variable name. Renamed to "+ escapeReservedWord(name));
name = escapeReservedWord(name);
}
// for reserved word or word starting with number, append _
if (name.matches("^\\d.*"))
@ -134,15 +151,27 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
return name;
}
@Override
protected boolean isReservedWord(String word) {
return word != null && reservedWords.contains(word);
}
@Override
public String toParamName(String name) {
// params should be lowerCamelCase. E.g. "person Person", instead of
// "Person Person".
//
name = camelize(toVarName(name), true);
// REVISIT: Actually, for idiomatic go, the param name should
// really should just be a letter, e.g. "p Person"), but we'll get
// around to that some other time... Maybe.
return camelize(toVarName(name), true);
if (isReservedWord(name)) {
LOGGER.warn(name + " (reserved word) cannot be used as parameter name. Renamed to "+ name + "_");
name = name + "_";
}
return name;
}
@Override

View File

@ -35,21 +35,6 @@ public class GoClientCodegen extends AbstractGoCodegen {
// default HIDE_GENERATION_TIMESTAMP to true
hideGenerationTimestamp = Boolean.TRUE;
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",
"const", "fallthrough", "if", "range", "type",
"continue", "for", "import", "return", "var", "error", "ApiResponse", "nil")
// Added "error" as it's used so frequently that it may as well be a keyword
);
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "Go package version.")
.defaultValue("1.0.0"));
cliOptions.add(CliOption.newBoolean(WITH_XML, "whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)"));

View File

@ -60,6 +60,7 @@ Class | Method | HTTP request | Description
- [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
- [Animal](docs/Animal.md)
- [AnimalFarm](docs/AnimalFarm.md)
- [ApiResponse](docs/ApiResponse.md)
- [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
- [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
- [ArrayTest](docs/ArrayTest.md)
@ -78,8 +79,6 @@ Class | Method | HTTP request | Description
- [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)
@ -87,6 +86,7 @@ Class | Method | HTTP request | Description
- [OuterEnum](docs/OuterEnum.md)
- [Pet](docs/Pet.md)
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [Return](docs/Return.md)
- [SpecialModelName](docs/SpecialModelName.md)
- [Tag](docs/Tag.md)
- [User](docs/User.md)

View File

@ -100,11 +100,11 @@ paths:
type: array
items:
type: string
default: available
enum:
- available
- pending
- sold
default: available
responses:
200:
description: successful operation
@ -613,20 +613,20 @@ paths:
type: array
items:
type: string
default: $
enum:
- '>'
- $
default: $
- name: enum_header_string
in: header
description: Header parameter enum test (string)
schema:
type: string
default: -efg
enum:
- _abc
- -efg
- (xyz)
default: -efg
- name: enum_query_string_array
in: query
description: Query parameter enum test (string array)
@ -635,20 +635,20 @@ paths:
type: array
items:
type: string
default: $
enum:
- '>'
- $
default: $
- name: enum_query_string
in: query
description: Query parameter enum test (string)
schema:
type: string
default: -efg
enum:
- _abc
- -efg
- (xyz)
default: -efg
- name: enum_query_integer
in: query
description: Query parameter enum test (double)
@ -677,18 +677,18 @@ paths:
description: Form parameter enum test (string array)
items:
type: string
default: $
enum:
- '>'
- $
default: $
enum_form_string:
type: string
description: Form parameter enum test (string)
default: -efg
enum:
- _abc
- -efg
- (xyz)
default: -efg
responses:
400:
description: Invalid request
@ -1100,11 +1100,11 @@ components:
name: Name
EnumClass:
type: string
default: -efg
enum:
- _abc
- -efg
- (xyz)
default: -efg
List:
type: object
properties:

View File

@ -11,13 +11,13 @@
package petstore
import (
"context"
"github.com/antihax/optional"
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"
"context"
"github.com/antihax/optional"
"os"
)
// Linger please
@ -96,7 +96,7 @@ func (a *FakeApiService) FakeOuterBooleanSerialize(ctx context.Context, localVar
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"))
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err == nil {
return localVarReturnValue, localVarHttpResponse, err
}
@ -109,7 +109,7 @@ func (a *FakeApiService) FakeOuterBooleanSerialize(ctx context.Context, localVar
}
if localVarHttpResponse.StatusCode == 200 {
var v bool
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"))
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHttpResponse, newErr
@ -196,7 +196,7 @@ func (a *FakeApiService) FakeOuterCompositeSerialize(ctx context.Context, localV
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"))
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err == nil {
return localVarReturnValue, localVarHttpResponse, err
}
@ -209,7 +209,7 @@ func (a *FakeApiService) FakeOuterCompositeSerialize(ctx context.Context, localV
}
if localVarHttpResponse.StatusCode == 200 {
var v OuterComposite
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"))
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHttpResponse, newErr
@ -292,7 +292,7 @@ func (a *FakeApiService) FakeOuterNumberSerialize(ctx context.Context, localVarO
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"))
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err == nil {
return localVarReturnValue, localVarHttpResponse, err
}
@ -305,7 +305,7 @@ func (a *FakeApiService) FakeOuterNumberSerialize(ctx context.Context, localVarO
}
if localVarHttpResponse.StatusCode == 200 {
var v float32
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"))
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHttpResponse, newErr
@ -388,7 +388,7 @@ func (a *FakeApiService) FakeOuterStringSerialize(ctx context.Context, localVarO
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"))
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err == nil {
return localVarReturnValue, localVarHttpResponse, err
}
@ -401,7 +401,7 @@ func (a *FakeApiService) FakeOuterStringSerialize(ctx context.Context, localVarO
}
if localVarHttpResponse.StatusCode == 200 {
var v string
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"))
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHttpResponse, newErr
@ -543,7 +543,7 @@ func (a *FakeApiService) TestClientModel(ctx context.Context, client Client) (Cl
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"))
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err == nil {
return localVarReturnValue, localVarHttpResponse, err
}
@ -556,7 +556,7 @@ func (a *FakeApiService) TestClientModel(ctx context.Context, client Client) (Cl
}
if localVarHttpResponse.StatusCode == 200 {
var v Client
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"))
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHttpResponse, newErr
@ -577,13 +577,13 @@ Fake endpoint for testing various parameters 假端點 偽のエンドポイン
* @param number None
* @param double None
* @param patternWithoutDelimiter None
* @param byte None
* @param byte_ None
* @param optional nil or *TestEndpointParametersOpts - Optional Parameters:
* @param "Integer" (optional.Int32) - None
* @param "Int32" (optional.Int32) - None
* @param "Int64" (optional.Int64) - None
* @param "Int32_" (optional.Int32) - None
* @param "Int64_" (optional.Int64) - None
* @param "Float" (optional.Float32) - None
* @param "String" (optional.String) - None
* @param "String_" (optional.String) - None
* @param "Binary" (optional.Interface of *os.File) - None
* @param "Date" (optional.String) - None
* @param "DateTime" (optional.Time) - None
@ -593,10 +593,10 @@ Fake endpoint for testing various parameters 假端點 偽のエンドポイン
type TestEndpointParametersOpts struct {
Integer optional.Int32
Int32 optional.Int32
Int64 optional.Int64
Int32_ optional.Int32
Int64_ optional.Int64
Float optional.Float32
String optional.String
String_ optional.String
Binary optional.Interface
Date optional.String
DateTime optional.Time
@ -604,7 +604,7 @@ type TestEndpointParametersOpts struct {
Callback optional.String
}
func (a *FakeApiService) TestEndpointParameters(ctx context.Context, number float32, double float64, patternWithoutDelimiter string, byte string, localVarOptionals *TestEndpointParametersOpts) (*http.Response, error) {
func (a *FakeApiService) TestEndpointParameters(ctx context.Context, number float32, double float64, patternWithoutDelimiter string, byte_ string, localVarOptionals *TestEndpointParametersOpts) (*http.Response, error) {
var (
localVarHttpMethod = strings.ToUpper("Post")
localVarPostBody interface{}
@ -651,22 +651,22 @@ func (a *FakeApiService) TestEndpointParameters(ctx context.Context, number floa
if localVarOptionals != nil && localVarOptionals.Integer.IsSet() {
localVarFormParams.Add("integer", parameterToString(localVarOptionals.Integer.Value(), ""))
}
if localVarOptionals != nil && localVarOptionals.Int32.IsSet() {
localVarFormParams.Add("int32", parameterToString(localVarOptionals.Int32.Value(), ""))
if localVarOptionals != nil && localVarOptionals.Int32_.IsSet() {
localVarFormParams.Add("int32", parameterToString(localVarOptionals.Int32_.Value(), ""))
}
if localVarOptionals != nil && localVarOptionals.Int64.IsSet() {
localVarFormParams.Add("int64", parameterToString(localVarOptionals.Int64.Value(), ""))
if localVarOptionals != nil && localVarOptionals.Int64_.IsSet() {
localVarFormParams.Add("int64", parameterToString(localVarOptionals.Int64_.Value(), ""))
}
localVarFormParams.Add("number", parameterToString(number, ""))
if localVarOptionals != nil && localVarOptionals.Float.IsSet() {
localVarFormParams.Add("float", parameterToString(localVarOptionals.Float.Value(), ""))
}
localVarFormParams.Add("double", parameterToString(double, ""))
if localVarOptionals != nil && localVarOptionals.String.IsSet() {
localVarFormParams.Add("string", parameterToString(localVarOptionals.String.Value(), ""))
if localVarOptionals != nil && localVarOptionals.String_.IsSet() {
localVarFormParams.Add("string", parameterToString(localVarOptionals.String_.Value(), ""))
}
localVarFormParams.Add("pattern_without_delimiter", parameterToString(patternWithoutDelimiter, ""))
localVarFormParams.Add("byte", parameterToString(byte, ""))
localVarFormParams.Add("byte", parameterToString(byte_, ""))
var localVarFile *os.File
if localVarOptionals != nil && localVarOptionals.Binary.IsSet() {
localVarFileOk := false

View File

@ -594,7 +594,7 @@ PetApiService uploads an image
* @param optional nil or *UploadFileOpts - Optional Parameters:
* @param "AdditionalMetadata" (optional.String) - Additional data to pass to server
* @param "File" (optional.Interface of *os.File) - file to upload
@return ModelApiResponse
@return ApiResponse
*/
type UploadFileOpts struct {
@ -602,13 +602,13 @@ type UploadFileOpts struct {
File optional.Interface
}
func (a *PetApiService) UploadFile(ctx context.Context, petId int64, localVarOptionals *UploadFileOpts) (ModelApiResponse, *http.Response, error) {
func (a *PetApiService) UploadFile(ctx context.Context, petId int64, localVarOptionals *UploadFileOpts) (ApiResponse, *http.Response, error) {
var (
localVarHttpMethod = strings.ToUpper("Post")
localVarPostBody interface{}
localVarFileName string
localVarFileBytes []byte
localVarReturnValue ModelApiResponse
localVarReturnValue ApiResponse
)
// create path and map variables
@ -683,7 +683,7 @@ func (a *PetApiService) UploadFile(ctx context.Context, petId int64, localVarOpt
error: localVarHttpResponse.Status,
}
if localVarHttpResponse.StatusCode == 200 {
var v ModelApiResponse
var v ApiResponse
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err != nil {
newErr.error = err.Error()

View File

@ -0,0 +1,12 @@
# ApiResponse
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Code** | **int32** | | [optional] [default to null]
**Type** | **string** | | [optional] [default to null]
**Message** | **string** | | [optional] [default to null]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -212,7 +212,7 @@ No authorization required
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **TestEndpointParameters**
> TestEndpointParameters(ctx, number, double, patternWithoutDelimiter, byte, optional)
> TestEndpointParameters(ctx, number, double, patternWithoutDelimiter, byte_, optional)
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
@ -225,7 +225,7 @@ Name | Type | Description | Notes
**number** | **float32**| None |
**double** | **float64**| None |
**patternWithoutDelimiter** | **string**| None |
**byte** | **string**| None |
**byte_** | **string**| None |
**optional** | ***TestEndpointParametersOpts** | optional parameters | nil if no parameters
### Optional Parameters
@ -238,10 +238,10 @@ Name | Type | Description | Notes
**integer** | **optional.Int32**| None |
**int32** | **optional.Int32**| None |
**int64** | **optional.Int64**| None |
**int32_** | **optional.Int32**| None |
**int64_** | **optional.Int64**| None |
**float** | **optional.Float32**| None |
**string** | **optional.String**| None |
**string_** | **optional.String**| None |
**binary** | **optional.Interface of *os.File****optional.*os.File**| None |
**date** | **optional.String**| None |
**dateTime** | **optional.Time**| None |

View File

@ -4,13 +4,13 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Integer** | **int32** | | [optional] [default to null]
**Int32_** | **int32** | | [optional] [default to null]
**Int64_** | **int64** | | [optional] [default to null]
**Int32** | **int32** | | [optional] [default to null]
**Int64** | **int64** | | [optional] [default to null]
**Number** | **float32** | | [default to null]
**Float** | **float32** | | [optional] [default to null]
**Double** | **float64** | | [optional] [default to null]
**String_** | **string** | | [optional] [default to null]
**Byte_** | **string** | | [default to null]
**String** | **string** | | [optional] [default to null]
**Byte** | **string** | | [default to null]
**Binary** | [****os.File**](*os.File.md) | | [optional] [default to null]
**Date** | **string** | | [default to null]
**DateTime** | [**time.Time**](time.Time.md) | | [optional] [default to null]

View File

@ -5,7 +5,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Uuid** | **string** | | [optional] [default to null]
**DateTime** | [**time.Time**](time.Time.md) | | [optional] [default to null]
**Map_** | [**map[string]Animal**](Animal.md) | | [optional] [default to null]
**Map** | [**map[string]Animal**](Animal.md) | | [optional] [default to null]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -222,7 +222,7 @@ Name | Type | Description | Notes
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **UploadFile**
> ModelApiResponse UploadFile(ctx, petId, optional)
> ApiResponse UploadFile(ctx, petId, optional)
uploads an image
### Required Parameters
@ -244,7 +244,7 @@ Name | Type | Description | Notes
### Return type
[**ModelApiResponse**](ApiResponse.md)
[**ApiResponse**](ApiResponse.md)
### Authorization

View File

@ -0,0 +1,10 @@
# Return
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Return** | **int32** | | [optional] [default to null]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -10,8 +10,8 @@
package petstore
type ModelApiResponse struct {
type ApiResponse struct {
Code int32 `json:"code,omitempty"`
Type_ string `json:"type,omitempty"`
Type string `json:"type,omitempty"`
Message string `json:"message,omitempty"`
}

View File

@ -16,13 +16,13 @@ import (
type FormatTest struct {
Integer int32 `json:"integer,omitempty"`
Int32_ int32 `json:"int32,omitempty"`
Int64_ int64 `json:"int64,omitempty"`
Int32 int32 `json:"int32,omitempty"`
Int64 int64 `json:"int64,omitempty"`
Number float32 `json:"number"`
Float float32 `json:"float,omitempty"`
Double float64 `json:"double,omitempty"`
String_ string `json:"string,omitempty"`
Byte_ string `json:"byte"`
String string `json:"string,omitempty"`
Byte string `json:"byte"`
Binary **os.File `json:"binary,omitempty"`
Date string `json:"date"`
DateTime time.Time `json:"dateTime,omitempty"`

View File

@ -16,5 +16,5 @@ import (
type MixedPropertiesAndAdditionalPropertiesClass struct {
Uuid string `json:"uuid,omitempty"`
DateTime time.Time `json:"dateTime,omitempty"`
Map_ map[string]Animal `json:"map,omitempty"`
Map map[string]Animal `json:"map,omitempty"`
}

View File

@ -11,6 +11,6 @@
package petstore
// Model for testing reserved words
type ModelReturn struct {
Return_ int32 `json:"return,omitempty"`
type Return struct {
Return int32 `json:"return,omitempty"`
}