@Test public void testEmptyOperationSummary() throws IOException { final ProvidedApiTemplate template = new ProvidedApiTemplate(dummyConnection(), "fromAction", "toAction"); final String specification = TestHelper.resource("/openapi/v2/empty-summary.json"); final OpenApiGenerator generator = new OpenApiGenerator(); final APIIntegration apiIntegration = generator.generateIntegration(specification, template); assertThat(apiIntegration).isNotNull(); assertThat(apiIntegration.getIntegration().getFlows()).hasSize(3); final List<Flow> flows = apiIntegration.getIntegration().getFlows(); assertThat(flows).filteredOn(operationIdEquals("operation-1")).first() .hasFieldOrPropertyWithValue("description", Optional.of("GET /hi")) .hasFieldOrPropertyWithValue("name", "Receiving GET request on /hi"); assertThat(flows).filteredOn(operationIdEquals("operation-2")).first() .hasFieldOrPropertyWithValue("description", Optional.of("POST /hi")) .hasFieldOrPropertyWithValue("name", "post operation"); assertThat(flows).filteredOn(operationIdEquals("operation-3")).first() .hasFieldOrPropertyWithValue("description", Optional.of("PUT /hi")) .hasFieldOrPropertyWithValue("name", "Receiving PUT request on /hi"); }
@Override @SuppressWarnings({"PMD.ExcessiveMethodLength"}) public APIIntegration generateIntegration(final String specification, final ProvidedApiTemplate template) { final OpenApiModelInfo info = OpenApiModelParser.parse(specification, APIValidationContext.NONE); final OasDocument openApiDoc = info.getModel(); final String name = Optional.ofNullable(openApiDoc.info) .flatMap(i -> Optional.ofNullable(i.title)) .orElse("Untitled"); final Integration.Builder integration = new Integration.Builder() .addTag("api-provider") .createdAt(System.currentTimeMillis()) .name(name); switch (info.getApiVersion()) { case V2: oas20FlowGenerator.generateFlows(info.getV2Model(), integration, info, template); break; case V3: oas30FlowGenerator.generateFlows(info.getV3Model(), integration, info, template); break; default: throw new IllegalStateException(String.format("Unable to retrieve integration flow generator for OpenAPI document type '%s'", openApiDoc.getClass())); } final byte[] updatedSpecification = Library.writeDocumentToJSONString(openApiDoc).getBytes(StandardCharsets.UTF_8); final String apiId = KeyGenerator.createKey(); final OpenApi api = new OpenApi.Builder() .id(apiId) .name(name) .document(updatedSpecification) .putMetadata("Content-Type", getContentType(specification)) .build(); integration.addResource(new ResourceIdentifier.Builder() .id(apiId) .kind(Kind.OpenApi) .build()); return new APIIntegration(integration.build(), api); }
OpenApiGenerator implements APIGenerator { @Override @SuppressWarnings({"PMD.ExcessiveMethodLength"}) public APIIntegration generateIntegration(final String specification, final ProvidedApiTemplate template) { final OpenApiModelInfo info = OpenApiModelParser.parse(specification, APIValidationContext.NONE); final OasDocument openApiDoc = info.getModel(); final String name = Optional.ofNullable(openApiDoc.info) .flatMap(i -> Optional.ofNullable(i.title)) .orElse("Untitled"); final Integration.Builder integration = new Integration.Builder() .addTag("api-provider") .createdAt(System.currentTimeMillis()) .name(name); switch (info.getApiVersion()) { case V2: oas20FlowGenerator.generateFlows(info.getV2Model(), integration, info, template); break; case V3: oas30FlowGenerator.generateFlows(info.getV3Model(), integration, info, template); break; default: throw new IllegalStateException(String.format("Unable to retrieve integration flow generator for OpenAPI document type '%s'", openApiDoc.getClass())); } final byte[] updatedSpecification = Library.writeDocumentToJSONString(openApiDoc).getBytes(StandardCharsets.UTF_8); final String apiId = KeyGenerator.createKey(); final OpenApi api = new OpenApi.Builder() .id(apiId) .name(name) .document(updatedSpecification) .putMetadata("Content-Type", getContentType(specification)) .build(); integration.addResource(new ResourceIdentifier.Builder() .id(apiId) .kind(Kind.OpenApi) .build()); return new APIIntegration(integration.build(), api); } }
OpenApiGenerator implements APIGenerator { @Override @SuppressWarnings({"PMD.ExcessiveMethodLength"}) public APIIntegration generateIntegration(final String specification, final ProvidedApiTemplate template) { final OpenApiModelInfo info = OpenApiModelParser.parse(specification, APIValidationContext.NONE); final OasDocument openApiDoc = info.getModel(); final String name = Optional.ofNullable(openApiDoc.info) .flatMap(i -> Optional.ofNullable(i.title)) .orElse("Untitled"); final Integration.Builder integration = new Integration.Builder() .addTag("api-provider") .createdAt(System.currentTimeMillis()) .name(name); switch (info.getApiVersion()) { case V2: oas20FlowGenerator.generateFlows(info.getV2Model(), integration, info, template); break; case V3: oas30FlowGenerator.generateFlows(info.getV3Model(), integration, info, template); break; default: throw new IllegalStateException(String.format("Unable to retrieve integration flow generator for OpenAPI document type '%s'", openApiDoc.getClass())); } final byte[] updatedSpecification = Library.writeDocumentToJSONString(openApiDoc).getBytes(StandardCharsets.UTF_8); final String apiId = KeyGenerator.createKey(); final OpenApi api = new OpenApi.Builder() .id(apiId) .name(name) .document(updatedSpecification) .putMetadata("Content-Type", getContentType(specification)) .build(); integration.addResource(new ResourceIdentifier.Builder() .id(apiId) .kind(Kind.OpenApi) .build()); return new APIIntegration(integration.build(), api); }  }
OpenApiGenerator implements APIGenerator { @Override @SuppressWarnings({"PMD.ExcessiveMethodLength"}) public APIIntegration generateIntegration(final String specification, final ProvidedApiTemplate template) { final OpenApiModelInfo info = OpenApiModelParser.parse(specification, APIValidationContext.NONE); final OasDocument openApiDoc = info.getModel(); final String name = Optional.ofNullable(openApiDoc.info) .flatMap(i -> Optional.ofNullable(i.title)) .orElse("Untitled"); final Integration.Builder integration = new Integration.Builder() .addTag("api-provider") .createdAt(System.currentTimeMillis()) .name(name); switch (info.getApiVersion()) { case V2: oas20FlowGenerator.generateFlows(info.getV2Model(), integration, info, template); break; case V3: oas30FlowGenerator.generateFlows(info.getV3Model(), integration, info, template); break; default: throw new IllegalStateException(String.format("Unable to retrieve integration flow generator for OpenAPI document type '%s'", openApiDoc.getClass())); } final byte[] updatedSpecification = Library.writeDocumentToJSONString(openApiDoc).getBytes(StandardCharsets.UTF_8); final String apiId = KeyGenerator.createKey(); final OpenApi api = new OpenApi.Builder() .id(apiId) .name(name) .document(updatedSpecification) .putMetadata("Content-Type", getContentType(specification)) .build(); integration.addResource(new ResourceIdentifier.Builder() .id(apiId) .kind(Kind.OpenApi) .build()); return new APIIntegration(integration.build(), api); }  @Override @SuppressWarnings({"PMD.ExcessiveMethodLength"}) APIIntegration generateIntegration(final String specification, final ProvidedApiTemplate template); @Override APISummary info(final String specification, final APIValidationContext validation); @Override Integration updateFlowExcerpts(final Integration integration); }
OpenApiGenerator implements APIGenerator { @Override @SuppressWarnings({"PMD.ExcessiveMethodLength"}) public APIIntegration generateIntegration(final String specification, final ProvidedApiTemplate template) { final OpenApiModelInfo info = OpenApiModelParser.parse(specification, APIValidationContext.NONE); final OasDocument openApiDoc = info.getModel(); final String name = Optional.ofNullable(openApiDoc.info) .flatMap(i -> Optional.ofNullable(i.title)) .orElse("Untitled"); final Integration.Builder integration = new Integration.Builder() .addTag("api-provider") .createdAt(System.currentTimeMillis()) .name(name); switch (info.getApiVersion()) { case V2: oas20FlowGenerator.generateFlows(info.getV2Model(), integration, info, template); break; case V3: oas30FlowGenerator.generateFlows(info.getV3Model(), integration, info, template); break; default: throw new IllegalStateException(String.format("Unable to retrieve integration flow generator for OpenAPI document type '%s'", openApiDoc.getClass())); } final byte[] updatedSpecification = Library.writeDocumentToJSONString(openApiDoc).getBytes(StandardCharsets.UTF_8); final String apiId = KeyGenerator.createKey(); final OpenApi api = new OpenApi.Builder() .id(apiId) .name(name) .document(updatedSpecification) .putMetadata("Content-Type", getContentType(specification)) .build(); integration.addResource(new ResourceIdentifier.Builder() .id(apiId) .kind(Kind.OpenApi) .build()); return new APIIntegration(integration.build(), api); }  @Override @SuppressWarnings({"PMD.ExcessiveMethodLength"}) APIIntegration generateIntegration(final String specification, final ProvidedApiTemplate template); @Override APISummary info(final String specification, final APIValidationContext validation); @Override Integration updateFlowExcerpts(final Integration integration);  }