Class Swagger
The Swagger Object is the root document that describes an entire API. It contains metadata about the API, available paths and operations, parameters, responses, security definitions, and other information. This is the Swagger 2.0 specification (predecessor to OpenAPI 3.0).
Swagger Specification:
The Swagger Object is composed of the following fields:
swagger (string, REQUIRED) - The Swagger Specification version (must be"2.0" )info (Info
, REQUIRED) - Provides metadata about the APIhost (string) - The host (name or IP) serving the APIbasePath (string) - The base path on which the API is served (relative to host)schemes (array of string) - The transfer protocols of the API (e.g.,"http" ,"https" )consumes (array of string) - A list of MIME types the APIs can consumeproduces (array of string) - A list of MIME types the APIs can producepaths (map ofOperationMap
, REQUIRED) - The available paths and operations for the APIdefinitions (map ofSchemaInfo
) - Schema definitions that can be referencedparameters (map ofParameterInfo
) - Parameters definitions that can be referencedresponses (map ofResponseInfo
) - Response definitions that can be referencedsecurityDefinitions (map ofSecurityScheme
) - Security scheme definitionssecurity (array of map) - Security requirements applied to all operationstags (array ofTag
) - A list of tags used by the specification with additional metadataexternalDocs (ExternalDocumentation
) - Additional external documentation
Example:
See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddConsumes
(Collection<MediaType> values) Bean property appender:consumes .addConsumes
(MediaType... values) Bean property appender:consumes .addDefinition
(String name, JsonMap schema) Bean property appender:definitions .addParameter
(String name, ParameterInfo parameter) Bean property appender:parameters .Bean property appender:paths .addProduces
(Collection<MediaType> values) Bean property appender:produces .addProduces
(MediaType... values) Adds one or more values to theproduces property.addResponse
(String name, ResponseInfo response) Bean property appender:responses .addSchemes
(String... values) Bean property appender:schemes .addSchemes
(Collection<String> values) Bean property appender:schemes .addSecurity
(String scheme, String... alternatives) Bean property appender:security .addSecurity
(Collection<Map<String, List<String>>> values) Bean property fluent setter:security .addSecurityDefinition
(String name, SecurityScheme securityScheme) Bean property appender:securityDefinitions .addTags
(Collection<Tag> values) Bean property appender:tags .Bean property appender:tags .asJson()
A synonym oftoString()
.copy()
Make a deep copy of this object.<T> T
Resolves a"$ref" tags to nodes in this swagger document.<T> T
Generic property getter.Bean property getter:basePath .Bean property getter:consumes .Bean property getter:definitions .Bean property getter:externalDocs .getHost()
Bean property getter:host .getInfo()
Bean property getter:info .getOperation
(String path, String operation) Shortcut for callinggetPaths().get(path).get(operation); getParameterInfo
(String path, String method, String in, String name) Convenience method for callinggetPath(path).get(method).getParameter(in,name); Bean property getter:parameters .Shortcut for callinggetPaths().get(path); getPaths()
Bean property getter:paths .Bean property getter:produces .getResponseInfo
(String path, String operation, int status) Shortcut for callinggetPaths().get(path).get(operation).getResponse(status); getResponseInfo
(String path, String operation, String status) Shortcut for callinggetPaths().get(path).get(operation).getResponse(status); Bean property getter:responses .Bean property getter:schemes .Bean property getter:security .Bean property getter:securityDefinitions .Bean property getter:swagger .getTags()
Bean property getter:tags .keySet()
Returns all the keys on this element.Generic property setter.setBasePath
(String value) Bean property setter:basePath .setConsumes
(Collection<MediaType> value) Bean property setter:consumes .setConsumes
(MediaType... value) Bean property fluent setter:consumes .setDefinitions
(Map<String, JsonMap> value) Bean property setter:definitions .Bean property setter:externalDocs .Bean property setter:host .Bean property setter:info .setParameters
(Map<String, ParameterInfo> value) Bean property setter:parameters .setPaths
(Map<String, OperationMap> value) Bean property setter:paths .setProduces
(Collection<MediaType> value) Bean property setter:produces .setProduces
(MediaType... value) Bean property fluent setter:produces .setResponses
(Map<String, ResponseInfo> value) Bean property setter:responses .setSchemes
(String... value) Bean property fluent setter:schemes .setSchemes
(Collection<String> value) Bean property setter:schemes .setSecurity
(Collection<Map<String, List<String>>> value) Bean property setter:security .Bean property setter:securityDefinitions .setSwagger
(String value) Bean property setter:swagger .setTags
(Collection<Tag> value) Bean property setter:tags .Bean property setter:tags .strict()
Sets strict mode on this bean.Sets strict mode on this bean.toString()
Methods inherited from class org.apache.juneau.bean.swagger.SwaggerElement
asMap, extraKeys, get, isStrict
-
Field Details
-
NULL
Represents a null swagger
-
-
Constructor Details
-
Swagger
public Swagger()Default constructor. -
Swagger
Copy constructor.- Parameters:
copyFrom
- The object to copy.
-
-
Method Details
-
copy
Make a deep copy of this object.- Returns:
- A deep copy of this object.
-
getBasePath
Bean property getter:basePath .The base path on which the API is served, which is relative to the
host .- Returns:
- The property value, or
null if it is not set.
-
setBasePath
Bean property setter:basePath .The base path on which the API is served, which is relative to the
host .- Parameters:
value
- The new value for this property.
If it is not included, the API is served directly under thehost .
The value MUST start with a leading slash (/).
ThebasePath does not support path templating.
Can benull to unset the property.- Returns:
- This object.
-
getConsumes
Bean property getter:consumes .A list of MIME types the APIs can consume.
- Returns:
- The property value, or
null if it is not set.
-
setConsumes
Bean property setter:consumes .A list of MIME types the APIs can consume.
- Parameters:
value
- The new value for this property.
Value MUST be as described under Swagger Mime Types.
Can benull to unset the property.- Returns:
- This object.
-
addConsumes
Bean property appender:consumes .A list of MIME types the APIs can consume.
- Parameters:
values
- The values to add to this property.
Values MUST be as described under Swagger Mime Types.
Ignored ifnull .- Returns:
- This object.
-
addConsumes
Bean property appender:consumes .A list of MIME types the APIs can consume.
- Parameters:
values
- The values to add to this property.
Ignored ifnull .- Returns:
- This object.
-
setConsumes
Bean property fluent setter:consumes .A list of MIME types the APIs can consume.
- Parameters:
value
- The values to set on this property.- Returns:
- This object.
-
getDefinitions
Bean property getter:definitions .An object to hold data types produced and consumed by operations.
- Returns:
- The property value, or
null if it is not set.
-
setDefinitions
Bean property setter:definitions .An object to hold data types produced and consumed by operations.
- Parameters:
value
- The new value for this property.
Can benull to unset the property.- Returns:
- This object.
-
addDefinition
Bean property appender:definitions .Adds a single value to the
definitions property.- Parameters:
name
- A definition name. Must not benull .schema
- The schema that the name defines. Must not benull .- Returns:
- This object.
-
getExternalDocs
Bean property getter:externalDocs .Additional external documentation.
- Returns:
- The property value, or
null if it is not set.
-
setExternalDocs
Bean property setter:externalDocs .Additional external documentation.
- Parameters:
value
- The new value for this property.
Can benull to unset the property.- Returns:
- This object.
-
getHost
Bean property getter:host .The host (name or IP) serving the API.
- Returns:
- The property value, or
null if it is not set.
-
setHost
Bean property setter:host .The host (name or IP) serving the API.
- Parameters:
value
- The new value for this property.
This MUST be the host only and does not include the scheme nor sub-paths.
It MAY include a port.
If the host is not included, the host serving the documentation is to be used (including the port).
The host does not support path templating
Can benull to unset the property.- Returns:
- This object.
-
getInfo
Bean property getter:info .Provides metadata about the API.
- Returns:
- The property value, or
null if it is not set.
-
setInfo
Bean property setter:info .Provides metadata about the API.
- Parameters:
value
- The new value for this property.
Property value is required.
Can benull to unset the property.- Returns:
- This object.
-
getParameters
Bean property getter:parameters .An object to hold parameters that can be used across operations.
- Returns:
- The property value, or
null if it is not set.
-
setParameters
Bean property setter:parameters .An object to hold parameters that can be used across operations.
- Parameters:
value
- The new value for this property.
Can benull to unset the property.- Returns:
- This object.
-
addParameter
Bean property appender:parameters .Adds a single value to the
parameter property.- Parameters:
name
- The parameter name. Must not benull .parameter
- The parameter definition. Must not benull .- Returns:
- This object.
-
getPaths
Bean property getter:paths .The available paths and operations for the API.
- Returns:
- The property value, or
null if it is not set.
-
setPaths
Bean property setter:paths .The available paths and operations for the API.
- Parameters:
value
- The new value for this property.
Property value is required.
Can benull to unset the property.- Returns:
- This object.
-
addPath
Bean property appender:paths .Adds a single value to the
paths property.- Parameters:
path
- The path template. Must not benull .methodName
- The HTTP method name. Must not benull .operation
- The operation that describes the path. Must not benull .- Returns:
- This object.
-
getProduces
Bean property getter:produces .A list of MIME types the APIs can produce.
- Returns:
- The property value, or
null if it is not set.
-
setProduces
Bean property setter:produces .A list of MIME types the APIs can produce.
- Parameters:
value
- The new value for this property.
Value MUST be as described under Swagger Mime Types.
Can benull to unset the property.- Returns:
- This object.
-
addProduces
Adds one or more values to theproduces property.A list of MIME types the APIs can produce.
- Parameters:
values
- The values to add to this property.
Value MUST be as described under Swagger Mime Types.
Can benull to unset the property.- Returns:
- This object.
-
addProduces
Bean property appender:produces .A list of MIME types the APIs can produce.
- Parameters:
values
- The values to add to this property.
Value MUST be as described under Swagger Mime Types.
Ignored ifnull .- Returns:
- This object.
-
setProduces
Bean property fluent setter:produces .A list of MIME types the APIs can produce.
- Parameters:
value
- The new value for this property.- Returns:
- This object.
-
getResponses
Bean property getter:responses .An object to hold responses that can be used across operations.
- Returns:
- The property value, or
null if it is not set.
-
setResponses
Bean property setter:responses .An object to hold responses that can be used across operations.
- Parameters:
value
- The new value for this property.
Can benull to unset the property.- Returns:
- This object.
-
addResponse
Bean property appender:responses .Adds a single value to the
responses property.- Parameters:
name
- The response name. Must not benull .response
- The response definition. Must not benull .- Returns:
- This object.
-
getSchemes
Bean property getter:schemes .The transfer protocol of the API.
- Returns:
- The property value, or
null if it is not set.
-
setSchemes
Bean property setter:schemes .The transfer protocol of the API.
- Parameters:
value
- The new value for this property.
Valid values:"http" "https" "ws" "wss"
Can benull to unset the property.- Returns:
- This object.
-
addSchemes
Bean property appender:schemes .The transfer protocol of the API.
- Parameters:
values
- The values to add to this property.
Valid values:"http" "https" "ws" "wss"
Ignored ifnull .- Returns:
- This object.
-
addSchemes
Bean property appender:schemes .The transfer protocol of the API.
- Parameters:
values
- The values to add to this property.
Valid values:"http" "https" "ws" "wss"
Ignored ifnull .- Returns:
- This object.
-
setSchemes
Bean property fluent setter:schemes .The transfer protocol of the API.
- Parameters:
value
- The new value for this property.
Strings can be JSON arrays.- Returns:
- This object.
-
getSecurity
Bean property getter:security .A declaration of which security schemes are applied for the API as a whole.
- Returns:
- The property value, or
null if it is not set.
-
setSecurity
Bean property setter:security .A declaration of which security schemes are applied for the API as a whole.
- Parameters:
value
- The new value for this property.
Can benull to unset the property.- Returns:
- This object.
-
addSecurity
Bean property appender:security .Adds a single value to the
securityDefinitions property.- Parameters:
scheme
- The security scheme that applies to this operation Must not benull .alternatives
- The list of values describes alternative security schemes that can be used (that is, there is a logical OR between the security requirements).- Returns:
- This object.
-
addSecurity
Bean property fluent setter:security .A declaration of which security schemes are applied for the API as a whole.
- Parameters:
values
- The values to add to this property.
Ignored ifnull .- Returns:
- This object.
-
getSecurityDefinitions
Bean property getter:securityDefinitions .Security scheme definitions that can be used across the specification.
- Returns:
- The property value, or
null if it is not set.
-
setSecurityDefinitions
Bean property setter:securityDefinitions .Security scheme definitions that can be used across the specification.
- Parameters:
value
- The new value for this property.
Can benull to unset the property.- Returns:
- This object.
-
addSecurityDefinition
Bean property appender:securityDefinitions .Adds a single value to the
securityDefinitions property.- Parameters:
name
- A security name. Must not benull .securityScheme
- A security schema. Must not benull .- Returns:
- This object.
-
getSwagger
Bean property getter:swagger .Specifies the Swagger Specification version being used.
- Returns:
- The property value, or
null if it is not set.
-
setSwagger
Bean property setter:swagger .Specifies the Swagger Specification version being used.
- Parameters:
value
- The new value for this property.
Property value is required.
Can benull to unset the property.- Returns:
- This object.
-
getTags
Bean property getter:tags .A list of tags used by the specification with additional metadata.
- Returns:
- The property value, or
null if it is not set.
-
setTags
Bean property setter:tags .A list of tags used by the specification with additional metadata.
- Parameters:
value
- The new value for this property.
The order of the tags can be used to reflect on their order by the parsing tools.
Not all tags that are used by the Operation Object must be declared.
The tags that are not declared may be organized randomly or based on the tools' logic.
Each tag name in the list MUST be unique.
Can benull to unset the property.- Returns:
- This object.
-
setTags
Bean property setter:tags .A list of tags used by the specification with additional metadata.
- Parameters:
value
- The new value for this property.
The order of the tags can be used to reflect on their order by the parsing tools.
Not all tags that are used by the Operation Object must be declared.
The tags that are not declared may be organized randomly or based on the tools' logic.
Each tag name in the list MUST be unique.
Ignored ifnull .- Returns:
- This object.
-
addTags
Bean property appender:tags .A list of tags used by the specification with additional metadata.
- Parameters:
values
- The values to add to this property.
The order of the tags can be used to reflect on their order by the parsing tools.
Not all tags that are used by the Operation Object must be declared.
The tags that are not declared may be organized randomly or based on the tools' logic.
Each tag name in the list MUST be unique.
Ignored ifnull .- Returns:
- This object.
-
addTags
Bean property appender:tags .A list of tags used by the specification with additional metadata.
- Parameters:
values
- The values to add to this property.
The order of the tags can be used to reflect on their order by the parsing tools.
Not all tags that are used by the Operation Object must be declared.
The tags that are not declared may be organized randomly or based on the tools' logic.
Each tag name in the list MUST be unique.
Ignored ifnull .- Returns:
- This object.
-
getPath
Shortcut for callinggetPaths().get(path); - Parameters:
path
- The path (e.g."/foo" ). Must not benull .- Returns:
- The operation map for the specified path, or
null if it doesn't exist.
-
getOperation
Shortcut for callinggetPaths().get(path).get(operation); - Parameters:
path
- The path (e.g."/foo" ). Must not benull .operation
- The HTTP operation (e.g."get" ). Must not benull .- Returns:
- The operation for the specified path and operation id, or
null if it doesn't exist.
-
getResponseInfo
Shortcut for callinggetPaths().get(path).get(operation).getResponse(status); - Parameters:
path
- The path (e.g."/foo" ). Must not benull .operation
- The HTTP operation (e.g."get" ). Must not benull .status
- The HTTP response status (e.g."200" ). Must not benull .- Returns:
- The operation for the specified path and operation id, or
null if it doesn't exist.
-
getResponseInfo
Shortcut for callinggetPaths().get(path).get(operation).getResponse(status); - Parameters:
path
- The path (e.g."/foo" ).operation
- The HTTP operation (e.g."get" ).status
- The HTTP response status (e.g."200" ).- Returns:
- The operation for the specified path and operation id, or
null if it doesn't exist.
-
getParameterInfo
Convenience method for callinggetPath(path).get(method).getParameter(in,name); - Parameters:
path
- The HTTP path. Must not benull .method
- The HTTP method. Must not benull .in
- The parameter type. Must not benull .name
- The parameter name. Can benull for parameter typebody .- Returns:
- The parameter information or
null if not found.
-
get
Description copied from class:SwaggerElement
Generic property getter.Can be used to retrieve non-standard Swagger fields such as
"$ref" .- Overrides:
get
in classSwaggerElement
- Type Parameters:
T
- The datatype to cast the value to.- Parameters:
property
- The property name to retrieve.type
- The datatype to cast the value to.- Returns:
- The property value, or
null if the property does not exist or is not set.
-
set
Description copied from class:SwaggerElement
Generic property setter.Can be used to set non-standard Swagger fields such as
"$ref" .- Overrides:
set
in classSwaggerElement
- Parameters:
property
- The property name to set. Must not benull .value
- The new value for the property.- Returns:
- This object.
-
keySet
Description copied from class:SwaggerElement
Returns all the keys on this element.- Overrides:
keySet
in classSwaggerElement
- Returns:
- All the keys on this element.
Nevernull .
-
asJson
A synonym oftoString()
.- Returns:
- This object serialized as JSON.
-
toString
- Overrides:
toString
in classSwaggerElement
-
findRef
Resolves a"$ref" tags to nodes in this swagger document.- Type Parameters:
T
- The class to convert the reference to.- Parameters:
ref
- The ref tag value. Must not benull or blank.c
- The class to convert the reference to. Must not benull .- Returns:
- The referenced node, or
null if not found.
-
strict
Sets strict mode on this bean.- Overrides:
strict
in classSwaggerElement
- Returns:
- This object.
-
strict
Sets strict mode on this bean.- Overrides:
strict
in classSwaggerElement
- Parameters:
value
- The new value for this property.
Non-boolean values will be converted to boolean usingBoolean.
.valueOf (value.toString())
Can benull (interpreted asfalse ).- Returns:
- This object.
-