Class RouteDoc

java.lang.Object
com.jsgalactic.axiom.routing.RouteDoc

public final class RouteDoc extends Object
Optional, immutable documentation of one route: what it is for, which parameters, request body and responses it has, and which security requirements apply. It is plain data attached with Application.describe(route, doc); nothing is scanned, no annotations are read and the runtime never consults it when routing or handling requests. Tools such as the axiom-openapi module read it with Application.doc(route).

 app.describe(app.post("/notes", create),
         RouteDoc.summary("Create a note").tags("notes").operationId("createNote")
                 .requestBody(NewNote.class)
                 .response(201, "Created", Note.class)
                 .response(422, "Validation failed"));
 

Types are Type values, so generic types such as a List<Note> can be given through a ParameterizedType; a plain Class is the common case. Every wither returns a new instance, so a partly built description can be shared and extended. Instances are thread-safe. Media types default to application/json. Names, tags and operation ids are validated when the description is built.

  • Method Details

    • type

      public static Type type(Class<?> raw, Type... arguments)
      Creates the type raw<arguments...>, for example type(Page.class, Note.class) for a Page<Note>, since a Class literal cannot carry type arguments.
      Parameters:
      raw - generic class
      arguments - its type arguments, one per type parameter
      Returns:
      a parameterized type usable wherever a RouteDoc takes a type
      Throws:
      IllegalArgumentException - if the count differs from the class's type parameters
    • listOf

      public static Type listOf(Type element)
      Creates the type List<element>.
      Parameters:
      element - element type
      Returns:
      a parameterized list type
    • empty

      public static RouteDoc empty()
      Returns the empty description: no metadata at all.
      Returns:
      the empty description
    • summary

      public static RouteDoc summary(String summary)
      Starts a description with a one-line summary.
      Parameters:
      summary - short summary of what the route does
      Returns:
      a description
    • withSummary

      public RouteDoc withSummary(String summary)
      Returns a copy with another summary.
      Parameters:
      summary - short summary
      Returns:
      the new description
    • description

      public RouteDoc description(String description)
      Returns a copy with a longer description.
      Parameters:
      description - description text
      Returns:
      the new description
    • tags

      public RouteDoc tags(String... names)
      Returns a copy with more tags, appended in order; duplicates are ignored.
      Parameters:
      names - tag names, none blank
      Returns:
      the new description
    • operationId

      public RouteDoc operationId(String operationId)
      Returns a copy with an operation id, which should be unique across the application.
      Parameters:
      operationId - 1 to 128 characters of letters, digits, _, . and -
      Returns:
      the new description
    • deprecated

      public RouteDoc deprecated()
      Returns a copy marked deprecated.
      Returns:
      the new description
    • hidden

      public RouteDoc hidden()
      Returns a copy that tools leave out of generated documentation, for example an internal route.
      Returns:
      the new description
    • requestBody

      public RouteDoc requestBody(Type type)
      Returns a copy documenting a JSON request body.
      Parameters:
      type - body type
      Returns:
      the new description
    • requestBody

      public RouteDoc requestBody(Type type, String... mediaTypes)
      Returns a copy documenting the request body, replacing an earlier one.
      Parameters:
      type - body type
      mediaTypes - accepted media types, at least one
      Returns:
      the new description
    • response

      public RouteDoc response(int status, String description)
      Returns a copy documenting a response without a body.
      Parameters:
      status - HTTP status
      description - what the response means
      Returns:
      the new description
      Throws:
      IllegalArgumentException - if the status is already documented
    • response

      public RouteDoc response(int status, String description, Type type)
      Returns a copy documenting a JSON response body.
      Parameters:
      status - HTTP status
      description - what the response means
      type - body type
      Returns:
      the new description
      Throws:
      IllegalArgumentException - if the status is already documented
    • response

      public RouteDoc response(int status, String description, Type type, String... mediaTypes)
      Returns a copy documenting a response body.
      Parameters:
      status - HTTP status
      description - what the response means
      type - body type
      mediaTypes - media types the response can have, at least one
      Returns:
      the new description
      Throws:
      IllegalArgumentException - if the status is already documented
    • pathParam

      public RouteDoc pathParam(String name, Type type, String description)
      Returns a copy documenting a path parameter (a :name or *name capture).
      Parameters:
      name - capture name
      type - simple type
      description - description, or null
      Returns:
      the new description
    • queryParam

      public RouteDoc queryParam(String name, Type type, String description, boolean required)
      Returns a copy documenting a query parameter.
      Parameters:
      name - parameter name
      type - simple type
      description - description, or null
      required - whether it must be present
      Returns:
      the new description
    • headerParam

      public RouteDoc headerParam(String name, Type type, String description, boolean required)
      Returns a copy documenting a request header.
      Parameters:
      name - header name
      type - simple type
      description - description, or null
      required - whether it must be present
      Returns:
      the new description
    • security

      public RouteDoc security(String... schemeNames)
      Returns a copy with security requirements, appended in order. Each name refers to a scheme the consuming tool knows; any one of the listed requirements satisfies the route.
      Parameters:
      schemeNames - names of security schemes, none blank
      Returns:
      the new description
    • summary

      public Optional<String> summary()
      Returns the summary.
      Returns:
      the summary, if set
    • description

      public Optional<String> description()
      Returns the description.
      Returns:
      the description, if set
    • tags

      public List<String> tags()
      Returns the tags.
      Returns:
      tags in declaration order
    • operationId

      public Optional<String> operationId()
      Returns the operation id.
      Returns:
      the operation id, if set
    • isDeprecated

      public boolean isDeprecated()
      Tells whether the route is deprecated.
      Returns:
      true if deprecated
    • isHidden

      public boolean isHidden()
      Tells whether tools should leave the route out.
      Returns:
      true if hidden
    • requestBody

      public Optional<RouteDoc.Body> requestBody()
      Returns the request body.
      Returns:
      the request body, if documented
    • responses

      public List<RouteDoc.Reply> responses()
      Returns the responses.
      Returns:
      documented responses in declaration order
    • parameters

      public List<RouteDoc.Param> parameters()
      Returns the parameters.
      Returns:
      documented parameters in declaration order
    • security

      public List<String> security()
      Returns the security scheme names.
      Returns:
      names in declaration order