Skip to content

Conversation

@nguyen-andrew
Copy link
Member

@nguyen-andrew nguyen-andrew commented Jan 28, 2026

Add an optional subject query parameter to the GET /schemas/ids/{id} endpoint. This allows specifying the context for schema lookup by extracting the context from the provided subject name (e.g., :.myctx:mysubject).

Fixes CORE-15194

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v25.3.x
  • v25.2.x
  • v25.1.x

Release Notes

  • none

@nguyen-andrew nguyen-andrew self-assigned this Jan 28, 2026
Copilot AI review requested due to automatic review settings January 28, 2026 22:53
@nguyen-andrew nguyen-andrew requested a review from a team as a code owner January 28, 2026 22:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an optional subject query parameter to the GET /schemas/ids/{id} endpoint to enable context-aware schema lookups. When provided, the subject name (which can include context in the format :.context:subject) is used to determine the context for retrieving the schema, rather than always using the default context.

Changes:

  • Modified the endpoint handler to parse and use the optional subject parameter to extract context information
  • Updated the Python test client to support passing the subject parameter
  • Added comprehensive test coverage verifying the new parameter works correctly with default and non-default contexts
  • Updated API documentation to describe the new query parameter

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/v/pandaproxy/schema_registry/handlers.cc Added logic to parse the optional subject query parameter, extract context from it, and use the context when looking up schemas by ID
tests/rptest/tests/schema_registry_test.py Updated test client method to accept subject parameter and added comprehensive test case covering various scenarios
src/v/pandaproxy/api/api-doc/schema_registry.json Added documentation for the new subject query parameter

Add an optional `subject` query parameter to extract the context for
schema lookup. When provided, the context is parsed from the subject
using context_subject::from_string() and used to create a context-aware
schema ID. Without the parameter, the default context is used.
Add test for the `subject` query parameter on GET /schemas/ids/{id},
verifying that it correctly extracts context for schema lookup.
Also update the test client to support the new parameter.
@nguyen-andrew nguyen-andrew force-pushed the sr/subject-query-param branch from 6118d1f to fa5356c Compare January 28, 2026 23:22
@nguyen-andrew
Copy link
Member Author

Force push to rebase on latest dev.

@vbotbuildovich
Copy link
Collaborator

CI test results

test results on build#79806
test_class test_method test_arguments test_kind job_url test_status passed reason test_history
ScalingUpTest test_fast_node_addition null integration https://buildkite.com/redpanda/redpanda/builds/79806#019c06fb-10a4-47cf-a3ce-73980f76c3be FLAKY 19/21 Test PASSES after retries.No significant increase in flaky rate(baseline=0.0206, p0=0.3402, reject_threshold=0.0100. adj_baseline=0.1000, p1=0.3917, trust_threshold=0.5000) https://redpanda.metabaseapp.com/dashboard/87-tests?tab=142-dt-individual-test-history&test_class=ScalingUpTest&test_method=test_fast_node_addition

auto subject_param = parse::query_param<std::optional<ss::sstring>>(
*rq.req, "subject");

// Extract context from subject, or use default context
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the behaviour is a bit trickier here unfortunately:

# Register the same schema in two contexts
% curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" --data '{"schema": '"$(cat ~/tasks/avro-refs/address.avsc | jq -Rs .)"', "schemaType": "AVRO"}' http://localhost:8081/subjects/:.prod:Ad
dress/versions
{"id":1,"version":1,"guid":"a3d4c656-76ec-775d-35a1-1de29d031a17","schemaType":"AVRO","schema":"{\"type\":\"record\",\"name\":\"Address\",\"fields\":[{\"name\":\"street\",\"type\":\"string\"},{\"name\":\"city\",\"type\":\"string\"}]}"}%

% curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" --data '{"schema": '"$(cat ~/tasks/avro-refs/address.avsc | jq -Rs .)"', "schemaType": "AVRO"}' http://localhost:8081/subjects/:.shared:Address/versions
{"id":1,"version":1,"guid":"a3d4c656-76ec-775d-35a1-1de29d031a17","schemaType":"AVRO","schema":"{\"type\":\"record\",\"name\":\"Address\",\"fields\":[{\"name\":\"street\",\"type\":\"string\"},{\"name\":\"city\",\"type\":\"string\"}]}"}%


# Query the schemas

% curl "http://localhost:8081/schemas/ids/1?subject=:.shared:"
{"subject":":.shared:Address","version":1,"guid":"a3d4c656-76ec-775d-35a1-1de29d031a17","schemaType":"AVRO","schema":"{\"type\":\"record\",\"name\":\"Address\",\"fields\":[{\"name\":\"street\",\"type\":\"string\"},{\"name\":\"city\",\"type\":\"string\"}]}","ts":1769688260232,"deleted":false}%                                                                                                                                                                                                                                    

% curl "http://localhost:8081/schemas/ids/1?subject=:.prod:"
{"subject":":.prod:Address","version":1,"guid":"a3d4c656-76ec-775d-35a1-1de29d031a17","schemaType":"AVRO","schema":"{\"type\":\"record\",\"name\":\"Address\",\"fields\":[{\"name\":\"street\",\"type\":\"string\"},{\"name\":\"city\",\"type\":\"string\"}]}","ts":1769688254717,"deleted":false}%                                                                                                                                                                                                                                    

% curl "http://localhost:8081/schemas/ids/1?subject=Address"
{"subject":":.prod:Address","version":1,"guid":"a3d4c656-76ec-775d-35a1-1de29d031a17","schemaType":"AVRO","schema":"{\"type\":\"record\",\"name\":\"Address\",\"fields\":[{\"name\":\"street\",\"type\":\"string\"},{\"name\":\"city\",\"type\":\"string\"}]}","ts":1769688254717,"deleted":false}%                                                                                                                                                                                                                                    

% curl "http://localhost:8081/schemas/ids/1?subject=:.:"
{"error_code":40403,"message":"Schema 1 not found"}%

% curl "http://localhost:8081/schemas/ids/1?subject=:.prod:NotAddress"
{"error_code":40403,"message":"Schema 1 not found"}%

% curl "http://localhost:8081/schemas/ids/1?subject=:.shared:NotAddress"
{"error_code":40403,"message":"Schema 1 not found"}%

I think we might need to treat the subject parameter differently depending on whether it contains only a context (empty subject) or a real subject.

To be honest, we might be able to get away with partial support of the parameter, by throwing if it contains a real subject, and not just a context. But if we can implement it fully, that would be great.

"required": false,
"type": "string",
"description": "Redpanda version 25.2 or later. For Avro and Protobuf schemas only. Supported values: an empty string `''` returns the schema in its current format (default), and `serialized` (Protobuf only) returns the schema in its Base64-encoded wire binary format. Unsupported values return a 501 error."
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I should have been clearer in the ticket, but can you please also implement this for GET /schemas/ids/{id}/versions and GET /schemas/ids/{id}/schema too, in addition to GET /schemas/ids/{id}?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants