use of fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl in project Payara by payara.
the class APIResponseImpl method createInstance.
public static APIResponseImpl createInstance(AnnotationModel annotation, ApiContext context) {
APIResponseImpl from = new APIResponseImpl();
from.setDescription(annotation.getValue("description", String.class));
HeaderImpl.createInstances(annotation, context).forEach(from::addHeader);
final List<ContentImpl> contents = createList();
// If the annotation is @APIResponseSchema, parse the schema and description
final String implementationClass = annotation.getValue("value", String.class);
if (implementationClass != null) {
ContentImpl content = new ContentImpl().addMediaType(MediaType.WILDCARD, new MediaTypeImpl().schema(SchemaImpl.fromImplementation(implementationClass, context)));
contents.add(content);
from.setDescription(annotation.getValue("responseDescription", String.class));
}
extractAnnotations(annotation, context, "content", ContentImpl::createInstance, contents::add);
for (ContentImpl content : contents) {
content.getMediaTypes().forEach(from.content::addMediaType);
}
extractAnnotations(annotation, context, "links", "name", LinkImpl::createInstance, from::addLink);
String ref = annotation.getValue("ref", String.class);
if (ref != null && !ref.isEmpty()) {
from.setRef(ref);
}
from.setResponseCode(annotation.getValue("responseCode", String.class));
return from;
}
use of fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl in project Payara by payara.
the class ApplicationProcessor method insertDefaultResponse.
/**
* Creates a new {@link APIResponse} to model the default response of a
* {@link Method}, and inserts it into the {@link Operation} responses.
*
* @param context the API context.
* @param operation the {@link Operation} to add the default response to.
* @param method the {@link Method} to model the default response on.
* @return the newly created {@link APIResponse}.
*/
private void insertDefaultResponse(ApiContext context, OperationImpl operation, MethodModel method) {
final APIResponsesImpl responses = new APIResponsesImpl();
operation.setResponses(responses);
// Add the default response
APIResponse defaultResponse = new APIResponseImpl();
responses.addAPIResponse(APIResponses.DEFAULT, defaultResponse);
defaultResponse.setDescription("Default Response.");
// Configure the default response with a wildcard mediatype
MediaType mediaType = new MediaTypeImpl().schema(createSchema(context, method.getReturnType()));
defaultResponse.getContent().addMediaType(javax.ws.rs.core.MediaType.WILDCARD, mediaType);
// Add responses for the applicable declared exceptions
for (String exceptionType : method.getExceptionTypes()) {
final APIResponseImpl mappedResponse = (APIResponseImpl) context.getMappedExceptionResponses().get(exceptionType);
if (mappedResponse != null) {
final String responseCode = mappedResponse.getResponseCode();
if (responseCode != null) {
responses.addAPIResponse(responseCode, mappedResponse);
}
}
operation.addExceptionType(exceptionType);
}
}
use of fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl in project Payara by payara.
the class ApplicationProcessor method visitFormParam.
@Override
public void visitFormParam(AnnotationModel param, AnnotatedElement element, ApiContext context) {
// Find the aggregate schema type of all the parameters
SchemaType formSchemaType = null;
if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
List<org.glassfish.hk2.classmodel.reflect.Parameter> parameters = ((org.glassfish.hk2.classmodel.reflect.Parameter) element).getMethod().getParameters();
for (org.glassfish.hk2.classmodel.reflect.Parameter methodParam : parameters) {
if (methodParam.getAnnotation(FormParam.class.getName()) != null) {
formSchemaType = ModelUtils.getParentSchemaType(formSchemaType, ModelUtils.getSchemaType(methodParam, context));
}
}
}
final Operation workingOperation = context.getWorkingOperation();
if (workingOperation != null) {
// If there's no request body, fill out a new one right down to the schema
if (workingOperation.getRequestBody() == null) {
workingOperation.setRequestBody(new RequestBodyImpl().content(new ContentImpl().addMediaType(javax.ws.rs.core.MediaType.WILDCARD, new MediaTypeImpl().schema(new SchemaImpl()))));
}
for (MediaType mediaType : workingOperation.getRequestBody().getContent().getMediaTypes().values()) {
final Schema schema = mediaType.getSchema();
if (schema != null) {
schema.setType(formSchemaType);
}
}
}
}
use of fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl in project Payara by payara.
the class ApplicationProcessor method insertDefaultRequestBody.
// PRIVATE METHODS
private RequestBody insertDefaultRequestBody(ApiContext context, Operation operation, MethodModel method) {
RequestBody requestBody = new RequestBodyImpl();
// Get the request body type of the method
org.glassfish.hk2.classmodel.reflect.ParameterizedType bodyType = null;
for (org.glassfish.hk2.classmodel.reflect.Parameter methodParam : method.getParameters()) {
if (ModelUtils.isRequestBody(context, methodParam)) {
bodyType = methodParam;
break;
}
}
if (bodyType == null) {
return null;
}
// Create the default request body with a wildcard mediatype
MediaType mediaType = new MediaTypeImpl().schema(createSchema(context, bodyType));
requestBody.getContent().addMediaType(javax.ws.rs.core.MediaType.WILDCARD, mediaType);
operation.setRequestBody(requestBody);
return requestBody;
}
use of fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl in project Payara by payara.
the class ModelInvariantsTest method addKeyValueIgnoresNull.
@Test
public void addKeyValueIgnoresNull() {
BiPredicate<Extensible<?>, String> hasExtension = (obj, key) -> obj.getExtensions().containsKey(key);
assertAddIgnoresNull(new CallbackImpl(), Callback::addPathItem, Callback::hasPathItem);
assertAddIgnoresNull(new CallbackImpl(), Callback::addExtension, hasExtension);
assertAddIgnoresNull(new ExampleImpl(), Example::addExtension, hasExtension);
assertAddIgnoresNull(new HeaderImpl(), Header::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new HeaderImpl(), Header::addExtension, hasExtension);
assertAddIgnoresNull(new ContactImpl(), Contact::addExtension, hasExtension);
assertAddIgnoresNull(new InfoImpl(), Info::addExtension, hasExtension);
assertAddIgnoresNull(new LicenseImpl(), License::addExtension, hasExtension);
assertAddIgnoresNull(new LinkImpl(), Link::addParameter, (obj, key) -> obj.getParameters().containsKey(key));
assertAddIgnoresNull(new LinkImpl(), Link::addExtension, hasExtension);
assertAddIgnoresNull(new ContentImpl(), Content::addMediaType, Content::hasMediaType);
assertAddIgnoresNull(new DiscriminatorImpl(), Discriminator::addMapping, (obj, key) -> obj.getMapping().containsKey(key));
assertAddIgnoresNull(new EncodingImpl(), Encoding::addHeader, (obj, key) -> obj.getHeaders().containsKey(key));
assertAddIgnoresNull(new EncodingImpl(), Encoding::addExtension, hasExtension);
assertAddIgnoresNull(new MediaTypeImpl(), MediaType::addEncoding, (obj, key) -> obj.getEncoding().containsKey(key));
assertAddIgnoresNull(new MediaTypeImpl(), MediaType::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new MediaTypeImpl(), MediaType::addExtension, hasExtension);
assertAddIgnoresNull(new SchemaImpl(), Schema::addProperty, (obj, key) -> obj.getProperties().containsKey(key));
assertAddIgnoresNull(new SchemaImpl(), Schema::addExtension, hasExtension);
assertAddIgnoresNull(new XMLImpl(), XML::addExtension, hasExtension);
assertAddIgnoresNull(new ParameterImpl(), Parameter::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new ParameterImpl(), Parameter::addExtension, hasExtension);
assertAddIgnoresNull(new RequestBodyImpl(), RequestBody::addExtension, hasExtension);
assertAddIgnoresNull(new APIResponseImpl(), APIResponse::addHeader, (obj, key) -> obj.getHeaders().containsKey(key));
assertAddIgnoresNull(new APIResponseImpl(), APIResponse::addLink, (obj, key) -> obj.getLinks().containsKey(key));
assertAddIgnoresNull(new APIResponseImpl(), APIResponse::addExtension, hasExtension);
assertAddIgnoresNull(new APIResponsesImpl(), APIResponses::addAPIResponse, APIResponses::hasAPIResponse);
assertAddIgnoresNull(new APIResponsesImpl(), APIResponses::addExtension, hasExtension);
assertAddIgnoresNull(new OAuthFlowImpl(), OAuthFlow::addExtension, hasExtension);
assertAddIgnoresNull(new OAuthFlowsImpl(), OAuthFlows::addExtension, hasExtension);
assertAddIgnoresNull(new SecuritySchemeImpl(), SecurityScheme::addExtension, hasExtension);
assertAddIgnoresNull(new ServerImpl(), Server::addExtension, hasExtension);
assertAddIgnoresNull(new ServerVariableImpl(), ServerVariable::addExtension, hasExtension);
assertAddIgnoresNull(new TagImpl(), Tag::addExtension, hasExtension);
assertAddIgnoresNull(new ComponentsImpl(), Components::addCallback, (obj, key) -> obj.getCallbacks().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addHeader, (obj, key) -> obj.getHeaders().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addLink, (obj, key) -> obj.getLinks().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addParameter, (obj, key) -> obj.getParameters().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addRequestBody, (obj, key) -> obj.getRequestBodies().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addResponse, (obj, key) -> obj.getResponses().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addSchema, (obj, key) -> obj.getSchemas().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addSecurityScheme, (obj, key) -> obj.getSecuritySchemes().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addExtension, hasExtension);
assertAddIgnoresNull(new ExternalDocumentationImpl(), ExternalDocumentation::addExtension, hasExtension);
assertAddIgnoresNull(new OpenAPIImpl(), OpenAPI::addExtension, hasExtension);
assertAddIgnoresNull(new OperationImpl(), Operation::addCallback, (obj, key) -> obj.getCallbacks().containsKey(key));
assertAddIgnoresNull(new OperationImpl(), Operation::addExtension, hasExtension);
assertAddIgnoresNull(new PathItemImpl(), PathItem::addExtension, hasExtension);
assertAddIgnoresNull(new PathsImpl(), Paths::addPathItem, Paths::hasPathItem);
assertAddIgnoresNull(new PathsImpl(), Paths::addExtension, hasExtension);
}
Aggregations