swagger-api / swagger-api/swagger-codegen
[CSHARP] Add FromJson method to generated models
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I'm working on a project where we use codegen to only generate the models. It be really useful to have a method that deserializes a JSON string into an object similar to the ToJson method that serializes the object into a JSON string.
Swagger-codegen version
master branch
Swagger declaration file content or url
N/A
Command line used for generation
N/A
Steps to reproduce
N/A
Related issues/PRs
I will create a PR now.
Suggest a fix/enhancement
Add a FromJson method to modelGeneric.mustache
Example from MyClassWithInvalidRequiredEnumUsageOnRef integration test,
public static MyClassWithInvalidRequiredEnumUsageOnRef FromJson(string json)
{
return JsonConvert.DeserializeObject<MyClassWithInvalidRequiredEnumUsageOnRef>(json);
}
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
Start in modelGeneric.mustache and compare the existing ToJson method with the MyClassWithInvalidRequiredEnumUsageOnRef integration test example. Confirm that generated C# models expose the requested FromJson(string) behavior, then run the relevant integration test to verify the generated output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100