use of fish.payara.microprofile.openapi.impl.model.media.ContentImpl in project Payara by payara.
the class HeaderImpl method merge.
public static void merge(Header from, Header 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));
to.setDeprecated(mergeProperty(to.getDeprecated(), from.getDeprecated(), override));
to.setAllowEmptyValue(mergeProperty(to.getAllowEmptyValue(), from.getAllowEmptyValue(), override));
to.setStyle(Style.SIMPLE);
to.setExplode(mergeProperty(to.getExplode(), from.getExplode(), 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.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 HeaderImpl method createInstance.
public static Header createInstance(AnnotationModel annotation, ApiContext context) {
HeaderImpl from = new HeaderImpl();
String ref = annotation.getValue("ref", String.class);
if (ref != null && !ref.isEmpty()) {
from.setRef(ref);
}
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));
EnumModel styleEnum = annotation.getValue("style", EnumModel.class);
if (styleEnum != null) {
from.setStyle(Header.Style.valueOf(styleEnum.getValue()));
}
from.setExplode(annotation.getValue("explode", 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 RequestBodyImpl method createInstance.
public static RequestBodyImpl createInstance(AnnotationModel annotation, ApiContext context) {
RequestBodyImpl from = new RequestBodyImpl();
from.setDescription(annotation.getValue("description", String.class));
from.setRequired(annotation.getValue("required", Boolean.class));
String ref = annotation.getValue("ref", String.class);
if (ref != null && !ref.isEmpty()) {
from.setRef(ref);
}
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 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