swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[CSHARP] Add FromJson method to generated models

Open mhallin79 opened this issue 3 years ago • 0 comments

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);
}

mhallin79 avatar Sep 21 '22 02:09 mhallin79