use of fish.payara.microprofile.openapi.impl.model.PathItemImpl in project Payara by payara.
the class ApplicationProcessor method visitGET.
// JAX-RS method handlers
@Override
public void visitGET(AnnotationModel get, MethodModel element, ApiContext context) {
if (context.getPath() == null) {
return;
}
// Get or create the path item
PathItem pathItem = context.getApi().getPaths().getPathItems().getOrDefault(context.getPath(), new PathItemImpl());
context.getApi().getPaths().addPathItem(context.getPath(), pathItem);
OperationImpl operation = new OperationImpl();
pathItem.setGET(operation);
operation.setOperationId(element.getName());
operation.setMethod(HttpMethod.GET);
// Add the default request
insertDefaultRequestBody(context, operation, element);
// Add the default response
insertDefaultResponse(context, operation, element);
}
use of fish.payara.microprofile.openapi.impl.model.PathItemImpl in project Payara by payara.
the class ApplicationProcessor method visitPATCH.
@Override
public void visitPATCH(AnnotationModel patch, MethodModel element, ApiContext context) {
if (context.getPath() == null) {
return;
}
// Get or create the path item
PathItem pathItem = context.getApi().getPaths().getPathItems().getOrDefault(context.getPath(), new PathItemImpl());
context.getApi().getPaths().addPathItem(context.getPath(), pathItem);
OperationImpl operation = new OperationImpl();
pathItem.setPATCH(operation);
operation.setOperationId(element.getName());
operation.setMethod(HttpMethod.PATCH);
// Add the default request
insertDefaultRequestBody(context, operation, element);
// Add the default response
insertDefaultResponse(context, operation, element);
}
use of fish.payara.microprofile.openapi.impl.model.PathItemImpl in project Payara by payara.
the class ApplicationProcessor method visitHEAD.
@Override
public void visitHEAD(AnnotationModel head, MethodModel element, ApiContext context) {
if (context.getPath() == null) {
return;
}
// Get or create the path item
PathItem pathItem = context.getApi().getPaths().getPathItems().getOrDefault(context.getPath(), new PathItemImpl());
context.getApi().getPaths().addPathItem(context.getPath(), pathItem);
OperationImpl operation = new OperationImpl();
pathItem.setHEAD(operation);
operation.setOperationId(element.getName());
operation.setMethod(HttpMethod.HEAD);
// Add the default request
insertDefaultRequestBody(context, operation, element);
// Add the default response
insertDefaultResponse(context, operation, element);
}
use of fish.payara.microprofile.openapi.impl.model.PathItemImpl in project Payara by payara.
the class ApplicationProcessor method visitPOST.
@Override
public void visitPOST(AnnotationModel post, MethodModel element, ApiContext context) {
if (context.getPath() == null) {
return;
}
// Get or create the path item
PathItem pathItem = context.getApi().getPaths().getPathItems().getOrDefault(context.getPath(), new PathItemImpl());
context.getApi().getPaths().addPathItem(context.getPath(), pathItem);
OperationImpl operation = new OperationImpl();
pathItem.setPOST(operation);
operation.setOperationId(element.getName());
operation.setMethod(HttpMethod.POST);
// Add the default request
insertDefaultRequestBody(context, operation, element);
// Add the default response
insertDefaultResponse(context, operation, element);
}
use of fish.payara.microprofile.openapi.impl.model.PathItemImpl in project Payara by payara.
the class BaseProcessor method process.
@Override
public OpenAPI process(OpenAPI api, OpenApiConfiguration config) {
// Set the OpenAPI version if it hasn't been set
if (api.getOpenapi() == null) {
api.setOpenapi("3.0.0");
}
// Set the info if it hasn't been set
if (api.getInfo() == null) {
api.setInfo(new InfoImpl().title("Deployed Resources").version("1.0.0"));
}
if (config != null) {
// Add the config specified servers
if (!config.getServers().isEmpty()) {
// Clear all the other servers
api.setServers(new ArrayList<>());
// Add all the specified ones
config.getServers().forEach(serverUrl -> api.addServer(new ServerImpl().url(serverUrl)));
}
// Add the default server if there are none
if (api.getServers().isEmpty()) {
for (URL baseURL : baseURLs) {
api.addServer(new ServerImpl().url(baseURL.toString()).description("Default Server."));
}
}
// Add the path servers
for (Entry<String, Set<String>> entry : config.getPathServerMap().entrySet()) {
// Get the normalised path
String path = normaliseUrl(entry.getKey());
// If the path doesn't exist, create it
if (!api.getPaths().hasPathItem(path)) {
api.getPaths().addPathItem(path, new PathItemImpl());
}
// Clear the current list of servers
api.getPaths().getPathItem(path).setServers(new ArrayList<>());
// Add each url
for (String serverUrl : entry.getValue()) {
api.getPaths().getPathItem(path).addServer(new ServerImpl().url(serverUrl));
}
}
// Add the operation servers
for (Entry<String, Set<String>> entry : config.getOperationServerMap().entrySet()) {
// Find the matching operation
for (PathItem pathItem : api.getPaths().getPathItems().values()) {
for (Operation operation : pathItem.getOperations().values()) {
if (operation.getOperationId().equals(entry.getKey())) {
// Clear the current list of servers
operation.setServers(new ArrayList<>());
// Add each server url to the operation
for (String serverUrl : entry.getValue()) {
operation.addServer(new ServerImpl().url(serverUrl));
}
}
}
}
}
}
removeEmptyPaths(api.getPaths());
return api;
}
Aggregations