Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export class {{classname}} extends runtime.BaseAPI {
{{/formParams}}
{{/hasFormParams}}
const response = await this.request({
path: `{{{path}}}`{{#pathParams}}.replace(`{${"{{baseName}}"}}`, encodeURIComponent(String(requestParameters['{{paramName}}']))){{/pathParams}},
path: `{{{path}}}`{{#pathParams}}{{#isDateTimeType}}.replace(`{${"{{baseName}}"}}`, encodeURIComponent(requestParameters['{{paramName}}'].toISOString())){{/isDateTimeType}}{{^isDateTimeType}}{{#isDateType}}.replace(`{${"{{baseName}}"}}`, encodeURIComponent(requestParameters['{{paramName}}'].toISOString().substring(0,10))){{/isDateType}}{{^isDateType}}.replace(`{${"{{baseName}}"}}`, encodeURIComponent(String(requestParameters['{{paramName}}']))){{/isDateType}}{{/isDateTimeType}}{{/pathParams}},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how about

Suggested change
path: `{{{path}}}`{{#pathParams}}{{#isDateTimeType}}.replace(`{${"{{baseName}}"}}`, encodeURIComponent(requestParameters['{{paramName}}'].toISOString())){{/isDateTimeType}}{{^isDateTimeType}}{{#isDateType}}.replace(`{${"{{baseName}}"}}`, encodeURIComponent(requestParameters['{{paramName}}'].toISOString().substring(0,10))){{/isDateType}}{{^isDateType}}.replace(`{${"{{baseName}}"}}`, encodeURIComponent(String(requestParameters['{{paramName}}']))){{/isDateType}}{{/isDateTimeType}}{{/pathParams}},
path: `{{{path}}}`.replace(`{${"{{baseName}}"}}`,
{{#pathParams}}
{{#isDateTimeType}}
encodeURIComponent(requestParameters['{{paramName}}'].toISOString())
{{/isDateTimeType}}
{{^isDateTimeType}}
{{#isDateType}}
encodeURIComponent(requestParameters['{{paramName}}'].toISOString().substring(0,10))
{{/isDateType}}
{^isDateType}}
encodeURIComponent(String(requestParameters['{{paramName}}']))
{{/isDateType}}
{{/isDateTimeType}}
{{/pathParams}},

to simplify the template?

moreover, encodeURIComponent(requestParameters['{{paramName}}'].toISOString().substring(0,10)) is problematic because devs might be using a local date, and this converts the date to be in UTC. But at least this matches

'{{baseName}}': {{^required}}value['{{name}}'] == null ? undefined : {{/required}}({{#required}}{{#isNullable}}value['{{name}}'] == null ? null : {{/isNullable}}{{/required}}(value['{{name}}']{{#isNullable}} as any{{/isNullable}}).toISOString().substring(0,10)),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can do the expanded style. I wasn't sure what the standards (if any are for the generated code, so I was trying to maintain the style of that. But your version makes the template more readable.

Regarding the iso string handling, I pretty much just copied the code above that is handling query params (line 140 of this file). So while I don't disagree about the UTC thing, I think if that is an issue it might need to be addressed as part of a larger change

I can add the null handling stuff you have, but are path params allowed to be nullable? I'll admit I don't know the spec well enough to be sure but that seems really weird. I suppose in that case though that putting in null as the path value is the correct behavior?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Regarding the nullable bit, my reading of the spec (both version 2 and version 3.1.0) is that a path parameter can't be null because the required property must be set to true: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#fixed-fields-10

Determines whether this parameter is mandatory. If the parameter location is "path", this property is REQUIRED and its value MUST be true. Otherwise, the property MAY be included and its default value is false.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can also just add the null-safe operator „.?“ to be cautious

method: '{{httpMethod}}',
headers: headerParameters,
query: queryParameters,
Expand Down