I used swagger-codegen to build a service api in javascript. When the call works it returns my custom defined type and status 200, but when there is a validation error it returns an error but also a status 200.
For example:
{
"message": "Request validation failed: Parameter (model) is required",
"code": "REQUIRED",
"failedValidation": true,
"path": [
"paths",
"/make/ford",
"get",
"parameters",
"0"
],
"paramName": "model"
}
I would expect it to return status code 400 as my swagger.yml only specifies my user defined type as a response. How can I make the generated code return status 400 for validation errors?
The endpoint is described like this (partial file):
/make/ford:
x-swagger-router-controller: controller
get:
description: Description
operationId: get_car
parameters:
- name: model
in: query
description: Model
required: true
type: array
items:
type: string
responses:
"200":
description: Success
schema:
$ref: "#/definitions/ModelResponse"
# responses may fall through to errors
default:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"
definitions:
ModelResponse:
properties:
options:
type: array
items:
type: string
ErrorResponse:
required:
- message
properties:
message:
type: string
Note: AWS API Gateway doesn't not support default responses, so I may take that out.