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