use of fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl in project Payara by payara.
the class ApplicationProcessor method addParameter.
private static void addParameter(AnnotatedElement element, ApiContext context, String name, In in, Boolean required) {
Boolean hidden = false;
AnnotationModel paramAnnotation = element.getAnnotation(org.eclipse.microprofile.openapi.annotations.parameters.Parameter.class.getName());
if (paramAnnotation != null) {
hidden = paramAnnotation.getValue("hidden", Boolean.class);
}
if (hidden != null && hidden) {
return;
}
Parameter newParameter = new ParameterImpl();
newParameter.setName(name);
newParameter.setIn(in);
newParameter.setRequired(required);
SchemaImpl schema = new SchemaImpl();
String defaultValue = getDefaultValueIfPresent(element);
if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
org.glassfish.hk2.classmodel.reflect.Parameter parameter = (org.glassfish.hk2.classmodel.reflect.Parameter) element;
schema.setType(ModelUtils.getSchemaType(parameter.getTypeName(), context));
} else {
FieldModel field = (FieldModel) element;
schema.setType(ModelUtils.getSchemaType(field.getTypeName(), context));
}
if (schema.getType() == SchemaType.ARRAY) {
schema.setItems(getArraySchema(element, context));
if (defaultValue != null) {
schema.getItems().setDefaultValue(defaultValue);
}
} else if (defaultValue != null) {
schema.setDefaultValue(defaultValue);
}
newParameter.setSchema(schema);
final Operation workingOperation = context.getWorkingOperation();
if (workingOperation != null) {
for (Parameter parameter : workingOperation.getParameters()) {
final String parameterName = parameter.getName();
if (parameterName != null && parameterName.equals(newParameter.getName())) {
ParameterImpl.merge(newParameter, parameter, false, context);
return;
}
}
workingOperation.addParameter(newParameter);
} else {
LOGGER.log(SEVERE, "Couldn''t add {0} parameter, \"{1}\" to the OpenAPI Document. This is usually caused by declaring parameter under a method with an unsupported annotation.", new Object[] { newParameter.getIn(), newParameter.getName() });
}
}
use of fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl in project Payara by payara.
the class ComponentsImpl method merge.
public static void merge(Components from, Components to, boolean override, ApiContext context) {
if (from == null) {
return;
}
// Handle @Schema
if (from.getSchemas() != null) {
for (Entry<String, Schema> fromEntry : from.getSchemas().entrySet()) {
final String schemaName = fromEntry.getKey();
if (schemaName != null) {
final Schema fromSchema = fromEntry.getValue();
final Schema toSchema = to.getSchemas().getOrDefault(schemaName, new SchemaImpl());
SchemaImpl.merge(fromSchema, toSchema, override, context);
to.addSchema(schemaName, toSchema);
}
}
}
// Handle @Callback
if (from.getCallbacks() != null) {
for (String callbackName : from.getCallbacks().keySet()) {
if (callbackName != null) {
Callback newCallback = new CallbackImpl();
CallbackImpl.merge(from.getCallbacks().get(callbackName), newCallback, override, context);
to.addCallback(callbackName, newCallback);
}
}
}
// Handle @ExampleObject
if (from.getExamples() != null) {
for (String exampleName : from.getExamples().keySet()) {
if (exampleName != null) {
Example newExample = new ExampleImpl();
ExampleImpl.merge(from.getExamples().get(exampleName), newExample, override);
to.addExample(exampleName, newExample);
}
}
}
// Handle @Header
if (from.getHeaders() != null) {
for (String headerName : from.getHeaders().keySet()) {
if (headerName != null) {
Header newHeader = new HeaderImpl();
HeaderImpl.merge(from.getHeaders().get(headerName), newHeader, override, context);
to.addHeader(headerName, newHeader);
}
}
}
// Handle @Link
if (from.getLinks() != null) {
for (String linkName : from.getLinks().keySet()) {
if (linkName != null) {
Link newLink = new LinkImpl();
LinkImpl.merge(from.getLinks().get(linkName), newLink, override);
to.addLink(linkName, newLink);
}
}
}
// Handle @Parameter
if (from.getParameters() != null) {
for (String parameterName : from.getParameters().keySet()) {
if (parameterName != null) {
Parameter newParameter = new ParameterImpl();
ParameterImpl.merge(from.getParameters().get(parameterName), newParameter, override, context);
to.addParameter(parameterName, newParameter);
}
}
}
// Handle @RequestBody
if (from.getRequestBodies() != null) {
for (String requestBodyName : from.getRequestBodies().keySet()) {
if (requestBodyName != null) {
RequestBody newRequestBody = new RequestBodyImpl();
RequestBodyImpl.merge(from.getRequestBodies().get(requestBodyName), newRequestBody, override, context);
to.addRequestBody(requestBodyName, newRequestBody);
}
}
}
// Handle @APIResponse
if (from.getResponses() != null) {
for (String responseName : from.getResponses().keySet()) {
if (responseName != null) {
APIResponse newResponse = new APIResponseImpl();
APIResponseImpl.merge(from.getResponses().get(responseName), newResponse, override, context);
to.addResponse(responseName, newResponse);
}
}
}
// Handle @SecurityScheme
if (from.getSecuritySchemes() != null) {
for (String securitySchemeName : from.getSecuritySchemes().keySet()) {
if (securitySchemeName != null) {
SecurityScheme newSecurity = new SecuritySchemeImpl();
SecuritySchemeImpl.merge(from.getSecuritySchemes().get(securitySchemeName), newSecurity, override);
to.addSecurityScheme(securitySchemeName, newSecurity);
}
}
}
}
use of fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl in project Payara by payara.
the class OperationImpl method createInstance.
public static Operation createInstance(AnnotationModel annotation, ApiContext context) {
OperationImpl from = new OperationImpl();
from.setSummary(annotation.getValue("summary", String.class));
from.setDescription(annotation.getValue("description", String.class));
AnnotationModel externalDocs = annotation.getValue("externalDocs", AnnotationModel.class);
if (externalDocs != null) {
from.setExternalDocs(ExternalDocumentationImpl.createInstance(externalDocs));
}
from.setOperationId(annotation.getValue("operationId", String.class));
extractAnnotations(annotation, context, "parameters", ParameterImpl::createInstance, from::addParameter);
AnnotationModel requestBody = annotation.getValue("requestBody", AnnotationModel.class);
if (requestBody != null) {
from.setRequestBody(RequestBodyImpl.createInstance(requestBody, context));
}
extractAnnotations(annotation, context, "responses", "responseCode", APIResponseImpl::createInstance, from.responses::addAPIResponse);
extractAnnotations(annotation, context, "callbacks", "name", CallbackImpl::createInstance, from::addCallback);
from.setDeprecated(annotation.getValue("deprecated", Boolean.class));
extractAnnotations(annotation, context, "security", SecurityRequirementImpl::createInstance, from::addSecurityRequirement);
extractAnnotations(annotation, context, "servers", ServerImpl::createInstance, from::addServer);
from.setMethod(annotation.getValue("method", String.class));
return from;
}
use of fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl 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);
}
use of fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl in project Payara by payara.
the class ComponentsImpl method createInstance.
public static Components createInstance(AnnotationModel annotation, ApiContext context) {
Components from = new ComponentsImpl();
extractAnnotations(annotation, context, "schemas", "name", SchemaImpl::createInstance, from::addSchema);
extractAnnotations(annotation, context, "responses", "name", APIResponseImpl::createInstance, from::addResponse);
extractAnnotations(annotation, context, "parameters", "name", ParameterImpl::createInstance, from::addParameter);
extractAnnotations(annotation, context, "examples", "name", ExampleImpl::createInstance, from::addExample);
extractAnnotations(annotation, context, "requestBodies", "name", RequestBodyImpl::createInstance, from::addRequestBody);
extractAnnotations(annotation, context, "securitySchemes", "securitySchemeName", SecuritySchemeImpl::createInstance, from::addSecurityScheme);
extractAnnotations(annotation, context, "links", "name", LinkImpl::createInstance, from::addLink);
extractAnnotations(annotation, context, "callbacks", "name", CallbackImpl::createInstance, from::addCallback);
HeaderImpl.createInstances(annotation, context).forEach(from::addHeader);
return from;
}
Aggregations