You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an operation belongs to multiple tags the go swagger generator will create an api_<tag>.go file for each tag. The Opts struct that is created will have the same name in all the files which causes name collision.
Below you can see that List Pets operation has both the animals and the pets tag. This results in 2 files being created, api_animals.go and api_pets.go. Both files will contain the following struct definition for List Pets Options:
typeListPetsOptsstruct {
Limit optional.Int32
}
Swagger-codegen version
2.4.5
Swagger declaration file content or url
swagger: "2.0"info:
version: 1.0.0title: Swagger Petstorelicense:
name: MIThost: petstore.swagger.iobasePath: /v1schemes:
- httpconsumes:
- application/jsonproduces:
- application/jsonpaths:
/pets:
get:
summary: List all petsoperationId: listPetstags:
- pets
- animalsparameters:
- name: limitin: querydescription: How many items to return at one time (max 100)required: falsetype: integerformat: int32responses:
"200":
description: A paged array of petsheaders:
x-next:
type: stringdescription: A link to the next page of responsesschema:
$ref: '#/definitions/Pets'default:
description: unexpected errorschema:
$ref: '#/definitions/PetError'definitions:
Pet:
type: "object"required:
- id
- nameproperties:
id:
type: integerformat: int64name:
type: stringtag:
type: stringPets:
type: arrayitems:
$ref: '#/definitions/Pet'PetError:
type: "object"required:
- code
- messageproperties:
code:
type: integerformat: int32message:
type: string
Run the above command on the swagger file and try to compile in go. You will get a redeclared in this block error for ListPetsOpts struct that will appear both in api_animals.go and api_pets.go.
Related issues/PRs
n/a
Suggest a fix/enhancement
Prefix Tag name to struct Name to avoid collision.
eg in api_animals.go the struct will be called AnimalsListPetsOpts and in api_pets.go the struct will be called PetsListPetsOpts.
The text was updated successfully, but these errors were encountered:
Description
When an operation belongs to multiple tags the go swagger generator will create an
api_<tag>.go
file for each tag. The Opts struct that is created will have the same name in all the files which causes name collision.Below you can see that List Pets operation has both the animals and the pets tag. This results in 2 files being created,
api_animals.go
andapi_pets.go
. Both files will contain the following struct definition for List Pets Options:Swagger-codegen version
2.4.5
Swagger declaration file content or url
Command line used for generation
Steps to reproduce
Run the above command on the swagger file and try to compile in go. You will get a
redeclared in this block
error forListPetsOpts
struct that will appear both inapi_animals.go
andapi_pets.go
.Related issues/PRs
n/a
Suggest a fix/enhancement
Prefix Tag name to struct Name to avoid collision.
eg in
api_animals.go
the struct will be calledAnimalsListPetsOpts
and inapi_pets.go
the struct will be calledPetsListPetsOpts
.The text was updated successfully, but these errors were encountered: