swagger-api / swagger-api/swagger-codegen
[CSharp] Crash on 'allOf's that contain a '$ref' to 'allOf's
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
If we have a $ref in an allOf that points to an allOf of $refs codegen crashes with a NullPointerException.
Swagger-codegen version
CLI: 3.0.10
Swagger declaration file content or url
Here is a cut-down example file that seems to reproduce our issue. Our example is obviously more complex as the referenced schemas are used more than once.
https://gist.github.com/thomashardwick/13a8d5516c7e0718e212f6b396fd39e5
Command line used for generation
java -jar .\swagger-codegen-cli-3.0.10.jar generate -l csharp -i .\test.yaml
Steps to reproduce
Run command. Get output:
10:50:11.571 [Thread-0] DEBUG io.swagger.codegen.v3.config.CodegenConfigurator - getClientOptInput - parsed inputSpecURL .\test.yaml
10:50:11.579 [Thread-0] INFO io.swagger.codegen.v3.generators.dotnet.CSharpClientCodegen - Generating code for .NET Framework v4.5
10:50:11.663 [Thread-0] INFO io.swagger.codegen.v3.generators.dotnet.CSharpClientCodegen - adding parent variable Name
Exception in thread "Thread-0" java.lang.RuntimeException: Could not process model 'GroupUserItem'.Please make sure that your schema is correct!
at io.swagger.codegen.v3.DefaultGenerator.generateModels(DefaultGenerator.java:392)
at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:773)
at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:342)
at java.base/java.lang.Thread.run(Thread.java:835)
Caused by: java.lang.NullPointerException
at io.swagger.codegen.v3.generators.DefaultCodegenConfig.fromModel(DefaultCodegenConfig.java:1336)
at io.swagger.codegen.v3.generators.dotnet.CSharpClientCodegen.fromModel(CSharpClientCodegen.java:515)
at io.swagger.codegen.v3.generators.DefaultCodegenConfig.fromModel(DefaultCodegenConfig.java:1239)
at io.swagger.codegen.v3.generators.dotnet.CSharpClientCodegen.fromModel(CSharpClientCodegen.java:519)
at io.swagger.codegen.v3.DefaultGenerator.processModels(DefaultGenerator.java:1005)
at io.swagger.codegen.v3.DefaultGenerator.generateModels(DefaultGenerator.java:363)
... 3 more
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reduced schema in the linked gist and reproduce it using the shown swagger-codegen CLI command. Then inspect DefaultCodegenConfig.fromModel and CSharpClientCodegen.fromModel from the stack trace; done means the C# generator handles the nested allOf/$ref case without a NullPointerException and has a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, java, openapi
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100