Skip to content

Take most schemas as route arguments#823

Merged
jviotti merged 1 commit intomainfrom
response-schemas
Apr 8, 2026
Merged

Take most schemas as route arguments#823
jviotti merged 1 commit intomainfrom
response-schemas

Conversation

@jviotti
Copy link
Copy Markdown
Member

@jviotti jviotti commented Apr 8, 2026

Signed-off-by: Juan Cruz Viotti jv@jviotti.com

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 12 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/actions/action_serve_static_v1.h">

<violation number="1" location="src/actions/action_serve_static_v1.h:39">
P2: `error_schema_` can be empty when the route doesn’t provide `errorSchema`, but it is still used to build the Link header in `json_error`. This produces an invalid `Link: <>` header and drops the error schema reference. Consider providing a default or guarding against empty values before using it.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

request, response, sourcemeta::one::STATUS_INTERNAL_SERVER_ERROR,
"missing-base-path", "The base path is not configured for this route",
std::string{this->base_path()} + "/self/v1/schemas/api/error");
this->error_schema_);
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Apr 8, 2026

Choose a reason for hiding this comment

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

P2: error_schema_ can be empty when the route doesn’t provide errorSchema, but it is still used to build the Link header in json_error. This produces an invalid Link: <> header and drops the error schema reference. Consider providing a default or guarding against empty values before using it.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/actions/action_serve_static_v1.h, line 39:

<comment>`error_schema_` can be empty when the route doesn’t provide `errorSchema`, but it is still used to build the Link header in `json_error`. This produces an invalid `Link: <>` header and drops the error schema reference. Consider providing a default or guarding against empty values before using it.</comment>

<file context>
@@ -34,17 +36,18 @@ class ActionServeStatic_v1 : public sourcemeta::one::Action {
           request, response, sourcemeta::one::STATUS_INTERNAL_SERVER_ERROR,
           "missing-base-path", "The base path is not configured for this route",
-          std::string{this->base_path()} + "/self/v1/schemas/api/error");
+          this->error_schema_);
       return;
     }
</file context>
Fix with Cubic

@augmentcode
Copy link
Copy Markdown

augmentcode bot commented Apr 8, 2026

🤖 Augment PR Summary

Summary: This PR moves most schema URLs (response and error Problem Details schemas) from being derived at runtime from base_path() to being supplied as route arguments in the URI template router.

Changes:

  • Actions now read responseSchema / errorSchema from router.arguments(identifier, ...) and reuse them when writing Link headers or emitting JSON errors.
  • ActionJSONSchemaEvaluate_v1 and ActionSchemaSearch_v1 now write their described-by Link header using a route-provided response schema URI.
  • ActionServeMetapackFile_v1::serve and ActionJSONSchemaServe_v1::serve were updated to accept an explicit error schema URI instead of a base path used to derive it.
  • json_error now takes the schema as a std::string_view (avoiding string moves/allocations at call sites).
  • The route generator now injects errorSchema broadly, and adds per-route responseSchema for evaluate/trace/search endpoints.

Technical Notes: This centralizes schema routing configuration in routes.bin, making Link header targets configurable per route while keeping action logic simpler.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

request, response, sourcemeta::one::STATUS_METHOD_NOT_ALLOWED,
"method-not-allowed", "This HTTP method is invalid for this URL",
std::string{this->base_path()} + "/self/v1/schemas/api/error");
this->error_schema_);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

src/actions/action_health_check_v1.h:35: error_schema_ is never defaulted, so if errorSchema isn't present in the route arguments (for example, an older routes.bin), json_error will emit an invalid Link: <>; rel="describedby" header. Consider ensuring a non-empty default (like the prior base_path()+"/self/v1/schemas/api/error") or validating before calling json_error.

Severity: medium

Other Locations
  • src/actions/action_not_found_v1.h:33
  • src/actions/action_schema_search_v1.h:45
  • src/actions/action_serve_static_v1.h:39
  • src/actions/action_jsonschema_serve_v1.h:85
  • src/actions/action_serve_schema_artifact_v1.h:41

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

response, std::string{this->base_path()} +
"/self/v1/schemas/api/schemas/evaluate/response");
}
sourcemeta::one::write_link_header(response, this->response_schema_);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

src/actions/action_jsonschema_evaluate_v1.h:334: write_link_header is now driven by response_schema_ from route arguments; if that argument is missing/empty, the response will include an invalid Link header and lose the previous mode-based schema selection. Consider ensuring responseSchema is always populated for both evaluate/trace routes (or falling back based on mode_).

Severity: medium

Other Locations
  • src/actions/action_schema_search_v1.h:143
  • src/actions/action_serve_explorer_artifact_v1.h:44
  • src/actions/action_serve_schema_artifact_v1.h:48

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Benchmark Index (community)

Details
Benchmark suite Current: 5d7d412 Previous: 8434752 Ratio
Add one schema (0 existing) 18 ms 18 ms 1
Add one schema (100 existing) 23 ms 25 ms 0.92
Add one schema (1000 existing) 73 ms 80 ms 0.91
Add one schema (10000 existing) 884 ms 726 ms 1.22
Update one schema (1 existing) 16 ms 17 ms 0.94
Update one schema (101 existing) 33 ms 25 ms 1.32
Update one schema (1001 existing) 74 ms 81 ms 0.91
Update one schema (10001 existing) 885 ms 715 ms 1.24
Cached rebuild (1 existing) 9 ms 9 ms 1
Cached rebuild (101 existing) 14 ms 12 ms 1.17
Cached rebuild (1001 existing) 30 ms 34 ms 0.88
Cached rebuild (10001 existing) 258 ms 283 ms 0.91
Index 100 schemas 111 ms 126 ms 0.88
Index 1000 schemas 974 ms 1057 ms 0.92
Index 10000 schemas 13102 ms 13435 ms 0.98

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Benchmark Index (enterprise)

Details
Benchmark suite Current: 5d7d412 Previous: 9658355 Ratio
Add one schema (0 existing) 19 ms 20 ms 0.95
Add one schema (100 existing) 24 ms 26 ms 0.92
Add one schema (1000 existing) 72 ms 78 ms 0.92
Add one schema (10000 existing) 673 ms 703 ms 0.96
Update one schema (1 existing) 18 ms 18 ms 1
Update one schema (101 existing) 24 ms 26 ms 0.92
Update one schema (1001 existing) 74 ms 83 ms 0.89
Update one schema (10001 existing) 627 ms 656 ms 0.96
Cached rebuild (1 existing) 10 ms 10 ms 1
Cached rebuild (101 existing) 12 ms 13 ms 0.92
Cached rebuild (1001 existing) 32 ms 36 ms 0.89
Cached rebuild (10001 existing) 262 ms 291 ms 0.90
Index 100 schemas 116 ms 134 ms 0.87
Index 1000 schemas 974 ms 1312 ms 0.74
Index 10000 schemas 14233 ms 13178 ms 1.08

This comment was automatically generated by workflow using github-action-benchmark.

@jviotti jviotti merged commit 414a71a into main Apr 8, 2026
6 checks passed
@jviotti jviotti deleted the response-schemas branch April 8, 2026 22:54
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.

1 participant