use of io.swagger.v3.oas.annotations.callbacks.Callback in project carbon-apimgt by wso2.
the class RestApiCommonUtil method generateOpenAPIForAsync.
/**
* Generate a basic OpenAPI definition with given details.
*
* @param name name of the API.
* @param version version of the API.
* @param context context of the API.
* @param callbackEndpoint callback URL of the async API.
* @return OpenAPI definition as String.
* @throws JsonProcessingException Error occurred while generating the OpenAPI.
*/
public static String generateOpenAPIForAsync(String name, String version, String context, String callbackEndpoint) throws JsonProcessingException {
OpenAPI openAPI = new OpenAPI();
Info info = new Info();
info.setTitle(name);
info.setDescription("API Definition of " + name);
info.setVersion(version);
openAPI.setInfo(info);
ArrayList<Server> servers = new ArrayList<>();
Server server = new Server();
server.setUrl("/");
servers.add(server);
openAPI.setServers(Arrays.asList(server));
Paths paths = new Paths();
PathItem pathItem = new PathItem();
Operation operation = new Operation();
ApiResponses apiResponses = new ApiResponses();
ApiResponse apiResponse = new ApiResponse();
apiResponse.setDescription("Default response");
apiResponses.addApiResponse("default", apiResponse);
operation.setResponses(apiResponses);
pathItem.setPost(operation);
paths.addPathItem("/*", pathItem);
openAPI.paths(paths);
List<String> urls = new ArrayList<>();
urls.add(callbackEndpoint);
Map<String, Object> tempMap = new HashMap();
tempMap.put("type", "http");
tempMap.put("urls", urls);
openAPI.addExtension(X_WSO2_PRODUCTION_ENDPOINTS, tempMap);
openAPI.addExtension(X_WSO2_SANDBOX_ENDPOINTS, tempMap);
openAPI.addExtension(X_WSO2_AUTH_HEADER, "Authorization");
openAPI.addExtension(X_WSO2_BASEPATH, context + "/" + version);
openAPI.addExtension(X_WSO2_DISABLE_SECURITY, true);
return Json.mapper().writeValueAsString(openAPI);
}
use of io.swagger.v3.oas.annotations.callbacks.Callback in project swagger-parser by swagger-api.
the class OpenAPIDeserializer method getCallback.
public Callback getCallback(ObjectNode node, String location, ParseResult result) {
if (node == null) {
return null;
}
Callback callback = new Callback();
Set<String> keys = getKeys(node);
for (String name : keys) {
JsonNode value = node.get(name);
if (node != null) {
JsonNode ref = node.get("$ref");
if (ref != null) {
if (ref.getNodeType().equals(JsonNodeType.STRING)) {
String mungedRef = mungedRef(ref.textValue());
if (mungedRef != null) {
callback.set$ref(mungedRef);
} else {
callback.set$ref(ref.textValue());
}
return callback;
} else {
result.invalidType(location, "$ref", "string", node);
return null;
}
}
if (value.isObject()) {
callback.addPathItem(name, getPathItem((ObjectNode) value, location, result));
} else {
result.invalidType(location, name, "object", value);
}
Map<String, Object> extensions = getExtensions(node);
if (extensions != null && extensions.size() > 0) {
callback.setExtensions(extensions);
}
}
}
return callback;
}
use of io.swagger.v3.oas.annotations.callbacks.Callback in project swagger-parser by swagger-api.
the class OpenAPIDeserializer method getOperation.
public Operation getOperation(ObjectNode obj, String location, ParseResult result) {
if (obj == null) {
return null;
}
Operation operation = new Operation();
ArrayNode array = getArray("tags", obj, false, location, result);
List<String> tags = getTagsStrings(array, String.format("%s.%s", location, "tags"), result);
if (tags != null) {
operation.setTags(tags);
}
String value = getString("summary", obj, false, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
operation.setSummary(value);
}
value = getString("description", obj, false, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
operation.setDescription(value);
}
ObjectNode externalDocs = getObject("externalDocs", obj, false, location, result);
ExternalDocumentation docs = getExternalDocs(externalDocs, String.format("%s.%s", location, "externalDocs"), result);
if (docs != null) {
operation.setExternalDocs(docs);
}
value = getString("operationId", obj, false, location, result, operationIDs);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
operation.operationId(value);
}
ArrayNode parameters = getArray("parameters", obj, false, location, result);
if (parameters != null) {
operation.setParameters(getParameterList(parameters, String.format("%s.%s", location, "parameters"), result));
}
final ObjectNode requestObjectNode = getObject("requestBody", obj, false, location, result);
if (requestObjectNode != null) {
operation.setRequestBody(getRequestBody(requestObjectNode, String.format("%s.%s", location, "requestBody"), result));
}
ObjectNode responsesNode = getObject("responses", obj, true, location, result);
ApiResponses responses = getResponses(responsesNode, String.format("%s.%s", location, "responses"), result, false);
if (responses != null) {
operation.setResponses(responses);
}
ObjectNode callbacksNode = getObject("callbacks", obj, false, location, result);
Map<String, Callback> callbacks = getCallbacks(callbacksNode, String.format("%s.%s", location, "callbacks"), result, false);
if (callbacks != null) {
operation.setCallbacks(callbacks);
}
Boolean deprecated = getBoolean("deprecated", obj, false, location, result);
if (deprecated != null) {
operation.setDeprecated(deprecated);
}
array = getArray("servers", obj, false, location, result);
if (array != null && array.size() > 0) {
operation.setServers(getServersList(array, String.format("%s.%s", location, "servers"), result));
}
array = getArray("security", obj, false, location, result);
if (array != null) {
operation.setSecurity(getSecurityRequirementsList(array, String.format("%s.%s", location, "security"), result));
}
Map<String, Object> extensions = getExtensions(obj);
if (extensions != null && extensions.size() > 0) {
operation.setExtensions(extensions);
}
Set<String> keys = getKeys(obj);
for (String key : keys) {
if (!OPERATION_KEYS.contains(key) && !key.startsWith("x-")) {
result.extra(location, key, obj.get(key));
}
}
return operation;
}
use of io.swagger.v3.oas.annotations.callbacks.Callback in project swagger-parser by swagger-api.
the class ResolverFully method resolvePath.
public void resolvePath(PathItem pathItem) {
for (Operation op : pathItem.readOperations()) {
// inputs
if (op.getParameters() != null) {
for (Parameter parameter : op.getParameters()) {
parameter = parameter.get$ref() != null ? resolveParameter(parameter) : parameter;
if (parameter.getSchema() != null) {
Schema resolved = resolveSchema(parameter.getSchema());
if (resolved != null) {
parameter.setSchema(resolved);
}
}
if (parameter.getContent() != null) {
Map<String, MediaType> content = parameter.getContent();
for (String key : content.keySet()) {
if (content.get(key) != null && content.get(key).getSchema() != null) {
Schema resolvedSchema = resolveSchema(content.get(key).getSchema());
if (resolvedSchema != null) {
content.get(key).setSchema(resolvedSchema);
}
}
}
}
}
}
if (op.getCallbacks() != null) {
Map<String, Callback> callbacks = op.getCallbacks();
for (String name : callbacks.keySet()) {
Callback callback = callbacks.get(name);
callback = callback.get$ref() != null ? resolveCallback(callback) : callback;
if (callback != null) {
for (String callbackName : callback.keySet()) {
PathItem path = callback.get(callbackName);
if (path != null) {
resolvePath(path);
}
}
}
op.getCallbacks().put(name, callback);
}
}
RequestBody refRequestBody = op.getRequestBody();
if (refRequestBody != null) {
RequestBody requestBody = refRequestBody.get$ref() != null ? resolveRequestBody(refRequestBody) : refRequestBody;
op.setRequestBody(requestBody);
if (requestBody.getContent() != null) {
Map<String, MediaType> content = requestBody.getContent();
for (String key : content.keySet()) {
if (content.get(key) != null && content.get(key).getSchema() != null) {
Schema resolved = resolveSchema(content.get(key).getSchema());
if (resolved != null) {
content.get(key).setSchema(resolved);
}
}
}
}
}
// responses
ApiResponses responses = op.getResponses();
if (responses != null) {
for (String code : responses.keySet()) {
ApiResponse response = responses.get(code);
if (response.getContent() != null) {
Map<String, MediaType> content = response.getContent();
for (String mediaType : content.keySet()) {
if (content.get(mediaType).getSchema() != null) {
Schema resolved = resolveSchema(content.get(mediaType).getSchema());
response.getContent().get(mediaType).setSchema(resolved);
}
if (content.get(mediaType).getExamples() != null) {
Map<String, Example> resolved = resolveExample(content.get(mediaType).getExamples());
response.getContent().get(mediaType).setExamples(resolved);
}
}
}
resolveHeaders(response.getHeaders());
Map<String, Link> links = response.getLinks();
if (links != null) {
for (Map.Entry<String, Link> link : links.entrySet()) {
Link value = link.getValue();
Link resolvedValue = value.get$ref() != null ? resolveLink(value) : value;
link.setValue(resolvedValue);
}
}
}
}
}
}
use of io.swagger.v3.oas.annotations.callbacks.Callback in project swagger-parser by swagger-api.
the class ResolverFully method resolveCallback.
public Callback resolveCallback(Callback callback) {
RefFormat refFormat = computeRefFormat(callback.get$ref());
String $ref = callback.get$ref();
if (!isAnExternalRefFormat(refFormat)) {
if (callbacks != null && !callbacks.isEmpty()) {
String referenceKey = computeDefinitionName($ref);
return callbacks.getOrDefault(referenceKey, callback);
}
}
return callback;
}
Aggregations