@Test public void shouldMakeNonUniqueOperationIdsUnique() { final Oas20Document openApiDoc = new Oas20Document(); openApiDoc.paths = openApiDoc.createPaths(); Oas20PathItem pathItem = (Oas20PathItem) openApiDoc.paths.createPathItem("/path"); pathItem.get = pathItem.createOperation("get"); pathItem.get.operationId = "foo"; pathItem.post = pathItem.createOperation("post"); pathItem.post.operationId = "foo"; pathItem.put = pathItem.createOperation("put"); pathItem.put.operationId = "bar"; openApiDoc.paths.addPathItem("/path", pathItem); final Connector generated = generator.configureConnector(ApiConnectorTemplate.SWAGGER_TEMPLATE, new Connector.Builder().id("connector1").build(), createSettingsFrom(openApiDoc)); final List<ConnectorAction> actions = generated.getActions(); assertThat(actions).hasSize(3); assertThat(actions.get(0).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("foo")); assertThat(actions.get(1).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("foo1")); assertThat(actions.get(2).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("bar")); }
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 { 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(); }
OpenApiConnectorGenerator extends ConnectorGenerator { 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 { 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(); } }
OpenApiConnectorGenerator extends ConnectorGenerator { 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 { 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(); } OpenApiConnectorGenerator(final Connector baseConnector, final Supplier<String> operationIdGenerator);  OpenApiConnectorGenerator(final Connector baseConnector); }
OpenApiConnectorGenerator extends ConnectorGenerator { 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 { 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(); } OpenApiConnectorGenerator(final Connector baseConnector, final Supplier<String> operationIdGenerator);  OpenApiConnectorGenerator(final Connector baseConnector); @Override final Connector generate(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings); @Override final APISummary info(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings); }
OpenApiConnectorGenerator extends ConnectorGenerator { 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 { 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(); } OpenApiConnectorGenerator(final Connector baseConnector, final Supplier<String> operationIdGenerator);  OpenApiConnectorGenerator(final Connector baseConnector); @Override final Connector generate(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings); @Override final APISummary info(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings); static final String SPECIFICATION; }