use of io.apicurio.datamodels.openapi.models.OasPathItem in project apicurio-data-models by Apicurio.
the class AddPathItemCommand method execute.
/**
* @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void execute(Document document) {
LoggerCompat.info("[AddPathItemCommand] Executing.");
OasDocument doc = (OasDocument) document;
if (this.isNullOrUndefined(doc.paths)) {
doc.paths = doc.createPaths();
this._nullPathItems = true;
}
if (!this.isNullOrUndefined(doc.paths.getPathItem(this._newPathItemName))) {
LoggerCompat.info("[AddPathItemCommand] PathItem with name %s already exists.", this._newPathItemName);
this._pathItemExists = true;
} else {
OasPathItem pathItem = doc.paths.createPathItem(this._newPathItemName);
Library.readNode(this._newPathItemObj, pathItem);
doc.paths.addPathItem(this._newPathItemName, pathItem);
this._pathItemExists = false;
}
}
use of io.apicurio.datamodels.openapi.models.OasPathItem in project apicurio-data-models by Apicurio.
the class DeletePathCommand method undo.
/**
* @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void undo(Document document) {
LoggerCompat.info("[DeletePathCommand] Reverting.");
OasDocument odoc = (OasDocument) document;
OasPaths paths = odoc.paths;
if (this.isNullOrUndefined(paths) || this.isNullOrUndefined(this._oldPath)) {
return;
}
OasPathItem pathItem = paths.createPathItem(this._path);
Library.readNode(this._oldPath, pathItem);
paths.addPathItem(this._path, pathItem);
}
use of io.apicurio.datamodels.openapi.models.OasPathItem in project syndesis by syndesisio.
the class OasModelHelper method operationDescriptionOf.
public static OperationDescription operationDescriptionOf(final OasDocument openApiDoc, final OasOperation operation, final BiFunction<String, String, String> consumer) {
final List<OasPathItem> pathItems = getPathItems(openApiDoc.paths);
for (OasPathItem pathEntry : pathItems) {
final String path = pathEntry.getPath();
final Map<String, OasOperation> operations = getOperationMap(pathEntry);
for (Map.Entry<String, OasOperation> operationEntry : operations.entrySet()) {
if (operationEntry.getValue().equals(operation)) {
final String method = operationEntry.getKey().toUpperCase(Locale.US);
final String specifiedSummary = trimToNull(operation.summary);
final String specifiedDescription = trimToNull(operation.description);
final String name = ofNullable(toLiteralNull(specifiedSummary)).orElseGet(() -> method + " " + path);
final String description = ofNullable(toLiteralNull(specifiedDescription)).orElseGet(() -> consumer.apply(method, path));
return new OperationDescription(name, description);
}
}
}
throw new IllegalArgumentException(String.format("Unable to find operation '%s' in given paths in OpenAPI document", operation.operationId));
}
use of io.apicurio.datamodels.openapi.models.OasPathItem in project syndesis by syndesisio.
the class OpenApiConnectorGenerator method configureConnector.
final Connector configureConnector(final ConnectorTemplate connectorTemplate, final Connector connector, final ConnectorSettings connectorSettings) {
final Connector.Builder builder = new Connector.Builder().createFrom(connector);
final OpenApiModelInfo info = parseSpecification(connectorSettings, APIValidationContext.NONE);
final OasDocument openApiDoc = info.getModel();
addGlobalParameters(builder, info);
final OasPaths paths = ofNullable(openApiDoc.paths).orElse(openApiDoc.createPaths());
final String connectorId = connector.getId().orElseThrow(() -> new IllegalArgumentException("Missing connector identifier"));
final List<ConnectorAction> actions = new ArrayList<>();
final Map<String, Integer> operationIdCounts = new HashMap<>();
for (final OasPathItem path : OasModelHelper.getPathItems(paths)) {
final Map<String, OasOperation> operationMap = OasModelHelper.getOperationMap(path);
for (final Map.Entry<String, OasOperation> entry : operationMap.entrySet()) {
final OasOperation operation = entry.getValue();
final String operationId = operation.operationId;
if (operationId == null) {
operation.operationId = operationIdGenerator.get();
} else {
// we tolerate that some operations might have the same
// operationId, if that's the case we generate a unique
// operationId by appending the count of the duplicates,
// e.g. operation ids for non unique operation id "foo" will
// be "foo", "foo1", "foo2", ... this will be reflected in
// the Swagger specification stored in `specification`
// property
final Integer count = operationIdCounts.compute(operationId, (id, currentCount) -> ofNullable(currentCount).map(c -> ++c).orElse(0));
if (count > 0) {
operation.operationId = operationId + count;
}
}
final ConnectorDescriptor descriptor = createDescriptor(connectorId, info, operation);
final OperationDescription description = OasModelHelper.operationDescriptionOf(openApiDoc, operation, (m, p) -> "Send " + m + " request to " + p);
final ConnectorAction action = new ConnectorAction.Builder().id(createActionId(connectorId, operation)).name(description.name).description(description.description).pattern(Action.Pattern.To).descriptor(descriptor).tags(OasModelHelper.sanitizeTags(operation.tags).distinct()::iterator).build();
actions.add(action);
}
}
actions.sort(ActionComparator.INSTANCE);
builder.addAllActions(actions);
builder.putConfiguredProperty(SPECIFICATION, SpecificationOptimizer.minimizeForComponent(openApiDoc));
return builder.build();
}
use of io.apicurio.datamodels.openapi.models.OasPathItem in project syndesis by syndesisio.
the class OpenApiValidationRules method validateOperationsGiven.
public OpenApiModelInfo validateOperationsGiven(final OpenApiModelInfo modelInfo) {
final OasDocument openApiDoc = modelInfo.getModel();
if (openApiDoc == null) {
return modelInfo;
}
final OpenApiModelInfo.Builder withErrors = new OpenApiModelInfo.Builder().createFrom(modelInfo);
final List<OasPathItem> paths = OasModelHelper.getPathItems(openApiDoc.paths);
if (paths.isEmpty()) {
withErrors.addError(new Violation.Builder().property("paths").error("missing-paths").message("No paths defined").build());
} else if (paths.stream().allMatch(p -> OasModelHelper.getOperationMap(p).isEmpty())) {
withErrors.addError(new Violation.Builder().property("").error("missing-operations").message("No operations defined").build());
}
return withErrors.build();
}
Aggregations