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

description (string)

The @ApiOperation notes attribute. The notes attribute has some limited support for GFM syntax, for example, ** for bolding and ~~ for strikethrough. You can use the notes attribute to describe anything about the endpoint’s behavior that is not obvious from the value attribute and the endpoint’s input parameters.

operationId (string)

The endpoint’s Java method name, which can be overridden by the @ApiOperation nickname attribute.

parameter (array of objects)

A parameter array is added for each parameter in the method signature. Refer to the Using Endpoint Parameters section for further information.

responses (map keyed by response status codes)

Every endpoint must contain at least one response entry. Refer to the Using Endpoint Responses for further information.

summary (string)

The @ApiOperation value attribute. Can be up to 120 characters.

tags (array of strings)

The @APIOperation tags attribute or, if there are no @APIOperation tags, resource tags and ancestor resource tags.

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

description (string)

The @ApiParam value attribute.

enum (string)

The @ApiParam allowableValues attribute. Supply allowableValues for any non-body parameter that accepts a specific set of values.

in (body, path, query)

Uses path if @PathParam is present or query if @QueryParam is present or formData if @FormParam is present. Otherwise uses body. Note that there are additional choices for the in property, however they are not used.

name (string)

Uses body for in body, the @PathParam value for in path, or the @QueryParam value for in query or @FormParam value for in formData. It is overridden by the @ApiParam name attribute.

required (true, false)

The @ApiParam required attribute, which defaults to false.

schema (string)

The @APIOperation value attribute. This string can contain up to 120 characters. This property is required when using in body.

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:

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:

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.


Copyright © 1997, 2017 Oracle and/or its affiliates. All rights reserved. Legal Notices