Type names from typescript type alias definitions
See original GitHub issueTo start off: great library š !!!
Question/issue about the naming of Schemas.
Sorting
-
Iām submitting a ā¦
- bug report
- feature request
- support request
-
I confirm that I
- used the search to make sure that a similar issue hasnāt already been submit
Expected Behavior
type LoginStatus = {
loggedIn: boolean;
username: string;
}
/**
* A narrower LoginStatus
*/
type LoginStatusFailed = Pick<LoginStatus, 'loggedIn'>
@Route('api/v1/login')
export class LoginController extends Controller {
@Path('/')
@Post()
@Response<LoginStatusFailed>(StatusCode.UNAUTHORIZED, "Unauthorized", { loggedIn: false })
public async doLogin(...): Promise<LoginStatus> {
this.setStatus(StatusCode.UNAUTHORIZED)
return { loggedIn: false }
}
}
Current Behavior
Expecting LoginStatusFailed instead of Pick_LoginStatus.loggedIn_
.
Swagger UI
Spec Schemas
"LoginStatus": {
"properties": {
"username": {
"type": "string"
},
"loggedIn": {
"type": "boolean"
}
},
"required": [
"loggedIn", "username"
],
"type": "object"
},
"Pick_LoginStatus.loggedIn_": {
"properties": {
"loggedIn": {
"type": "boolean"
}
},
"required": [
"loggedIn"
],
"type": "object",
"description": "From T, pick a set of properties whose keys are in the union K"
},
"LoginStatusFailed": {
"$ref": "#/components/schemas/Pick_LoginStatus.loggedIn_",
"description": "A narrower LoginStatus"
},
...
DoLogin controller
This seems to be correct in swagger.json paths["/api/v1/login"].post.responses["401"].content["application/json"].schema.$ref
.
"schema": {
"$ref": "#/components/schemas/LoginStatusFailed"
},
Possible Solution
Steps to Reproduce
- Create type alias using Omit or Pick
- Make Controller method return type alias
- Expect type alias name to be the schema name
Context (Environment)
Version of the library: 3.3.0 Version of NodeJS: v12.18.3
Also using āswagger-ui-expressā 4.1.4 to display spec.
Detailed Description
Would also be nice if From T, pick a set of properties whose keys are in the union K
could be rendered with the proper types, not sure if achievable.
Breaking change?
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Documentation - Advanced Types - TypeScript
Type aliases create a new name for a type. Type aliases are sometimes similar to interfaces, but can name primitives, unions, tuples, and...
Read more >3 Ways to Name Types in Typescript - geekAbyte
Type aliases are another mechanism for naming types in TypeScript. It is a feature that makes it possible to give a name (or...
Read more >TypeScript | Type Aliases - Codecademy
In TypeScript, type aliases create type definitions, using the `type` keyword and a name, that can be reused throughout the code.
Read more >What are type aliases and how to create it in Typescript
In Typescript, Type aliases give a type a new name. They are similar to interfaces in that they can be used to name...
Read more >What are type aliases in TypeScript? - Educative.io
In TypeScript, type aliases are used to assign a name for any type. It doesn't create a new type. Instead, it provides a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Re: breaking change. Yeah, this would have to be opt-in, maybe via a flag in ātsoa.jsonā.
Re: readability. Since OpenAPI currently canāt represent generic types, tsoa has to generate a mangled name. Are there cases where someone would actually want these types present in generated spec, e.g.
Pick_LoginStatus.loggedIn_
? Again, Iām new to tsoa so maybe Iām missing some use cases.any update? I had faced same problem when I follow the official tutorial