Changing the name of a generated property of a data model in swagger-codegen

I am creating a data model using swagger-codegen. Template

/// <summary>
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
/// </summary>{{#description}}
/// <value>{{description}}</value>{{/description}}
[JsonProperty("{{baseName}}")]
public {{{datatype}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; }

generates

/// <summary>
/// Description of property.
/// </summary>
/// <value>Description of property.</value>
[JsonProperty("property_name")]
public String property_name { get; set; }

How can I change the case property namefrom snake_case to PascalCase? I suppose I need to do some kind of conversion to {{name}}, but I'm not very familiar with steering patterns.

/// <summary>
/// Description of property.
/// </summary>
/// <value>Description of property.</value>
[JsonProperty("property_name")]
public String PropertyName { get; set; }
+4
source share
1 answer

I don't know if there is anything in Swagger Codegen, but with handlebars.net you can register an assistant to convert a string to PascalCase:

Handlebars.RegisterHelper("PascalCase", (writer, context, parameters) => {
  // paramaters[0] should be name, convert it to PascalCase here
});

# , , PascalCasing , , .

:

public {{{datatype}}} {{PascalCase name}} ...

: , Swagger Codegen jmustache , , Lambdas

+1

Source: https://habr.com/ru/post/1671401/


All Articles