-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat dotnet mutlipart #970
Conversation
@@ -40,7 +40,7 @@ namespace {{ spec.title | caseUcfirst }}.Models | |||
|
|||
public static {{ definition.name | caseUcfirst | overrideIdentifier}} From(Dictionary<string, object> map) => new {{ definition.name | caseUcfirst | overrideIdentifier}}( | |||
{%~ for property in definition.properties %} | |||
{{ property.name | caseCamel | escapeKeyword | removeDollarSign }}: {% if property.sub_schema %}{% if property.type == 'array' %}((JArray)map["{{ property.name }}"]).ToObject<List<Dictionary<string, object>>>().Select(it => {{property.sub_schema | caseUcfirst | overrideIdentifier}}.From(map: it)).ToList(){% else %}{{property.sub_schema | caseUcfirst | overrideIdentifier}}.From(map: ((JObject)map["{{ property.name }}"]).ToObject<Dictionary<string, object>>()!){% endif %}{% else %}{% if property.type == 'array' %}((JArray)map["{{ property.name }}"]).ToObject<{{ property | typeName }}>(){% else %}{% if property.type == "integer" or property.type == "number" %}{% if not property.required %}map["{{ property.name }}"] == null ? null : {% endif %}Convert.To{% if property.type == "integer" %}Int64{% else %}Double{% endif %}(map["{{ property.name }}"]){% else %}{% if property.type == "boolean" %}({{ property | typeName }}{% if not property.required %}?{% endif %})map["{{ property.name }}"]{% else %}map{% if not property.required %}.TryGetValue("{{ property.name }}", out var {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}) ? {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}?.ToString() : null{% else %}["{{ property.name }}"]{% if not property.required %}?{% endif %}.ToString(){% endif %}{% endif %}{% endif %}{% endif %}{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %} | |||
{{ property.name | caseCamel | escapeKeyword | removeDollarSign }}: {% if property.sub_schema %}{% if property.type == 'array' %}((JArray)map["{{ property.name }}"]).ToObject<List<Dictionary<string, object>>>().Select(it => {{property.sub_schema | caseUcfirst | overrideIdentifier}}.From(map: it)).ToList(){% else %}{{property.sub_schema | caseUcfirst | overrideIdentifier}}.From(map: ((JObject)map["{{ property.name }}"]).ToObject<Dictionary<string, object>>()!){% endif %}{% else %}{% if property.type == 'array' %}((JArray)map["{{ property.name }}"]).ToObject<{{ property | typeName }}>(){% else %}{% if property.type == "integer" or property.type == "number" %}{% if not property.required %}map["{{ property.name }}"] == null ? null : {% endif %}Convert.To{% if property.type == "integer" %}Int64{% else %}Double{% endif %}(map["{{ property.name }}"]){% else %}{% if property.type == "boolean" %}({{ property | typeName }}{% if not property.required %}?{% endif %})map["{{ property.name }}"]{% else %}map{% if not property.required %}.TryGetValue("{{ property.name }}", out var {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}) ? {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}{% if property.name == "responseBody" or property.type | caseLower == "file" %} as Payload{% else %}?.ToString(){% endif %} : null{% else %}["{{ property.name }}"]{% if not property.required %}?{% endif %}{% if property.name == "responseBody" or property.type | caseLower == "payload" %} as Payload{% else %}.ToString(){% endif %}{% endif %}{% endif %}{% endif %}{% endif %}{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{{ property.name | caseCamel | escapeKeyword | removeDollarSign }}: {% if property.sub_schema %}{% if property.type == 'array' %}((JArray)map["{{ property.name }}"]).ToObject<List<Dictionary<string, object>>>().Select(it => {{property.sub_schema | caseUcfirst | overrideIdentifier}}.From(map: it)).ToList(){% else %}{{property.sub_schema | caseUcfirst | overrideIdentifier}}.From(map: ((JObject)map["{{ property.name }}"]).ToObject<Dictionary<string, object>>()!){% endif %}{% else %}{% if property.type == 'array' %}((JArray)map["{{ property.name }}"]).ToObject<{{ property | typeName }}>(){% else %}{% if property.type == "integer" or property.type == "number" %}{% if not property.required %}map["{{ property.name }}"] == null ? null : {% endif %}Convert.To{% if property.type == "integer" %}Int64{% else %}Double{% endif %}(map["{{ property.name }}"]){% else %}{% if property.type == "boolean" %}({{ property | typeName }}{% if not property.required %}?{% endif %})map["{{ property.name }}"]{% else %}map{% if not property.required %}.TryGetValue("{{ property.name }}", out var {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}) ? {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}{% if property.name == "responseBody" or property.type | caseLower == "file" %} as Payload{% else %}?.ToString(){% endif %} : null{% else %}["{{ property.name }}"]{% if not property.required %}?{% endif %}{% if property.name == "responseBody" or property.type | caseLower == "payload" %} as Payload{% else %}.ToString(){% endif %}{% endif %}{% endif %}{% endif %}{% endif %}{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %} | |
{{ property.name | caseCamel | escapeKeyword | removeDollarSign }}: | |
{%~ if property.sub_schema %} | |
{%~ if property.type == 'array' %} | |
((JArray)map["{{ property.name }}"]) | |
.ToObject<List<Dictionary<string, object>>>() | |
.Select(it => {{property.sub_schema | caseUcfirst | overrideIdentifier}}.From(map: it)) | |
.ToList() | |
{%~ else %} | |
{{property.sub_schema | caseUcfirst | overrideIdentifier}}.From( | |
map: ((JObject)map["{{ property.name }}"]) | |
.ToObject<Dictionary<string, object>>()! | |
) | |
{%~ endif %} | |
{%~ else %} | |
{%~ if property.type == 'array' %} | |
((JArray)map["{{ property.name }}"]) | |
.ToObject<{{ property | typeName }}>() | |
{%~ else %} | |
{%~ if property.type == "integer" or property.type == "number" %} | |
{%~ if not property.required -%} | |
map["{{ property.name }}"] == null | |
? null | |
: | |
{%~ endif -%} | |
Convert.To{% if property.type == "integer" %}Int64{% else %}Double{% endif %}(map["{{ property.name }}"]) | |
{%~ else %} | |
{%~ if property.type == "boolean" %} | |
({{ property | typeName }}{% if not property.required %}?{% endif %})map["{{ property.name }}"] | |
{%~ else %} | |
map{% if not property.required %}.TryGetValue("{{ property.name }}", out var {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}) | |
? {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}{% if property.name == "responseBody" or property.type | caseLower == "file" %} as Payload{% else %}?.ToString(){% endif %} | |
: null | |
{%~ else %} | |
["{{ property.name }}"]{% if not property.required %}?{% endif %}{% if property.name == "responseBody" or property.type | caseLower == "payload" %} as Payload{% else %}.ToString(){% endif %} | |
{%~ endif %} | |
{%~ endif %} | |
{%~ endif %} | |
{%~ endif %} | |
{%~ endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif -%} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this but I think it should be done as part of code quality project planned later this week. We have issue for it. There are many more places in sdk-generator that could benefit from this.
Simple linter for max row length can spot them all
What does this PR do?
(Provide a description of what this PR does.)
Test Plan
(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)
Related PRs and Issues
(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)
Have you read the Contributing Guidelines on issues?
(Write your answer here.)