-
Notifications
You must be signed in to change notification settings - Fork 200
Enunciate Specific Annotations
Note: The following applies to Enunciate version 2. For information about enunciate-specific annotations in Enunciate 1.x, see Enunciate Specific Annotations (Version 1)
This document serves as a reference for the set of Enunciate-specific annotations and JavaDoc tags that can be used to enhance the documentation for your Web service API.
All annotations are contained within the com.webcohesion.enunciate.metadata
package, which has been abbreviated to c.w.e.m
below for readability purposes.
All annotations are contained in the enunciate-core-annotations.jar
(Maven coordinates: com.webcohesion.enunciate:enunciate-core-annotations
).
Applied to a resource class or a resource method. Used to document the set of status codes that may be responses to the operation. The status codes annotated on a method are appended to the status codes annotated on the defining resource class.
@GET
@Path("person/{id}")
@StatusCodes ({
@ResponseCode ( code = 404, condition = "The person is not found.")
})
Person readPerson(@PathParam("id") String id);
@ResponseCode
optionally takes a type
property to associate a specific response object with this code. (Example: type=@TypeHint(ErrorResponse.class)
)
Applied to a resource class or a resource method. Used to document the set of status codes that may be responses to the operation. The status codes annotated on a method are appended to the status codes annotated on the defining resource class. Originally defined by jax-doclets.
/**
* @HTTP 404 If the person is not found.
*/
@GET
@Path("person/{id}")
Person readPerson(@PathParam("id") String id);
Applied to a resource class or a resource method. Used to document the set of warning headers that may be included upon invocation of the operation. The warnings annotated on a method are appended to the warnings annotated on the defining resource class.
@GET
@Path("person/{id}")
@Warnings ({
@ResponseCode ( code = 299, condition = "The reason the person wasn't found, if applicable.")
})
Person readPerson(@PathParam("id") String id);
Applied to a resource class or a resource method. Used to document the set of warning headers that may be included upon invocation of the operation. The warnings annotated on a method are appended to the warnings annotated on the defining resource class.
/**
* @HTTPWarning 299 The reason the person wasn't found, if applicable.
*/
@GET
@Path("person/{id}")
Person readPerson(@PathParam("id") String id);
Applied to a resource method or resource parameter. Enunciate might not be able to determine the structure of the request and/or response body from the method signature. (For example, some JAX-RS methods may return javax.ws.rs.core.Response
.) The TypeHint
annotation is used to give Enunciate a hint about what is to be returned or consumed.
@GET
@Path("person/{id}")
@TypeHint (Person.class)
Response readPerson(@PathParam("id") String id);
@GET
@Path("persons")
@TypeHint (Person[].class)
Response readPersons(@QueryParam("id") String[] ids);
@POST
@Path("person/{id}")
Person updatePerson(@TypeHint(Person.class) InputStream data);
Applied to a resource method. Enunciate might not be able to determine the structure of the response body from the method signature. (For example, some JAX-RS methods may return javax.ws.rs.core.Response
.) The @returnWrapped
JavaDoc tag is used to give Enunciate a hint about what is to be returned. Originally defined by jax-doclets.
/**
* @returnWrapped com.mycompany.Person
*/
@GET
@Path("person/{id}")
Person readPerson(@PathParam("id") String id);
Applied to a resource method. Enunciate might not be able to determine the structure of the request body from the method signature. The @inputWrapped
JavaDoc tag is used to give Enunciate a hint about what is to be consumed. Originally defined by jax-doclets.
/**
* @inputWrapped com.mycompany.Person
*/
@POST
@Path("person/{id}")
Person updatePerson(InputStream data);
(Since Enunciate 2.3)
Applied to a resource class or a resource method. Used to document the set of request headers that may be included upon invocation of the operation. The request headers annotated on a method are appended to the headers annotated on the defining resource class.
The @RequestHeaders
annotation was provided as a way to document request headers that aren't explicitly defined by the resource or resource method (such as are handled in a filter or other processor).
@GET
@RequestHeaders (
@RequestHeader( name = "X-Auth-Token", description = "The authentication token.")
)
Person getPerson(@PathParam("id") String id);
Applied to a resource class or a resource method. Used to document the set of request headers that may be included upon invocation of the operation. The request headers annotated on a method are appended to the headers annotated on the defining resource class. Originally defined by jax-doclets.
/**
* @ResponseHeader X-Auth-Token The authentication token.
*/
@GET
Person getPerson(@PathParam("id") String id);
Applied to a resource class or a resource method. Used to document the set of response headers that may be included upon invocation of the operation. The response headers annotated on a method are appended to the headers annotated on the defining resource class.
@POST
@ResponseHeaders (
@ResponseHeader( name = "Location", description = "The location of the created person.")
)
Person createPerson(Person person);
Applied to a resource class or a resource method. Used to document the set of response headers that may be included upon invocation of the operation. The response headers annotated on a method are appended to the headers annotated on the defining resource class. Originally defined by jax-doclets.
/**
* @ResponseHeader Location The location of the created person.
*/
@POST
Person createPerson(Person person);
Applied to a resource class or a resource method. Used to specify a different context root for resources and groups, often used when bundling services with different application paths within an EAR. If resources are grouped by path or by annotation, there exists the possibility of conflicting values for @ServiceContextRoot
. In such a case, the algorithm for resolving the conflict is undefined; the first annotation encountered by the processor will be selected.
@ServiceContextRoot("/context")
@Path("/resource")
public class MyResource {
...
}
Applied to a resource class, a data type, a web fault or a web service. Used to customize the label that is used for the element in the generated documentation.
@Label ("PersonRelativeAge")
enum Age {
old,
young
}
Applied to a resource class, a data type, a web fault or a web service. Used to customize the label that is used for the element in the generated documentation.
/**
* @label PersonRelativeAge
*/
enum Age {
old,
young
}
Applied to a data type accessor (field or property) or a resource method.
Used to suggest example value(s) for XML/JSON examples. As of Enunciate 2.3, the
@DocumentationExample
annotation also supports a second value
(e.g. @DocumentationExample( value = "male", value2 = "female")
) that will be used if the
example is used multiple times, such as in the case of arrays.
As of Enunciate 2.8, the @DocumentationExample
annotation can also be used to
suggest a specific data type to be used, such as when a specific subclass is
desired as the example.
class Person {
@DocumentationExample("male")
public String gender;
@DocumentationExample(type=@TypeHint(Cat.class))
public Pet pet;
}
Applied to a data type accessor (field or property). Used to suggest an example value for XML/JSON examples.
class Person {
/**
* @documentationExample male
*/
public String gender;
}
As of Enunciate 2.8, applied to a data type accessor (field or property) or a resource method, used to suggest a specific data type to be used, such as when a specific subclass is desired as the example.
class Person {
/**
* @documentationType com.mycompany.Cat
*/
public Pet pet;
}
Applied to a resource class or a resource method. Used to customize how resources are grouped in the documentation. See Module-JAXRS.
@Path("/persons")
@ResourceGroup("Person API")
class PersonResource {
}
Applied to a resource class or a resource method. Used to customize how resources or resource methods are labeled in the generated documentation.
@Path("/persons")
@ResourceLabel("Person Resource")
class PersonResource {
}
Applied to a data type, data property, service class, resource class, resource method, or resource resource parameter. Used to apply custom styles to the generated documentation for the specific properties. For more information, see the documentation on creating a custom skin.
@com.webcohesion.enunciate.metadata.Style("secured")
public Date created
@com.webcohesion.enunciate.metadata.Styles(
@com.webcohesion.enunciate.metadata.Style("secured"),
@com.webcohesion.enunciate.metadata.Style("conditional")
)
public Date created
Applied to a data type, data property, service class, resource class, resource method, or resource resource parameter. Used to apply custom styles to the generated documentation for the specific properties. For more information, see the documentation on creating a custom skin.
/**
* @style secured
* @style conditional
*/
public Date created
(Since 2.9.1)
Applied to a resource method. Used to provide a custom example response body. Requires the media type to which the example is applicable.
If the value starts with "classpath:", it will be interpreted as a reference to a text file on the classpath.
If the value starts with "file:", it will be interpreted as a reference to a text file on the file system.
/**
* @responseExample application/json { "name" : "Harry Truman", "birth" : "1884-05-08" }
* @responseExample application/xml
* <person>
* <name>Harry Truman</name>
* <birth>1884-05-08</birth>
* </person>
*/
@GET
Person getPerson(@PathParam("id") String id);
/**
* @responseExample application/json file:/path/to/example.json
* @responseExample application/xml classpath:/reference/to/example.xml
*/
@GET
Person getPerson(@PathParam("id") String id);
(Since 2.9.1)
Applied to a resource method. Used to provide a custom example request body. Requires the media type to which the example is applicable.
If the value starts with "classpath:", it will be interpreted as a reference to a text file on the classpath.
If the value starts with "file:", it will be interpreted as a reference to a text file on the file system.
/**
* @requestExample application/json { "name" : "Harry Truman", "birth" : "1884-05-08" }
* @requestExample application/xml
* <person>
* <name>Harry Truman</name>
* <birth>1884-05-08</birth>
* </person>
*/
@POST
void createPerson(Person person);
/**
* @requestExample application/json file:/path/to/example.json
* @requestExample application/xml classpath:/reference/to/example.xml
*/
@POST
void createPerson(Person person);
Applied to a Java class. Used to suggest to Enunciate that the annotated class should be ignored, if possible. The class may not be able to be ignored if it's explicitly referenced from a service, resource, or data type that is not excluded.
@Ignore
class PersonUtils {
}
(Since 2.10)
Applied to a Java class. Used to suggest to Enunciate that the annotated class should be ignored, if possible. The class may not be able to be ignored if it's explicitly referenced from a service, resource, or data type that is not excluded.
/**
* @ignore
*/
class PersonUtils {
}
Applied to a Java class that defines a JSON type. Used to suggest to Enunciate that other classes should be considered as JSON data types.
@JsonSeeAlso(
{ OtherJsonObject.class, OtherJsonObject2.class }
)
class MyJsonObject {
}