use of io.swagger.v3.parser.ResolverCache in project swagger-parser by swagger-api.
the class ComponentsProcessorTest method testComponentsSchemasProcessor.
@Test
public void testComponentsSchemasProcessor(@Injectable final Schema model1, @Injectable final Schema model2, @Injectable final ResolverCache cache) throws Exception {
final OpenAPI openAPI = new OpenAPI();
openAPI.components(new Components().addSchemas("foo", model1));
openAPI.getComponents().addSchemas("bar", model2);
new Expectations() {
{
new SchemaProcessor(cache, openAPI);
times = 1;
result = schemaProcessor;
schemaProcessor.processSchema((Schema) any);
times = 2;
}
};
new ComponentsProcessor(openAPI, cache).processComponents();
new Verifications() {
{
schemaProcessor.processSchema(model1);
schemaProcessor.processSchema(model2);
}
};
}
use of io.swagger.v3.parser.ResolverCache in project swagger-parser by swagger-api.
the class ResolverCacheTest method testLoadInternalDefinitionRef.
@Test
public void testLoadInternalDefinitionRef(@Injectable Schema mockedModel) throws Exception {
OpenAPI openAPI = new OpenAPI();
openAPI.components(new Components().addSchemas("foo", mockedModel));
ResolverCache cache = new ResolverCache(openAPI, auths, null);
Schema actualResult = cache.loadRef("#/components/schemas/foo", RefFormat.INTERNAL, Schema.class);
assertEquals(actualResult, mockedModel);
assertNull(cache.loadRef("#/components/schemas/bar", RefFormat.INTERNAL, Schema.class));
assertNull(cache.loadRef("#/defs/bar", RefFormat.INTERNAL, Schema.class));
}
use of io.swagger.v3.parser.ResolverCache 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.ResolverCache in project swagger-parser by swagger-api.
the class ResolverCacheTest method testRenameCache.
@Test
public void testRenameCache() throws Exception {
ResolverCache cache = new ResolverCache(openAPI, auths, null);
assertNull(cache.getRenamedRef("foo"));
cache.putRenamedRef("foo", "bar");
assertEquals(cache.getRenamedRef("foo"), "bar");
}
use of io.swagger.v3.parser.ResolverCache in project swagger-parser by swagger-api.
the class ResolverCacheTest method testLoadInternalDefinitionRefWithEscapedCharacters.
@Test
public void testLoadInternalDefinitionRefWithEscapedCharacters(@Injectable Schema mockedModel) throws Exception {
OpenAPI openAPI = new OpenAPI();
openAPI.components(new Components().addSchemas("foo~bar/baz~1", mockedModel));
ResolverCache cache = new ResolverCache(openAPI, auths, null);
Schema actualResult = cache.loadRef("#/components/schemas/foo~0bar~1baz~01", RefFormat.INTERNAL, Schema.class);
assertEquals(actualResult, mockedModel);
}
Aggregations