swagger-api / swagger-api/swagger-codegen

CSharp language generator fails for Bitbuckets swagger JSON

Open
#5,576 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: C-Sharp Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description
  1. Using codegen built from the latest master the CSharp language generator fails when trying to parse https://api.bitbucket.org/swagger.json.
Swagger-codegen version

Built from master @ commit ea16da813

Swagger declaration file content or url

https://api.bitbucket.org/swagger.json

Command line used for generation

java -jar C:\Users\mminn\Source\github.com\mminns\swagger-codegen\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -i swagger.json -l csharp -o client-mminns/csharp

Results:

"C:\Program Files (x86)\Java\jdk1.7.0_55\bin\java" -Dfile.encoding=windows-1252 -jar C:\Users\mminn\Source\github.com\mminns\swagger-codegen\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -i swagger.json -l csharp -o client-mminnns/csharp-debug
[main] INFO io.swagger.parser.Swagger20Parser - reading from swagger.json
[main] INFO io.swagger.codegen.languages.CSharpClientCodegen - Generating code for .NET Framework v4.5
Exception in thread "main" java.lang.RuntimeException: Could not process model 'pipeline_ref_target'.Please make sure that your schema is correct!
at io.swagger.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:315)
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:665)
at io.swagger.codegen.cmd.Generate.run(Generate.java:234)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:43)
Caused by: java.lang.NullPointerException
at io.swagger.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:1264)
at io.swagger.codegen.languages.CSharpClientCodegen.fromModel(CSharpClientCodegen.java:428)
at io.swagger.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:1246)
at io.swagger.codegen.languages.CSharpClientCodegen.fromModel(CSharpClientCodegen.java:431)
at io.swagger.codegen.DefaultGenerator.processModels(DefaultGenerator.java:907)
at io.swagger.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:310)
... 3 more

Process finished with exit code 1

The problem is in CSharpClientCodegen
https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java#L430

When it tries to look up the parent model it is using the parent model name, but the collection allDefinitions is keyed on schema name.

The PetStore examples never hit this problem because the Model's don't have parents.

Related issues

https://github.com/swagger-api/swagger-codegen/issues/5577

Suggest a Fix

Changing the line: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java#L430

  •        final Model parentModel = allDefinitions.get(toModelName(codegenModel.parent));
    
  •       final Model parentModel = allDefinitions.get(codegenModel.parentSchema);
    

see also: https://github.com/mminns/swagger-codegen/tree/issue/fix-csharp-for-bitbucket

I'd like to submit the above fix as a PR

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/languages/CSharpClientCodegen.java around line 430 and reproduce generation with the Bitbucket swagger.json using the supplied CLI command. Inspect how the parent model is resolved for pipeline_ref_target, then verify that CSharp generation completes successfully for this input and does not regress the existing PetStore examples.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.