use of io.swagger.v3.parser.ResolverCache in project swagger-parser by swagger-api.
the class ResolverCacheTest method testLoadInternalResponseRef.
@Test
public void testLoadInternalResponseRef(@Injectable ApiResponse mockedResponse) throws Exception {
OpenAPI openAPI = new OpenAPI();
openAPI.components(new Components().addResponses("foo", mockedResponse));
ResolverCache cache = new ResolverCache(openAPI, auths, null);
ApiResponse actualResult = cache.loadRef("#/components/responses/foo", RefFormat.INTERNAL, ApiResponse.class);
assertEquals(actualResult, mockedResponse);
assertNull(cache.loadRef("#/components/responses/bar", RefFormat.INTERNAL, ApiResponse.class));
}
use of io.swagger.v3.parser.ResolverCache in project swagger-parser by swagger-api.
the class ResolverCacheTest method testLoadExternalRefWithEscapedCharacters.
@Test
public void testLoadExternalRefWithEscapedCharacters() throws Exception {
final RefFormat format = RefFormat.URL;
final String ref = "http://my.company.com/path/to/main.yaml";
final String contentsOfExternalFile = "openAPI: \"2.0\"\n" + "\n" + "info:\n" + " version: 1.0.0\n" + " title: Path include test case child\n" + "\n" + "paths:\n" + " /foo~bar~1:\n" + " get:\n" + " responses:\n" + " 200:\n" + " description: \"Request successful\"\n";
new Expectations() {
{
RefUtils.readExternalUrlRef(ref, format, auths, "http://my.company.com/path/parent.json");
times = 1;
result = contentsOfExternalFile;
}
};
ResolverCache cache = new ResolverCache(openAPI, auths, "http://my.company.com/path/parent.json");
PathItem path = cache.loadRef(ref + "#/paths/~1foo~0bar~01", RefFormat.URL, PathItem.class);
assertNotNull(path);
}
use of io.swagger.v3.parser.ResolverCache in project swagger-parser by swagger-api.
the class ResolverCacheTest method testLoadExternalRef_NoDefinitionPath.
@Test
public void testLoadExternalRef_NoDefinitionPath() 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(contentsOfExternalFile, cache.getExternalFileCache().get(ref));
assertEquals(((Schema) cache.getResolutionCache().get(ref)).getType(), "string");
assertEquals(firstActualResult.getType(), "string");
// requesting the same ref a second time should not result in reading the external file again
Schema secondActualResult = cache.loadRef(ref, format, Schema.class);
assertEquals(secondActualResult.getType(), "string");
}
use of io.swagger.v3.parser.ResolverCache in project swagger-parser by swagger-api.
the class ResolverCacheTest method testLoadInternalDefinitionRefWithSpaces.
@Test
public void testLoadInternalDefinitionRefWithSpaces(@Injectable Schema mockedModel) throws Exception {
OpenAPI openAPI = new OpenAPI();
openAPI.components(new Components().addSchemas("foo bar", mockedModel));
ResolverCache cache = new ResolverCache(openAPI, auths, null);
Schema actualResult = cache.loadRef("#/components/schemas/foo bar", RefFormat.INTERNAL, Schema.class);
assertEquals(actualResult, mockedModel);
}
use of io.swagger.v3.parser.ResolverCache in project swagger-parser by swagger-api.
the class ResolverCacheTest method testLoadInternalParameterRefWithSpaces.
@Test
public void testLoadInternalParameterRefWithSpaces(@Injectable Parameter mockedParameter) throws Exception {
OpenAPI openAPI = new OpenAPI();
openAPI.components(new Components().addParameters("foo bar", mockedParameter));
ResolverCache cache = new ResolverCache(openAPI, auths, null);
Parameter actualResult = cache.loadRef("#/components/parameters/foo bar", RefFormat.INTERNAL, Parameter.class);
assertEquals(actualResult, mockedParameter);
}
Aggregations