use of fish.payara.microprofile.openapi.impl.model.media.ContentImpl in project Payara by payara.
the class ParameterImpl method merge.
public static void merge(Parameter from, Parameter to, boolean override, ApiContext context) {
if (from == null) {
return;
}
if (from.getRef() != null && !from.getRef().isEmpty()) {
applyReference(to, from.getRef());
return;
}
to.setName(mergeProperty(to.getName(), from.getName(), override));
to.setDescription(mergeProperty(to.getDescription(), from.getDescription(), override));
if (from.getIn() != null) {
to.setIn(mergeProperty(to.getIn(), from.getIn(), override));
}
to.setRequired(mergeProperty(to.getRequired(), from.getRequired(), override));
to.setDeprecated(mergeProperty(to.getDeprecated(), from.getDeprecated(), override));
to.setAllowEmptyValue(mergeProperty(to.getAllowEmptyValue(), from.getAllowEmptyValue(), override));
if (from.getStyle() != null) {
to.setStyle(mergeProperty(to.getStyle(), from.getStyle(), override));
}
if (from.getExplode() != null) {
to.setExplode(mergeProperty(to.getExplode(), false, override));
}
to.setAllowReserved(mergeProperty(to.getAllowReserved(), from.getAllowReserved(), override));
if (from.getSchema() != null) {
if (to.getSchema() == null) {
to.setSchema(new SchemaImpl());
}
SchemaImpl.merge(from.getSchema(), to.getSchema(), override, context);
}
to.setExample(mergeProperty(to.getExample(), from.getExample(), override));
if (from.getExamples() != null) {
for (String exampleName : from.getExamples().keySet()) {
if (exampleName != null) {
Example example = new ExampleImpl();
ExampleImpl.merge(from.getExamples().get(exampleName), example, override);
to.addExample(exampleName, example);
}
}
}
if (from instanceof ParameterImpl) {
ParameterImpl fromImpl = (ParameterImpl) from;
if (fromImpl.getContents() != null) {
if (to.getContent() == null) {
to.setContent(new ContentImpl());
}
for (ContentImpl content : fromImpl.getContents()) {
ContentImpl.merge(content, to.getContent(), override, context);
}
}
}
if (from.getContent() != null) {
if (to.getContent() == null) {
to.setContent(new ContentImpl());
}
ContentImpl.merge((ContentImpl) from.getContent(), to.getContent(), override, context);
}
}
use of fish.payara.microprofile.openapi.impl.model.media.ContentImpl in project Payara by payara.
the class ParameterImpl method createInstance.
public static Parameter createInstance(AnnotationModel annotation, ApiContext context) {
ParameterImpl from = new ParameterImpl();
from.setName(annotation.getValue("name", String.class));
EnumModel inEnum = annotation.getValue("in", EnumModel.class);
if (inEnum != null) {
from.setIn(In.valueOf(inEnum.getValue()));
}
from.setDescription(annotation.getValue("description", String.class));
from.setRequired(annotation.getValue("required", Boolean.class));
from.setDeprecated(annotation.getValue("deprecated", Boolean.class));
from.setAllowEmptyValue(annotation.getValue("allowEmptyValue", Boolean.class));
String ref = annotation.getValue("ref", String.class);
if (ref != null && !ref.isEmpty()) {
from.setRef(ref);
}
EnumModel styleEnum = annotation.getValue("style", EnumModel.class);
if (styleEnum != null) {
from.setStyle(Style.valueOf(styleEnum.getValue()));
}
from.setExplode(annotation.getValue("explode", Boolean.class));
from.setAllowReserved(annotation.getValue("allowReserved", Boolean.class));
AnnotationModel schemaAnnotation = annotation.getValue("schema", AnnotationModel.class);
if (schemaAnnotation != null) {
Boolean hidden = schemaAnnotation.getValue("hidden", Boolean.class);
if (hidden == null || !hidden) {
from.setSchema(SchemaImpl.createInstance(schemaAnnotation, context));
}
}
extractAnnotations(annotation, context, "examples", "name", ExampleImpl::createInstance, from::addExample);
from.setExample(annotation.getValue("example", Object.class));
final List<ContentImpl> contents = createList();
extractAnnotations(annotation, context, "content", ContentImpl::createInstance, contents::add);
for (ContentImpl content : contents) {
content.getMediaTypes().forEach(from.content::addMediaType);
}
return from;
}
use of fish.payara.microprofile.openapi.impl.model.media.ContentImpl 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.ContentImpl 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.ContentImpl in project Payara by payara.
the class RequestBodyImpl method merge.
public static void merge(RequestBody from, RequestBody to, boolean override, ApiContext context) {
if (from == null) {
return;
}
if (from.getRef() != null && !from.getRef().isEmpty()) {
applyReference(to, from.getRef());
return;
}
to.setDescription(mergeProperty(to.getDescription(), from.getDescription(), override));
to.setRequired(mergeProperty(to.getRequired(), from.getRequired(), override));
if (from.getContent() != null) {
if (to.getContent() == null) {
to.setContent(new ContentImpl());
}
ContentImpl.merge((ContentImpl) from.getContent(), to.getContent(), override, context);
}
}
Aggregations