use of io.swagger.v3.oas.annotations.headers.Header in project swagger-parser by swagger-api.
the class NetworkReferenceTest method testIssue411.
@Test
public void testIssue411() throws Exception {
final List<AuthorizationValue> auths = new ArrayList<>();
AuthorizationValue auth = new AuthorizationValue("Authorization", "OMG_SO_SEKR3T", "header");
auths.add(auth);
new Expectations() {
{
remoteUrl.urlToString("http://remote1/resources/swagger.yaml", auths);
result = issue_411_server;
remoteUrl.urlToString("http://remote2/resources/foo", auths);
result = issue_411_components;
}
};
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = parser.readLocation("http://remote1/resources/swagger.yaml", auths, options);
OpenAPI swagger = result.getOpenAPI();
assertNotNull(swagger.getPaths().get("/health"));
PathItem health = swagger.getPaths().get("/health");
assertTrue(health.getGet().getParameters().size() == 0);
Schema responseRef = health.getGet().getResponses().get("200").getContent().get("*/*").getSchema();
assertTrue(responseRef.get$ref() != null);
assertEquals(responseRef.get$ref(), "#/components/schemas/Success");
assertNotNull(swagger.getComponents().getSchemas().get("Success"));
Parameter param = swagger.getPaths().get("/stuff").getGet().getParameters().get(0);
assertEquals(param.getIn(), "query");
assertEquals(param.getName(), "skip");
ApiResponse response = swagger.getPaths().get("/stuff").getGet().getResponses().get("200");
assertNotNull(response);
assertTrue(response.getContent().get("*/*").getSchema() instanceof StringSchema);
ApiResponse error = swagger.getPaths().get("/stuff").getGet().getResponses().get("400");
assertNotNull(error);
Schema errorProp = error.getContent().get("*/*").getSchema();
assertNotNull(errorProp);
assertTrue(errorProp.get$ref() != null);
assertEquals(errorProp.get$ref(), "#/components/schemas/Error");
assertTrue(swagger.getComponents().getSchemas().get("Error") instanceof Schema);
}
use of io.swagger.v3.oas.annotations.headers.Header in project swagger-parser by swagger-api.
the class NetworkReferenceTest method testValidateExternalRefsTrueRemote.
@Test(description = "option true, adds Original Location to messages when ref is remote")
public void testValidateExternalRefsTrueRemote() throws Exception {
ParseOptions options = new ParseOptions();
options.setValidateExternalRefs(true);
options.setResolve(true);
new Expectations() {
{
remoteUrl.urlToString("http://localhost:8080/swos-443/root.yaml", new ArrayList<>());
result = issue_443_yaml;
remoteUrl.urlToString("http://localhost:8080/swos-443/ref.yaml", new ArrayList<>());
result = issue_443_ref_yaml;
}
};
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("http://localhost:8080/swos-443/root.yaml", null, options);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(result.getMessages());
assertEquals(result.getMessages().size(), 19);
assertNotNull(openAPI);
assertTrue(result.getMessages().contains("attribute components.requestBodies.NewItem.asdasd is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.requestBodies.NewItem.descasdasdription is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.responses.GeneralError.descrsaiption is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.responses.GeneralError.asdas is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.responses.GeneralError.description is missing (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.schemas.Examples.nonExpected is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.parameters.skipParam.[skip].in is not of type `[query|header|path|cookie]` (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.securitySchemes.api_key.namex is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.securitySchemes.api_key.name is missing (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.callbacks.webhookVerificationEvent.postx is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.headers.X-Rate-Limit-Limit.descriptasdd is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.links.unsubscribe.parametersx is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.examples.response-example.summaryx is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.examples.response-example. value and externalValue are both present (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.callbacks.failed.wrongField is not of type `object` (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute paths.~1refPet(get).responses is missing (./ref.yaml)"));
// error message in main file
assertTrue(result.getMessages().contains("attribute components.schemas.InvalidSchema.invalid is unexpected"));
}
use of io.swagger.v3.oas.annotations.headers.Header in project swagger-parser by swagger-api.
the class ExternalRefProcessor method processRefHeader.
private void processRefHeader(Header subRef, String externalFile) {
RefFormat format = computeRefFormat(subRef.get$ref());
if (!isAnExternalRefFormat(format)) {
subRef.set$ref(RefType.SCHEMAS.getInternalPrefix() + processRefToExternalSchema(externalFile + subRef.get$ref(), RefFormat.RELATIVE));
return;
}
String $ref = subRef.get$ref();
String subRefExternalPath = getExternalPath(subRef.get$ref()).orElse(null);
if (format.equals(RefFormat.RELATIVE) && !Objects.equals(subRefExternalPath, externalFile)) {
$ref = join(externalFile, subRef.get$ref());
subRef.set$ref($ref);
} else {
processRefToExternalHeader($ref, format);
}
}
use of io.swagger.v3.oas.annotations.headers.Header in project swagger-parser by swagger-api.
the class LinkProcessor method processLink.
public void processLink(Link link) {
if (link.get$ref() != null) {
RefFormat refFormat = computeRefFormat(link.get$ref());
String $ref = link.get$ref();
if (isAnExternalRefFormat(refFormat)) {
final String newRef = externalRefProcessor.processRefToExternalLink($ref, refFormat);
if (newRef != null) {
link.set$ref(newRef);
}
}
} else if (link.getHeaders() != null) {
Map<String, Header> headers = link.getHeaders();
for (String headerName : headers.keySet()) {
Header header = headers.get(headerName);
headerProcessor.processHeader(header);
}
}
}
use of io.swagger.v3.oas.annotations.headers.Header in project swagger-parser by swagger-api.
the class ResponseProcessor method processResponse.
public void processResponse(ApiResponse response) {
if (response.get$ref() != null) {
processReferenceResponse(response);
}
Schema schema = null;
if (response.getContent() != null) {
Map<String, MediaType> content = response.getContent();
for (String mediaName : content.keySet()) {
MediaType mediaType = content.get(mediaName);
if (mediaType.getSchema() != null) {
schema = mediaType.getSchema();
if (schema != null) {
schemaProcessor.processSchema(schema);
}
}
if (mediaType.getExamples() != null) {
for (Example ex : mediaType.getExamples().values()) {
exampleProcessor.processExample(ex);
}
}
}
}
if (response.getHeaders() != null) {
Map<String, Header> headers = response.getHeaders();
for (String headerName : headers.keySet()) {
Header header = headers.get(headerName);
headerProcessor.processHeader(header);
}
}
if (response.getLinks() != null) {
Map<String, Link> links = response.getLinks();
for (String linkName : links.keySet()) {
Link link = links.get(linkName);
linkProcessor.processLink(link);
}
}
}
Aggregations