use of io.swagger.v3.oas.models.links.Link in project swagger-parser by swagger-api.
the class OpenAPIDeserializer method getLink.
public Link getLink(ObjectNode linkNode, String location, ParseResult result) {
if (linkNode == null) {
return null;
}
Link link = new Link();
JsonNode ref = linkNode.get("$ref");
if (ref != null) {
if (ref.getNodeType().equals(JsonNodeType.STRING)) {
String mungedRef = mungedRef(ref.textValue());
if (mungedRef != null) {
link.set$ref(mungedRef);
} else {
link.set$ref(ref.textValue());
}
return link;
} else {
result.invalidType(location, "$ref", "string", linkNode);
return null;
}
}
String value = getString("operationRef", linkNode, false, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
link.setOperationRef(value);
}
value = getString("operationId", linkNode, false, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
link.setOperationId(value);
}
ObjectNode parametersObject = getObject("parameters", linkNode, false, location, result);
if (parametersObject != null) {
link.setParameters(getLinkParameters(parametersObject, location, result));
}
String requestBody = getString("requestBody", linkNode, false, location, result);
if (result.isAllowEmptyStrings() && requestBody != null) {
link.setRequestBody(requestBody);
}
ObjectNode headerObject = getObject("headers", linkNode, false, location, result);
if (headerObject != null) {
link.setHeaders(getHeaders(headerObject, location, result, false));
}
ObjectNode serverObject = getObject("server", linkNode, false, location, result);
if (serverObject != null) {
link.setServer(getServer(serverObject, location, result));
}
value = getString("description", linkNode, false, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
link.setDescription(value);
}
Map<String, Object> extensions = getExtensions(linkNode);
if (extensions != null && extensions.size() > 0) {
link.setExtensions(extensions);
}
Set<String> keys = getKeys(linkNode);
for (String key : keys) {
if (!LINK_KEYS.contains(key) && !key.startsWith("x-")) {
result.extra(location, key, linkNode.get(key));
}
}
return link;
}
use of io.swagger.v3.oas.models.links.Link in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testLinkIssue.
@Test
public void testLinkIssue() {
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/linkIssue.yaml", null, parseOptions);
Map<String, Link> links = openAPI.getPaths().get("/2.0/repositories/{username}").getGet().getResponses().get("200").getLinks();
Object requestBody = links.get("userRepository").getRequestBody();
assertEquals(requestBody, "$response.body#/slug");
}
use of io.swagger.v3.oas.models.links.Link in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testRefAdditionalProperties.
@Test
public void testRefAdditionalProperties() throws Exception {
OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/relative/additionalProperties.yaml");
Assert.assertNotNull(openAPI);
Assert.assertTrue(openAPI.getComponents().getSchemas().size() == 3);
Assert.assertNotNull(openAPI.getComponents().getSchemas().get("link-object"));
Assert.assertNotNull(openAPI.getComponents().getSchemas().get("rel-data"));
Assert.assertNotNull(openAPI.getComponents().getSchemas().get("result"));
}
use of io.swagger.v3.oas.models.links.Link in project swagger-parser by swagger-api.
the class OpenAPIDeserializer method getResponse.
public ApiResponse getResponse(ObjectNode node, String location, ParseResult result) {
if (node == null) {
return null;
}
ApiResponse apiResponse = new ApiResponse();
JsonNode ref = node.get("$ref");
if (ref != null) {
if (ref.getNodeType().equals(JsonNodeType.STRING)) {
String mungedRef = mungedRef(ref.textValue());
if (mungedRef != null) {
apiResponse.set$ref(mungedRef);
} else {
apiResponse.set$ref(ref.textValue());
}
return apiResponse;
} else {
result.invalidType(location, "$ref", "string", node);
return null;
}
}
String value = getString("description", node, true, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
apiResponse.description(value);
}
ObjectNode headerObject = getObject("headers", node, false, location, result);
if (headerObject != null) {
Map<String, Header> headers = getHeaders(headerObject, location, result, false);
if (headers != null && headers.size() > 0) {
apiResponse.setHeaders(headers);
}
}
ObjectNode linksObj = getObject("links", node, false, location, result);
if (linksObj != null) {
Map<String, Link> links = getLinks(linksObj, location, result, false);
if (links != null && links.size() > 0) {
apiResponse.setLinks(links);
}
}
ObjectNode contentObject = getObject("content", node, false, location, result);
if (contentObject != null) {
apiResponse.setContent(getContent(contentObject, String.format("%s.%s", location, "content"), result));
}
Map<String, Object> extensions = getExtensions(node);
if (extensions != null && extensions.size() > 0) {
apiResponse.setExtensions(extensions);
}
Set<String> keys = getKeys(node);
for (String key : keys) {
if (!RESPONSE_KEYS.contains(key) && !key.startsWith("x-")) {
result.extra(location, key, node.get(key));
}
}
return apiResponse;
}
use of io.swagger.v3.oas.models.links.Link in project swagger-parser by swagger-api.
the class OpenAPIDeserializer method getLinks.
public Map<String, Link> getLinks(ObjectNode obj, String location, ParseResult result, boolean underComponents) {
if (obj == null) {
return null;
}
Map<String, Link> links = new LinkedHashMap<>();
Set<String> linkKeys = getKeys(obj);
for (String linkName : linkKeys) {
if (underComponents) {
if (!Pattern.matches("^[a-zA-Z0-9\\.\\-_]+$", linkName)) {
result.warning(location, "Link name " + linkName + " doesn't adhere to regular expression " + "^[a-zA-Z0-9\\.\\-_]+$");
}
}
JsonNode linkValue = obj.get(linkName);
if (!linkValue.getNodeType().equals(JsonNodeType.OBJECT)) {
result.invalidType(location, linkName, "object", linkValue);
} else {
ObjectNode link = (ObjectNode) linkValue;
Link linkObj = getLink(link, String.format("%s.%s", location, linkName), result);
if (linkObj != null) {
links.put(linkName, linkObj);
}
}
}
return links;
}
Aggregations