@@ -44,6 +44,14 @@ type SchemaRegistrySubject struct {
4444 IsSoftDeleted bool `json:"isSoftDeleted"`
4545}
4646
47+ // SchemaRegistryContext represents a schema registry context along with
48+ // its mode and compatibility settings.
49+ type SchemaRegistryContext struct {
50+ Name string `json:"name"`
51+ Mode string `json:"mode"`
52+ Compatibility string `json:"compatibility"`
53+ }
54+
4755// For Schema Registry compatibility level and mode we have 2 custom responses:
4856// - DEFAULT: there is no per-subject configuration set.
4957// - UNKNOWN: there is an error, and we are unable to get the configuration.
@@ -674,24 +682,27 @@ func (s *Service) CreateSchemaRegistrySchema(ctx context.Context, subjectName st
674682 ctx = sr .WithParams (ctx , sr .Normalize )
675683 }
676684
677- subjectSchema , err := srClient .CreateSchema (ctx , subjectName , schema )
685+ // Use RegisterSchema instead of CreateSchema to avoid a follow-up
686+ // SchemaUsagesByID call that fails for named contexts (schema IDs
687+ // are context-scoped, but the lookup doesn't include context).
688+ schemaID , err := srClient .RegisterSchema (ctx , subjectName , schema , - 1 , - 1 )
678689 if err != nil {
679690 // If metadata was included and we got a parse error, retry without metadata.
680691 // Older Redpanda versions don't support the metadata field.
681692 if schema .SchemaMetadata != nil {
682693 s .logger .WarnContext (ctx , "retrying schema creation without metadata (unsupported by this Redpanda version)" ,
683694 slog .String ("subject" , subjectName ))
684695 schema .SchemaMetadata = nil
685- subjectSchema , err = srClient .CreateSchema (ctx , subjectName , schema )
696+ schemaID , err = srClient .RegisterSchema (ctx , subjectName , schema , - 1 , - 1 )
686697 if err != nil {
687698 return nil , err
688699 }
689- return & CreateSchemaResponse {ID : subjectSchema . ID }, nil
700+ return & CreateSchemaResponse {ID : schemaID }, nil
690701 }
691702 return nil , err
692703 }
693704
694- return & CreateSchemaResponse {ID : subjectSchema . ID }, nil
705+ return & CreateSchemaResponse {ID : schemaID }, nil
695706}
696707
697708// SchemaRegistrySchemaValidation is the response to a schema validation.
@@ -878,6 +889,46 @@ func (s *Service) CheckSchemaRegistryACLSupport(ctx context.Context) bool {
878889 return true
879890}
880891
892+ // GetSchemaRegistryContexts returns all contexts available in the schema registry,
893+ // enriched with per-context mode and compatibility settings.
894+ func (s * Service ) GetSchemaRegistryContexts (ctx context.Context ) ([]SchemaRegistryContext , error ) {
895+ srClient , err := s .schemaClientFactory .GetSchemaRegistryClient (ctx )
896+ if err != nil {
897+ return nil , err
898+ }
899+
900+ names , err := srClient .Contexts (ctx )
901+ if err != nil {
902+ return nil , err
903+ }
904+
905+ results := make ([]SchemaRegistryContext , len (names ))
906+ grp , grpCtx := errgroup .WithContext (ctx )
907+ grp .SetLimit (10 )
908+
909+ for i , name := range names {
910+ grp .Go (func () error {
911+ // For default context ".", query with empty subject to get global values.
912+ // For named contexts, use qualified syntax :.contextName:
913+ qualifiedSubject := ""
914+ if name != "." {
915+ qualifiedSubject = ":" + name + ":"
916+ }
917+ results [i ] = SchemaRegistryContext {
918+ Name : name ,
919+ Mode : s .getSubjectMode (grpCtx , srClient , qualifiedSubject ),
920+ Compatibility : s .getSubjectCompatibilityLevel (grpCtx , srClient , qualifiedSubject ),
921+ }
922+ return nil
923+ })
924+ }
925+
926+ if err := grp .Wait (); err != nil {
927+ return nil , err
928+ }
929+ return results , nil
930+ }
931+
881932// CheckSchemaRegistryContextsSupport checks if the Schema Registry supports
882933// the Contexts feature. For Redpanda clusters with Admin API, it checks the
883934// cluster config. For Kafka clusters, it probes the /contexts endpoint.
@@ -915,8 +966,7 @@ func (s *Service) CheckSchemaRegistryContextsSupport(ctx context.Context) bool {
915966 return false
916967 }
917968
918- var contexts []string
919- err = srClient .Do (ctx , http .MethodGet , "/contexts" , nil , & contexts )
969+ _ , err = srClient .Contexts (ctx )
920970 if err != nil {
921971 var se * sr.ResponseError
922972 if errors .As (err , & se ) && se .StatusCode == http .StatusNotFound {
0 commit comments