use of org.eclipse.microprofile.openapi.models.links.Link in project wildfly-swarm by wildfly-swarm.
the class OpenApiAnnotationScanner method readLinks.
/**
* Reads a map of Link annotations.
* @param value
*/
private Map<String, Link> readLinks(AnnotationValue value) {
if (value == null) {
return null;
}
LOG.debug("Processing a map of @Link annotations.");
Map<String, Link> map = new LinkedHashMap<>();
AnnotationInstance[] nestedArray = value.asNestedArray();
for (AnnotationInstance nested : nestedArray) {
String name = JandexUtil.stringValue(nested, OpenApiConstants.PROP_NAME);
if (name == null && JandexUtil.isRef(nested)) {
name = JandexUtil.nameFromRef(nested);
}
if (name != null) {
map.put(name, readLink(nested));
}
}
return map;
}
use of org.eclipse.microprofile.openapi.models.links.Link in project wildfly-swarm by wildfly-swarm.
the class FilterUtil method filterLinks.
/**
* Filters the given models.
* @param filter
* @param models
*/
private static void filterLinks(OASFilter filter, Map<String, Link> models) {
if (models == null) {
return;
}
Collection<String> keys = new ArrayList<>(models.keySet());
for (String key : keys) {
Link model = models.get(key);
filterLink(filter, model);
if (filter.filterLink(model) == null) {
models.remove(key);
}
}
}
use of org.eclipse.microprofile.openapi.models.links.Link in project Payara by payara.
the class LinkImpl method createInstance.
public static Link createInstance(AnnotationModel annotation, ApiContext context) {
Link from = new LinkImpl();
from.setOperationRef(annotation.getValue("operationRef", String.class));
from.setOperationId(annotation.getValue("operationId", String.class));
List<AnnotationModel> parametersAnnotation = annotation.getValue("parameters", List.class);
if (parametersAnnotation != null) {
for (AnnotationModel parameterAnnotation : parametersAnnotation) {
from.addParameter(parameterAnnotation.getValue("name", String.class), parameterAnnotation.getValue("expression", String.class));
}
}
from.setRequestBody(annotation.getValue("requestBody", String.class));
from.setDescription(annotation.getValue("description", String.class));
String ref = annotation.getValue("ref", String.class);
if (ref != null && !ref.isEmpty()) {
from.setRef(ref);
}
AnnotationModel serverAnnotation = annotation.getValue("server", AnnotationModel.class);
if (serverAnnotation != null) {
from.setServer(ServerImpl.createInstance(serverAnnotation, context));
}
return from;
}
use of org.eclipse.microprofile.openapi.models.links.Link in project Payara by payara.
the class LinkImpl method merge.
public static void merge(String linkName, Link link, Map<String, Link> links, boolean override) {
if (link == null) {
return;
}
// Get the link name
if (linkName == null || linkName.isEmpty()) {
linkName = UNKNOWN_ELEMENT_NAME;
}
// Get or create the link
Link model = links.getOrDefault(linkName, new LinkImpl());
links.put(linkName, model);
// Merge the annotation
merge(link, model, override);
// If the merged annotation has a reference, set the name to the reference
if (model.getRef() != null) {
links.remove(linkName);
links.put(model.getRef().split("/")[3], model);
}
}
use of org.eclipse.microprofile.openapi.models.links.Link 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);
}
}
}
}
Aggregations