Comments (8)
Would be great to be fixed since the .net core feature of the ProblemDetails runs into this problem when documented via the ProducesResponseTypeAttribute
from openapi-typescript.
Here's a patchfile for anyone else who needs this. I'll put a PR together too.
diff --git a/node_modules/@manifoldco/swagger-to-ts/dist-node/index.js b/node_modules/@manifoldco/swagger-to-ts/dist-node/index.js
index ff14209..3f5f525 100644
--- a/node_modules/@manifoldco/swagger-to-ts/dist-node/index.js
+++ b/node_modules/@manifoldco/swagger-to-ts/dist-node/index.js
@@ -216,7 +216,17 @@ function generateTypesV2(schema, options) {
let properties = createKeys(node.properties || {}, node.required);
if (node.additionalProperties) {
- properties += `[key: string]: ${nodeType(node.additionalProperties) || "any"};\n`;
+ const nodeTypeOfAdditionalProps = nodeType(node.additionalProperties)
+ if (nodeTypeOfAdditionalProps === 'array') {
+ const nodeTypeOfAdditionalItems = nodeType(node.additionalProperties.items)
+ if (nodeTypeOfAdditionalItems === 'ref') {
+ properties += `[key: string]: ${tsArrayOf(transform(node.additionalProperties.items))};\n`;
+ } else {
+ properties += `[key: string]: ${nodeTypeOfAdditionalItems || "any"};\n`;
+ }
+ } else {
+ properties += `[key: string]: ${nodeTypeOfAdditionalProps || "any"};\n`;
+ }
}
return tsIntersectionOf([...(node.allOf ? node.allOf.map(transform) : []), ...(properties ? [`{ ${properties} }`] : [])]);
@@ -307,7 +317,6 @@ function generateTypesV3(schema, options) {
}
}
- return "";
}
function createKeys(obj, required) {
from openapi-typescript.
I have a similar problem which seems related. Given the schema
components:
schemas:
Example:
type: object
properties:
dictionary:
type: object
additionalProperties:
type: number
nullable: true
required:
- dictionary
swagger-to-ts generates
export interface components {
schemas: {
Example: {
dictionary: { [key: string]: number };
};
};
}
whereas it should be
export interface components {
schemas: {
Example: {
dictionary: { [key: string]: number | null };
};
};
}
from openapi-typescript.
Here's another minimal reproduction for the lack of additionalProperties
support. Given this part of an API spec:
"components": {
"schemas": {
"ProblemDetails": {
"type": "object",
"properties": {
"type": {
"type": "string",
"nullable": true
},
"title": {
"type": "string",
"nullable": true
},
"status": {
"type": "integer",
"format": "int32",
"nullable": true
},
"detail": {
"type": "string",
"nullable": true
},
"instance": {
"type": "string",
"nullable": true
}
},
"additionalProperties": {
"type": "object",
"additionalProperties": false
}
}
}
}
swagger-to-ts
generates:
export interface components {
schemas: {
ProblemDetails: {
type?: string | null;
title?: string | null;
status?: number | null;
detail?: string | null;
instance?: string | null;
[key: string]: { [key: string]: any };
};
};
}
which has an invalid index signature. The index signature needs to be:
[key: string]: { [key: string]: any } | string | null | number;
from openapi-typescript.
#324 related?
from openapi-typescript.
I see this is in #294.... how can I make use of this?
from openapi-typescript.
Just improved support for additionalProperties
in #442 but will be taking a look at this next to see if I missed any cases (more than likely I did)
from openapi-typescript.
Support for additionalProperties has been greatly improved in this library since this issue was filed. I’m going to close this, but if there are any cases I’ve missed please let me know, either in this issue or by opening a new one with a specific schema to test.
from openapi-typescript.
Related Issues (20)
- Cannot find name 'HeadersInit'. HOT 4
- Headers lost in fetch request when using BUN HOT 1
- Problem after using ver 7 with generated types for mapping of discriminator HOT 5
- CLI option to validate existing file HOT 4
- bug: request body fields with default values are treated as required HOT 4
- Bug: references to nested properties in schemas generate invalid types
- Error saving output on windows with full file paths instead of relative
- Setup section in npm and the docs are not similar HOT 3
- Types are not enforced with typescript `5.5.3` HOT 6
- Generates invalid types when API paths are nested HOT 3
- Inject option dropped in v7 HOT 1
- Document for conditional authentication failed. HOT 1
- transform function changing objects to not-nullable no longer working in v7 HOT 3
- openapi-fetch: example for extending api client methods HOT 2
- Undefined properties on body object are not flagged if required fields are filled in
- Support cookie parameters
- Default values override "required" state in output types HOT 2
- params always required HOT 1
- Consider using codegen instead of generics HOT 5
- Problem using --array-length when minItems equals to maxItems HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openapi-typescript.