swagger-api / swagger-api/swagger-codegen

[CSHARP] Add FromJson method to generated models

Open
#11,903 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

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.