Comments (6)
Good find, should be able to look at this today.
On Jul 23, 2016 9:59 PM, "Dave Leaver" [email protected] wrote:
Make a controller with a return result that includes a string union
interface Result {
value: 'success' | 'failure';
}Then try generate routes with tsoa.
You get the error: Unknown type: UnionType—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#5, or mute the thread
https://github.com/notifications/unsubscribe-auth/AIXUAOybc6gxQs-AYL5Mu8PX-h_ZHcWxks5qYsbpgaJpZM4JTe-X
.
from tsoa.
Started looking into the implementation for this, but I think there's a challenging limitation of Swagger/OpenAPI we'll have to figure out.
Swagger spec deliberately disallows multiple response types ("union types")
So, the question becomes: what should happen if a referenced model in your API code has a union type property, or the return type of an endpoint itself is a union type?
We can:
- Throw an error during generation (this is what happens now, and is obviously not great)
- We could somehow try to find a merged/common type between union types, or merge the type info into a combined type (this seems super confusing to me)
- We can find some way to essentially represent a union type as dynamic, i.e. no generated swagger definition (not super useful to a consumer, but at least you'd know that that an endpoint returning type "Result" has some value by key 'value'.
I think from an API design standpoint, an enum makes a lot more sense here than the union type string values. That said, there's no support in this library for enums at the moment, although I plan to implement that soon.
from tsoa.
@danzel After further reflection I've decided on option 3 above - see 305dd32
TLDR: union types will be set to type 'object' in swagger generation, which you can think of as 'any' or 'dynamic' type since Swagger/OpenAPI doesn't offer a way to represent this.
Let me know if this doesn't quite meet your expectations or if you have some additional thoughts to share.
from tsoa.
You are right that I wanted to use an enum, hadn't actually tried an enum type though.
I'll make an issue for adding that, thanks!
from tsoa.
Oh you beat me to it :)
from tsoa.
Actually swagger has a way of expressing "any". It is omitting the "type" property.
So in a schema instead of
"values": {
"type": "object",
"properties": {}
"description": "descr"
}
you can have just:
"values": {
"description": "descr"
}
Having object as type has another meaning, since it says the type will be an object - and not a string, number, boolean..
I suggest removing the "type" property completely for any, and also for union types. Though this definitely requires more testing, i am not sure if omitting the type is allowed in all cases.
regards,
Thomas
from tsoa.
Related Issues (20)
- Errors are logging PII HOT 3
- @Queries Can't support 'refObject' type HOT 4
- ValidateError does not produce valid swagger.json HOT 3
- Problem with swagger generation, when using generic value in nested generic
- OpenTelemetry for distributed tracing with TSOA HOT 4
- Errors thrown in custom middleware do not get passed to error handler HOT 2
- Not Possible to chain multiple middlewares with @Middlewares decorator HOT 2
- await or return missing on promiseHandler in express.hbs template HOT 2
- Key of schema with `$` are generated, but `$` is invalid character. HOT 4
- Custom templates Handlebars HOT 3
- [resolved but might be handles better?] Generic controller's methods HOT 3
- MIME based responses in OpenAPI/Swagger HOT 2
- Question: arguments-aware authorization possible? HOT 5
- Is it possible to split routers with tsoa for lambdas? HOT 3
- Nullable information is lost with Typescript Utility Type (Pick, Partial, ...) HOT 4
- PR 1498 break generating spec or routes HOT 4
- Duplicate component name in spec HOT 1
- Help requested: Using in-memory caching with TSOA HOT 2
- GenerateMetadataError: Unknown type: BigIntKeyword HOT 2
- Support string variable in the first argument of @Extension 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 tsoa.