|
1 | 1 | import propertyMapper from "./property-mapper";
|
2 |
| -import { OpenAPI2, OpenAPI2SchemaObject, OpenAPI2Schemas, SwaggerToTSOptions } from "./types"; |
3 |
| -import { comment, nodeType, transformRef, tsArrayOf, tsIntersectionOf, tsUnionOf } from "./utils"; |
| 2 | +import { OpenAPI2, OpenAPI2Reference, OpenAPI2SchemaObject, OpenAPI2Schemas, SwaggerToTSOptions } from "./types"; |
| 3 | +import { comment, nodeType, transformRef, tsArrayOf, tsIntersectionOf, tsUnionOf, isOpenAPI2Reference } from "./utils"; |
4 | 4 |
|
5 | 5 | export const PRIMITIVES: { [key: string]: "boolean" | "string" | "number" } = {
|
6 | 6 | // boolean types
|
@@ -40,6 +40,14 @@ export default function generateTypesV2(input: OpenAPI2 | OpenAPI2Schemas, optio
|
40 | 40 | // propertyMapper
|
41 | 41 | const propertyMapped = options ? propertyMapper(definitions, options.propertyMapper) : definitions;
|
42 | 42 |
|
| 43 | + //this functionality could perhaps be added to the nodeType function, but I don't want to mess with that code |
| 44 | + function getAdditionalPropertiesType(additionalProperties: OpenAPI2SchemaObject | OpenAPI2Reference | boolean) { |
| 45 | + if (isOpenAPI2Reference(additionalProperties)) { |
| 46 | + return transformRef(additionalProperties.$ref, rawSchema ? "definitions/" : ""); |
| 47 | + } |
| 48 | + return nodeType(additionalProperties); |
| 49 | + } |
| 50 | + |
43 | 51 | // type conversions
|
44 | 52 | function transform(node: OpenAPI2SchemaObject): string {
|
45 | 53 | switch (nodeType(node)) {
|
@@ -67,7 +75,7 @@ export default function generateTypesV2(input: OpenAPI2 | OpenAPI2Schemas, optio
|
67 | 75 |
|
68 | 76 | // if additional properties, add to end of properties
|
69 | 77 | if (node.additionalProperties) {
|
70 |
| - properties += `[key: string]: ${nodeType(node.additionalProperties) || "any"};\n`; |
| 78 | + properties += `[key: string]: ${getAdditionalPropertiesType(node.additionalProperties) || "any"};\n`; |
71 | 79 | }
|
72 | 80 |
|
73 | 81 | return tsIntersectionOf([
|
|
0 commit comments