Skip to content

Commit 7c3c213

Browse files
authored
Support for components.responses (#258)
* Added type support for responses property in components * Added support for mapping responses in v3 * Fixed linting errors
1 parent 1ebac68 commit 7c3c213

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

src/types/OpenAPI3.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface OpenAPI3 {
88
openapi: string;
99
components: {
1010
schemas: { [key: string]: OpenAPI3SchemaObject | OpenAPI3Reference };
11+
responses?: { [key: string]: OpenAPI3SchemaObject | OpenAPI3Reference };
1112
};
1213
[key: string]: any; // handle other properties beyond swagger-to-ts’ concern
1314
}

src/v3.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,22 @@ export default function generateTypesV3(
126126
return output;
127127
}
128128

129+
const schemas = `schemas: {
130+
${createKeys(propertyMapped, Object.keys(propertyMapped))}
131+
}`;
132+
133+
const responses = !schema.components.responses
134+
? ``
135+
: `responses: {
136+
${createKeys(
137+
schema.components.responses,
138+
Object.keys(schema.components.responses)
139+
)}
140+
}`;
141+
129142
// note: make sure that base-level schemas are required
130143
return `export interface components {
131-
schemas: {
132-
${createKeys(propertyMapped, Object.keys(propertyMapped))}
133-
}
144+
${schemas}
145+
${responses}
134146
}`;
135147
}

tests/v3/expected/petstore.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export interface components {
4242
*/
4343
status?: "available" | "pending" | "sold";
4444
};
45+
};
46+
responses: {
4547
ApiResponse: { code?: number; type?: string; message?: string };
4648
};
4749
}

tests/v3/specs/petstore.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ components:
707707
- sold
708708
xml:
709709
name: Pet
710+
responses:
710711
ApiResponse:
711712
type: object
712713
properties:

0 commit comments

Comments
 (0)