With latest version, there seems to be a problem with SendResponseMiddleware. When returning the value in controller serialization fails, because it takes the wrong model for validation.
I tracked down where this model gets checked and found that it takes invalid type. ExceptionModel is taken instead of GenerateApiKeyResponseModel.
Here is the place where this gets injected:
I'm using this piece of code to generate endpoint:
@Post('/')
@Returns(200, { description: 'On success', type: GenerateApiKeyResponseModel })
@Returns(400, { description: 'Validation error', type: ExceptionModel })
@Returns(401, { description: 'Invalid token', type: ExceptionModel })
public async post() {
return {
apiKey: apiKeyId
};
}
Haa ok I fix that :)
v5.39.2 :)
Excuse my intrusion, but can this be closed?
There are many others that can be closed.
Yes we can close. It's just because I forgot to mentionne the issue in the commit which is resolve this problem.
Hey @Romakita ,
I've updated version from 5.39.0 to the latest 5.41.1 and I'm still getting an error at validation when returning a value.
I was debugging and found that when function statusResponse() on class EndpointMetadata is called it always sets response type. Because of this, it overrides property type if 200 if first called.
This is called from OpenApiEndpointBuilder.createResponse() for every @Returns().
If I put this code into EndpointMetadata.ts at line 123, validation error disappeared.
if (code && Number(code) >= 200 && Number(code) < 300) {
const {type, collectionType} = get(code);
this.type = type;
this.collectionType = collectionType;
}
But this won't work either if you have multiple responses between 200 and 300.
Hi, I'm not sure if this is related but I can't seem to use multiple @Returns() decorators on a controller anymore, so I've been stuck using 5.36.0. For example, in the latest version (5.42.1) of tsed:
This will produce swagger docs that do not include a response for "400", "404", and "401" although it will include docs for "200":
@Returns(200, {description:'I will show up in swagger docs on the latest version'})
@Returns(400, {description:'I will NOT show up in swagger docs on the latest version'})
@Returns(404, {description:'I will NOT show up in swagger docs on the latest version'})
@Returns(401, {description:'I will NOT show up in swagger docs on the latest version'})
public controllerName(): void {}
If I add a required parameter, it will create docs for "200" and "400" but not any other response codes:
@Returns(200, {description:'I WILL show up in swagger docs on the latest version'})
@Returns(400, {description:'I WILL show up in swagger docs on the latest version'})
@Returns(404, {description:'I will NOT show up in swagger docs on the latest version'})
@Returns(401, {description:'I will NOT show up in swagger docs on the latest version'})
public controllerName(
@Required()
@QueryParams('exampleParam', String) param: string
): void {}
But, when I use 5.36.0, everything works like I'd expect it to:
@Returns(200, {description:'I WILL show up in swagger docs on 5.36.0'})
@Returns(400, {description:'I WILL show up in swagger docs on 5.36.0'})
@Returns(404, {description:'I WILL show up in swagger docs on 5.36.0'})
@Returns(401, {description:'I WILL show up in swagger docs on 5.36.0'})
public controllerName(): void {}
Again, sorry if this is unrelated & I can open a separate issue if it is.