Comments (5)
#1574 was merged into main now. Working on backporting to 6.x now.
from openapi-typescript.
I had a good look at the code now and read the discriminator unit tests. This case of oneOf seems to be not supported. There is a oneOf case that is tested, but it doesn't seem to even use a discriminator, the OpenAPI input is invalid and the output is simply a oneOf union:
The default usecase for oneOf discriminators seems to be not handled right now, so I changed the title of this feature request accordingly.
I also have a proposal now and might be able to implement this. The hard part is searching for all discriminator properties referenced by a discriminator. This should be done via the mapping itself, where we already get the path of the schema object. If the object consists of an allOf (for example a base object for the discriminator, where the discriminator property really is), the allOf needs to be resolved. Finally we need to overwrite the discriminator property with the single mapped value to mimick the Typescript union discimination.
We probably need to enhance the discriminator scan and add the discriminator property paths to the ctx information. That way we should be able to quickly find the discriminator properties inside transformSchemaObjectCore
and transform { type: 'string', enum: [value] }
instead of the full enum.
That doesn't take the resolved allOfs into account. Maybe we can append the discriminator property to the mapped schema objects to overwrite any inherited discriminator properties?
@drwpow Shall I try to implement the easy case from the OpenAPI above? It is the default case for oneOf from the OpenAPI documentation for discriminators.
from openapi-typescript.
I PR'd a proposal so we can discuss the new support: #1574
from openapi-typescript.
Sadly, I had little time to do the backport. It is also taking much longer due to the big differences in the code base. So I gave this more thought and I feel like we probably should not do a backport to v6. The new discriminator code is a major change for the output, so this really belongs in v7 to avoid any surprises.
@drwpow How do you feel about this?
from openapi-typescript.
I will close this Issue to clean up a little.
from openapi-typescript.
Related Issues (20)
- Metadata generation
- Allow client option for custom dispatcher into fetch requests (e.g. to disable certificate validation) HOT 6
- advice on how to connect a frontend (swagger?) while using this lib
- Set baseUrl per request
- 0.9.4 breaks some Typescript configurations HOT 3
- Response types from openapi-fetch ignore null values
- Multiple security schemes not supported
- With React Query: Invariant: headers() expects to have requestAsyncStorage, none available. HOT 3
- `--properties-required-by-default` and `--default-non-nullable` flags do not work HOT 1
- Nested object's properties are mapped to unknown, but in OpenAPI they are typed correctly HOT 3
- "AdditionalProperties" reflects onto existing properties and causes TypeScript compile errors HOT 1
- Issues with references (`$ref`) resolution HOT 2
- Error with negative numbers in enums HOT 2
- Allow for custom types in path params serialization (and maybe other places serialization too)
- Types derived for oneOf construct result in TS2502 error HOT 7
- Uncaught error when body is `undefined` in request init HOT 6
- 'path' does not exist in type '{ query?: Record<string, unknown> | undefined; }' HOT 4
- issue on - generate client when yaml has mutiple same external ref
- Generate subset of schema
- Deduplicate enums
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.