use of io.apicurio.datamodels.openapi.v3.models.Oas30PathItem in project apicurio-data-models by Apicurio.
the class OasMissingPathParamDefinitionRule method visitOperation.
/**
* @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitOperation(io.apicurio.datamodels.core.models.common.Operation)
*/
@Override
public void visitOperation(Operation node) {
// Perform operation level checks only if there are no issues at the pathItem level.
Oas30PathItem pathItem = (Oas30PathItem) node.parent();
String path = pathItem.getPath();
if (this.pathItemsWithError.indexOf(path) != -1) {
return;
}
// Check parameters are unique within operation
List<OasParameter> mergedParameters = mergeParameters((OasOperation) node);
List<PathSegment> pathSegs = getPathSegments(path);
// Report all the path segments that don't have an associated parameter definition
for (PathSegment pathSeg : pathSegs) {
if (!hasValue(pathSeg.formalName)) {
continue;
}
boolean valid = hasPathParameter(pathSeg.formalName, mergedParameters);
this.reportIfInvalid(valid, node, null, map("param", pathSeg.formalName, "path", path, "method", node.getType().toUpperCase()));
}
}
use of io.apicurio.datamodels.openapi.v3.models.Oas30PathItem in project apicurio-data-models by Apicurio.
the class Oas20to30TransformationVisitor method visitOperation.
/**
* @see io.apicurio.datamodels.core.visitors.IVisitor#visitOperation(io.apicurio.datamodels.core.models.common.Operation)
*/
@Override
public void visitOperation(Operation node) {
Oas20Operation op = (Oas20Operation) node;
Oas30PathItem pathItem30 = (Oas30PathItem) this.lookup(node.parent());
Oas30Operation operation30 = (Oas30Operation) pathItem30.createOperation(node.getType());
pathItem30.setOperation(operation30);
operation30.tags = op.tags;
operation30.summary = op.summary;
operation30.description = op.description;
operation30.operationId = op.operationId;
operation30.deprecated = op.deprecated;
if (!NodeCompat.isNullOrUndefined(op.schemes) && op.schemes.size() > 0 && !NodeCompat.isNullOrUndefined(this.doc30.servers) && this.doc30.servers.size() > 0) {
Oas30Server server30 = (Oas30Server) operation30.createServer();
operation30.servers = new ArrayList<>();
operation30.servers.add(server30);
server30.url = this.doc30.servers.get(0).url;
if (op.schemes.size() == 1) {
server30.url = server30.url.replace("{scheme}", op.schemes.get(0));
server30.removeServerVariable("scheme");
} else {
server30.url = "{scheme}" + server30.url.substring(server30.url.indexOf("://"));
Oas30ServerVariable var30 = (Oas30ServerVariable) server30.createServerVariable("scheme");
server30.addServerVariable("scheme", var30);
var30.description = "The supported protocol schemes.";
var30.default_ = op.schemes.get(0);
var30.enum_ = NodeCompat.copyList(op.schemes);
}
}
// Note: consumes/produces will be handled elsewhere (when Request Body and Response models are created)
this.mapNode(op, operation30);
}
use of io.apicurio.datamodels.openapi.v3.models.Oas30PathItem in project syndesis by syndesisio.
the class Oas30ValidationRulesTest method shouldValidateOperationsArePresent.
@Test
public void shouldValidateOperationsArePresent() {
final Oas30Document openApiDoc = new Oas30Document();
final Oas30PathItem pathItem = new Oas30PathItem("/test");
openApiDoc.paths = openApiDoc.createPaths();
openApiDoc.paths.addPathItem("/test", pathItem);
final OpenApiModelInfo info = new OpenApiModelInfo.Builder().model(openApiDoc).build();
final OpenApiModelInfo validated = RULES.validateOperationsGiven(info);
final List<Violation> errors = validated.getErrors();
assertThat(errors).containsExactly(new Violation.Builder().property("").error("missing-operations").message("No operations defined").build());
}
use of io.apicurio.datamodels.openapi.v3.models.Oas30PathItem in project syndesis by syndesisio.
the class Oas30ValidationRulesTest method shouldNotGenerateErrorWhenOperationsArePresent.
@Test
public void shouldNotGenerateErrorWhenOperationsArePresent() {
final Oas30Document openApiDoc = new Oas30Document();
final Oas30PathItem pathItem = new Oas30PathItem("/test");
pathItem.get = new Oas30Operation("get");
openApiDoc.paths = openApiDoc.createPaths();
openApiDoc.paths.addPathItem("/test", pathItem);
final OpenApiModelInfo info = new OpenApiModelInfo.Builder().model(openApiDoc).build();
final OpenApiModelInfo validated = RULES.validateOperationsGiven(info);
assertThat(validated.getErrors()).isEmpty();
assertThat(validated.getWarnings()).isEmpty();
}
use of io.apicurio.datamodels.openapi.v3.models.Oas30PathItem in project syndesis by syndesisio.
the class Oas30ValidationRulesTest method shouldValidateMissingResponseBodySchema.
@Test
public void shouldValidateMissingResponseBodySchema() {
final Oas30Document openApiDoc = new Oas30Document();
final Oas30PathItem pathItem = new Oas30PathItem("/path");
Oas30Operation get = new Oas30Operation("get");
get.operationId = "o1";
get.responses = get.createResponses();
get.responses.addResponse("404", get.responses.createResponse("404"));
get.responses.addResponse("200", get.responses.createResponse("200"));
pathItem.get = get;
Oas30Operation post = new Oas30Operation("post");
post.operationId = "o2";
final Oas30Parameter headerParameter = new Oas30Parameter();
headerParameter.in = "header";
post.parameters = Collections.singletonList(headerParameter);
post.requestBody = post.createRequestBody();
Oas30Schema bodySchema = new Oas30Schema();
bodySchema.addProperty("foo", new Oas30Schema());
Oas30MediaType requestBody = post.requestBody.createMediaType("application/json");
requestBody.schema = bodySchema;
post.requestBody.content = Collections.singletonMap("application/json", requestBody);
pathItem.post = post;
openApiDoc.paths = openApiDoc.createPaths();
openApiDoc.paths.addPathItem("/path", pathItem);
final OpenApiModelInfo info = new OpenApiModelInfo.Builder().model(openApiDoc).build();
final OpenApiModelInfo validated = RULES.validateRequestResponseBodySchemas(info);
final List<Violation> warnings = validated.getWarnings();
assertThat(warnings).hasSize(1);
final Violation reportedWarning = warnings.get(0);
assertThat(reportedWarning.error()).isEqualTo("missing-response-schema");
assertThat(reportedWarning.property()).isEmpty();
assertThat(reportedWarning.message()).isEqualTo("Operation GET /path does not provide a response schema for code 200");
}
Aggregations