Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ export class {{classname}} extends runtime.BaseAPI {
async {{nickname}}RequestOpts({{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request{{/allParams.0}}): Promise<runtime.RequestOpts> {
{{#allParams}}
{{#required}}
if (requestParameters['{{paramName}}'] == null) {
if (requestParameters['{{paramName}}'] {{#isBodyParam}}{{#isNullable}}=== undefined{{/isNullable}}{{^isNullable}}== null{{/isNullable}}{{/isBodyParam}}{{^isBodyParam}}== null{{/isBodyParam}}) {
throw new runtime.RequiredError(
'{{paramName}}',
'Required parameter "{{paramName}}" was null or undefined when calling {{nickname}}().'
'Required parameter "{{paramName}}" was {{#isBodyParam}}{{#isNullable}}undefined{{/isNullable}}{{^isNullable}}null or undefined{{/isNullable}}{{/isBodyParam}}{{^isBodyParam}}null or undefined{{/isBodyParam}} when calling {{nickname}}().'
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,27 @@ public void testOptionalNullableFieldDeserializesToNull() throws Exception {
TestUtils.assertFileNotContains(modelPath, "json['required_property'] === undefined ? undefined : json['required_property'] === null ? null :");
}

@Test(description = "Required nullable bodies should reject undefined but accept null (fix #23493)")
public void testRequiredNullableBodyRejectsOnlyUndefined() throws Exception {
File output = generate(
Collections.emptyMap(),
"src/test/resources/3_0/typescript-fetch/issue_23493.yaml"
);

Path apiPath = Paths.get(output + "/apis/DefaultApi.ts");
TestUtils.assertFileContains(apiPath,
"if (requestParameters['body'] === undefined)",
"Required parameter \"body\" was undefined when calling nullableBody().",
"body: boolean | null;",
"body: requestParameters['body'] as any");
TestUtils.assertFileContains(apiPath,
"if (requestParameters['body'] == null)",
"Required parameter \"body\" was null or undefined when calling nonNullableBody().");
TestUtils.assertFileContains(apiPath,
"if (requestParameters['requiredNullableQuery'] == null)",
"Required parameter \"requiredNullableQuery\" was null or undefined when calling nullableBody().");
}

@Test(description = "Verify Omit uses the camelCase property name instead of the baseName for readOnly fields")
public void testIssue23380_OmitUsesCorrectPropertyName() throws Exception {
File output = generate(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
openapi: 3.0.1
info:
title: Required nullable request body
version: 1.0.0
paths:
/nullable:
post:
operationId: nullableBody
parameters:
- name: requiredNullableQuery
in: query
required: true
schema:
type: string
nullable: true
requestBody:
required: true
content:
application/json:
schema:
type: boolean
nullable: true
responses:
'200':
description: OK
/non-nullable:
post:
operationId: nonNullableBody
requestBody:
required: true
content:
application/json:
schema:
type: boolean
responses:
'200':
description: OK
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,10 @@ export class FakeApi extends runtime.BaseAPI {
* Creates request options for testBodyWithBinary without sending the request
*/
async testBodyWithBinaryRequestOpts(requestParameters: TestBodyWithBinaryRequest): Promise<runtime.RequestOpts> {
if (requestParameters['body'] == null) {
if (requestParameters['body'] === undefined) {
throw new runtime.RequiredError(
'body',
'Required parameter "body" was null or undefined when calling testBodyWithBinary().'
'Required parameter "body" was undefined when calling testBodyWithBinary().'
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,10 @@ export class FakeApi extends runtime.BaseAPI {
* Creates request options for testBodyWithBinary without sending the request
*/
async testBodyWithBinaryRequestOpts(requestParameters: TestBodyWithBinaryRequest): Promise<runtime.RequestOpts> {
if (requestParameters['body'] == null) {
if (requestParameters['body'] === undefined) {
throw new runtime.RequiredError(
'body',
'Required parameter "body" was null or undefined when calling testBodyWithBinary().'
'Required parameter "body" was undefined when calling testBodyWithBinary().'
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,10 @@ export class FakeApi extends runtime.BaseAPI {
* Creates request options for testBodyWithBinary without sending the request
*/
async testBodyWithBinaryRequestOpts(requestParameters: TestBodyWithBinaryRequest): Promise<runtime.RequestOpts> {
if (requestParameters['body'] == null) {
if (requestParameters['body'] === undefined) {
throw new runtime.RequiredError(
'body',
'Required parameter "body" was null or undefined when calling testBodyWithBinary().'
'Required parameter "body" was undefined when calling testBodyWithBinary().'
);
}

Expand Down
Loading