Every endpoint is represented in the swagger.json
file by a path and an operation pair.
The following is a list of the most common swagger.json
properties for an endpoint, and the source of their values:
Property | Source Value |
---|---|
| The |
| The endpoint’s Java method name, which can be overridden by the |
| A parameter array is added for each parameter in the method signature. Refer to the Using Endpoint Parameters section for further information. |
| Every endpoint must contain at least one response entry. Refer to the Using Endpoint Responses for further information. |
| The |
| The |
Using Endpoint Parameters
Swagger adds an entry to an endpoint’s parameter array for each parameter in the method signature. The @ApiParam
annotation is not required for a parameter to be included in swagger.json
. The most common uses of @ApiParam
are to supply a description and to flag a parameter as required. The following is a list of the most common swagger.json
properties for a parameter and the source of their values:
Property | Source Value |
---|---|
| The |
| The |
| Uses |
| Uses |
| The |
| The |
There are additional Swagger properties that could be useful when creating path and query parameters. Unless otherwise noted, these properties come from the @ApiParam
annotation:
defaultValue
-@DefaultValue value
or@ApiParam defaultValue
attributeexample
Using Endpoint Responses
Swagger requires that every endpoint have at least one entry in the responses map. The Swagger scan usually adds “200” with the “successful operation” description by default.
The Swagger extensions in Core Commerce automatically fill in the following if not specified in the @Endpoint
annotation:
200 – “successful operation” for endpoints other than DELETE, unless the
@Endpoint
annotation specifies a different 2xx response204 – “successful operation” for DELETE endpoints, unless the
@Endpoint
annotation specifies a different 2xx response404 – “resource not found” for GET endpoints
500 – “internal server error” for all endpoints
Specify other status codes by using the @ApiResponse
and @ApiResponses
annotations. It is important to not specify the same status code more than once per endpoint as Swagger cannot hold more than one message per code.
If your endpoint’s normal status code is something other than 200 or 204, use the @ApiOperation
annotation with the code
attribute set to the appropriate status code.