Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/defs-optional-property.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-typescript": patch
---

Emit the generated `$defs` container as an optional property so schemas that declare `$defs` are no longer required to provide it when used as input types. `$refs` that index into `$defs` continue to resolve.
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ function transformSchemaObjectCore(schemaObject: SchemaObject, options: Transfor
ts.factory.createPropertySignature(
/* modifiers */ undefined,
/* name */ tsPropertyIndex("$defs"),
/* questionToken */ undefined,
/* questionToken */ QUESTION_TOKEN,
/* type */ ts.factory.createTypeLiteralNode(defKeys),
),
);
Expand Down
6 changes: 3 additions & 3 deletions packages/openapi-typescript/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,18 +590,18 @@ export interface components {
rootDef?: $defs["StringType"];
nestedDef?: components["schemas"]["OtherObject"]["$defs"]["nestedDef"];
remoteDef?: components["schemas"]["remoteDef"];
$defs: {
$defs?: {
hasDefs: boolean;
};
};
ArrayOfDefs: $defs["StringType"][];
OtherObject: {
$defs: {
$defs?: {
nestedDef: boolean;
};
};
RemoteDefs: {
$defs: {
$defs?: {
remoteDef: components["schemas"]["remoteDef"];
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ describe("transformSchemaObject > object", () => {
},
want: `{
foo?: string;
$defs: {
$defs?: {
/** @enum {string} */
defEnum: "one" | "two" | "three";
};
Expand Down Expand Up @@ -612,7 +612,7 @@ describe("transformSchemaObject > object", () => {
},
want: `{
foo?: string;
$defs: {
$defs?: {
readOnlyDef: $Read<string>;
writeOnlyDef: $Write<number>;
normalDef: boolean;
Expand Down
Loading