Comments (3)
That’s correct. A { "type": "object" }
has no properties (Record<string, never>
), and you didn’t declare additionalProperties
explicitly. And the | null
is correct. See the docs on this behavior.
openapi-typescript will never generate a any
type because that’s basically not typechecking at all. In order to achieve that behavior, you’ll have to either make your OpenAPI schema more explicit (recommended), or override the type with the desired type (i.e. OpenAPI schema didn’t declare a descriptive type, therefore openapi-typescript couldn’t, so I’ll have to override it manually in TypeScript).
from openapi-typescript.
That’s correct. A
{ "type": "object" }
has no properties (Record<string, never>
), and you didn’t declareadditionalProperties
explicitly. And the| null
is correct. See the docs on this behavior.openapi-typescript will never generate a
any
type because that’s basically not typechecking at all. In order to achieve that behavior, you’ll have to either make your OpenAPI schema more explicit (recommended), or override the type with the desired type (i.e. OpenAPI schema didn’t declare a descriptive type, therefore openapi-typescript couldn’t, so I’ll have to override it manually in TypeScript).
What if it's intended that I can send something with whatever keys and values I want to the backend (for example, it's an extra field that's saved to the DB as a JSON type)? Is there a good way to represent that the type of the record doesn't matter?
from openapi-typescript.
Yes! That’s additionalProperties
. You can give that a type, and be as descriptive as possible. It will let any arbitrary keys return the provided shape.
You can also set additionalProperties: true
to generate Record<string, unknown>
, but it’s always best to just pass a full Schema Object to additionalProperties ($ref
s work too)
from openapi-typescript.
Related Issues (20)
- openapi-typescript cmd idle when using redocly.yaml HOT 2
- Empty object inside of allOf creates Record<string, never> in a type intersection HOT 2
- Query param type safety only works for the first param. HOT 5
- client["/endpoint"].GET style call pattern to enable go-to-definition HOT 2
- immutable option and readonly arrays HOT 1
- failure on attempting to GET a binary image response HOT 3
- `--exclude-deprecated` flag is not applied to query and path HOT 2
- Query parameter serialization for objects is not the openapi default HOT 4
- Redocly not using auth headers from env var when trying to pull a yaml from a private repo HOT 3
- Operation types are being mapped incorrectly (v7) HOT 3
- Add an option to generate type aliases for schemas HOT 2
- Exception in catch block: `TypeError: Response.text: Body has already been consumed.` HOT 2
- Request Header 'Content-Type' no longer set for requests with body serialized as FormData HOT 3
- after upgrade from 0.8.2 to 0.9.1, receiving several errors all inside openapi-fetch HOT 5
- transforming enum to delete the pathname at the enum name HOT 4
- Copy the API version to output file HOT 1
- proposal: openapi-fetch new send function HOT 7
- Document Chinese support HOT 8
- Allow providing custom `Request` and `Response` HOT 1
- 7.x nullable enum bug HOT 6
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.