I am building an API and using Google App engine standard environment, Java 8 runtime.
The REST api itself is built over guice + google endpoints apis.
I have configured the API Key based security for the endpoint as well. The issue I am facing is that when I provide an incorrect key, the service responds 400 Bad request with an HTML error payload.
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>400 API key not valid. Please pass a valid API key</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: API key not valid. Please pass a valid API key</h1>
</body>
</html>
Is there a way to make the endpoint send a JSON message instead? I'd rather not burden the clients to parse HTML in some one-off cases.
Thanks
OpenAPI.json (Generated using :mvn endpoints-framework:openApiDocs ) Edited to remove sensitive info.
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "my-app.appspot.com"
},
"host": "my-app.appspot.com",
"basePath": "/_ah/api",
"schemes": [
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/operation/v1/query/{type}": {
"get": {
"operationId": "Lookup",
"parameters": [
{
"name": "type",
"in": "path",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "A successful response",
"schema": {
"$ref": "#/definitions/Result"
}
}
},
"security": [
{
"api_key": [ ]
}
]
}
}
},
"securityDefinitions": {
"api_key": {
"type": "apiKey",
"name": "key",
"in": "query"
}
},
"definitions": {
"Result": {
"type": "object",
"properties": {
"field1": {
"type": "string"
},
"field2": {
"type": "string"
}
}
},
}
}