swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

collectionFormat 'multi' is not properly handled in generated code

Open sophiezhang666 opened this issue 1 year ago • 0 comments

Description

Query array declared with collectionFormat(multi) is not generated correctly, with ids concatenated without separator.

Swagger-codegen version

main branch

Swagger declaration file content or url
{
	"type": "array",
	"items": {
		"type": "string"
	},
	"collectionFormat": "multi",
	"description": "ids to query for objects",
	"name": "ids",
	"in": "query"
},
Command line used for generation

swag init

Steps to reproduce
  • Make a REST API endpoint which takes a list of ids and declare it with collectionFormat(multi) e.g. // @Param ids query []string false "ids to query for objects" collectionFormat(multi)
  • Generate API client with swagger-codegen for golang
  • Send a request to API with generated API client code and find on server side that ids are concatenated without separators
Related issues/PRs

Not related, but probably in similar area. https://github.com/swagger-api/swagger-codegen/issues/10963

Suggest a fix/enhancement

Add handling for collectionFormat multi to the following function: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/go/client.mustache#L129

Similar to python https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/python/api_client.mustache#L423

sophiezhang666 avatar Aug 13 '24 16:08 sophiezhang666