swagger-api / swagger-api/swagger-codegen

[C#] Instantiation type is ignored

Open
#12,275 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

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
  1. Run csharp-petstore-net-standard.sh
csharp-petstore-net-standard.sh --type-mappings array=IReadOnlyList --instantiation-types array=List
  1. 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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.