Skip to content

Commit dd567d6

Browse files
committed
updated annotations
1 parent 9a93557 commit dd567d6

File tree

11 files changed

+500
-180
lines changed

11 files changed

+500
-180
lines changed

modules/swagger-annotations/src/main/java/com/wordnik/swagger/annotations/Api.java

Lines changed: 76 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,90 @@
2323

2424

2525
/**
26-
* describes a top-level api. Classes with @Api annotations will
27-
* be included in the Resource Listing: https://github.com/wordnik/swagger-core/wiki/Resource-Listing
28-
* for details
26+
* Marks a class as a Swagger resource.
27+
* <p/>
28+
* The resource affects both the root document of Swagger, the Resource
29+
* Listing, and the API Declaration of that specific resource.
30+
* <p/>
31+
* Swagger will only include and introspect only classes that are annotated
32+
* with {@code @Api} and will ignore other resources (JAX-RS endpoints, Servlets and
33+
* so on).
2934
*/
3035
@Target(ElementType.TYPE)
3136
@Retention(RetentionPolicy.RUNTIME)
3237
public @interface Api {
33-
/** Short description of the Api */
34-
String value();
38+
/**
39+
* The 'path' that is going to be used to host the API Declaration of the
40+
* resource.
41+
* <p/>
42+
* For JAX-RS resources, this would normally have the same value as the {@code @Path}
43+
* on the resource, but can be any other value as well. It will serve as the path
44+
* where the documentation is hosted.
45+
* <p/>
46+
* For Servlets, this path has to be the path serving the Servlet.
47+
* <p/>
48+
* If the value isn't preceded with a slash, one would be added to it.
49+
*/
50+
String value();
3551

36-
/** General description of this class */
37-
String description() default "";
52+
/**
53+
* Corresponds to the `description` field of the Resource Listing API operation.
54+
* <p/>
55+
* This should be a short description of the resource.
56+
*/
57+
String description() default "";
3858

39-
/** The base path that is prepended to all @Path elements. This may be an override for certain scenarios only */
40-
String basePath() default "";
41-
42-
/** optional explicit ordering of this Api in the Resource Listing */
43-
int position() default 0;
59+
/**
60+
* Corresponds to the `basePath` field of the API Declaration.
61+
* <p/>
62+
* The `basePath` is derived automatically by Swagger. This property allows
63+
* overriding the default value if needed.
64+
*/
65+
String basePath() default "";
4466

45-
/** content type produced by this Api */
46-
String produces() default "";
67+
/**
68+
* Optional explicit ordering of this API resource in the Resource Listing.
69+
*/
70+
int position() default 0;
4771

48-
/** media type consumed by this Api */
49-
String consumes() default "";
72+
/**
73+
* Corresponds to the `produces` field of the API Declaration.
74+
* <p/>
75+
* Takes in comma-separated values of content types.
76+
* For example, "application/json, application/xml" would suggest this API Resource
77+
* generates JSON and XML output.
78+
* <p/>
79+
* For JAX-RS resources, this would automatically take the value of the {@code @Produces}
80+
* annotation if such exists. It can also be used to override the {@code @Produces} values
81+
* for the Swagger documentation.
82+
*/
83+
String produces() default "";
5084

51-
/** protocols that this Api requires (i.e. https) */
52-
String protocols() default "";
85+
/**
86+
* Corresponds to the `consumes` field of the API Declaration.
87+
* <p/>
88+
* Takes in comma-separated values of content types.
89+
* For example, "application/json, application/xml" would suggest this API Resource
90+
* accepts JSON and XML input.
91+
* <p/>
92+
* For JAX-RS resources, this would automatically take the value of the {@code @Consumes}
93+
* annotation if such exists. It can also be used to override the {@code @Consumes} values
94+
* for the Swagger documentation.
95+
*/
96+
String consumes() default "";
5397

54-
/** authorizations required by this Api */
55-
// String authorizations() default "";
56-
/** authorizations required by this Api */
57-
Authorization[] authorizations() default @Authorization("");
98+
/**
99+
* This property is currently not in use.
100+
*/
101+
String protocols() default "";
102+
103+
/**
104+
* Corresponds to the `authorizations` field of the API Declaration.
105+
* <p/>
106+
* Takes in a list of the required authorizations for this API Resource.
107+
* This may be overridden by specific operations.
108+
*
109+
* @see Authorization
110+
*/
111+
Authorization[] authorizations() default @Authorization("");
58112
}

modules/swagger-annotations/src/main/java/com/wordnik/swagger/annotations/ApiImplicitParam.java

Lines changed: 75 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,91 @@
2222
import java.lang.annotation.Target;
2323

2424
/**
25-
* Represents a single parameter in an Api Operation. A parameter is an input
26-
* to the operation. The difference with the ApiImplicitParam is that they are
27-
* not bound to a variable, and allow for more manually-defined descriptions.
25+
* Represents a single parameter in an API Operation.
26+
* <p/>
27+
* While {@link com.wordnik.swagger.annotations.ApiParam} is bound to a JAX-RS parameter,
28+
* method or field, this allows you to manually define a parameter in a fine-tuned manner.
29+
* This is the only way to define parameters when using Servlets or other non-JAX-RS
30+
* environments.
31+
* <p/>
32+
* This annotation must be used as a value of {@link com.wordnik.swagger.annotations.ApiImplicitParams}
33+
* in order to be parsed.
34+
*
35+
* @see com.wordnik.swagger.annotations.ApiImplicitParams
2836
*/
2937
@Target(ElementType.METHOD)
3038
@Retention(RetentionPolicy.RUNTIME)
3139
public @interface ApiImplicitParam {
32-
/** Name of the parameter */
33-
String name() default "";
40+
/**
41+
* Name of the parameter.
42+
* <p/>
43+
* For proper Swagger functionality, follow these rules when naming your parameters based on {@link #paramType()}:
44+
* <ol>
45+
* <li>If {@code paramType} is "path", the name should be the associated section in the path.</li>
46+
* <li>If {@code paramType} is "body", the name should be "body".</li>
47+
* <li>For all other cases, the name should be the parameter name as your application expects to accept.</li>
48+
* </ol>
49+
*
50+
* @see #paramType()
51+
*/
52+
String name() default "";
3453

35-
/** Description of the parameter */
36-
String value() default "";
54+
/**
55+
* A brief description of the parameter.
56+
*/
57+
String value() default "";
3758

38-
/** Default value - if e.g. no JAX-RS @DefaultValue is given */
39-
String defaultValue() default "";
59+
/**
60+
* Describes the default value for the parameter.
61+
*/
62+
String defaultValue() default "";
4063

41-
/** Description of values this endpoint accepts */
42-
String allowableValues() default "";
64+
/**
65+
* Limits the acceptable values for this parameter.
66+
* <p/>
67+
* There are three ways to describe the allowable values:
68+
* <ol>
69+
* <li>To set a list of values, provide a comma-separated list surrounded by square brackets.
70+
* For example: {@code [first, second, third]}.</li>
71+
* <li>To set a range of values, start the value with "range", and surrounding by square
72+
* brackets include the minimum and maximum values. For example: {@code range[1, 5]}.</li>
73+
* <li>To set a minimum/maximum value, use the same format for range but use "infinity"
74+
* or "-infinity" as the second value. For example, {@code range[1, infinity]} means the
75+
* minimum allowable value of this parameter is 1.</li>
76+
* </ol>
77+
*/
78+
String allowableValues() default "";
4379

44-
/** specifies if the parameter is required or not */
45-
boolean required() default false;
80+
/**
81+
* Specifies if the parameter is required or not.
82+
* <p/>
83+
* Path parameters should always be set as required.
84+
*/
85+
boolean required() default false;
4686

47-
/**
48-
* specify an optional access value for filtering in a Filter
49-
* implementation. This
50-
* allows you to hide certain parameters if a user doesn't have access to them
51-
*/
52-
String access() default "";
87+
/**
88+
* Allows for filtering a parameter from the API documentation.
89+
*
90+
* @see com.wordnik.swagger.core.filter.SwaggerSpecFilter
91+
*/
92+
String access() default "";
5393

54-
/** specifies whether or not the parameter can have multiple values provided */
55-
boolean allowMultiple() default false;
94+
/**
95+
* Specifies whether the parameter can accept multiple comma-separated values.
96+
*/
97+
boolean allowMultiple() default false;
5698

57-
/** manually set the dataType */
58-
String dataType() default "";
99+
/**
100+
* The data type of the parameter.
101+
* <p/>
102+
* This can be the class name or a primitive.
103+
*/
104+
String dataType() default "";
59105

60-
/** manually set the param type, i.e. query, path, etc. */
61-
String paramType() default "";
106+
/**
107+
* The parameter type of the parameter.
108+
*
109+
* Valid values are {@code path}, {@code query}, {@code body}, {@code header} or {@code form}.
110+
*/
111+
String paramType() default "";
62112
}

modules/swagger-annotations/src/main/java/com/wordnik/swagger/annotations/ApiImplicitParams.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@
2222
import java.lang.annotation.Target;
2323

2424
/**
25-
* A simple array wrapper to contain multiple ApiImplicitParam objects
25+
* A wrapper to allow a list of multiple {@link com.wordnik.swagger.annotations.ApiImplicitParam} objects.
26+
*
27+
* @see com.wordnik.swagger.annotations.ApiImplicitParam
2628
*/
2729
@Target(ElementType.METHOD)
2830
@Retention(RetentionPolicy.RUNTIME)
2931
public @interface ApiImplicitParams {
30-
ApiImplicitParam[] value();
32+
/**
33+
* A list of {@link com.wordnik.swagger.annotations.ApiImplicitParam}s available to the API operation.
34+
*/
35+
ApiImplicitParam[] value();
3136
}

modules/swagger-annotations/src/main/java/com/wordnik/swagger/annotations/ApiModel.java

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,41 @@
2222
import java.lang.annotation.Target;
2323

2424
/**
25-
* A bean class used in the REST-api.
26-
* Suppose you have an interface
27-
* <code>@PUT @ApiOperation(...) void foo(FooBean fooBean)</code>, there is
28-
* no direct way to see what fields <code>FooBean</code> would have. This
29-
* annotation is meant to give a description of <code>FooBean</code> and
30-
* then have the fields of it be annotated with
31-
* <code>@ApiModelProperty</code>.
32-
*
33-
* @author Heiko W. Rupp
25+
* Provides additional information about Swagger models.
26+
* <p/>
27+
* Classes will be introspected automatically as they are used as types in operations,
28+
* but you may want to manipulate the structure of the models.
3429
*/
3530
@Target({ElementType.TYPE})
3631
@Retention(RetentionPolicy.RUNTIME)
3732
public @interface ApiModel {
38-
/** Provide a synopsis of this class */
39-
String value() default "";
40-
/** Provide a longer description of the class */
41-
String description() default "";
42-
/** Provide a superclass for the model to allow describing inheritence */
43-
Class<?> parent() default Void.class;
44-
/** for models with a base class, a discriminator can be provided for polymorphic use cases */
45-
String discriminator() default "";
46-
Class<?>[] subTypes() default {};
33+
/**
34+
* Provide an alternative name for the model.
35+
* <p/>
36+
* By default, the class name is used.
37+
*/
38+
String value() default "";
39+
40+
/**
41+
* Provide a longer description of the class.
42+
*/
43+
String description() default "";
44+
45+
/**
46+
* Provide a superclass for the model to allow describing inheritance.
47+
*/
48+
Class<?> parent() default Void.class;
49+
50+
/**
51+
* Supports model inheritance and polymorphism.
52+
* <p/>
53+
* This is the name of the field used as a discriminator. Based on this field,
54+
* it would be possible to assert which sub type needs to be used.
55+
*/
56+
String discriminator() default "";
57+
58+
/**
59+
* An array of the sub types inheriting from this model.
60+
*/
61+
Class<?>[] subTypes() default {};
4762
}

0 commit comments

Comments
 (0)