Package com.jsgalactic.axiom.routing
Class RouteDoc
java.lang.Object
com.jsgalactic.axiom.routing.RouteDoc
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA documented request body.static enumWhere a parameter is read from.static final recordA documented parameter.static final recordA documented response. -
Method Summary
Modifier and TypeMethodDescriptionReturns a copy marked deprecated.Returns the description.description(String description) Returns a copy with a longer description.static RouteDocempty()Returns the empty description: no metadata at all.headerParam(String name, Type type, String description, boolean required) Returns a copy documenting a request header.hidden()Returns a copy that tools leave out of generated documentation, for example an internal route.booleanTells whether the route is deprecated.booleanisHidden()Tells whether tools should leave the route out.static TypeCreates the typeList<element>.Returns the operation id.operationId(String operationId) Returns a copy with an operation id, which should be unique across the application.Returns the parameters.Returns a copy documenting a path parameter (a:nameor*namecapture).queryParam(String name, Type type, String description, boolean required) Returns a copy documenting a query parameter.Returns the request body.requestBody(Type type) Returns a copy documenting a JSON request body.requestBody(Type type, String... mediaTypes) Returns a copy documenting the request body, replacing an earlier one.Returns a copy documenting a response without a body.Returns a copy documenting a JSON response body.Returns a copy documenting a response body.Returns the responses.security()Returns the security scheme names.Returns a copy with security requirements, appended in order.summary()Returns the summary.static RouteDocStarts a description with a one-line summary.tags()Returns the tags.Returns a copy with more tags, appended in order; duplicates are ignored.static TypeCreates the typeraw<arguments...>, for exampletype(Page.class, Note.class)for aPage<Note>, since aClassliteral cannot carry type arguments.withSummary(String summary) Returns a copy with another summary.
-
Method Details
-
type
Creates the typeraw<arguments...>, for exampletype(Page.class, Note.class)for aPage<Note>, since aClassliteral cannot carry type arguments.- Parameters:
raw- generic classarguments- its type arguments, one per type parameter- Returns:
- a parameterized type usable wherever a
RouteDoctakes a type - Throws:
IllegalArgumentException- if the count differs from the class's type parameters
-
listOf
Creates the typeList<element>.- Parameters:
element- element type- Returns:
- a parameterized list type
-
empty
Returns the empty description: no metadata at all.- Returns:
- the empty description
-
summary
Starts a description with a one-line summary.- Parameters:
summary- short summary of what the route does- Returns:
- a description
-
withSummary
Returns a copy with another summary.- Parameters:
summary- short summary- Returns:
- the new description
-
description
Returns a copy with a longer description.- Parameters:
description- description text- Returns:
- the new description
-
tags
Returns a copy with more tags, appended in order; duplicates are ignored.- Parameters:
names- tag names, none blank- Returns:
- the new description
-
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
Returns a copy marked deprecated.- Returns:
- the new description
-
requestBody
Returns a copy documenting a JSON request body.- Parameters:
type- body type- Returns:
- the new description
-
requestBody
Returns a copy documenting the request body, replacing an earlier one.- Parameters:
type- body typemediaTypes- accepted media types, at least one- Returns:
- the new description
-
response
Returns a copy documenting a response without a body.- Parameters:
status- HTTP statusdescription- what the response means- Returns:
- the new description
- Throws:
IllegalArgumentException- if the status is already documented
-
response
Returns a copy documenting a JSON response body.- Parameters:
status- HTTP statusdescription- what the response meanstype- body type- Returns:
- the new description
- Throws:
IllegalArgumentException- if the status is already documented
-
response
Returns a copy documenting a response body.- Parameters:
status- HTTP statusdescription- what the response meanstype- body typemediaTypes- media types the response can have, at least one- Returns:
- the new description
- Throws:
IllegalArgumentException- if the status is already documented
-
pathParam
Returns a copy documenting a path parameter (a:nameor*namecapture).- Parameters:
name- capture nametype- simple typedescription- description, or null- Returns:
- the new description
-
queryParam
Returns a copy documenting a query parameter.- Parameters:
name- parameter nametype- simple typedescription- description, or nullrequired- whether it must be present- Returns:
- the new description
-
headerParam
Returns a copy documenting a request header.- Parameters:
name- header nametype- simple typedescription- description, or nullrequired- whether it must be present- Returns:
- the new description
-
security
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
Returns the summary.- Returns:
- the summary, if set
-
description
Returns the description.- Returns:
- the description, if set
-
tags
Returns the tags.- Returns:
- tags in declaration order
-
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
Returns the request body.- Returns:
- the request body, if documented
-
responses
Returns the responses.- Returns:
- documented responses in declaration order
-
parameters
Returns the parameters.- Returns:
- documented parameters in declaration order
-
security
Returns the security scheme names.- Returns:
- names in declaration order
-