I am working on a project that uses Swagger 2.0 to generate an API interface which is then implemented in production code. There is a problem with a parameter that comes from the header.
There are 2 desired behaviors -
- If a value is provided and does not match the enum, it should throw an error
- If no value is provided, it should be given the default value of 'English'
Here is the code -
parameters:
language:
in: header
name: language
description: language the request will be processed in
type: string
default: English
enum: [English, Spanish, German, French]
required: false
However, the API accepts any value and does not provide a default value.
The generated code does not give any hint that it should be an enum. It does show the default value but did not provide it when I performed an integration test.
@ApiParam(value = "language the request will be processed in" , defaultValue="English") @RequestHeader(value="language", required=false) String language);
I found other similiar questions on here but no answers - Swagger does not validate enum query parameter