OpenAPITools / OpenAPITools/openapi-generator

NetCore Generator using DataMember Attributes Instead of DeserializeAs Attributes

Open
#8,170 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

When the DotNetCore Generator Generates the models for the the various components the models are marked up with DataMember Attributes:

IE:

        [DataMember(Name = "public", EmitDefaultValue = false)]
        public string _public { get; set; }

However the Deserializer that is used is the RestSharp.Deserializer which uses the RestSharp DeserializeAs attribute
IE:

        [DeserializeAs(Name = "public")]
        public string _public { get; set; }

Thus
The current [DataMember] attributes are completely ignored and anything that relies on them tries to use the property name to deserialize instead of the specified deserialize name.

openapi-generator version

5.0.0-beta3

Suggest a fix

Update modelGeneric.mustache to include
[DeserializeAs(Name = "{{{name}}}")] or [DeserializeAs(Name = "{{{baseName}}}")]
Any place
[DataMember is used

IE:
line 5: [DeserializeAs(Name = "{{{name}}}")]
line 6: [DataContract(Name = "{{{name}}}")]

also update model.mustache to include
using RestSharp.Deserializers;

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 modelGeneric.mustache and model.mustache, then inspect the generated DotNetCore models that currently use DataMember attributes. Update the templates so generated properties use the RestSharp DeserializeAs attribute and the model includes the RestSharp.Deserializers import; done means serialized names such as "public" are used during deserialization.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.