Skip to content

Fix OpenAPI Structure #577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 ), includeQueryPathNode );
endpointPathsNode.set( config.baseUrl() + String.format( QUERY_SERVER_PATH, apiVersion ) + finalResourcePath,
includeQueryPathNode );
}

final Optional<ObjectNode> operationsNode = getRequestEndpointOperations( aspect, propertiesNode, config.baseUrl(), apiVersion,
Expand Down Expand Up @@ -620,7 +621,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 ) );
Expand All @@ -645,7 +646,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;
}
Expand All @@ -656,7 +657,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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading