Open daniimara opened 3 years ago
Seems like we should consider intersection and union scenarios. Your suggestion is good, we need to generalize it beyond the one use case from the initial bug report. If we encounter an intersection, we need to get properties from all n branches recursively. Similarly, in case of a union, we should get properties from all n branches and mark them as optional (?).
I bump into the same issue, any updates on it?
I use Zod and it doesn't take required into consideration for validation
controller:
public async createUser(
@Body() body: UserCreateRequest
): Promise<UserResponse> {
type definition:
export const UserCreate = UserBase.omit({ id: true })
.required({
email: true,
})
.and(UserSchema.pick({ password: true }))
export type UserCreateRequest = ReturnType<typeof UserCreate.parse>
This is very problematic - makes intersection types utterly useless in tsoa - can't update a type to make some properties optional (or required) - can't get proper schema validation or examples for anything using an intersection type.
For the intersection scenario below, the fields
active
andresults
are missing on the swagger.json generated:Sorting
I'm submitting a ...
I confirm that I
Expected Behavior
The fields
active
andresults
should be on the swagger.json generated:Current Behavior
The fields
active
andresults
are missing on the swagger.json generated:Possible Solution
I suggest change the function
getModelInheritedProperties
atcli/src/metadataGeneration/typeResolver.ts
:Steps to Reproduce
Try to generate the spec to:
Context (Environment)
Version of the library: 3.9.0 Version of NodeJS: v12.13.1
Detailed Description
I am proposing a change to support the intersection scenario described.
Breaking change?
No.