typoa icon indicating copy to clipboard operation
typoa copied to clipboard

null value management

Open MatthieuVegreville opened this issue 1 year ago • 4 comments

Hello team,

Great repo, answering almost all problems we encountered with tsoa. The only issue remaining from our list is null management. Today a query param such as @Query('marketBased') marketBased: boolean|null, or @Query('marketBased') marketBased?: boolean|null,

will always result in required false (logic for the second, not for the first one) and never nullable:true for any of the two, which is what we would expect (first one we would expect required:true and nullable:true and second one required:false and nullable: true)

I think it comes from this bit -- happy to suggest a PR if you agree on the target behavior.

const resolvedType = resolve(propertyType, spec, (nonNullableType, isUndefined, spec) => { if (isUndefined) { required = false return resolve(nonNullableType, spec) } return appendMetaToResolvedType(resolve(nonNullableType, spec), { nullable: true }) })

Let me know

MatthieuVegreville avatar Nov 30 '24 12:11 MatthieuVegreville

Indeed that make sense, feel free to open a PR i'll review it

vmarchaud avatar Dec 04 '24 15:12 vmarchaud