swagger-api / swagger-api/swagger-codegen

Selective generation doesn't support CSV list

Open
#10,476 2 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

When passing models or apis as a CSV for selective generation only the first part is used. Documentation: https://github.com/swagger-api/swagger-codegen#selective-generation

Swagger-codegen version

2.4.16 (current master branch).

Swagger declaration file content or url

https://petstore.swagger.io/v2/swagger.json

Command line used for generation

Windows 10 command prompt
Java jdk1.8.0_261

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i https://petstore.swagger.io/v2/swagger.json -l csharp -o /var/tmp/pet_api_client -D apis=User,Pet -D models=User,Pet -D supportingFiles

Steps to reproduce

If you change the command line system properties other models will be generated.

  • -D apis=User,Pet -D models=User,Pet
    Generates only the UserApi.cs and User.cs
  • -D apis=Pet,User -D models=Pet,User
    Generates only the PetApi.cs and Pet.cs

I've added some logging to DefaultGenerator.java.

String apiNames = System.getProperty("apis");
LOGGER.info("apiNames " + apiNames);

String modelNames = System.getProperty("models");
LOGGER.info("modelNames " + modelNames);

They always only print the part before the first comma.

Also tested with this:

  • -D apis=Us,erPet -D models=Us,erPet
    This prints "Us" both times.

So nothing beyond the first comma works.

Suggest a fix/enhancement

Somehow getting the entire CSV. Not sure if there are alternatives for System.getProperty if that doesn't work.
Lines of code:

https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java#L309

https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java#L461

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/java/io/swagger/codegen/DefaultGenerator.java at the referenced lines around 309 and 461, then reproduce the issue with the petstore specification and comma-separated apis and models options. Done means the complete CSV values are read and both requested API and model entries are generated rather than only the first item.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, java
Domain
cli, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.