Comments (15)
I think we should be able to process anonymous types, but I don't think we should generate interfaces for them or anything. I think we should simply have inline descriptions in the swagger spec with the properties contained in that anonymous type.
from tsoa.
you can set it in tsoa.config, inside the swagger block:
"noImplicitAdditionalProperties": "silently-remove-extras"
Hope it helps
from tsoa.
I guess this is a common issue for anonymous types. Either a type name needs to be generated, or more meaningful error reported. @lukeautry what's your position on this? I was looking into this for hashmaps support (field: {[key:string]: xxxxx};
) - may as well fix this if you'll approve type generation
from tsoa.
Any update on that?
from tsoa.
+1 This would definitely be a great improvement : Being forced to define distinct classes for properties that will never exist by themselves is painful and add unnecessary complexity to the documentation.
from tsoa.
@ThorstenBux / @fhewitt / @donahchoo / @manast-apsis if tsoa
were to generate the swagger model "on-the-fly" it doesn't have a name for the model. And that's the problem, swagger requires a name for the "$ref" (see here). So my question for you is, how would you like it create that name?
An example @manast-apsis provided looks like this:
class myClass {
nodes: {
[nodeName: string]: Node;
};
}
I imagine that we could create something like RecordOfNodeNameToNodeValue
since that would be RecordOf{indexName}To{valueType}Value
. But even then, I'm wondering if we would get collisions. For instance:
export interface ModelToUser {
toys: {
[key: string]: any
},
chores {
[key: string]: any
}
}
That would produce to $refs with the same name RecordOfKeyToAnyValue
.
I'm just raising some scenarios. Also I'd love your input to know what you'd like the auto-generated name to look like. I'll add the [Help Wanted] PR to this so new contributors can give it a shot.
P.S. it's been mentioned before, but the workaround is to make explicit interfaces (even if that is unpalatable for some). So in the case of the MyClass.nodes
issue I presented above, the current solution would be
interface INodeDictionary {
[nodeName: string]: Node;
}
class myClass {
nodes: INodeDictionary;
}
from tsoa.
This is super helpful for us. Would it be possible to get a release soon with all the recent improvements? Thanks
from tsoa.
@javichi I just pushed version 2.5.0 that allows nested anonymous types. Please let us know if it works for you so we can consider closing this isue. Btw, I don't think it allows it at the first level because we need to be able to create a $ref name in swagger. So don't expect something like this to work:
@Post()
public async Create(@Body() user: IUserAbstraction): Promise<{foo: string}> {
// ...
}
However, I believe that PR #415 allows you to do this:
export interface IHaveAnAnonymousChild {
foo: string,
nestedAnonymous: {
bar: string
}
}
@Post()
public async Create(@Body() user: IUserAbstraction): Promise<IHaveAnAnonymousChild> {
// ...
}
from tsoa.
@ThorstenBux / @fhewitt / @donahchoo / @manast-apsis now that this feature was released in v2.5.0 if you could test and let us know what you think, that would really help us! :) See above for potential limitations.
from tsoa.
@dgreene1 You should try (inlining inside the Promise) π
from tsoa.
Trying 2.5.0. I still can't get dictionaries of model objects to work properly. For example the following model:
export interface AccountUser {
_id: string;
email: string;
role: AccountUserRole;
status: AccountUserStatus;
actions: AccountUserAction[];
}
export interface AccountEntity {
_id: string;
type: string;
name: string;
address: string;
lat?: number;
long?: number;
users: {
[k: string]: AccountUser;
};
}
is generating the following swagger model with tsoa v2.5.0:
{
"_id": "string",
"type": "string",
"name": "string",
"address": "string",
"lat": 0,
"long": 0,
"users": {}
}
I noticed a difference though, before 2.5.0 it was including an additionalProp1 key inside the model that has now disappeared in 2.5.0
{
"_id": "string",
"type": "string",
"name": "string",
"address": "string",
"lat": 0,
"long": 0,
"users": {
"additionalProp1": {}
}
}
from tsoa.
@javichi Iβve reopened #374 for you which is more closely related to your specific use case.
As for the additionalProp1, it seems to me that it never should have been there, right? Like itβs good that itβs gone now, correct?
from tsoa.
Yes, I think #374 covers the issue i explained better.
from tsoa.
Hey
I'm using 2.5.9 and still seeing
additionalProp1
at the end of every post request on swagger
Any idea why?
from tsoa.
@oreporan no one has reported that bug yet. So can you please create a github issue and be careful to fill out all of the information so we can reproduce it?
Please include all of your typescript interfaces and your route controllers.
from tsoa.
Related Issues (20)
- 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
- jsdoc @example is used for union type but ignored for enum HOT 3
- programmatic way to generate the spec and routes HOT 12
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.