Search in sources :

Example 1 with OperationDescription

use of io.syndesis.server.connector.generator.swagger.util.OperationDescription in project syndesis by syndesisio.

the class BaseSwaggerConnectorGenerator method configureConnector.

protected final Connector configureConnector(final ConnectorTemplate connectorTemplate, final Connector connector, final ConnectorSettings connectorSettings) {
    final Connector.Builder builder = new Connector.Builder().createFrom(connector);
    final SwaggerModelInfo info = parseSpecification(connectorSettings, false);
    final Swagger swagger = info.getModel();
    addGlobalParameters(builder, swagger);
    final Map<String, Path> paths = swagger.getPaths();
    final String connectorId = connector.getId().get();
    final String connectorGav = connectorTemplate.getCamelConnectorGAV();
    final String connectorScheme = connectorTemplate.getCamelConnectorPrefix();
    final List<ConnectorAction> actions = new ArrayList<>();
    int idx = 0;
    for (final Entry<String, Path> pathEntry : paths.entrySet()) {
        final Path path = pathEntry.getValue();
        final Map<HttpMethod, Operation> operationMap = path.getOperationMap();
        for (final Entry<HttpMethod, Operation> entry : operationMap.entrySet()) {
            final Operation operation = entry.getValue();
            if (operation.getOperationId() == null) {
                operation.operationId("operation-" + idx++);
            }
            final ConnectorDescriptor descriptor = // 
            createDescriptor(info.getResolvedSpecification(), swagger, operation).camelConnectorGAV(// 
            connectorGav).camelConnectorPrefix(// 
            connectorScheme).connectorId(// 
            connectorId).build();
            final OperationDescription description = SwaggerHelper.operationDescriptionOf(swagger, operation);
            final ConnectorAction action = // 
            new ConnectorAction.Builder().id(// 
            createActionId(connectorId, connectorGav, operation)).name(// 
            description.name).description(// 
            description.description).pattern(// 
            Action.Pattern.To).descriptor(descriptor).tags(// 
            ofNullable(operation.getTags()).orElse(Collections.emptyList())).build();
            actions.add(action);
        }
    }
    actions.sort(ActionComparator.INSTANCE);
    builder.addAllActions(actions);
    builder.putConfiguredProperty("specification", SwaggerHelper.serialize(swagger));
    return builder.build();
}
Also used : Path(io.swagger.models.Path) Connector(io.syndesis.common.model.connection.Connector) ArrayList(java.util.ArrayList) Operation(io.swagger.models.Operation) OperationDescription(io.syndesis.server.connector.generator.swagger.util.OperationDescription) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) Swagger(io.swagger.models.Swagger) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) HttpMethod(io.swagger.models.HttpMethod)

Aggregations

HttpMethod (io.swagger.models.HttpMethod)1 Operation (io.swagger.models.Operation)1 Path (io.swagger.models.Path)1 Swagger (io.swagger.models.Swagger)1 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)1 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)1 Connector (io.syndesis.common.model.connection.Connector)1 OperationDescription (io.syndesis.server.connector.generator.swagger.util.OperationDescription)1 ArrayList (java.util.ArrayList)1