Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@
* Valid values are "List", "Set" or "Map". Any other value will be ignored.
*/
String responseContainer() default "";

Example examples() default @Example(value = @ExampleProperty(value = "", mediaType = ""));
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*
* @return the name of the property
*/
String mediaType() default "default";
String mediaType() default "";

/**
* The value of the example.
Expand Down
45 changes: 28 additions & 17 deletions modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,7 @@
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
import com.fasterxml.jackson.databind.type.TypeFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiKeyAuthDefinition;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.BasicAuthDefinition;
import io.swagger.annotations.Info;
import io.swagger.annotations.OAuth2Definition;
import io.swagger.annotations.ResponseHeader;
import io.swagger.annotations.Scope;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.*;
import io.swagger.converter.ModelConverters;
import io.swagger.jaxrs.config.DefaultReaderConfig;
import io.swagger.jaxrs.config.ReaderConfig;
Expand Down Expand Up @@ -1001,9 +987,11 @@ private void processOperationDecorator(Operation operation, Method method) {

private void addResponse(Operation operation, ApiResponse apiResponse) {
Map<String, Property> responseHeaders = parseResponseHeaders(apiResponse.responseHeaders());
//map of response examples annotated with @Example
Map<String, Object> examples = parseExamples(apiResponse.examples());

Response response = new Response()
.description(apiResponse.message()).headers(responseHeaders);
Response response = new Response().description(apiResponse.message()).headers(responseHeaders);
response.setExamples(examples);

if (apiResponse.code() == 0) {
operation.defaultResponse(response);
Expand All @@ -1023,6 +1011,29 @@ private void addResponse(Operation operation, ApiResponse apiResponse) {
}
}

/**
* Parses the example snippets which is provided in the annotation @{@link Example}
* @param examples
* @return - a map of example strings
*/
private Map<String, Object> parseExamples(Example examples) {
if(examples == null){
return null;
}

Map<String, Object> map = null;
for(ExampleProperty prop : examples.value()){

if(prop.mediaType().equals("") && prop.value().equals("")){
continue;
}

map = map == null ? new HashMap<String, Object>() : map;
map.put(prop.mediaType(), prop.value());
}
return map;
}

private List<Parameter> getParameters(Type type, List<Annotation> annotations) {
final Iterator<SwaggerExtension> chain = SwaggerExtensions.chain();
if (!chain.hasNext()) {
Expand Down