use of io.syndesis.server.api.generator.openapi.util.OperationDescription 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();
}
Aggregations