Class OperationMap

java.lang.Object
java.util.AbstractMap<K,V>
java.util.TreeMap<String,Operation>
org.apache.juneau.bean.swagger.OperationMap
All Implemented Interfaces:
Serializable, Cloneable, Map<String,Operation>, NavigableMap<String,Operation>, SortedMap<String,Operation>

public class OperationMap extends TreeMap<String,Operation>
Map meant for method-name/operation mappings.

The OperationMap is a specialized TreeMap that represents the operations available on a single path in Swagger 2.0. It forces entries to be sorted in a specific order to ensure consistent output. This map is used within PathItem objects to define the HTTP methods and their corresponding operations.

Swagger Specification:

The OperationMap represents the operations field in a Path Item Object, where each key is an HTTP method and each value is an Operation object. The supported HTTP methods are:

  • get (Operation) - A definition of a GET operation
  • put (Operation) - A definition of a PUT operation
  • post (Operation) - A definition of a POST operation
  • delete (Operation) - A definition of a DELETE operation
  • options (Operation) - A definition of an OPTIONS operation
  • head (Operation) - A definition of a HEAD operation
  • patch (Operation) - A definition of a PATCH operation

Forces entries to be sorted in the following order:

  • GET
  • PUT
  • POST
  • DELETE
  • OPTIONS
  • HEAD
  • PATCH
  • Everything else.
Example:

// Construct using SwaggerBuilder. OperationMap operations = operationMap() .append("get", operation().setSummary("Get users")) .append("post", operation().setSummary("Create user")); // Serialize using JsonSerializer. String json = Json.from(operations); // Or just use toString() which does the same as above. json = operations.toString();

// Output { "get": { "summary": "Get users" }, "post": { "summary": "Create user" } }

See Also:
  • Constructor Details

  • Method Details

    • put

      public Operation put(String key, Operation value)
      Override put to normalize keys to lowercase.
      Specified by:
      put in interface Map<String,Operation>
      Overrides:
      put in class TreeMap<String,Operation>
      Parameters:
      key - The key.
      value - The value.
      Returns:
      The previous value associated with key, or null if there was no mapping for key.
    • append

      public OperationMap append(String httpMethodName, Operation operation)
      Fluent-style put method.
      Parameters:
      httpMethodName - The HTTP method name.
      operation - The operation.
      Returns:
      This object.