Skip to content

Commit 9826652

Browse files
committed
Don't remove null type if a default is present.
1 parent 82e98b4 commit 9826652

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

packages/openapi-typescript/examples/github-api-next.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -108750,7 +108750,7 @@ export interface operations {
108750108750
/** @description The name of the task for the deployment (e.g., `deploy` or `deploy:migrations`). */
108751108751
task?: string;
108752108752
/** @description The name of the environment that was deployed to (e.g., `staging` or `production`). */
108753-
environment?: string;
108753+
environment?: string | null;
108754108754
/** @description The number of results per page (max 100). For more information, see "[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api)." */
108755108755
per_page?: components["parameters"]["per-page"];
108756108756
/** @description The page number of the results to fetch. For more information, see "[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api)." */

packages/openapi-typescript/src/transform/schema-object.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,7 @@ function transformSchemaObjectCore(schemaObject: SchemaObject, options: Transfor
405405
} else {
406406
for (const t of schemaObject.type) {
407407
if (t === "null" || t === null) {
408-
if (!schemaObject.default) {
409-
uniqueTypes.push(NULL);
410-
}
408+
uniqueTypes.push(NULL);
411409
} else {
412410
uniqueTypes.push(transformSchemaObject({ ...schemaObject, type: t } as SchemaObject, options));
413411
}

packages/openapi-typescript/test/transform/schema-object/string.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe("transformSchemaObject > string", () => {
102102
"default + nullable",
103103
{
104104
given: { type: ["string", "null"], default: "en" },
105-
want: "string",
105+
want: "string | null",
106106
},
107107
],
108108
[

0 commit comments

Comments
 (0)