use of io.swagger.v3.parser.OpenAPIV3Parser 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.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class FileReferenceTest method testIssue316.
@Test
public void testIssue316() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/nested-file-references/issue-316.yaml", null, options);
assertNotNull(result.getOpenAPI());
OpenAPI swagger = result.getOpenAPI();
assertNotNull(swagger.getPaths().get("/events"));
PathItem path = swagger.getPaths().get("/events");
assertNotNull(path.getGet());
Operation get = path.getGet();
assertEquals(get.getOperationId(), "getEvents");
assertTrue(swagger.getComponents().getSchemas().size() == 3);
assertTrue(swagger.getComponents().getSchemas().get("Foobar").getProperties().size() == 1);
assertTrue(swagger.getComponents().getSchemas().get("StatusResponse").getProperties().size() == 1);
assertTrue(swagger.getComponents().getSchemas().get("Paging2").getProperties().size() == 2);
Schema model = swagger.getComponents().getSchemas().get("Paging2");
Schema property = (Schema) model.getProperties().get("foobar");
assertTrue(property.get$ref() != null);
assertEquals(property.get$ref(), "#/components/schemas/Foobar");
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class FileReferenceTest method testRelativeRefIssue421.
@Test
public void testRelativeRefIssue421() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/main.yaml", null, options);
assertNotNull(result.getOpenAPI());
OpenAPI swagger = result.getOpenAPI();
assertNotNull(swagger);
assertNotNull(swagger.getPaths().get("pets"));
assertNotNull(swagger.getPaths().get("pets").getGet());
assertNotNull(swagger.getPaths().get("pets").getGet().getResponses());
assertNotNull(swagger.getPaths().get("pets").getGet().getResponses().get("200"));
assertNotNull(swagger.getPaths().get("pets").getGet().getResponses().get("200").getContent().get("*/*").getSchema());
assertTrue(swagger.getPaths().get("pets").getGet().getResponses().get("200").getContent().get("*/*").getSchema().get$ref() != null);
assertEquals(swagger.getPaths().get("pets").getGet().getResponses().get("200").getContent().get("*/*").getSchema().get$ref(), "#/components/schemas/Pet");
assertTrue(swagger.getComponents().getSchemas().get("Pet") instanceof Schema);
assertTrue(swagger.getComponents().getSchemas().get("Pet").getProperties().size() == 2);
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class FileReferenceTest method testIssue421.
@Test
public void testIssue421() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/nested-file-references/issue-421.yaml", null, options);
assertNotNull(result.getOpenAPI());
OpenAPI swagger = result.getOpenAPI();
assertNotNull(swagger.getPaths().get("/pet/{petId}"));
assertNotNull(swagger.getPaths().get("/pet/{petId}").getGet());
assertNotNull(swagger.getPaths().get("/pet/{petId}").getGet().getParameters());
assertTrue(swagger.getPaths().get("/pet/{petId}").getGet().getParameters().size() == 1);
assertTrue(swagger.getPaths().get("/pet/{petId}").getGet().getParameters().get(0).getName().equals("petId"));
assertTrue(swagger.getComponents().getSchemas().get("Pet") instanceof Schema);
assertTrue(swagger.getComponents().getSchemas().get("Pet").getProperties().size() == 6);
assertNotNull(swagger.getPaths().get("/pet/{petId}").getPost());
assertNotNull(swagger.getPaths().get("/pet/{petId}").getPost().getParameters());
assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getParameters().size() == 1);
assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody() != null);
assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody().get$ref() != null);
assertEquals(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody().get$ref(), "#/components/requestBodies/requestBody");
assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody().get$ref().equals("#/components/requestBodies/requestBody"));
assertNotNull(swagger.getPaths().get("/store/order"));
assertNotNull(swagger.getPaths().get("/store/order").getPost());
assertNotNull(swagger.getPaths().get("/store/order").getPost().getRequestBody());
assertNotNull(swagger.getPaths().get("/store/order").getPost().getRequestBody().getContent().get("application/json").getSchema());
assertTrue(swagger.getPaths().get("/store/order").getPost().getRequestBody().getContent().get("application/json").getSchema().get$ref() != null);
assertTrue(swagger.getPaths().get("/store/order").getPost().getRequestBody().getContent().get("application/json").getSchema().get$ref().equals("#/components/schemas/Order"));
assertTrue(swagger.getComponents().getSchemas().get("Order") instanceof Schema);
assertTrue(swagger.getComponents().getSchemas().get("Order").getProperties().size() == 6);
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OAIDeserializationTest method testIssue911.
@Test
public void testIssue911() {
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("issue_911.yaml", null, null);
assertEquals(result.getMessages().size(), 1);
assertNotNull(result.getOpenAPI());
}
Aggregations