use of io.apicurio.datamodels.openapi.models.OasPaths in project apicurio-data-models by Apicurio.
the class DeletePathCommand method execute.
/**
* @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void execute(Document document) {
LoggerCompat.info("[DeletePathCommand] Executing for path: %s", this._path);
OasDocument odoc = (OasDocument) document;
this._oldPath = null;
OasPaths paths = odoc.paths;
if (this.isNullOrUndefined(paths)) {
return;
}
this._oldPath = Library.writeNode(paths.removePathItem(this._path));
}
use of io.apicurio.datamodels.openapi.models.OasPaths in project apicurio-data-models by Apicurio.
the class Oas30Document method createPaths.
/**
* @see io.apicurio.datamodels.openapi.models.OasDocument#createPaths()
*/
@Override
public OasPaths createPaths() {
OasPaths rval = new Oas30Paths();
rval._ownerDocument = this.ownerDocument();
rval._parent = this;
return rval;
}
use of io.apicurio.datamodels.openapi.models.OasPaths in project syndesis by syndesisio.
the class OpenApiConnectorGenerator method info.
@Override
public final APISummary info(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) {
final OpenApiModelInfo modelInfo = parseSpecification(connectorSettings, APIValidationContext.CONSUMED_API);
final OasDocument model = modelInfo.getModel();
if (model == null) {
final APISummary.Builder summaryBuilder = new APISummary.Builder().errors(modelInfo.getErrors()).warnings(modelInfo.getWarnings());
if (modelInfo.getResolvedSpecification() != null) {
summaryBuilder.putConfiguredProperty(SPECIFICATION, modelInfo.getResolvedSpecification());
}
return summaryBuilder.build();
}
// No matter if the validation fails, try to process the swagger
final Connector connector = basicConnector(connectorTemplate, connectorSettings);
final OasPaths paths = model.paths;
final AtomicInteger total = new AtomicInteger(0);
final Map<String, Integer> tagCounts;
if (paths == null) {
tagCounts = Collections.emptyMap();
} else {
tagCounts = OasModelHelper.getPathItems(paths).stream().flatMap(p -> OasModelHelper.getOperationMap(p).values().stream()).peek(o -> total.incrementAndGet()).flatMap(o -> OasModelHelper.sanitizeTags(o.tags).distinct()).collect(Collectors.groupingBy(Function.identity(), Collectors.reducing(0, (e) -> 1, Integer::sum)));
}
final ActionsSummary actionsSummary = new ActionsSummary.Builder().totalActions(total.intValue()).actionCountByTags(tagCounts).build();
return APISummary.Builder.createFrom(connector).actionsSummary(actionsSummary).errors(modelInfo.getErrors()).warnings(modelInfo.getWarnings()).putAllConfiguredProperties(connectorSettings.getConfiguredProperties()).putConfiguredProperty(SPECIFICATION, modelInfo.getResolvedSpecification()).build();
}
use of io.apicurio.datamodels.openapi.models.OasPaths in project syndesis by syndesisio.
the class OpenApiFlowGenerator method generateFlows.
/**
* Generate integration flows from given Open API document.
* @param openApiDoc the open api document.
* @param integration the integration builder
* @param info the open api model info.
* @param template the provided api template.
*/
public void generateFlows(T openApiDoc, Integration.Builder integration, OpenApiModelInfo info, ProvidedApiTemplate template) {
final Set<String> alreadyUsedOperationIds = new HashSet<>();
final OasPaths paths = Optional.ofNullable(openApiDoc.paths).orElse(openApiDoc.createPaths());
for (final OasPathItem pathEntry : OasModelHelper.getPathItems(paths)) {
for (final Map.Entry<String, O> operationEntry : getOperationsMap(pathEntry).entrySet()) {
final O operation = operationEntry.getValue();
final String operationDescription = operationEntry.getKey().toUpperCase(Locale.US) + " " + pathEntry.getPath();
final String operationId = requireUniqueOperationId(operation.operationId, alreadyUsedOperationIds);
alreadyUsedOperationIds.add(operationId);
// Update open api spec
operation.operationId = operationId;
final DataShape startDataShape = dataShapeGenerator.createShapeFromRequest(info.getResolvedJsonGraph(), openApiDoc, operation);
final Action startAction = template.getStartAction().orElseThrow(() -> new IllegalStateException("cannot find start action"));
final Step startStep = createStartStep(operationId, getBasePath(openApiDoc), startAction, startDataShape, template.getConnection());
final DataShape endDataShape = dataShapeGenerator.createShapeFromResponse(info.getResolvedJsonGraph(), openApiDoc, operation);
final Action endAction = template.getEndAction().orElseThrow(() -> new IllegalStateException("cannot find end action"));
final Step endStep = createEndStep(operation, endAction, endDataShape, template.getConnection());
final String flowId = KeyGenerator.createKey();
final Flow flow = new Flow.Builder().id(flowId).type(Flow.FlowType.API_PROVIDER).putMetadata(OpenApi.OPERATION_ID, operationId).putMetadata(FlowMetadata.EXCERPT, "501 Not Implemented").putMetadata(DEFAULT_RETURN_CODE_METADATA_KEY, getDefaultCode(operation)).addStep(startStep).addStep(endStep).name(getOperationName(openApiDoc, operation)).description(operationDescription).build();
integration.addFlow(flow);
}
}
}
use of io.apicurio.datamodels.openapi.models.OasPaths 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();
}
Aggregations