Skip to content

fix(api): return 400 for invalid graph traversal modes - #169

Open
hamdirahalpartner-del wants to merge 3 commits into
mainfrom
CPDE-3321-idp-core-error-response-when-uknow-graph-mode
Open

hamdirahalpartner-del wants to merge 3 commits into
mainfrom
CPDE-3321-idp-core-error-response-when-uknow-graph-mode

Conversation

@hamdirahalpartner-del

@hamdirahalpartner-del hamdirahalpartner-del commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Handle request parameter type mismatches with descriptive error messages and list allowed enum values instead of returning 500.

Document the graph endpoint's 400 response and add regression tests.

PR Description

What this PR Provides

  • Return HTTP 400 Bad Request instead of 500 for request parameter type mismatches.
  • Include the invalid parameter name and value in the error description.
  • List allowed enum values when an unsupported value is provided.
  • Preserve supported traversal modes and the default DIRECT_LINEAGE mode.
  • Document the graph endpoint's 400 response in OpenAPI annotations and the static Swagger specification.
  • Add regression tests for invalid parameters and supported traversal modes.

Fixes

Review

The reviewer must double-check these points:

  • The reviewer has tested the fix
  • The reviewer has reviewed the implementation
  • The documentation has been updated

How to test

Initial state

Run the application and authenticate with an account authorized to access the graph endpoint.

Ensure an entity exists and use its template identifier and entity identifier in the requests below.

Invalid traversal mode

Call the endpoint with an unsupported traversal mode:

GET /api/v1/entities/{templateIdentifier}/{entityIdentifier}/graph?traversal_mode=OUTBOUND_ONL

Expected result: HTTP 400 Bad Request with this response:

{
  "error": "BAD_REQUEST",
  "error_description": "Invalid value 'OUTBOUND_ONL' for parameter 'traversal_mode'. Allowed values: [DIRECT_LINEAGE, BIDIRECTIONAL, OUTBOUND_ONLY]."
}

Supported traversal modes

Call the endpoint with each supported value: DIRECT_LINEAGE, BIDIRECTIONAL, and OUTBOUND_ONLY.

Expected result: HTTP 200 OK with the entity graph.

Call the endpoint without the traversal_mode parameter.

Expected result: HTTP 200 OK, using DIRECT_LINEAGE as the default.

Other invalid parameter types

Call the endpoint with depth=abc or include_data=invalid.

Expected result: HTTP 400 Bad Request with an error description identifying the invalid parameter, its value, and the expected type.

API documentation

Open the documentation site's Swagger UI and inspect the graph endpoint.

Expected result: the endpoint documents the 400 response with the ErrorResponse schema.

Breaking changes (if any)

  • N/A. Valid requests and response schemas remain unchanged. Invalid parameter values now return HTTP 400 instead of HTTP 500.

Context of the Breaking Change

N/A.

Result of the Breaking Change

N/A.

Handle request parameter type mismatches with descriptive error messages
and list allowed enum values instead of returning 500.

Document the graph endpoint's 400 response and add regression tests.

Signed-off-by: hamdirahalpartner-del <hamdi.rahal.partner@decathlon.com>
@hamdirahalpartner-del
hamdirahalpartner-del requested review from brandPittCode and a balanced review from Copilot October 16, 2026 07:09
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The published static OpenAPI contract still needs regeneration to include the new 400 response.

1 open finding
What changed in this PR

Improves API error handling so invalid graph parameters return descriptive 400 responses instead of 500 errors.

Changes:

  • Adds type-mismatch handling with allowed enum values.
  • Documents the graph endpoint’s 400 response.
  • Adds regression tests for invalid, supported, and default parameters.
File Description
src/​test/​java/​com/​decathlon/​idp_core/​infrastructure/​adapters/​api/​handler/​ApiExceptionHandlerTest.java Tests parameter conversion and error responses.
src/​main/​java/​com/​decathlon/​idp_core/​infrastructure/​adapters/​api/​handler/​ApiExceptionHandler.java Handles parameter type mismatches as 400 errors.
src/​main/​java/​com/​decathlon/​idp_core/​infrastructure/​adapters/​api/​controller/​EntityGraphController.java Declares the graph endpoint’s 400 response.
src/​main/​java/​com/​decathlon/​idp_core/​infrastructure/​adapters/​api/​configuration/​SwaggerDescription.java Adds the invalid-query response description.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ResponseStatus(OK)
@Operation(summary = ENDPOINT_GET_ENTITY_GRAPH_FLAT_SUMMARY, description = ENDPOINT_GET_ENTITY_GRAPH_FLAT_DESCRIPTION, responses = {
@ApiResponse(responseCode = OK_CODE, description = RESPONSE_ENTITY_GRAPH_FLAT_SUCCESS, content = @Content(schema = @Schema(implementation = EntityGraphFlatDtoOut.class))),
@ApiResponse(responseCode = BAD_REQUEST_CODE, description = RESPONSE_INVALID_GRAPH_QUERY, content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
Signed-off-by: hamdirahalpartner-del <hamdi.rahal.partner@decathlon.com>
@github-code-quality

github-code-quality Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Java

Java / code-coverage/jacoco

main 1e7741b CPDE-3321-idp-core-e... e2f4aeb +/-
91% 91% 0%
View coverage of the 3 most impacted files.
File main 1e7741b CPDE-3321-idp-core-e... e2f4aeb +/-
com/decathlon/i...ationUtils.java 87% 87% 0%
com/decathlon/i...ionHandler.java 83% 84% +1%
com/decathlon/i...oOutMapper.java 95% 97% +2%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 16, 2026 07:49 UTC

Signed-off-by: hamdirahalpartner-del <hamdi.rahal.partner@decathlon.com>
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused handler change, regression coverage, and API documentation are consistent; no blocking issues were identified, though tests were not executed.

1 open finding

🧠 Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants