Skip to content
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

Merged
merged 13 commits into from
Sep 17, 2024
Merged

Feat dotnet mutlipart #970

merged 13 commits into from
Sep 17, 2024

Conversation

byawitz
Copy link
Member

@byawitz byawitz commented Sep 2, 2024

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

@@ -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 %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{ 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 -%}

Copy link
Contributor

@Meldiron Meldiron Sep 17, 2024

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

tests/resources/spec.json Outdated Show resolved Hide resolved
@Meldiron Meldiron merged commit 88d469b into feat-multipart Sep 17, 2024
22 of 33 checks passed
@Meldiron Meldiron deleted the feat-dotnet-mutlipart branch September 17, 2024 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants