swagger-api / swagger-api/swagger-codegen

csharp client test compile failure

Open
#4,503 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

The addition of the OuterEnum property to the Enum_Test definition in petstore-with-fake-endpoints-models-for-testing.yaml has caused the generated csharp client to fail compilation. This is due to the fact that OuterEnum is not in the IsEnum collection when the model template is compiled and is not being defined as a nullable type. What makes this obvious is the fact that OuterEnum is being defined after the constructor (see EnumTest.cs).

Swagger-codegen version

current master branch

Swagger declaration file content or url

https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml

Command line used for generation

.\bin\windows\csharp-petstore.bat (windows)
or
./bin/csharp-petstore.sh (!windows)

Steps to reproduce

After you generate try and compile the resulting project, the csharp compiler will throw an error on line 114 of EnumTest.cs where OuterEnum is supplied a default value of null but isn't defined as nullable on line 126.

Related issues

Currently the generated csharp model has to be manually corrected to prevent appveyor from failing.

Suggest a Fix

My first thought is that the bug is likely in parsing a model with a stand alone enum definition, but i haven't had a chance to confirm this. We could find a work around in the template processing but the right fix would be to correct the property classification prior to code generation.

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 with modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml and the generated samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Model/EnumTest.cs. Run bin/csharp-petstore.bat or bin/csharp-petstore.sh, then compile the generated project and inspect the model template's property classification. Done means OuterEnum is generated consistently and the C# client compiles without the nullable-type error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.