swagger-api / swagger-api/swagger-codegen
[C#] Instantiation type is ignored
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When using --type-mapping defining interfaces for list and adding --instantiation-types to provide a concrete type when required, whenever the contract defines an array type, the template output defined the array type inheriting from the interface (type-mappings) and not the concrete type (instantion-types)
The result in the output is for modules/swagger-codegen/src/test/resources/3_0_0/petstore-with-fake-endpoints-models-for-testing.yaml for one of the classes in this example the output is:
public partial class AllPetsResponse : IReadOnlyList<OneOfAllPetsResponseItems> ...
instead of
public partial class AllPetsResponse : List<OneOfAllPetsResponseItems>
Swagger-codegen version
3.0.46, but this issue was present for a long time. I'm not sure if we can consider this an issue or a feature request.
Swagger declaration file content or url
Use the sample in the source code modules/swagger-codegen/src/test/resources/3_0_0/petstore-with-fake-endpoints-models-for-testing.yaml
Command line used for generation
The interesting part of the command to reproduce this is:
--type-mappings array=IReadOnlyList --instantiation-types array=List
The full command is
generate -i modules/swagger-codegen/src/test/resources/3_0_0/petstore-with-fake-endpoints-models-for-testing.yaml -l csharp -o samples/client/petstore/csharp/SwaggerClientNetStandard --additional-properties packageGuid={321C8C3F-0156-40C1-AE42-D59761FB9B6C} -c ./bin/csharp-petstore-net-standard.json --type-mappings array=IReadOnlyList --instantiation-types array=List
NOTE this is the command for generating the sources for csharp netstandard from csharp-petstore-net-standard.sh with the interesting part appended to it
Steps to reproduce
csharp-petstore-net-standard.sh --type-mappings array=IReadOnlyList --instantiation-types array=List
- Check the output and you will notice the behavior described
Related issues/PRs
Suggest a fix/enhancement
For the base of classes for C#, the values from --instantiation-types should be used instead of the values from --type-mappings
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
Run csharp-petstore-net-standard.sh with --type-mappings array=IReadOnlyList --instantiation-types array=List using petstore-with-fake-endpoints-models-for-testing.yaml. Trace the C# generation path and templates that determine the base type for AllPetsResponse. Done means the generated class uses List while other type mappings remain correct.
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
- Clearly specified
- Newbie friendliness
- 48/100