use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testEmptyStrings_False.
@Test
public void testEmptyStrings_False() throws Exception {
ParseOptions options = new ParseOptions();
options.setAllowEmptyString(false);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("src/test/resources/empty-strings.yaml", null, options);
Assert.assertNotNull(result);
Assert.assertNotNull(result.getOpenAPI());
OpenAPI openAPI = result.getOpenAPI();
assertNull(openAPI.getInfo().getTitle());
assertNotNull(openAPI.getInfo().getVersion());
assertNull(openAPI.getInfo().getLicense().getName());
assertNull(openAPI.getPaths().get("/something").getGet().getResponses().get("200").getDescription());
assertNull(openAPI.getPaths().get("/something").getGet().getParameters().get(0).getDescription());
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class ResolverCacheTest method testMock.
@Test
public void testMock() throws Exception {
final RefFormat format = RefFormat.URL;
final String ref = "http://my.company.com/path/to/file.json";
final String contentsOfExternalFile = "really good json";
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true);
parseOptions.setValidateExternalRefs(true);
new Expectations(DeserializationUtils.class) {
{
RefUtils.readExternalUrlRef(ref, format, auths, "http://my.company.com/path/parent.json");
times = 1;
result = contentsOfExternalFile;
DeserializationUtils.deserializeIntoTree(contentsOfExternalFile, ref, parseOptions, (SwaggerParseResult) any);
times = 1;
result = new ObjectMapper().readTree("{\"type\": \"string\"}");
}
};
ResolverCache cache = new ResolverCache(openAPI, auths, "http://my.company.com/path/parent.json", new HashSet<>(), parseOptions);
Schema firstActualResult = cache.loadRef(ref, RefFormat.URL, Schema.class);
assertEquals(firstActualResult.getType(), "string");
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class RelativeReferenceTest method testResolveRelativePaths.
@Test
public void testResolveRelativePaths() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("/relative-references-example/openapi.yaml", null, options);
Assert.assertNotNull(parseResult.getOpenAPI());
HashSet<String> validationMessages = new HashSet<>(null != parseResult.getMessages() ? parseResult.getMessages() : new ArrayList<>());
// validationMessages.forEach(msg->System.out.println(msg));
// OpenAPI specification = parseResult.getOpenAPI();
Assert.assertTrue(validationMessages.isEmpty(), validationMessages.toString());
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class RelativeReferenceTest method testIssueServerUrlValidation.
@Test
public void testIssueServerUrlValidation() throws Exception {
new Expectations() {
{
RemoteUrl.urlToString("http://foo.bar.com/swagger.json", Arrays.asList(new AuthorizationValue[] {}));
times = 1;
result = spec;
}
};
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation("http://foo.bar.com/swagger.json", null, new ParseOptions());
assertNotNull(swaggerParseResult.getOpenAPI());
assertTrue(swaggerParseResult.getMessages().isEmpty());
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testValidateDefinition.
@Test(description = "directly parsed definition, tested in previous method as reference relative/local ")
public void testValidateDefinition() {
ParseOptions options = new ParseOptions();
options.setValidateExternalRefs(false);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./swos-443/ref.yaml", null, options);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);
assertNotNull(result.getMessages());
assertTrue(result.getMessages().contains("attribute components.schemas.ErrorModel.properties is not of type `object`"));
assertTrue(result.getMessages().contains("attribute components.schemas.Examples.properties is not of type `object`"));
}
Aggregations