Swagger validation slow with large response
Opened this issue · 0 comments
I have an API which returns a large response (~5000 records and each record has around 40 properties) I am using express (4.16.3) and swagger-tools (0.9.16) for validation. I found something different today. The API was taking a lot of time when the number of records increases. I set the data and response like this
res.status(200).json(data);
and response in swagger.yaml looks like this
responses:
'200':
description: OK
schema:
type: array
items:
$ref: '#/definitions/testResponse'
default:
description: Error
schema:
$ref: '#/definitions/ErrorResponse'
where data is the JSON response. I found that express stringfies the response here https://github.com/expressjs/express/blob/master/lib/response.js#L260-L267
The response type is defined as array for this endpoint. But in the code here https://github.com/apigee-127/swagger-tools/blob/master/lib/validators.js#L613-L624, I can see that, if it is an array, it goes over each element in the array. But in our case, since express has stringified the response, it takes each character and validates it. Since there are around ~2 million characters in the response, it takes a while (~15 seconds) to get the response. Has anyone noticed this behavior with swagger-tools? Thanks.