use of io.swagger.v3.oas.models.responses.ApiResponses in project atlasmap by atlasmap.
the class AtlasService method listMappings.
/**
* Retrieves a list of mapping file name saved with specified mapping definition ID.
* @param uriInfo URI info
* @param filter filter
* @param mappingDefinitionId mapping definition ID
* @return A list of mapping file name in {@link StringMap}
*/
@GET
@Path("/mappings/{mappingDefinitionId}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "List Mappings", description = "Retrieves a list of mapping file name saved with specified mappingDefinitionId")
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = StringMap.class)), description = "Return a list of a pair of mapping file name and content"))
public Response listMappings(@Context UriInfo uriInfo, @QueryParam("filter") final String filter, @Parameter(description = "Mapping Definition ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId) {
StringMap sMap = new StringMap();
LOG.debug("listMappings with filter '{}'", filter);
ADMArchiveHandler handler = loadExplodedMappingDirectory(mappingDefinitionId);
AtlasMapping map = handler.getMappingDefinition();
if (map == null) {
return Response.ok().entity(toJson(sMap)).build();
}
StringMapEntry mapEntry = new StringMapEntry();
mapEntry.setName(map.getName());
UriBuilder builder = uriInfo.getBaseUriBuilder().path("v2").path("atlas").path("mapping").path(map.getName());
mapEntry.setValue(builder.build().toString());
sMap.getStringMapEntry().add(mapEntry);
byte[] serialized = toJson(sMap);
if (LOG.isDebugEnabled()) {
LOG.debug(new String(serialized));
}
return Response.ok().entity(serialized).build();
}
use of io.swagger.v3.oas.models.responses.ApiResponses in project flow by vaadin.
the class OpenAPIObjectGenerator method createPathItems.
private Map<String, PathItem> createPathItems(String endpointName, String tagName, ClassOrInterfaceDeclaration typeDeclaration, ResolvedTypeParametersMap resolvedTypeParametersMap, CompilationUnit compilationUnit) {
Map<String, PathItem> newPathItems = new HashMap<>();
Collection<MethodDeclaration> methods = typeDeclaration.getMethods();
for (MethodDeclaration methodDeclaration : methods) {
if (isAccessForbidden(typeDeclaration, methodDeclaration)) {
continue;
}
String methodName = methodDeclaration.getNameAsString();
Operation post = createPostOperation(methodDeclaration);
if (methodDeclaration.getParameters().isNonEmpty()) {
post.setRequestBody(createRequestBody(methodDeclaration, resolvedTypeParametersMap));
}
ApiResponses responses = createApiResponses(methodDeclaration, resolvedTypeParametersMap);
post.setResponses(responses);
post.tags(Collections.singletonList(tagName));
PathItem pathItem = new PathItem().post(post);
String pathName = "/" + endpointName + "/" + methodName;
pathItem.readOperationsMap().forEach((httpMethod, operation) -> operation.setOperationId(String.join("_", endpointName, methodName, httpMethod.name())));
newPathItems.put(pathName, pathItem);
}
Stream.concat(typeDeclaration.getExtendedTypes().stream(), typeDeclaration.getImplementedTypes().stream()).map(resolvedType -> getDeclarationAndResolvedTypeParametersMap(resolvedType, resolvedTypeParametersMap)).filter(Objects::nonNull).forEach(pair -> newPathItems.putAll(createPathItems(endpointName, tagName, pair.a, pair.b, compilationUnit)));
return newPathItems;
}
use of io.swagger.v3.oas.models.responses.ApiResponses 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.models.responses.ApiResponses 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.models.responses.ApiResponses in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testResponseRemoteRefs.
private void testResponseRemoteRefs(String remoteRef) {
final OpenAPI swagger = new OpenAPI();
swagger.path("/fun", new PathItem().get(new Operation().responses(new ApiResponses().addApiResponse("200", new ApiResponse().content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().$ref(remoteRef))))))));
final OpenAPI resolved = new OpenAPIResolver(swagger, null).resolve();
final ApiResponse response = swagger.getPaths().get("/fun").getGet().getResponses().get("200");
final Schema ref = response.getContent().get("*/*").getSchema();
assertEquals(ref.get$ref(), "#/components/schemas/Tag");
assertNotNull(swagger.getComponents().getSchemas().get("Tag"));
}
Aggregations