From 6177e1649470526f9cf47701c545094c8c3a0cee Mon Sep 17 00:00:00 2001 From: Yauhenikapl Date: Thu, 23 May 2024 10:58:27 +0300 Subject: [PATCH 1/2] Fix OpenAPI Structure --- .../generator/openapi/AspectModelOpenApiGenerator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/esmf-aspect-model-document-generators/src/main/java/org/eclipse/esmf/aspectmodel/generator/openapi/AspectModelOpenApiGenerator.java b/core/esmf-aspect-model-document-generators/src/main/java/org/eclipse/esmf/aspectmodel/generator/openapi/AspectModelOpenApiGenerator.java index 8f64dc6b0..ed5d9e582 100644 --- a/core/esmf-aspect-model-document-generators/src/main/java/org/eclipse/esmf/aspectmodel/generator/openapi/AspectModelOpenApiGenerator.java +++ b/core/esmf-aspect-model-document-generators/src/main/java/org/eclipse/esmf/aspectmodel/generator/openapi/AspectModelOpenApiGenerator.java @@ -527,7 +527,7 @@ private ObjectNode getPathsNode( final Aspect aspect, final OpenApiSchemaGenerat final ObjectNode includeQueryPathNode = FACTORY.objectNode(); includeQueryPathNode.set( FIELD_POST, getRequestEndpointFilter( aspect, propertiesNode, config.baseUrl(), apiVersion, config.resourcePath() ) ); - endpointPathsNode.set( config.baseUrl() + String.format( QUERY_SERVER_PATH, apiVersion ), includeQueryPathNode ); + endpointPathsNode.set( config.baseUrl() + String.format( QUERY_SERVER_PATH, apiVersion ) + finalResourcePath, includeQueryPathNode ); } final Optional operationsNode = getRequestEndpointOperations( aspect, propertiesNode, config.baseUrl(), apiVersion, @@ -620,7 +620,7 @@ private ObjectNode getRequestEndpointFilter( final Aspect aspect, final ObjectNo final ObjectNode objectNode = FACTORY.objectNode(); setServers( objectNode, baseUrl, apiVersion, QUERY_SERVER_PATH ); objectNode.set( "tags", FACTORY.arrayNode().add( aspect.getName() ) ); - objectNode.put( FIELD_OPERATION_ID, FIELD_POST + aspect.getName() ); + objectNode.put( FIELD_OPERATION_ID, FIELD_POST + "Base" + aspect.getName() ); objectNode.set( FIELD_PARAMETERS, getRequiredParameters( parameterNode, isEmpty( resourcePath ) ) ); objectNode.set( FIELD_REQUEST_BODY, getRequestBodyForFilter() ); objectNode.set( FIELD_RESPONSES, getResponsesForGet( aspect ) ); @@ -645,7 +645,7 @@ private ObjectNode getRequestEndpointsCreate( final Aspect aspect, final ObjectN objectNode.set( "tags", FACTORY.arrayNode().add( aspect.getName() ) ); objectNode.put( FIELD_OPERATION_ID, FIELD_POST + aspect.getName() ); objectNode.set( FIELD_PARAMETERS, getRequiredParameters( parameterNode, isEmpty( resourcePath ) ) ); - objectNode.set( FIELD_REQUEST_BODY, FACTORY.objectNode() ); + objectNode.set( FIELD_REQUEST_BODY, FACTORY.objectNode().put( REF, COMPONENTS_REQUESTS + aspect.getName() ) ); objectNode.set( FIELD_RESPONSES, getResponsesForGet( aspect ) ); return objectNode; } @@ -656,7 +656,7 @@ private ObjectNode getRequestEndpointsUpdate( final Aspect aspect, final ObjectN objectNode.set( "tags", FACTORY.arrayNode().add( aspect.getName() ) ); objectNode.put( FIELD_OPERATION_ID, (isPut ? FIELD_PUT : FIELD_PATCH) + aspect.getName() ); objectNode.set( FIELD_PARAMETERS, getRequiredParameters( parameterNode, isEmpty( resourcePath ) ) ); - objectNode.set( FIELD_REQUEST_BODY, FACTORY.objectNode() ); + objectNode.set( FIELD_REQUEST_BODY, FACTORY.objectNode().put( REF, COMPONENTS_REQUESTS + aspect.getName() ) ); objectNode.set( FIELD_RESPONSES, getResponsesForGet( aspect ) ); return objectNode; } From 816294639f7ac43e73149c5b45d04494f330336b Mon Sep 17 00:00:00 2001 From: Yauhenikapl Date: Fri, 24 May 2024 09:27:33 +0300 Subject: [PATCH 2/2] Fix lint and tests for update structure of OpenAPI --- .../openapi/AspectModelOpenApiGenerator.java | 3 +- .../AspectModelOpenApiGeneratorTest.java | 34 ++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/core/esmf-aspect-model-document-generators/src/main/java/org/eclipse/esmf/aspectmodel/generator/openapi/AspectModelOpenApiGenerator.java b/core/esmf-aspect-model-document-generators/src/main/java/org/eclipse/esmf/aspectmodel/generator/openapi/AspectModelOpenApiGenerator.java index ed5d9e582..06333bf4a 100644 --- a/core/esmf-aspect-model-document-generators/src/main/java/org/eclipse/esmf/aspectmodel/generator/openapi/AspectModelOpenApiGenerator.java +++ b/core/esmf-aspect-model-document-generators/src/main/java/org/eclipse/esmf/aspectmodel/generator/openapi/AspectModelOpenApiGenerator.java @@ -527,7 +527,8 @@ private ObjectNode getPathsNode( final Aspect aspect, final OpenApiSchemaGenerat final ObjectNode includeQueryPathNode = FACTORY.objectNode(); includeQueryPathNode.set( FIELD_POST, getRequestEndpointFilter( aspect, propertiesNode, config.baseUrl(), apiVersion, config.resourcePath() ) ); - endpointPathsNode.set( config.baseUrl() + String.format( QUERY_SERVER_PATH, apiVersion ) + finalResourcePath, includeQueryPathNode ); + endpointPathsNode.set( config.baseUrl() + String.format( QUERY_SERVER_PATH, apiVersion ) + finalResourcePath, + includeQueryPathNode ); } final Optional operationsNode = getRequestEndpointOperations( aspect, propertiesNode, config.baseUrl(), apiVersion, diff --git a/core/esmf-aspect-model-document-generators/src/test/java/org/eclipse/esmf/aspectmodel/generator/openapi/AspectModelOpenApiGeneratorTest.java b/core/esmf-aspect-model-document-generators/src/test/java/org/eclipse/esmf/aspectmodel/generator/openapi/AspectModelOpenApiGeneratorTest.java index bbd7c9e56..1b8c46009 100644 --- a/core/esmf-aspect-model-document-generators/src/test/java/org/eclipse/esmf/aspectmodel/generator/openapi/AspectModelOpenApiGeneratorTest.java +++ b/core/esmf-aspect-model-document-generators/src/test/java/org/eclipse/esmf/aspectmodel/generator/openapi/AspectModelOpenApiGeneratorTest.java @@ -168,7 +168,8 @@ void testIncludeQueryApiWithSemanticVersion( final KnownVersion metaModelVersion final JsonNode json = apiJsonGenerator.apply( aspect, config ).getContent(); final SwaggerParseResult result = new OpenAPIParser().readContents( json.toString(), null, null ); final OpenAPI openApi = result.getOpenAPI(); - assertThat( openApi.getPaths().get( "https://test-aspect.example.com/query-api/v1.0.0" ).getPost().getServers().get( 0 ).getUrl() ) + assertThat( openApi.getPaths().get( "https://test-aspect.example.com/query-api/v1.0.0/" + TEST_RESOURCE_PATH ).getPost().getServers() + .get( 0 ).getUrl() ) .isEqualTo( "https://test-aspect.example.com/query-api/v1.0.0" ); } @@ -185,11 +186,14 @@ void testDefaultResourcePath( final KnownVersion metaModelVersion ) { final SwaggerParseResult result = new OpenAPIParser().readContents( json.toString(), null, null ); final OpenAPI openApi = result.getOpenAPI(); - assertThat( openApi.getPaths().get( "/{tenant-id}/aspect-without-see-attribute" ).getPost() ).isNull(); - assertThat( openApi.getPaths().get( "/{tenant-id}/aspect-without-see-attribute" ).getPut() ).isNull(); - assertThat( openApi.getPaths().get( "/{tenant-id}/aspect-without-see-attribute" ).getPatch() ).isNull(); - assertThat( openApi.getPaths().keySet() ).anyMatch( path -> path.equals( "/{tenant-id}/aspect-without-see-attribute" ) ); - assertThat( openApi.getPaths().keySet() ).anyMatch( path -> path.equals( "https://test-aspect.example.com/query-api/v1.0.0" ) ); + final String apiEndpoint = "/{tenant-id}/aspect-without-see-attribute"; + + assertThat( openApi.getPaths().get( apiEndpoint ).getPost() ).isNull(); + assertThat( openApi.getPaths().get( apiEndpoint ).getPut() ).isNull(); + assertThat( openApi.getPaths().get( apiEndpoint ).getPatch() ).isNull(); + assertThat( openApi.getPaths().keySet() ).anyMatch( path -> path.equals( apiEndpoint ) ); + assertThat( openApi.getPaths().keySet() ).anyMatch( + path -> path.equals( "https://test-aspect.example.com/query-api/v1.0.0" + apiEndpoint ) ); } @ParameterizedTest @@ -221,7 +225,8 @@ void testWithValidResourcePath( final KnownVersion metaModelVersion ) { final OpenAPI openApi = result.getOpenAPI(); assertThat( openApi.getPaths().keySet() ).anyMatch( path -> path.equals( "/" + TEST_RESOURCE_PATH ) ); - assertThat( openApi.getPaths().keySet() ).anyMatch( path -> path.equals( "https://test-aspect.example.com/query-api/v1.0.0" ) ); + assertThat( openApi.getPaths().keySet() ).anyMatch( + path -> path.equals( "https://test-aspect.example.com/query-api/v1.0.0/" + TEST_RESOURCE_PATH ) ); } @ParameterizedTest @@ -532,7 +537,8 @@ void testAspectWithAllCrud( final KnownVersion metaModelVersion ) { assertThat( openApi.getPaths().get( apiEndpoint ).getPost() ).isNotNull(); assertThat( openApi.getPaths().get( apiEndpoint ).getPut() ).isNotNull(); assertThat( openApi.getPaths().get( apiEndpoint ).getPatch() ).isNotNull(); - assertThat( openApi.getPaths().keySet() ).anyMatch( path -> path.equals( "https://test-aspect.example.com/query-api/v1.0.0" ) ); + assertThat( openApi.getPaths().keySet() ).anyMatch( + path -> path.equals( "https://test-aspect.example.com/query-api/v1.0.0" + apiEndpoint ) ); } @ParameterizedTest @@ -555,7 +561,8 @@ void testAspectWithPostOperation( final KnownVersion metaModelVersion ) { assertThat( openApi.getPaths().get( apiEndpoint ).getPost() ).isNotNull(); assertThat( openApi.getPaths().get( apiEndpoint ).getPut() ).isNull(); assertThat( openApi.getPaths().get( apiEndpoint ).getPatch() ).isNull(); - assertThat( openApi.getPaths().keySet() ).anyMatch( path -> path.equals( "https://test-aspect.example.com/query-api/v1.0.0" ) ); + assertThat( openApi.getPaths().keySet() ).anyMatch( + path -> path.equals( "https://test-aspect.example.com/query-api/v1.0.0" + apiEndpoint ) ); } @ParameterizedTest @@ -578,7 +585,8 @@ void testAspectWithPutOperation( final KnownVersion metaModelVersion ) { assertThat( openApi.getPaths().get( apiEndpoint ).getPost() ).isNull(); assertThat( openApi.getPaths().get( apiEndpoint ).getPut() ).isNotNull(); assertThat( openApi.getPaths().get( apiEndpoint ).getPatch() ).isNull(); - assertThat( openApi.getPaths().keySet() ).anyMatch( path -> path.equals( "https://test-aspect.example.com/query-api/v1.0.0" ) ); + assertThat( openApi.getPaths().keySet() ).anyMatch( + path -> path.equals( "https://test-aspect.example.com/query-api/v1.0.0" + apiEndpoint ) ); } @ParameterizedTest @@ -601,7 +609,8 @@ void testAspectWithPatchOperation( final KnownVersion metaModelVersion ) { assertThat( openApi.getPaths().get( apiEndpoint ).getPost() ).isNull(); assertThat( openApi.getPaths().get( apiEndpoint ).getPut() ).isNull(); assertThat( openApi.getPaths().get( apiEndpoint ).getPatch() ).isNotNull(); - assertThat( openApi.getPaths().keySet() ).anyMatch( path -> path.equals( "https://test-aspect.example.com/query-api/v1.0.0" ) ); + assertThat( openApi.getPaths().keySet() ).anyMatch( + path -> path.equals( "https://test-aspect.example.com/query-api/v1.0.0" + apiEndpoint ) ); } @ParameterizedTest @@ -625,7 +634,8 @@ void testAspectWithPatchAndPostOperation( final KnownVersion metaModelVersion ) assertThat( openApi.getPaths().get( apiEndpoint ).getPost() ).isNotNull(); assertThat( openApi.getPaths().get( apiEndpoint ).getPut() ).isNull(); assertThat( openApi.getPaths().get( apiEndpoint ).getPatch() ).isNotNull(); - assertThat( openApi.getPaths().keySet() ).anyMatch( path -> path.equals( "https://test-aspect.example.com/query-api/v1.0.0" ) ); + assertThat( openApi.getPaths().keySet() ).anyMatch( + path -> path.equals( "https://test-aspect.example.com/query-api/v1.0.0" + apiEndpoint ) ); } @ParameterizedTest