From c36838d9ff333eb918ad8b48a60f59fa0dd44d3f Mon Sep 17 00:00:00 2001 From: Aplus Kminus <43415953+AplusKminus@users.noreply.github.com> Date: Fri, 7 Apr 2023 17:50:13 +0200 Subject: [PATCH] Ensure not required parameters are created as optional properties (#1053) * Add missing 'vite' dependency * Ensure not required params are created as optional properties (#1052) According to the OpenAPI 3.1.0 spec, a parameter is required if one of these matches: - it has 'in: "path"' - it has 'required: true' See spec at Parameter Object - Fixed Fields: https://spec.openapis.org/oas/v3.1.0#fixed-fields-9 Fixes #1052 --- examples/github-api-next.ts | 122 +++++++++++------------ examples/github-api.ts | 122 +++++++++++------------ examples/octokit-ghes-3.6-diff-to-api.ts | 56 +++++------ package.json | 1 + pnpm-lock.yaml | 3 + src/transform/components-object.ts | 3 + test/components-object.test.ts | 32 ++++++ 7 files changed, 189 insertions(+), 150 deletions(-) diff --git a/examples/github-api-next.ts b/examples/github-api-next.ts index bd90957e..6fbf2261 100644 --- a/examples/github-api-next.ts +++ b/examples/github-api-next.ts @@ -76546,14 +76546,14 @@ export interface components { }; parameters: { /** @description The number of results per page (max 100). */ - "per-page": number; + "per-page"?: number; /** @description Used for pagination: the starting delivery from which the page of deliveries is fetched. Refer to the `link` header for the next and previous page cursors. */ - cursor: string; + cursor?: string; "delivery-id": number; /** @description Page number of the results to fetch. */ - page: number; + page?: number; /** @description Only show notifications updated after the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`. */ - since: string; + since?: string; /** @description The unique identifier of the installation. */ "installation-id": number; /** @description The client ID of the GitHub app. */ @@ -76566,99 +76566,99 @@ export interface components { * * Can be: `dismissed`, `fixed`, `open` */ - "dependabot-alert-comma-separated-states": string; + "dependabot-alert-comma-separated-states"?: string; /** * @description A comma-separated list of severities. If specified, only alerts with these severities will be returned. * * Can be: `low`, `medium`, `high`, `critical` */ - "dependabot-alert-comma-separated-severities": string; + "dependabot-alert-comma-separated-severities"?: string; /** * @description A comma-separated list of ecosystems. If specified, only alerts for these ecosystems will be returned. * * Can be: `composer`, `go`, `maven`, `npm`, `nuget`, `pip`, `pub`, `rubygems`, `rust` */ - "dependabot-alert-comma-separated-ecosystems": string; + "dependabot-alert-comma-separated-ecosystems"?: string; /** @description A comma-separated list of package names. If specified, only alerts for these packages will be returned. */ - "dependabot-alert-comma-separated-packages": string; + "dependabot-alert-comma-separated-packages"?: string; /** @description The scope of the vulnerable dependency. If specified, only alerts with this scope will be returned. */ - "dependabot-alert-scope": "development" | "runtime"; + "dependabot-alert-scope"?: "development" | "runtime"; /** * @description The property by which to sort the results. * `created` means when the alert was created. * `updated` means when the alert's state last changed. */ - "dependabot-alert-sort": "created" | "updated"; + "dependabot-alert-sort"?: "created" | "updated"; /** @description The direction to sort the results by. */ - direction: "asc" | "desc"; + direction?: "asc" | "desc"; /** @description A cursor, as given in the [Link header](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api#using-link-headers). If specified, the query only searches for results before this cursor. */ - "pagination-before": string; + "pagination-before"?: string; /** @description A cursor, as given in the [Link header](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api#using-link-headers). If specified, the query only searches for results after this cursor. */ - "pagination-after": string; + "pagination-after"?: string; /** * @description **Deprecated**. The number of results per page (max 100), starting from the first matching result. * This parameter must not be used in combination with `last`. * Instead, use `per_page` in combination with `after` to fetch the first page of results. */ - "pagination-first": number; + "pagination-first"?: number; /** * @description **Deprecated**. The number of results per page (max 100), starting from the last matching result. * This parameter must not be used in combination with `first`. * Instead, use `per_page` in combination with `before` to fetch the last page of results. */ - "pagination-last": number; + "pagination-last"?: number; /** @description Set to `open` or `resolved` to only list secret scanning alerts in a specific state. */ - "secret-scanning-alert-state": "open" | "resolved"; + "secret-scanning-alert-state"?: "open" | "resolved"; /** * @description A comma-separated list of secret types to return. By default all secret types are returned. * See "[Secret scanning patterns](https://docs.github.com/code-security/secret-scanning/secret-scanning-patterns#supported-secrets-for-advanced-security)" * for a complete list of secret types. */ - "secret-scanning-alert-secret-type": string; + "secret-scanning-alert-secret-type"?: string; /** @description A comma-separated list of resolutions. Only secret scanning alerts with one of these resolutions are listed. Valid resolutions are `false_positive`, `wont_fix`, `revoked`, `pattern_edited`, `pattern_deleted` or `used_in_tests`. */ - "secret-scanning-alert-resolution": string; + "secret-scanning-alert-resolution"?: string; /** @description The property to sort the results by. `created` means when the alert was created. `updated` means when the alert was updated or resolved. */ - "secret-scanning-alert-sort": "created" | "updated"; + "secret-scanning-alert-sort"?: "created" | "updated"; /** @description The unique identifier of the gist. */ "gist-id": string; /** @description The unique identifier of the comment. */ "comment-id": number; /** @description A list of comma separated label names. Example: `bug,ui,@high` */ - labels: string; + labels?: string; /** @description account_id parameter */ "account-id": number; /** @description The unique identifier of the plan. */ "plan-id": number; /** @description The property to sort the results by. */ - sort: "created" | "updated"; + sort?: "created" | "updated"; /** @description The account owner of the repository. The name is not case sensitive. */ owner: string; /** @description The name of the repository. The name is not case sensitive. */ repo: string; /** @description If `true`, show notifications marked as read. */ - all: boolean; + all?: boolean; /** @description If `true`, only shows notifications in which the user is directly participating or mentioned. */ - participating: boolean; + participating?: boolean; /** @description Only show notifications updated before the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`. */ - before: string; + before?: string; /** @description The unique identifier of the notification thread. This corresponds to the value returned in the `id` field when you retrieve notifications (for example with the [`GET /notifications` operation](https://docs.github.com/rest/reference/activity#list-notifications-for-the-authenticated-user)). */ "thread-id": number; /** @description An organization ID. Only return organizations with an ID greater than this ID. */ - "since-org": number; + "since-org"?: number; /** @description The organization name. The name is not case sensitive. */ org: string; /** @description The property by which to sort the results. */ - "personal-access-token-sort": "created_at"; + "personal-access-token-sort"?: "created_at"; /** @description A list of owner usernames to use to filter the results. */ - "personal-access-token-owner": (string)[]; + "personal-access-token-owner"?: (string)[]; /** @description The name of the repository to use to filter the results. */ - "personal-access-token-repository": string; + "personal-access-token-repository"?: string; /** @description The permission to use to filter the results. */ - "personal-access-token-permission": string; + "personal-access-token-permission"?: string; /** @description Only show fine-grained personal access tokens used before the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`. */ - "personal-access-token-before": string; + "personal-access-token-before"?: string; /** @description Only show fine-grained personal access tokens used after the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`. */ - "personal-access-token-after": string; + "personal-access-token-after"?: string; /** @description The unique identifier of the fine-grained personal access token. */ "fine-grained-personal-access-token-id": number; /** @description The unique identifier of the repository. */ @@ -76672,15 +76672,15 @@ export interface components { /** @description The name of the secret. */ "secret-name": string; /** @description The number of results per page (max 30). */ - "variables-per-page": number; + "variables-per-page"?: number; /** @description The name of the variable. */ "variable-name": string; /** @description The handle for the GitHub user account. */ username: string; /** @description The name of a code scanning tool. Only results by this tool will be listed. You can specify the tool by using either `tool_name` or `tool_guid`, but not both. */ - "tool-name": components["schemas"]["code-scanning-analysis-tool-name"]; + "tool-name"?: components["schemas"]["code-scanning-analysis-tool-name"]; /** @description The GUID of a code scanning tool. Only results by this tool will be listed. Note that some code scanning tools may not include a GUID in their analysis data. You can specify the tool by using either `tool_guid` or `tool_name`, but not both. */ - "tool-guid": components["schemas"]["code-scanning-analysis-tool-guid"]; + "tool-guid"?: components["schemas"]["code-scanning-analysis-tool-guid"]; /** @description The unique identifier of the hook. */ "hook-id": number; /** @description The unique identifier of the invitation. */ @@ -76697,7 +76697,7 @@ export interface components { * The `internal` visibility is only supported for GitHub Packages registries that allow for granular permissions. For other ecosystems `internal` is synonymous with `private`. * For the list of GitHub Packages registries that support granular permissions, see "[About permissions for GitHub Packages](https://docs.github.com/packages/learn-github-packages/about-permissions-for-github-packages#granular-permissions-for-userorganization-scoped-packages)." */ - "package-visibility": "public" | "private" | "internal"; + "package-visibility"?: "public" | "private" | "internal"; /** @description The type of supported package. Packages in GitHub's Gradle registry have the type `maven`. Docker images pushed to GitHub's Container registry (`ghcr.io`) have the type `container`. You can use the type `docker` to find images that were pushed to GitHub's Docker registry (`docker.pkg.github.com`), even if these have now been migrated to the Container registry. */ "package-type": "npm" | "maven" | "rubygems" | "docker" | "nuget" | "container"; /** @description The name of the package. */ @@ -76705,9 +76705,9 @@ export interface components { /** @description Unique identifier of the package version. */ "package-version-id": number; /** @description A cursor, as given in the [Link header](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api#using-link-headers). If specified, the query only searches for events before this cursor. To receive an initial cursor on your first request, include an empty "before" query string. */ - "secret-scanning-pagination-before-org-repo": string; + "secret-scanning-pagination-before-org-repo"?: string; /** @description A cursor, as given in the [Link header](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api#using-link-headers). If specified, the query only searches for events after this cursor. To receive an initial cursor on your first request, include an empty "after" query string. */ - "secret-scanning-pagination-after-org-repo": string; + "secret-scanning-pagination-after-org-repo"?: string; /** @description The slug of the team name. */ "team-slug": string; /** @description The number that identifies the discussion. */ @@ -76736,11 +76736,11 @@ export interface components { /** @description The unique identifier of the artifact. */ "artifact-id": number; /** @description The full Git reference for narrowing down the cache. The `ref` for a branch should be formatted as `refs/heads/`. To reference a pull request use `refs/pull//merge`. */ - "actions-cache-git-ref-full": string; + "actions-cache-git-ref-full"?: string; /** @description An explicit key or prefix for identifying the cache */ - "actions-cache-key": string; + "actions-cache-key"?: string; /** @description The property to sort the results by. `created_at` means when the cache was created. `last_accessed_at` means when the cache was last accessed. `size_in_bytes` is the size of the cache in bytes. */ - "actions-cache-list-sort": "created_at" | "last_accessed_at" | "size_in_bytes"; + "actions-cache-list-sort"?: "created_at" | "last_accessed_at" | "size_in_bytes"; /** @description A key for identifying the cache. */ "actions-cache-key-required": string; /** @description The unique identifier of the GitHub Actions cache. */ @@ -76748,21 +76748,21 @@ export interface components { /** @description The unique identifier of the job. */ "job-id": number; /** @description Returns someone's workflow runs. Use the login for the user who created the `push` associated with the check suite or workflow run. */ - actor: string; + actor?: string; /** @description Returns workflow runs associated with a branch. Use the name of the branch of the `push`. */ - "workflow-run-branch": string; + "workflow-run-branch"?: string; /** @description Returns workflow run triggered by the event you specify. For example, `push`, `pull_request` or `issue`. For more information, see "[Events that trigger workflows](https://docs.github.com/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows)." */ - event: string; + event?: string; /** @description Returns workflow runs with the check run `status` or `conclusion` that you specify. For example, a conclusion can be `success` or a status can be `in_progress`. Only GitHub can set a status of `waiting` or `requested`. */ - "workflow-run-status": "completed" | "action_required" | "cancelled" | "failure" | "neutral" | "skipped" | "stale" | "success" | "timed_out" | "in_progress" | "queued" | "requested" | "waiting" | "pending"; + "workflow-run-status"?: "completed" | "action_required" | "cancelled" | "failure" | "neutral" | "skipped" | "stale" | "success" | "timed_out" | "in_progress" | "queued" | "requested" | "waiting" | "pending"; /** @description Returns workflow runs created within the given date-time range. For more information on the syntax, see "[Understanding the search syntax](https://docs.github.com/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax#query-for-dates)." */ - created: string; + created?: string; /** @description If `true` pull requests are omitted from the response (empty array). */ - "exclude-pull-requests": boolean; + "exclude-pull-requests"?: boolean; /** @description Returns workflow runs with the `check_suite_id` that you specify. */ - "workflow-run-check-suite-id": number; + "workflow-run-check-suite-id"?: number; /** @description Only returns workflow runs that are associated with the specified `head_sha`. */ - "workflow-run-head-sha": string; + "workflow-run-head-sha"?: string; /** @description The unique identifier of the workflow run. */ "run-id": number; /** @description The attempt number of the workflow run. */ @@ -76778,17 +76778,17 @@ export interface components { /** @description The unique identifier of the check suite. */ "check-suite-id": number; /** @description Returns check runs with the specified `name`. */ - "check-name": string; + "check-name"?: string; /** @description Returns check runs with the specified `status`. */ - status: "queued" | "in_progress" | "completed"; + status?: "queued" | "in_progress" | "completed"; /** @description The Git reference for the results you want to list. The `ref` for a branch can be formatted either as `refs/heads/` or simply ``. To reference a pull request use `refs/pull//merge`. */ - "git-ref": components["schemas"]["code-scanning-ref"]; + "git-ref"?: components["schemas"]["code-scanning-ref"]; /** @description The number that identifies an alert. You can find this at the end of the URL for a code scanning alert within GitHub, and in the `number` field in the response from the `GET /repos/{owner}/{repo}/code-scanning/alerts` operation. */ "alert-number": components["schemas"]["alert-number"]; /** @description The SHA of the commit. */ "commit-sha": string; /** @description A comma-separated list of full manifest paths. If specified, only alerts for these manifests will be returned. */ - "dependabot-alert-comma-separated-manifests": string; + "dependabot-alert-comma-separated-manifests"?: string; /** * @description The number that identifies a Dependabot alert in its repository. * You can find this at the end of the URL for a Dependabot alert within GitHub, @@ -76797,7 +76797,7 @@ export interface components { */ "dependabot-alert-number": components["schemas"]["alert-number"]; /** @description The full path, relative to the repository root, of the dependency manifest file. */ - "manifest-path": string; + "manifest-path"?: string; /** @description deployment_id parameter */ "deployment-id": number; /** @description The name of the environment. */ @@ -76805,7 +76805,7 @@ export interface components { /** @description The unique identifier of the branch policy. */ "branch-policy-id": number; /** @description A user ID. Only return users with an ID greater than this ID. */ - "since-user": number; + "since-user"?: number; /** @description The number that identifies the issue. */ "issue-number": number; /** @description The unique identifier of the key. */ @@ -76823,27 +76823,27 @@ export interface components { /** @description The unique identifier of the tag protection. */ "tag-protection-id": number; /** @description The time frame to display results for. */ - per: "day" | "week"; + per?: "day" | "week"; /** @description A repository ID. Only return repositories with an ID greater than this ID. */ - "since-repo": number; + "since-repo"?: number; /** @description Determines whether the first search result returned is the highest number of matches (`desc`) or lowest number of matches (`asc`). This parameter is ignored unless you provide `sort`. */ - order: "desc" | "asc"; + order?: "desc" | "asc"; /** @description The unique identifier of the team. */ "team-id": number; /** @description ID of the Repository to filter on */ - "repository-id-in-query": number; + "repository-id-in-query"?: number; /** @description The ID of the export operation, or `latest`. Currently only `latest` is currently supported. */ "export-id": string; /** @description The unique identifier of the GPG key. */ "gpg-key-id": number; /** @description Only show repositories updated after the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`. */ - "since-repo-date": string; + "since-repo-date"?: string; /** @description Only show repositories updated before the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`. */ - "before-repo-date": string; + "before-repo-date"?: string; /** @description The unique identifier of the SSH signing key. */ "ssh-signing-key-id": number; /** @description The property to sort the results by. `created` means when the repository was starred. `updated` means when the repository was last pushed to. */ - "sort-starred": "created" | "updated"; + "sort-starred"?: "created" | "updated"; }; requestBodies: never; headers: { diff --git a/examples/github-api.ts b/examples/github-api.ts index d5bb1a76..dfbf713d 100644 --- a/examples/github-api.ts +++ b/examples/github-api.ts @@ -78656,14 +78656,14 @@ export interface components { }; parameters: { /** @description The number of results per page (max 100). */ - "per-page": number; + "per-page"?: number; /** @description Used for pagination: the starting delivery from which the page of deliveries is fetched. Refer to the `link` header for the next and previous page cursors. */ - cursor: string; + cursor?: string; "delivery-id": number; /** @description Page number of the results to fetch. */ - page: number; + page?: number; /** @description Only show notifications updated after the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`. */ - since: string; + since?: string; /** @description The unique identifier of the installation. */ "installation-id": number; /** @description The client ID of the GitHub app. */ @@ -78676,99 +78676,99 @@ export interface components { * * Can be: `dismissed`, `fixed`, `open` */ - "dependabot-alert-comma-separated-states": string; + "dependabot-alert-comma-separated-states"?: string; /** * @description A comma-separated list of severities. If specified, only alerts with these severities will be returned. * * Can be: `low`, `medium`, `high`, `critical` */ - "dependabot-alert-comma-separated-severities": string; + "dependabot-alert-comma-separated-severities"?: string; /** * @description A comma-separated list of ecosystems. If specified, only alerts for these ecosystems will be returned. * * Can be: `composer`, `go`, `maven`, `npm`, `nuget`, `pip`, `pub`, `rubygems`, `rust` */ - "dependabot-alert-comma-separated-ecosystems": string; + "dependabot-alert-comma-separated-ecosystems"?: string; /** @description A comma-separated list of package names. If specified, only alerts for these packages will be returned. */ - "dependabot-alert-comma-separated-packages": string; + "dependabot-alert-comma-separated-packages"?: string; /** @description The scope of the vulnerable dependency. If specified, only alerts with this scope will be returned. */ - "dependabot-alert-scope": "development" | "runtime"; + "dependabot-alert-scope"?: "development" | "runtime"; /** * @description The property by which to sort the results. * `created` means when the alert was created. * `updated` means when the alert's state last changed. */ - "dependabot-alert-sort": "created" | "updated"; + "dependabot-alert-sort"?: "created" | "updated"; /** @description The direction to sort the results by. */ - direction: "asc" | "desc"; + direction?: "asc" | "desc"; /** @description A cursor, as given in the [Link header](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api#using-link-headers). If specified, the query only searches for results before this cursor. */ - "pagination-before": string; + "pagination-before"?: string; /** @description A cursor, as given in the [Link header](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api#using-link-headers). If specified, the query only searches for results after this cursor. */ - "pagination-after": string; + "pagination-after"?: string; /** * @description **Deprecated**. The number of results per page (max 100), starting from the first matching result. * This parameter must not be used in combination with `last`. * Instead, use `per_page` in combination with `after` to fetch the first page of results. */ - "pagination-first": number; + "pagination-first"?: number; /** * @description **Deprecated**. The number of results per page (max 100), starting from the last matching result. * This parameter must not be used in combination with `first`. * Instead, use `per_page` in combination with `before` to fetch the last page of results. */ - "pagination-last": number; + "pagination-last"?: number; /** @description Set to `open` or `resolved` to only list secret scanning alerts in a specific state. */ - "secret-scanning-alert-state": "open" | "resolved"; + "secret-scanning-alert-state"?: "open" | "resolved"; /** * @description A comma-separated list of secret types to return. By default all secret types are returned. * See "[Secret scanning patterns](https://docs.github.com/code-security/secret-scanning/secret-scanning-patterns#supported-secrets-for-advanced-security)" * for a complete list of secret types. */ - "secret-scanning-alert-secret-type": string; + "secret-scanning-alert-secret-type"?: string; /** @description A comma-separated list of resolutions. Only secret scanning alerts with one of these resolutions are listed. Valid resolutions are `false_positive`, `wont_fix`, `revoked`, `pattern_edited`, `pattern_deleted` or `used_in_tests`. */ - "secret-scanning-alert-resolution": string; + "secret-scanning-alert-resolution"?: string; /** @description The property to sort the results by. `created` means when the alert was created. `updated` means when the alert was updated or resolved. */ - "secret-scanning-alert-sort": "created" | "updated"; + "secret-scanning-alert-sort"?: "created" | "updated"; /** @description The unique identifier of the gist. */ "gist-id": string; /** @description The unique identifier of the comment. */ "comment-id": number; /** @description A list of comma separated label names. Example: `bug,ui,@high` */ - labels: string; + labels?: string; /** @description account_id parameter */ "account-id": number; /** @description The unique identifier of the plan. */ "plan-id": number; /** @description The property to sort the results by. */ - sort: "created" | "updated"; + sort?: "created" | "updated"; /** @description The account owner of the repository. The name is not case sensitive. */ owner: string; /** @description The name of the repository. The name is not case sensitive. */ repo: string; /** @description If `true`, show notifications marked as read. */ - all: boolean; + all?: boolean; /** @description If `true`, only shows notifications in which the user is directly participating or mentioned. */ - participating: boolean; + participating?: boolean; /** @description Only show notifications updated before the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`. */ - before: string; + before?: string; /** @description The unique identifier of the notification thread. This corresponds to the value returned in the `id` field when you retrieve notifications (for example with the [`GET /notifications` operation](https://docs.github.com/rest/reference/activity#list-notifications-for-the-authenticated-user)). */ "thread-id": number; /** @description An organization ID. Only return organizations with an ID greater than this ID. */ - "since-org": number; + "since-org"?: number; /** @description The organization name. The name is not case sensitive. */ org: string; /** @description The property by which to sort the results. */ - "personal-access-token-sort": "created_at"; + "personal-access-token-sort"?: "created_at"; /** @description A list of owner usernames to use to filter the results. */ - "personal-access-token-owner": (string)[]; + "personal-access-token-owner"?: (string)[]; /** @description The name of the repository to use to filter the results. */ - "personal-access-token-repository": string; + "personal-access-token-repository"?: string; /** @description The permission to use to filter the results. */ - "personal-access-token-permission": string; + "personal-access-token-permission"?: string; /** @description Only show fine-grained personal access tokens used before the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`. */ - "personal-access-token-before": string; + "personal-access-token-before"?: string; /** @description Only show fine-grained personal access tokens used after the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`. */ - "personal-access-token-after": string; + "personal-access-token-after"?: string; /** @description The unique identifier of the fine-grained personal access token. */ "fine-grained-personal-access-token-id": number; /** @description The unique identifier of the repository. */ @@ -78782,15 +78782,15 @@ export interface components { /** @description The name of the secret. */ "secret-name": string; /** @description The number of results per page (max 30). */ - "variables-per-page": number; + "variables-per-page"?: number; /** @description The name of the variable. */ "variable-name": string; /** @description The handle for the GitHub user account. */ username: string; /** @description The name of a code scanning tool. Only results by this tool will be listed. You can specify the tool by using either `tool_name` or `tool_guid`, but not both. */ - "tool-name": components["schemas"]["code-scanning-analysis-tool-name"]; + "tool-name"?: components["schemas"]["code-scanning-analysis-tool-name"]; /** @description The GUID of a code scanning tool. Only results by this tool will be listed. Note that some code scanning tools may not include a GUID in their analysis data. You can specify the tool by using either `tool_guid` or `tool_name`, but not both. */ - "tool-guid": components["schemas"]["code-scanning-analysis-tool-guid"]; + "tool-guid"?: components["schemas"]["code-scanning-analysis-tool-guid"]; /** @description The unique identifier of the hook. */ "hook-id": number; /** @description The unique identifier of the invitation. */ @@ -78807,7 +78807,7 @@ export interface components { * The `internal` visibility is only supported for GitHub Packages registries that allow for granular permissions. For other ecosystems `internal` is synonymous with `private`. * For the list of GitHub Packages registries that support granular permissions, see "[About permissions for GitHub Packages](https://docs.github.com/packages/learn-github-packages/about-permissions-for-github-packages#granular-permissions-for-userorganization-scoped-packages)." */ - "package-visibility": "public" | "private" | "internal"; + "package-visibility"?: "public" | "private" | "internal"; /** @description The type of supported package. Packages in GitHub's Gradle registry have the type `maven`. Docker images pushed to GitHub's Container registry (`ghcr.io`) have the type `container`. You can use the type `docker` to find images that were pushed to GitHub's Docker registry (`docker.pkg.github.com`), even if these have now been migrated to the Container registry. */ "package-type": "npm" | "maven" | "rubygems" | "docker" | "nuget" | "container"; /** @description The name of the package. */ @@ -78815,9 +78815,9 @@ export interface components { /** @description Unique identifier of the package version. */ "package-version-id": number; /** @description A cursor, as given in the [Link header](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api#using-link-headers). If specified, the query only searches for events before this cursor. To receive an initial cursor on your first request, include an empty "before" query string. */ - "secret-scanning-pagination-before-org-repo": string; + "secret-scanning-pagination-before-org-repo"?: string; /** @description A cursor, as given in the [Link header](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api#using-link-headers). If specified, the query only searches for events after this cursor. To receive an initial cursor on your first request, include an empty "after" query string. */ - "secret-scanning-pagination-after-org-repo": string; + "secret-scanning-pagination-after-org-repo"?: string; /** @description The slug of the team name. */ "team-slug": string; /** @description The number that identifies the discussion. */ @@ -78846,11 +78846,11 @@ export interface components { /** @description The unique identifier of the artifact. */ "artifact-id": number; /** @description The full Git reference for narrowing down the cache. The `ref` for a branch should be formatted as `refs/heads/`. To reference a pull request use `refs/pull//merge`. */ - "actions-cache-git-ref-full": string; + "actions-cache-git-ref-full"?: string; /** @description An explicit key or prefix for identifying the cache */ - "actions-cache-key": string; + "actions-cache-key"?: string; /** @description The property to sort the results by. `created_at` means when the cache was created. `last_accessed_at` means when the cache was last accessed. `size_in_bytes` is the size of the cache in bytes. */ - "actions-cache-list-sort": "created_at" | "last_accessed_at" | "size_in_bytes"; + "actions-cache-list-sort"?: "created_at" | "last_accessed_at" | "size_in_bytes"; /** @description A key for identifying the cache. */ "actions-cache-key-required": string; /** @description The unique identifier of the GitHub Actions cache. */ @@ -78858,21 +78858,21 @@ export interface components { /** @description The unique identifier of the job. */ "job-id": number; /** @description Returns someone's workflow runs. Use the login for the user who created the `push` associated with the check suite or workflow run. */ - actor: string; + actor?: string; /** @description Returns workflow runs associated with a branch. Use the name of the branch of the `push`. */ - "workflow-run-branch": string; + "workflow-run-branch"?: string; /** @description Returns workflow run triggered by the event you specify. For example, `push`, `pull_request` or `issue`. For more information, see "[Events that trigger workflows](https://docs.github.com/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows)." */ - event: string; + event?: string; /** @description Returns workflow runs with the check run `status` or `conclusion` that you specify. For example, a conclusion can be `success` or a status can be `in_progress`. Only GitHub can set a status of `waiting` or `requested`. */ - "workflow-run-status": "completed" | "action_required" | "cancelled" | "failure" | "neutral" | "skipped" | "stale" | "success" | "timed_out" | "in_progress" | "queued" | "requested" | "waiting" | "pending"; + "workflow-run-status"?: "completed" | "action_required" | "cancelled" | "failure" | "neutral" | "skipped" | "stale" | "success" | "timed_out" | "in_progress" | "queued" | "requested" | "waiting" | "pending"; /** @description Returns workflow runs created within the given date-time range. For more information on the syntax, see "[Understanding the search syntax](https://docs.github.com/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax#query-for-dates)." */ - created: string; + created?: string; /** @description If `true` pull requests are omitted from the response (empty array). */ - "exclude-pull-requests": boolean; + "exclude-pull-requests"?: boolean; /** @description Returns workflow runs with the `check_suite_id` that you specify. */ - "workflow-run-check-suite-id": number; + "workflow-run-check-suite-id"?: number; /** @description Only returns workflow runs that are associated with the specified `head_sha`. */ - "workflow-run-head-sha": string; + "workflow-run-head-sha"?: string; /** @description The unique identifier of the workflow run. */ "run-id": number; /** @description The attempt number of the workflow run. */ @@ -78888,17 +78888,17 @@ export interface components { /** @description The unique identifier of the check suite. */ "check-suite-id": number; /** @description Returns check runs with the specified `name`. */ - "check-name": string; + "check-name"?: string; /** @description Returns check runs with the specified `status`. */ - status: "queued" | "in_progress" | "completed"; + status?: "queued" | "in_progress" | "completed"; /** @description The Git reference for the results you want to list. The `ref` for a branch can be formatted either as `refs/heads/` or simply ``. To reference a pull request use `refs/pull//merge`. */ - "git-ref": components["schemas"]["code-scanning-ref"]; + "git-ref"?: components["schemas"]["code-scanning-ref"]; /** @description The number that identifies an alert. You can find this at the end of the URL for a code scanning alert within GitHub, and in the `number` field in the response from the `GET /repos/{owner}/{repo}/code-scanning/alerts` operation. */ "alert-number": components["schemas"]["alert-number"]; /** @description The SHA of the commit. */ "commit-sha": string; /** @description A comma-separated list of full manifest paths. If specified, only alerts for these manifests will be returned. */ - "dependabot-alert-comma-separated-manifests": string; + "dependabot-alert-comma-separated-manifests"?: string; /** * @description The number that identifies a Dependabot alert in its repository. * You can find this at the end of the URL for a Dependabot alert within GitHub, @@ -78907,7 +78907,7 @@ export interface components { */ "dependabot-alert-number": components["schemas"]["alert-number"]; /** @description The full path, relative to the repository root, of the dependency manifest file. */ - "manifest-path": string; + "manifest-path"?: string; /** @description deployment_id parameter */ "deployment-id": number; /** @description The name of the environment. */ @@ -78915,7 +78915,7 @@ export interface components { /** @description The unique identifier of the branch policy. */ "branch-policy-id": number; /** @description A user ID. Only return users with an ID greater than this ID. */ - "since-user": number; + "since-user"?: number; /** @description The number that identifies the issue. */ "issue-number": number; /** @description The unique identifier of the key. */ @@ -78933,27 +78933,27 @@ export interface components { /** @description The unique identifier of the tag protection. */ "tag-protection-id": number; /** @description The time frame to display results for. */ - per: "day" | "week"; + per?: "day" | "week"; /** @description A repository ID. Only return repositories with an ID greater than this ID. */ - "since-repo": number; + "since-repo"?: number; /** @description Determines whether the first search result returned is the highest number of matches (`desc`) or lowest number of matches (`asc`). This parameter is ignored unless you provide `sort`. */ - order: "desc" | "asc"; + order?: "desc" | "asc"; /** @description The unique identifier of the team. */ "team-id": number; /** @description ID of the Repository to filter on */ - "repository-id-in-query": number; + "repository-id-in-query"?: number; /** @description The ID of the export operation, or `latest`. Currently only `latest` is currently supported. */ "export-id": string; /** @description The unique identifier of the GPG key. */ "gpg-key-id": number; /** @description Only show repositories updated after the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`. */ - "since-repo-date": string; + "since-repo-date"?: string; /** @description Only show repositories updated before the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`. */ - "before-repo-date": string; + "before-repo-date"?: string; /** @description The unique identifier of the SSH signing key. */ "ssh-signing-key-id": number; /** @description The property to sort the results by. `created` means when the repository was starred. `updated` means when the repository was last pushed to. */ - "sort-starred": "created" | "updated"; + "sort-starred"?: "created" | "updated"; }; requestBodies: never; headers: { diff --git a/examples/octokit-ghes-3.6-diff-to-api.ts b/examples/octokit-ghes-3.6-diff-to-api.ts index d341a183..637ea880 100644 --- a/examples/octokit-ghes-3.6-diff-to-api.ts +++ b/examples/octokit-ghes-3.6-diff-to-api.ts @@ -5665,13 +5665,13 @@ export interface components { }; parameters: { /** @description The number of results per page (max 100). */ - "per-page": number; + "per-page"?: number; /** @description Page number of the results to fetch. */ - page: number; + page?: number; /** @description The unique identifier of the hook. */ "hook-id": number; /** @description The direction to sort the results by. */ - direction: "asc" | "desc"; + direction?: "asc" | "desc"; /** @description The unique identifier of the key. */ "key-ids": string; /** @description The unique identifier of the team. */ @@ -5687,7 +5687,7 @@ export interface components { /** @description The unique identifier of the token. */ "token-id": number; /** @description Only show notifications updated after the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`. */ - since: string; + since?: string; /** @description The unique identifier of the installation. */ "installation-id": number; /** @description The unique identifier of the grant. */ @@ -5701,7 +5701,7 @@ export interface components { /** @description The slug version of the enterprise name. You can also substitute this value with the enterprise id. */ enterprise: string; /** @description A search phrase. For more information, see [Searching the audit log](https://docs.github.com/enterprise-server@3.6/github/setting-up-and-managing-organizations-and-teams/reviewing-the-audit-log-for-your-organization#searching-the-audit-log). */ - "audit-log-phrase": string; + "audit-log-phrase"?: string; /** * @description The event types to include: * @@ -5711,33 +5711,33 @@ export interface components { * * The default is `web`. */ - "audit-log-include": "web" | "git" | "all"; + "audit-log-include"?: "web" | "git" | "all"; /** @description A cursor, as given in the [Link header](https://docs.github.com/enterprise-server@3.6/rest/overview/resources-in-the-rest-api#link-header). If specified, the query only searches for events after this cursor. */ - "audit-log-after": string; + "audit-log-after"?: string; /** @description A cursor, as given in the [Link header](https://docs.github.com/enterprise-server@3.6/rest/overview/resources-in-the-rest-api#link-header). If specified, the query only searches for events before this cursor. */ - "audit-log-before": string; + "audit-log-before"?: string; /** * @description The order of audit log events. To list newest events first, specify `desc`. To list oldest events first, specify `asc`. * * The default is `desc`. */ - "audit-log-order": "desc" | "asc"; + "audit-log-order"?: "desc" | "asc"; /** @description Set to `open` or `resolved` to only list secret scanning alerts in a specific state. */ - "secret-scanning-alert-state": "open" | "resolved"; + "secret-scanning-alert-state"?: "open" | "resolved"; /** * @description A comma-separated list of secret types to return. By default all secret types are returned. * See "[Secret scanning patterns](https://docs.github.com/enterprise-server@3.6/code-security/secret-scanning/secret-scanning-patterns#supported-secrets-for-advanced-security)" * for a complete list of secret types. */ - "secret-scanning-alert-secret-type": string; + "secret-scanning-alert-secret-type"?: string; /** @description A comma-separated list of resolutions. Only secret scanning alerts with one of these resolutions are listed. Valid resolutions are `false_positive`, `wont_fix`, `revoked`, `pattern_edited`, `pattern_deleted` or `used_in_tests`. */ - "secret-scanning-alert-resolution": string; + "secret-scanning-alert-resolution"?: string; /** @description The property to sort the results by. `created` means when the alert was created. `updated` means when the alert was updated or resolved. */ - "secret-scanning-alert-sort": "created" | "updated"; + "secret-scanning-alert-sort"?: "created" | "updated"; /** @description A cursor, as given in the [Link header](https://docs.github.com/enterprise-server@3.6/rest/overview/resources-in-the-rest-api#link-header). If specified, the query only searches for events before this cursor. */ - "pagination-before": string; + "pagination-before"?: string; /** @description A cursor, as given in the [Link header](https://docs.github.com/enterprise-server@3.6/rest/overview/resources-in-the-rest-api#link-header). If specified, the query only searches for events after this cursor. */ - "pagination-after": string; + "pagination-after"?: string; /** @description The unique identifier of the group. */ "group-id": number; /** @description The slug of the team name. */ @@ -5747,19 +5747,19 @@ export interface components { /** @description The name of the repository. The name is not case sensitive. */ repo: string; /** @description Returns someone's workflow runs. Use the login for the user who created the `push` associated with the check suite or workflow run. */ - actor: string; + actor?: string; /** @description Returns workflow runs associated with a branch. Use the name of the branch of the `push`. */ - "workflow-run-branch": string; + "workflow-run-branch"?: string; /** @description Returns workflow run triggered by the event you specify. For example, `push`, `pull_request` or `issue`. For more information, see "[Events that trigger workflows](https://docs.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows)." */ - event: string; + event?: string; /** @description Returns workflow runs with the check run `status` or `conclusion` that you specify. For example, a conclusion can be `success` or a status can be `in_progress`. Only GitHub can set a status of `waiting` or `requested`. */ - "workflow-run-status": "completed" | "action_required" | "cancelled" | "failure" | "neutral" | "skipped" | "stale" | "success" | "timed_out" | "in_progress" | "queued" | "requested" | "waiting"; + "workflow-run-status"?: "completed" | "action_required" | "cancelled" | "failure" | "neutral" | "skipped" | "stale" | "success" | "timed_out" | "in_progress" | "queued" | "requested" | "waiting"; /** @description Returns workflow runs created within the given date-time range. For more information on the syntax, see "[Understanding the search syntax](https://docs.github.com/enterprise-server@3.6/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax#query-for-dates)." */ - created: string; + created?: string; /** @description If `true` pull requests are omitted from the response (empty array). */ - "exclude-pull-requests": boolean; + "exclude-pull-requests"?: boolean; /** @description Returns workflow runs with the `check_suite_id` that you specify. */ - "workflow-run-check-suite-id": number; + "workflow-run-check-suite-id"?: number; /** @description The unique identifier of the workflow run. */ "run-id": number; /** @description The attempt number of the workflow run. */ @@ -5769,11 +5769,11 @@ export interface components { /** @description The unique identifier of the autolink. */ "autolink-id": number; /** @description The name of a code scanning tool. Only results by this tool will be listed. You can specify the tool by using either `tool_name` or `tool_guid`, but not both. */ - "tool-name": components["schemas"]["code-scanning-analysis-tool-name"]; + "tool-name"?: components["schemas"]["code-scanning-analysis-tool-name"]; /** @description The GUID of a code scanning tool. Only results by this tool will be listed. Note that some code scanning tools may not include a GUID in their analysis data. You can specify the tool by using either `tool_guid` or `tool_name`, but not both. */ - "tool-guid": components["schemas"]["code-scanning-analysis-tool-guid"]; + "tool-guid"?: components["schemas"]["code-scanning-analysis-tool-guid"]; /** @description The full path, relative to the repository root, of the dependency manifest file. */ - "manifest-path": string; + "manifest-path"?: string; /** @description The unique identifier of the key. */ "key-id": number; /** @description The unique identifier of the release. */ @@ -5781,11 +5781,11 @@ export interface components { /** @description The number that identifies an alert. You can find this at the end of the URL for a code scanning alert within GitHub, and in the `number` field in the response from the `GET /repos/{owner}/{repo}/code-scanning/alerts` operation. */ "alert-number": components["schemas"]["alert-number"]; /** @description A repository ID. Only return repositories with an ID greater than this ID. */ - "since-repo": number; + "since-repo"?: number; /** @description Used for pagination: the index of the first result to return. */ - "start-index": number; + "start-index"?: number; /** @description Used for pagination: the number of results to return. */ - count: number; + count?: number; /** @description Identifier generated by the GitHub SCIM endpoint. */ "scim-group-id": string; /** @description The unique identifier of the SCIM user. */ diff --git a/package.json b/package.json index bdffcbb5..83b068e2 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "execa": "^6.1.0", "prettier": "^2.8.7", "typescript": "^5.0.3", + "vite": "^4.1.4", "vite-node": "^0.29.8", "vitest": "^0.29.8" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 292b14fc..ed15e37b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -63,6 +63,9 @@ devDependencies: typescript: specifier: ^5.0.3 version: 5.0.3 + vite: + specifier: ^4.1.4 + version: 4.2.1(@types/node@18.15.11) vite-node: specifier: ^0.29.8 version: 0.29.8(@types/node@18.15.11)(supports-color@9.3.1) diff --git a/src/transform/components-object.ts b/src/transform/components-object.ts index 72c0cb20..93466408 100644 --- a/src/transform/components-object.ts +++ b/src/transform/components-object.ts @@ -80,6 +80,9 @@ export default function transformComponentsObject(components: ComponentsObject, ) ); } else { + if (parameterObject.in !== "path" && !parameterObject.required) { + key = tsOptionalProperty(key); + } const parameterType = transformParameterObject(parameterObject, { path: `#/components/parameters/${name}`, ctx: { ...ctx, indentLv }, diff --git a/test/components-object.test.ts b/test/components-object.test.ts index 4c576c4f..df2f28d9 100644 --- a/test/components-object.test.ts +++ b/test/components-object.test.ts @@ -41,6 +41,7 @@ const basicSchema: ComponentsObject = { Search: { name: "search", in: "query", + required: true, schema: { type: "string" }, }, }, @@ -78,6 +79,22 @@ const basicSchema: ComponentsObject = { }, }; +const optionalParamSchema: ComponentsObject = { + parameters: { + myParam: { + name: "myParam", + in: "query", + required: false, + schema: { type: "string" }, + }, + myParam2: { + name: "myParam2", + in: "query", + schema: { type: "string" }, + }, + }, +}; + describe("Components Object", () => { test("basic", () => { const generated = transformComponentsObject(basicSchema, options); @@ -219,4 +236,19 @@ describe("Components Object", () => { }); }); }); + + test("parameters with required: false", () => { + const generated = transformComponentsObject(optionalParamSchema, options); + expect(generated).toBe(`{ + schemas: never; + responses: never; + parameters: { + myParam?: string; + myParam2?: string; + }; + requestBodies: never; + headers: never; + pathItems: never; +}`); + }); });