swagger-api / swagger-api/swagger-codegen
[C#] Base class with enum field causes NullPointerException
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Base class with enum field causes NullPointerException:
Exception in thread "main" java.lang.RuntimeException: Could not process model 'TestNs.TestClass2'.Please make sure that
your schema is correct!
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:297)
at io.swagger.codegen.cmd.Generate.run(Generate.java:223)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:36)
Caused by: java.lang.NullPointerException
at io.swagger.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:1176)
at io.swagger.codegen.languages.CSharpClientCodegen.fromModel(CSharpClientCodegen.java:313)
at io.swagger.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:1158)
at io.swagger.codegen.languages.CSharpClientCodegen.fromModel(CSharpClientCodegen.java:316)
at io.swagger.codegen.DefaultGenerator.processModels(DefaultGenerator.java:875)
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:290)
... 2 more
Swagger-codegen version
2.2.1
Swagger declaration file content or url
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "TestNs"
},
"host": "localhost:80",
"schemes": [ "https" ],
"paths": {
"/Test": {
"get": {
"tags": [ "Test" ],
"summary": "Tests the method.",
"operationId": "TestMethod",
"consumes": [ ],
"produces": [ "application/json", "text/json", "application/xml", "text/xml" ],
"responses": {
"200": {
"description": "OK",
"schema": { "$ref": "#/definitions/TestNs.TestClass" }
}
},
"deprecated": false
}
}
},
"definitions": {
"TestNs.TestClass": {
"required": [ "$Type" ],
"type": "object",
"properties": {
"Enum": {
"enum": [ "Value1", "Value2" ],
"type": "string"
},
"$Type": {
"description": "The discriminator.",
"type": "string"
}
},
"discriminator": "$Type"
},
"TestNs.TestClass2": {
"type": "object",
"allOf": [
{ "$ref": "#/definitions/TestNs.TestClass" },
{
"type": "object",
"properties": { }
}
],
"properties": { }
}
Command line used for generation
java -jar Tools\swagger-codegen-cli-2.2.1.jar generate -i $swaggerEndpoint -l csharp -D packageName=$projectName -o $clientFolder
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
Reproduce the failure with the supplied Swagger definition and the stated swagger-codegen CLI command. Start at CSharpClientCodegen.fromModel and DefaultCodegen.fromModel, using the stack trace to follow processing of the inherited enum field. Done means the same base-class and allOf model generates a C# client without a NullPointerException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100