swagger-api / swagger-api/swagger-codegen

collectionFormat 'multi' is not properly handled in generated code

Open Beginner friendly
#12,445 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in modules/swagger-codegen/src/main/resources/go/client.mustache at the referenced parameter-handling function, then compare the multi collectionFormat handling in modules/swagger-codegen/src/main/resources/python/api_client.mustache. Generate a Go client from the example declaration with swag init and verify that a multi-valued ids query is sent with separators rather than concatenated.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.