use of com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType in project enunciate by stoicflame.
the class StatusCodeImpl method getMediaTypes.
@Override
public List<? extends MediaTypeDescriptor> getMediaTypes() {
ArrayList<MediaTypeDescriptor> mts = new ArrayList<MediaTypeDescriptor>();
DecoratedTypeMirror type = this.responseCode.getType();
if (type != null) {
ResourceMethod resourceMethod = this.responseCode.getResourceMethod();
Set<MediaType> produces = resourceMethod.getProducesMediaTypes();
for (com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType mt : produces) {
for (Syntax syntax : resourceMethod.getContext().getContext().getApiRegistry().getSyntaxes(registrationContext)) {
MediaTypeDescriptor descriptor = syntax.findMediaTypeDescriptor(mt.getMediaType(), type);
if (descriptor != null) {
mts.add(new MediaTypeDescriptorImpl(descriptor, mt, descriptor.getExample()));
}
}
}
}
return mts;
}
use of com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType in project enunciate by stoicflame.
the class JaxrsModule method addReferencedDataTypeDefinitions.
/**
* Add the referenced type definitions for the specified resource method.
*
* @param resourceMethod The resource method.
*/
protected void addReferencedDataTypeDefinitions(ResourceMethod resourceMethod, LinkedList<Element> contextStack) {
if (AnnotationUtils.isIgnored(resourceMethod)) {
return;
}
ResourceEntityParameter ep = resourceMethod.getEntityParameter();
if (ep != null) {
Set<com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType> consumesMt = resourceMethod.getConsumesMediaTypes();
Set<String> consumes = new TreeSet<>();
for (MediaType mediaType : consumesMt) {
consumes.add(mediaType.getMediaType());
}
contextStack.push(ep.getDelegate());
TypeMirror type = ep.getType();
contextStack.push(resourceMethod);
try {
for (MediaTypeDefinitionModule mediaTypeModule : this.mediaTypeModules) {
mediaTypeModule.addDataTypeDefinitions(type, consumes, contextStack);
}
} catch (RuntimeException e) {
if (e.getClass().getName().endsWith("CompletionFailure")) {
throw new CompletionFailureException(contextStack, e);
}
throw e;
} finally {
contextStack.pop();
}
}
ResourceRepresentationMetadata outputPayload = resourceMethod.getRepresentationMetadata();
if (outputPayload != null) {
TypeMirror type = outputPayload.getDelegate();
Set<com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType> producesMt = resourceMethod.getProducesMediaTypes();
Set<String> produces = new TreeSet<>();
for (MediaType mediaType : producesMt) {
produces.add(mediaType.getMediaType());
}
contextStack.push(resourceMethod);
try {
for (MediaTypeDefinitionModule mediaTypeModule : this.mediaTypeModules) {
mediaTypeModule.addDataTypeDefinitions(type, produces, contextStack);
}
} catch (RuntimeException e) {
if (e.getClass().getName().endsWith("CompletionFailure")) {
throw new CompletionFailureException(contextStack, e);
}
throw e;
} finally {
contextStack.pop();
}
}
List<? extends ResponseCode> statusCodes = resourceMethod.getStatusCodes();
if (statusCodes != null) {
for (ResponseCode statusCode : statusCodes) {
TypeMirror type = statusCode.getType();
if (type != null) {
Set<com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType> producesMt = resourceMethod.getProducesMediaTypes();
Set<String> produces = new TreeSet<>();
for (MediaType mediaType : producesMt) {
produces.add(mediaType.getMediaType());
}
contextStack.push(resourceMethod);
try {
for (MediaTypeDefinitionModule mediaTypeModule : this.mediaTypeModules) {
mediaTypeModule.addDataTypeDefinitions(type, produces, contextStack);
}
} catch (RuntimeException e) {
if (e.getClass().getName().endsWith("CompletionFailure")) {
throw new CompletionFailureException(contextStack, e);
}
throw e;
} finally {
contextStack.pop();
}
}
}
}
}
Aggregations