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)
- programmatic way to generate the spec and routes HOT 13
- Custom parameters in controller HOT 3
- Evaluate @Security in order of definition HOT 3
- AuthenticationMiddleware should also depend on authenticationModule being present HOT 2
- Unable to assign null to properties defined as number | null | undefined after updating to version 6.2.0 HOT 3
- Reasoning for always setting defaultNumberType HOT 2
- Can't send stream to injected error responder when using '@Security()` decorator. (Really I'm just trying to create a plain-text error) HOT 2
- Declare Auth schema without need to implement handlers HOT 2
- Make express request injectable HOT 2
- Problem with @types/express version 4.17.21 HOT 2
- Upload multiple files using @UploadedFiles() and @UploadedFile causes multer error HOT 2
- Using combination of @UploadedFile() and @UploadedFiles() decorators throws MulterError: Unexpected field HOT 2
- GenerateMetadataError: Unknown type: IndexedAccessType HOT 3
- GenerateMetadataError: Unknown type: IntrinsicKeyword HOT 1
- Routes.ts TSC Error expressAuthenticationRecasted
- Multiple runtime dependencies for backend frameworks.
- nullable: true and allOf HOT 1
- Support verbatimModuleSyntax (tsconfig) HOT 2
- Regression in route generation from 5.1.1 to 6.x.x: "This node kind is unknown"
- CLI cannot import tsoa-config.js in ESM project HOT 2
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.