use of io.syndesis.server.api.generator.APIValidationContext in project syndesis by syndesisio.
the class OpenApiGenerator method info.
@Override
public APISummary info(final String specification, final APIValidationContext validation) {
final OpenApiModelInfo modelInfo = OpenApiModelParser.parse(specification, validation);
final OasDocument model = modelInfo.getModel();
if (model == null) {
return new APISummary.Builder().errors(modelInfo.getErrors()).warnings(modelInfo.getWarnings()).build();
}
final OasPaths paths = model.paths;
final ActionsSummary actionsSummary = determineSummaryFrom(OasModelHelper.getPathItems(paths));
final Info info = model.info;
final String title = Optional.ofNullable(info).map(i -> i.title).orElse("unspecified");
final String description = Optional.ofNullable(info).map(i -> i.description).orElse("unspecified");
return //
new APISummary.Builder().name(//
title).description(//
description).actionsSummary(//
actionsSummary).errors(//
modelInfo.getErrors()).warnings(//
modelInfo.getWarnings()).putConfiguredProperty("specification", modelInfo.getResolvedSpecification()).build();
}
use of io.syndesis.server.api.generator.APIValidationContext in project syndesis by syndesisio.
the class OpenApiModelParser method parse.
public static OpenApiModelInfo parse(final String specification, final APIValidationContext validationContext) {
final OpenApiModelInfo.Builder resultBuilder = new OpenApiModelInfo.Builder();
final String resolvedSpecification;
try {
resolvedSpecification = resolve(specification);
resultBuilder.resolvedSpecification(resolvedSpecification);
} catch (final Exception e) {
LOG.debug("Unable to resolve OpenAPI document\n{}\n", specification, e);
return resultBuilder.addError(new Violation.Builder().error("error").property("").message("Unable to resolve OpenAPI document from: " + ofNullable(specification).map(s -> StringUtils.abbreviate(s, 100)).orElse("")).build()).build();
}
final JsonNode tree;
try {
tree = JsonUtils.reader().readTree(resolvedSpecification);
} catch (final IOException e) {
return new OpenApiModelInfo.Builder().addError(new Violation.Builder().property("").error("unreadable-document").message("Unable to read OpenAPI document: " + e.getMessage()).build()).build();
}
OpenApiVersion openApiVersion = getOpenApiVersion(tree);
if (openApiVersion == null) {
return new OpenApiModelInfo.Builder().addError(new Violation.Builder().property("").error("unsupported-version").message(String.format("This document cannot be uploaded. " + "Provide an OpenAPI document (supported versions are %s).", OpenApiVersion.getSupportedVersions())).build()).build();
}
final Document parsed = Library.readDocumentFromJSONString(resolvedSpecification);
if (!(parsed instanceof OasDocument)) {
LOG.debug("Unable to read OpenAPI document\n{}\n", specification);
return resultBuilder.addError(new Violation.Builder().error("error").property("").message("Unable to read OpenAPI document from: '" + StringUtils.abbreviate(resolvedSpecification, 100)).build()).build();
}
resultBuilder.model((OasDocument) parsed);
if (validationContext != APIValidationContext.NONE) {
try {
validateJsonSchema(convertToJson(resolvedSpecification), resultBuilder, openApiVersion, parsed.getClass());
} catch (IOException e) {
return resultBuilder.addError(new Violation.Builder().error("error").property("").message("Unable to read OpenAPI document from: '" + StringUtils.abbreviate(resolvedSpecification, 100)).build()).build();
}
return applyValidationRules(validationContext, resultBuilder.build(), openApiVersion);
}
return resultBuilder.build();
}
Aggregations