use of io.swagger.v3.oas.annotations.tags.Tags in project cxf by apache.
the class OpenApiCustomizer method customize.
public void customize(final OpenAPI oas) {
if (replaceTags || javadocProvider != null) {
Map<String, ClassResourceInfo> operations = new HashMap<>();
Map<Pair<String, String>, OperationResourceInfo> methods = new HashMap<>();
cris.forEach(cri -> {
cri.getMethodDispatcher().getOperationResourceInfos().forEach(ori -> {
String normalizedPath = getNormalizedPath(cri.getURITemplate().getValue(), ori.getURITemplate().getValue());
operations.put(normalizedPath, cri);
methods.put(Pair.of(ori.getHttpMethod(), normalizedPath), ori);
});
});
List<Tag> tags = new ArrayList<>();
oas.getPaths().forEach((pathKey, pathItem) -> {
Optional<Tag> tag;
if (replaceTags && operations.containsKey(pathKey)) {
ClassResourceInfo cri = operations.get(pathKey);
tag = Optional.of(new Tag());
tag.get().setName(cri.getURITemplate().getValue().replaceAll("/", "_"));
if (javadocProvider != null) {
tag.get().setDescription(javadocProvider.getClassDoc(cri));
}
if (!tags.contains(tag.get())) {
tags.add(tag.get());
}
} else {
tag = Optional.empty();
}
pathItem.readOperationsMap().forEach((method, operation) -> {
if (replaceTags && tag.isPresent()) {
operation.setTags(Collections.singletonList(tag.get().getName()));
}
Pair<String, String> key = Pair.of(method.name(), pathKey);
if (methods.containsKey(key) && javadocProvider != null) {
OperationResourceInfo ori = methods.get(key);
if (StringUtils.isBlank(operation.getSummary())) {
operation.setSummary(javadocProvider.getMethodDoc(ori));
}
if (operation.getParameters() == null) {
List<Parameter> parameters = new ArrayList<>();
addParameters(parameters);
operation.setParameters(parameters);
}
for (int i = 0; i < operation.getParameters().size(); i++) {
if (StringUtils.isBlank(operation.getParameters().get(i).getDescription())) {
operation.getParameters().get(i).setDescription(extractJavadoc(operation, ori, i));
}
}
addParameters(operation.getParameters());
customizeResponses(operation, ori);
}
});
});
if (replaceTags && oas.getTags() != null) {
oas.setTags(tags);
}
}
}
use of io.swagger.v3.oas.annotations.tags.Tags in project snow-owl by b2ihealthcare.
the class SnomedReferenceSetMemberRestService method searchByGet.
@Operation(summary = "Retrieve reference set members from a path", description = "Returns a list with all reference set members from a path." + "<p>The following properties can be expanded:" + "<p>" + "• referencedComponent(expand(pt(),...)) – the referenced component, and any applicable nested expansions<br>")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Branch not found") })
@GetMapping(produces = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseBody
public Promise<SnomedReferenceSetMembers> searchByGet(@Parameter(description = "The resource path", required = true) @PathVariable(value = "path") final String path, @ParameterObject final SnomedReferenceSetMemberRestSearch params, @Parameter(description = "Accepted language tags, in order of preference", example = "en-US;q=0.8,en-GB;q=0.6") @RequestHeader(value = "Accept-Language", defaultValue = "en-US;q=0.8,en-GB;q=0.6", required = false) final String acceptLanguage) {
final SnomedRefSetMemberSearchRequestBuilder req = SnomedRequests.prepareSearchMember().setLimit(params.getLimit()).setSearchAfter(params.getSearchAfter()).filterByIds(params.getId()).filterByActive(params.getActive()).filterByModules(params.getModule()).filterByEffectiveTime(params.getEffectiveTime()).filterByRefSet(params.getRefsetId()).filterByReferencedComponent(params.getReferencedComponentId()).setExpand(params.getExpand()).setFields(params.getField()).setLocales(acceptLanguage).sortBy(extractSortFields(params.getSort()));
Options propFilters = params.toPropsFilter();
if (!propFilters.isEmpty()) {
req.filterByProps(propFilters);
}
return req.build(path).execute(getBus());
}
use of io.swagger.v3.oas.annotations.tags.Tags in project swagger-parser by swagger-api.
the class OpenAPIDeserializer method parseRoot.
public OpenAPI parseRoot(JsonNode node, ParseResult result, String path) {
String location = "";
OpenAPI openAPI = new OpenAPI();
if (node.getNodeType().equals(JsonNodeType.OBJECT)) {
ObjectNode rootNode = (ObjectNode) node;
// required
String value = getString("openapi", rootNode, true, location, result);
// we don't even try if the version isn't there
if (value == null || !value.startsWith("3.0")) {
return null;
}
openAPI.setOpenapi(value);
ObjectNode obj = getObject("info", rootNode, true, location, result);
if (obj != null) {
Info info = getInfo(obj, "info", result);
openAPI.setInfo(info);
}
obj = getObject("components", rootNode, false, location, result);
if (obj != null) {
Components components = getComponents(obj, "components", result);
openAPI.setComponents(components);
this.components = components;
}
obj = getObject("paths", rootNode, true, location, result);
if (obj != null) {
Paths paths = getPaths(obj, "paths", result);
openAPI.setPaths(paths);
}
ArrayNode array = getArray("servers", rootNode, false, location, result);
if (array != null && array.size() > 0) {
openAPI.setServers(getServersList(array, String.format("%s.%s", location, "servers"), result, path));
} else {
Server defaultServer = new Server();
defaultServer.setUrl("/");
List<Server> servers = new ArrayList<>();
servers.add(defaultServer);
openAPI.setServers(servers);
}
obj = getObject("externalDocs", rootNode, false, location, result);
if (obj != null) {
ExternalDocumentation externalDocs = getExternalDocs(obj, "externalDocs", result);
openAPI.setExternalDocs(externalDocs);
}
array = getArray("tags", rootNode, false, location, result);
if (array != null && array.size() > 0) {
openAPI.setTags(getTagList(array, "tags", result));
}
array = getArray("security", rootNode, false, location, result);
if (array != null && array.size() > 0) {
List<SecurityRequirement> securityRequirements = getSecurityRequirementsList(array, "security", result);
if (securityRequirements != null && securityRequirements.size() > 0) {
openAPI.setSecurity(securityRequirements);
}
}
Map<String, Object> extensions = getExtensions(rootNode);
if (extensions != null && extensions.size() > 0) {
openAPI.setExtensions(extensions);
}
Set<String> keys = getKeys(rootNode);
for (String key : keys) {
if (!ROOT_KEYS.contains(key) && !key.startsWith("x-")) {
result.extra(location, key, node.get(key));
}
}
} else {
result.invalidType(location, "openapi", "object", node);
result.invalid();
return null;
}
return openAPI;
}
use of io.swagger.v3.oas.annotations.tags.Tags in project swagger-parser by swagger-api.
the class OpenAPIDeserializer method getTagList.
public List<Tag> getTagList(ArrayNode obj, String location, ParseResult result) {
if (obj == null) {
return null;
}
List<Tag> tags = new ArrayList<>();
Set<String> tagsTracker = new HashSet<>();
for (JsonNode item : obj) {
if (item.getNodeType().equals(JsonNodeType.OBJECT)) {
Tag tag = getTag((ObjectNode) item, location, result);
if (tag != null) {
tags.add(tag);
if (tagsTracker.contains((String) tag.getName())) {
result.uniqueTags(location, tag.getName());
}
tagsTracker.add(tag.getName());
}
}
}
return tags;
}
use of io.swagger.v3.oas.annotations.tags.Tags in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testPetstore.
@Test
public void testPetstore() throws Exception {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = parser.readLocation("src/test/resources/petstore.yaml", null, options);
assertNotNull(result);
assertTrue(result.getMessages().size() == 2);
OpenAPI openAPI = result.getOpenAPI();
Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
Set<String> expectedDefinitions = new HashSet<String>();
expectedDefinitions.add("User");
expectedDefinitions.add("Category");
expectedDefinitions.add("Pet");
expectedDefinitions.add("Tag");
expectedDefinitions.add("Order");
expectedDefinitions.add("PetArray");
assertEquals(definitions.keySet(), expectedDefinitions);
Schema petModel = definitions.get("Pet");
Set<String> expectedPetProps = new HashSet<String>();
expectedPetProps.add("id");
expectedPetProps.add("category");
expectedPetProps.add("name");
expectedPetProps.add("photoUrls");
expectedPetProps.add("tags");
expectedPetProps.add("status");
assertEquals(petModel.getProperties().keySet(), expectedPetProps);
ArraySchema petArrayModel = (ArraySchema) definitions.get("PetArray");
assertEquals(petArrayModel.getType(), "array");
Schema refProp = petArrayModel.getItems();
assertEquals(refProp.get$ref(), "#/components/schemas/Pet");
assertNull(petArrayModel.getProperties());
}
Aggregations