use of io.swagger.v3.parser.util.ResolverFully in project swagger-parser by swagger-api.
the class OpenAPIV3Parser method resolve.
private SwaggerParseResult resolve(SwaggerParseResult result, List<AuthorizationValue> auth, ParseOptions options, String location) {
try {
if (options != null) {
if (options.isResolve() || options.isResolveFully()) {
OpenAPIResolver resolver = new OpenAPIResolver(result.getOpenAPI(), emptyListIfNull(auth), location, null, options);
resolver.resolve(result);
if (options.isResolveFully()) {
new ResolverFully(options.isResolveCombinators()).resolveFully(result.getOpenAPI());
}
}
if (options.isFlatten()) {
final InlineModelResolver inlineModelResolver = new InlineModelResolver(options.isFlattenComposedSchemas(), options.isCamelCaseFlattenNaming(), options.isSkipMatches());
if (result.getOpenAPI() != null) {
inlineModelResolver.flatten(result.getOpenAPI());
}
}
}
} catch (Exception e) {
LOGGER.warn("Exception while resolving:", e);
// TODO verify if this change makes sense (adding resolve messages instead of replacing)
result.getMessages().add(e.getMessage());
// result.setMessages(Collections.singletonList(e.getMessage()));
}
return result;
}
use of io.swagger.v3.parser.util.ResolverFully in project swagger-parser by swagger-api.
the class SwaggerConverter method readResult.
private SwaggerParseResult readResult(SwaggerDeserializationResult result, List<AuthorizationValue> auth, ParseOptions options) {
SwaggerParseResult out = convert(result);
if (out != null && options != null) {
if (options.isResolveFully()) {
new ResolverFully(options.isResolveCombinators()).resolveFully(out.getOpenAPI());
}
if (options.isFlatten()) {
try {
SwaggerParseResult resultV3 = new OpenAPIV3Parser().readContents(Yaml.pretty(out.getOpenAPI()), auth, options);
out.setOpenAPI(resultV3.getOpenAPI());
if (out.getMessages() != null) {
out.getMessages().addAll(resultV3.getMessages());
out.messages(out.getMessages().stream().distinct().collect(Collectors.toList()));
} else {
out.messages(resultV3.getMessages());
}
} catch (Exception ignore) {
}
}
}
return out;
}
use of io.swagger.v3.parser.util.ResolverFully in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testIssue85.
@Test
public void testIssue85(@Injectable final List<AuthorizationValue> auths) {
String yaml = "openapi: '3.0.1'\n" + "paths: \n" + " /test/method: \n" + " post: \n" + " parameters: \n" + " - \n" + " in: \"path\"\n" + " name: \"body\"\n" + " required: false\n" + " schema: \n" + " $ref: '#/components/Schemas/StructureA'\n" + "components: \n" + " schemas:\n" + " StructureA: \n" + " type: object\n" + " properties: \n" + " someProperty: \n" + " type: string\n" + " arrayOfOtherType: \n" + " type: array\n" + " items: \n" + " $ref: '#/definitions/StructureB'\n" + " StructureB: \n" + " type: object\n" + " properties: \n" + " someProperty: \n" + " type: string\n";
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, auths, options).getOpenAPI();
ResolverFully resolverUtil = new ResolverFully();
resolverUtil.resolveFully(openAPI);
Parameter param = openAPI.getPaths().get("/test/method").getPost().getParameters().get(0);
Schema schema = param.getSchema();
assertNotNull(schema.getProperties().get("someProperty"));
ArraySchema am = (ArraySchema) schema.getProperties().get("arrayOfOtherType");
assertNotNull(am);
Schema prop = am.getItems();
assertTrue(prop instanceof Schema);
}
use of io.swagger.v3.parser.util.ResolverFully in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testSelfReferenceResolution.
@Test
public void testSelfReferenceResolution(@Injectable final List<AuthorizationValue> auths) throws Exception {
String yaml = "" + "openapi: 3.0.1\n" + "paths:\n" + " \"/selfRefB\":\n" + " get:\n" + " requestBody:\n" + " description: user to add to the system\\n\"+\n" + " content:\n" + " 'application/json':\n" + " schema:\n" + " $ref: '#/components/schemas/SchemaB'\n" + "components:\n" + " schemas:\n" + " SchemaA:\n" + " properties:\n" + " name:\n" + " type: string\n" + " modelB:\n" + " $ref: '#/components/schemas/SchemaB'\n" + " SchemaB:\n" + " properties:\n" + " modelB:\n" + " $ref: '#/components/schemas/SchemaB'";
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, auths, options).getOpenAPI();
ResolverFully resolverUtil = new ResolverFully();
resolverUtil.resolveFully(openAPI);
RequestBody body = openAPI.getPaths().get("/selfRefB").getGet().getRequestBody();
Schema schema = body.getContent().get("application/json").getSchema();
assertEquals(schema, openAPI.getComponents().getSchemas().get("SchemaB"));
}
Aggregations