use of io.apicurio.datamodels.openapi.v2.models.Oas20Operation in project apicurio-data-models by Apicurio.
the class OasUnmatchedExampleTypeRule method visitExample.
/**
* @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitExample(io.apicurio.datamodels.core.models.common.IExample)
*/
@Override
public void visitExample(IExample node) {
Oas20Example example20 = (Oas20Example) node;
Oas20Document doc = (Oas20Document) example20.ownerDocument();
List<String> produces = doc.produces;
Oas20Operation operation = (Oas20Operation) findParentOperation(example20);
if (isDefined(operation)) {
if (hasValue(operation.produces)) {
produces = operation.produces;
}
if (!hasValue(produces)) {
produces = new ArrayList<>();
}
List<String> ctypes = example20.getExampleContentTypes();
for (String ct : ctypes) {
this.reportIfInvalid(produces.indexOf(ct) != -1, example20, Constants.PROP_PRODUCES, map("contentType", ct));
}
}
}
use of io.apicurio.datamodels.openapi.v2.models.Oas20Operation in project apicurio-data-models by Apicurio.
the class Oas20to30TransformationVisitor method findParentOperation.
private Oas20Operation findParentOperation(Parameter node) {
OperationFinder finder = new OperationFinder();
Library.visitTree(node, finder, TraverserDirection.up);
return (Oas20Operation) finder.found;
}
use of io.apicurio.datamodels.openapi.v2.models.Oas20Operation 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.v2.models.Oas20Operation in project syndesis by syndesisio.
the class Oas20DataShapeGeneratorHelper method getOperationParameters.
static List<Oas20Parameter> getOperationParameters(Oas20Document openApiDoc, Oas20Operation operation) {
final List<Oas20Parameter> operationParameters = Oas20ModelHelper.getParameters(operation);
OasPathItem parent = ofNullable(operation.parent()).filter(OasPathItem.class::isInstance).map(OasPathItem.class::cast).orElse(null);
final List<Oas20Parameter> pathParameters = Oas20ModelHelper.getParameters(parent);
operationParameters.addAll(pathParameters);
final List<Oas20ParameterDefinition> globalParameters = ofNullable(openApiDoc.parameters).map(Oas20ParameterDefinitions::getItems).orElse(Collections.emptyList());
operationParameters.addAll(globalParameters);
return operationParameters;
}
use of io.apicurio.datamodels.openapi.v2.models.Oas20Operation in project syndesis by syndesisio.
the class CyclicValidationCheckTest method shouldFindTwoStepCyclicReferencesInResponses.
@Test
public void shouldFindTwoStepCyclicReferencesInResponses() {
final Oas20Document openApiDoc = new Oas20Document();
final Oas20PathItem pathItem = new Oas20PathItem("/api");
final Oas20Operation operation = new Oas20Operation("post");
Oas20Response response = new Oas20Response("200");
Oas20Schema responseSchema = new Oas20Schema();
responseSchema.$ref = "#/definitions/A";
response.schema = responseSchema;
operation.responses = operation.createResponses();
operation.responses.addResponse("200", response);
pathItem.post = operation;
openApiDoc.paths = openApiDoc.createPaths();
openApiDoc.paths.addPathItem("/api", pathItem);
Oas20SchemaDefinition schemaDefinitionA = new Oas20SchemaDefinition("A");
schemaDefinitionA.type = "object";
Oas20Schema propertySchemaA = new Oas20Schema();
propertySchemaA.$ref = "#/definitions/B";
schemaDefinitionA.properties = new HashMap<>();
schemaDefinitionA.properties.put("b", propertySchemaA);
openApiDoc.definitions = openApiDoc.createDefinitions();
openApiDoc.definitions.addDefinition("A", schemaDefinitionA);
Oas20SchemaDefinition schemaDefinitionB = new Oas20SchemaDefinition("B");
schemaDefinitionB.type = "object";
Oas20Schema propertySchemaB = new Oas20Schema();
propertySchemaB.$ref = "#/definitions/A";
schemaDefinitionB.properties = new HashMap<>();
schemaDefinitionB.properties.put("a", propertySchemaB);
openApiDoc.definitions.addDefinition("B", schemaDefinitionB);
assertThat(CyclicValidationCheck.hasCyclicReferences(getSchemaDefinitions(openApiDoc))).isTrue();
}
Aggregations