Skip to content

requestBody fields optional even with defaults #1681

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

Merged
merged 3 commits into from
Jun 19, 2024
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

Large diffs are not rendered by default.

228 changes: 114 additions & 114 deletions packages/openapi-typescript/examples/github-api-immutable.ts

Large diffs are not rendered by default.

228 changes: 114 additions & 114 deletions packages/openapi-typescript/examples/github-api-next.ts

Large diffs are not rendered by default.

228 changes: 114 additions & 114 deletions packages/openapi-typescript/examples/github-api.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7195,7 +7195,7 @@ export interface operations {
* @description Determines if notifications are sent when the webhook is triggered. Set to `true` to send notifications.
* @default true
*/
active: boolean;
active?: boolean;
};
};
};
Expand Down Expand Up @@ -7285,7 +7285,7 @@ export interface operations {
* @description Determines if notifications are sent when the webhook is triggered. Set to `true` to send notifications.
* @default true
*/
active: boolean;
active?: boolean;
};
};
};
Expand Down Expand Up @@ -9332,12 +9332,12 @@ export interface operations {
* @default read
* @enum {string}
*/
default_repository_permission: "read" | "write" | "admin" | "none";
default_repository_permission?: "read" | "write" | "admin" | "none";
/**
* @description Whether of non-admin organization members can create repositories. **Note:** A parameter can override this parameter. See `members_allowed_repository_creation_type` in this table for details.
* @default true
*/
members_can_create_repositories: boolean;
members_can_create_repositories?: boolean;
/** @description Whether organization members can create internal repositories, which are visible to all enterprise members. You can only allow members to create internal repositories if your organization is associated with an enterprise account using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+. For more information, see "[Restricting repository creation in your organization](https://docs.github.com/github/setting-up-and-managing-organizations-and-teams/restricting-repository-creation-in-your-organization)" in the GitHub Help documentation. */
members_can_create_internal_repositories?: boolean;
/** @description Whether organization members can create private repositories, which are visible to organization members with permission. For more information, see "[Restricting repository creation in your organization](https://docs.github.com/github/setting-up-and-managing-organizations-and-teams/restricting-repository-creation-in-your-organization)" in the GitHub Help documentation. */
Expand All @@ -9354,17 +9354,17 @@ export interface operations {
* @description Whether organization members can create GitHub Pages sites. Existing published sites will not be impacted.
* @default true
*/
members_can_create_pages: boolean;
members_can_create_pages?: boolean;
/**
* @description Whether organization members can fork private organization repositories.
* @default false
*/
members_can_fork_private_repositories: boolean;
members_can_fork_private_repositories?: boolean;
/**
* @description Whether contributors to organization repositories are required to sign off on commits they make through GitHub's web interface.
* @default false
*/
web_commit_signoff_required: boolean;
web_commit_signoff_required?: boolean;
/** @example "http://github.blog" */
blog?: string;
};
Expand Down Expand Up @@ -9795,7 +9795,7 @@ export interface operations {
* @default pull
* @enum {string}
*/
permission: "pull" | "push";
permission?: "pull" | "push";
/** @description The ID of a team to set as the parent team. */
parent_team_id?: number;
/** @description The [distinguished name](https://www.ldap.com/ldap-dns-and-rdns) (DN) of the LDAP entry to map to a team. LDAP synchronization must be enabled to map LDAP entries to a team. Use the "[Update LDAP mapping for a team](https://docs.github.com/[email protected]/rest/reference/enterprise-admin#update-ldap-mapping-for-a-team)" endpoint to change the LDAP DN. For more information, see "[Using LDAP](https://docs.github.com/[email protected]/admin/identity-and-access-management/authenticating-users-for-your-github-enterprise-server-instance/using-ldap#enabling-ldap-sync)." */
Expand Down Expand Up @@ -10240,7 +10240,7 @@ export interface operations {
* @description Whether this autolink reference matches alphanumeric characters. If true, the `<num>` parameter of the `url_template` matches alphanumeric characters `A-Z` (case insensitive), `0-9`, and `-`. If false, this autolink reference only matches numeric characters.
* @default true
*/
is_alphanumeric: boolean;
is_alphanumeric?: boolean;
};
};
};
Expand Down Expand Up @@ -10771,17 +10771,17 @@ export interface operations {
* @description `true` to create a draft (unpublished) release, `false` to create a published one.
* @default false
*/
draft: boolean;
draft?: boolean;
/**
* @description `true` to identify the release as a prerelease. `false` to identify the release as a full release.
* @default false
*/
prerelease: boolean;
prerelease?: boolean;
/**
* @description Whether to automatically generate the name and body for this release. If `name` is specified, the specified name will be used; otherwise, a name will be automatically generated. If `body` is specified, the body will be pre-pended to the automatically generated notes.
* @default false
*/
generate_release_notes: boolean;
generate_release_notes?: boolean;
};
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ function transformSchemaObjectCore(schemaObject: SchemaObject, options: Transfor
let optional =
schemaObject.required?.includes(k) ||
(schemaObject.required === undefined && options.ctx.propertiesRequiredByDefault) ||
("default" in v && options.ctx.defaultNonNullable && !options.path?.includes("parameters")) // parameters can’t be required, even with defaults
("default" in v &&
options.ctx.defaultNonNullable &&
!options.path?.includes("parameters") &&
!options.path?.includes("requestBody")) // parameters can’t be required, even with defaults
? undefined
: QUESTION_TOKEN;
let type =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,45 @@ describe("transformRequestBodyObject", () => {
"*/*"?: never;
};
}`,
// options: DEFAULT_OPTIONS,
},
],
[
"POST data with default values",
{
given: {
content: {
"application/x-www-form-urlencoded": {
schema: {
type: "object",
properties: {
required: { type: "string" },
optional: { type: "string" },
flag_optional: { type: "boolean", default: false },
flag_required: { type: "boolean", default: false },
},
required: ["required", "flag_required"],
},
},
},
required: true,
description: "description",
},
want: `{
content: {
"application/x-www-form-urlencoded": {
required: string;
optional?: string;
/** @default false */
flag_optional?: boolean;
/** @default false */
flag_required: boolean;
};
};
}`,
options: {
path: "#/paths/~post-item/post/requestBody/application~1x-www-form-urlencoded",
ctx: { ...DEFAULT_CTX },
},
},
],
];
Expand Down