Comments (21)
I think the string representation that you've proposed is ideal. The number
representation is basically meaningless from a human readability standpoint.
On Jul 24, 2016 9:14 PM, "Dave Leaver" [email protected] wrote:
For my uses I'd like to declare an enum and have the field be the string
valuesenum ResultType {
Success,
FailureNoPermission
}Should result in swagger like:
"type": "string","enum": [ "Success", "FailureNoPermission" ],
Not sure if other people would like the numeric values.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#6 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AIXUACHjNUQlYCqctcorqtKXO6XZKti9ks5qZA3sgaJpZM4JTt7o
.
from tsoa.
You can try using this:
export type CaseEnum = "Unchanged" | "Capitalized" | "FirstLetterUppercase" | "CamelCase" | "PascalCase" | "Lower" | "Upper";
export const CaseEnum = {
Unchanged: "Unchanged" as CaseEnum,
Capitalized: "Capitalized" as CaseEnum,
FirstLetterUppercase: "FirstLetterUppercase" as CaseEnum,
CamelCase: "CamelCase" as CaseEnum,
PascalCase: "PascalCase" as CaseEnum,
Lower: "Lower" as CaseEnum,
Upper: "Upper" as CaseEnum
};
It feels like an enum - but it's actually a class/string
from tsoa.
For my uses I'd like to declare an enum and have the field be the string values
enum ResultType {
Success,
FailureNoPermission
}
Should result in swagger like:
"type": "string",
"enum": [ "Success", "FailureNoPermission" ],
Not sure if other people would like the numeric values.
from tsoa.
@danzel Just wanted to provide an update here; enum support hasn't been straightforward, at least for the routing side of things. Generating the correct swagger spec is a straightforward, but wiring up the autogenerated routes to 1) convert strings to their enum values and 2) validate enum values takes a bit more work. Hope to have something in the next week or so.
from tsoa.
Thanks, no hurry the string work around is fine :)
from tsoa.
@lukeautry would it be easier to support string literal types instead of enums?
for example:
type Auth = "Facebook" | "Google"
from tsoa.
@maxcan Yeah, I have a branch going to implement that exact thing; the issue you opened #39 is caused by the inability to parse a type alias/string literal type.
Feel free to take a stab at it though, it'll probably be next week sometime before it can be completed.
from tsoa.
from tsoa.
from tsoa.
@lukeautry is it worth using it as a starting point? If not, I can start off master, just tell me where to look in the code
from tsoa.
hey @lukeautry I'm only interested in swagger support... any chance you could share the code that gets enums to work with swagger? I could then use it in a fork.
from tsoa.
@maxcan do you plan to add support for using string literal types as @path arguments?
from tsoa.
@alexey-pelykh I'm actually not using tsoa at the moment - jumped over to the graphql dark side so I won't be making any more changes. Happy to give some tips if you want to take it up though.
Max
from tsoa.
@maxcan yeah, I have no choice then :) I've looked through the code more or less, string literal as "pathable" type - just something that was missed out or there was a reason for not doing that?
from tsoa.
what do you mean by "pathable"?
from tsoa.
union (string literals) fails over here https://github.com/lukeautry/tsoa/blob/master/src/metadataGeneration/parameterGenerator.ts#L128
So it's impossible to use type test = 'a' | 'b';
in Header, Query or Path parameters. I do hope to address that soon
from tsoa.
ah ok, I see what you mean. no, I never added support for that. I imagine i shouldn't be too difficult though, just not on my radar. maybe use the PR above as a guide?
from tsoa.
@lukeautry I'd love to submit a PR regarding enums-as-union-types and alias types, yet it bases on #77 and #75 so I'd like to ask to take a look on those
from tsoa.
Hello, any update for this support, I'm actually trying to add type and enumeration to the response body, but it fails in TypeResolver, the enumeration name (Merchant Status) is not the same as SafeArray
export enum MerchantStatus {
active = 'active',
pending = 'pending',
}
export class User {
uid: string;
merchantStatus: MerchantStatus;
}
Unhandled rejection Error: No matching model found for referenced type MerchantStatus. If MerchantStatus comes from a dependency, please create an interface in your own code that has the same structure. Tsoa can not utilize interfaces from external dependencies. Read more at
https://github.com/lukeautry/tsoa/blob/master/docs/ExternalInterfacesExplanation.MD
return (modelTypeDeclaration.name as ts.Identifier).text === typeName;
in this block filter its empty because
the typename no is SafeArray
from tsoa.
Could you tell me if this issue still applies to the v3 beta releases?
from tsoa.
Could you tell me if this issue still applies to the v3 beta releases?
I just upgraded to version 3.0.4, and the problem has been solved thanks very much
from tsoa.
Related Issues (20)
- Problem with validation when dealing with unions and deep models
- Multiple Examples with @Response Decorator not possible anymore HOT 4
- Snyk security vulnerability for inflight (one of tsoa indirect dependencies) HOT 3
- Version 6.1.0 leads to missing packages, breaks existing builds HOT 20
- v6.1.0 breaking change on Authentication middleware HOT 1
- Using `Omit` causes extra model to be output in OpenAPI file HOT 2
- Cannot read properties of undefined (reading 'length') with @UploadedFile HOT 1
- Build error: Property 'name' is missing HOT 7
- Can't Handle File and Non-File Field on multipart/form-data simultaneously HOT 4
- Can't Handle Optional File Field on multipart/form-data HOT 1
- Proposal/file upload configurations HOT 2
- UnknownType: IndexedAccessType error when using enum to index type object HOT 1
- The latest version 6.1.4 causes new build issues. HOT 10
- Middleware after response HOT 6
- After update 6.1.5 Types of property 'successStatus' are incompatible HOT 16
- Handling parameters that include mapped types with `Date` as a generic argument HOT 1
- ErrorHandlerMiddleware is ignore with 6.1.* HOT 11
- Populate causes error log: Debug Failure. False expression: Node must have a real position for this operation HOT 3
- ' HOT 1
- Treat null values as no value or undefined 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.