From f3d5490cff3af3fea97cfdaeea2b366f7cdae29f Mon Sep 17 00:00:00 2001 From: Murad Biashimov Date: Thu, 25 Jul 2024 13:12:24 +0200 Subject: [PATCH] fix: service schema registry subject version get response --- Taskfile.yml | 2 +- .../kafkaschemaregistry.go | 50 +++++++++++++++---- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 5feea90..77889ec 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -15,11 +15,11 @@ tasks: cmds: - rm -rf {{.GEN_OUT_DIR}} - GEN_OUT_DIR={{.GEN_OUT_DIR}} go run -tags=generator ./generator/... + - task: fmt-imports generate: cmds: - task: get-openapi-spec - task: go-generate - - task: fmt-imports test: cmds: - go test -v ./... diff --git a/handler/kafkaschemaregistry/kafkaschemaregistry.go b/handler/kafkaschemaregistry/kafkaschemaregistry.go index 6f3b181..b9425ff 100644 --- a/handler/kafkaschemaregistry/kafkaschemaregistry.go +++ b/handler/kafkaschemaregistry/kafkaschemaregistry.go @@ -68,7 +68,7 @@ type Handler interface { // ServiceSchemaRegistrySubjectVersionGet get Schema Registry Subject version // GET /v1/project/{project}/service/{service_name}/kafka/schema/subjects/{subject_name}/versions/{version_id} // https://api.aiven.io/doc/#tag/Service:_Kafka/operation/ServiceSchemaRegistrySubjectVersionGet - ServiceSchemaRegistrySubjectVersionGet(ctx context.Context, project string, serviceName string, subjectName string, versionId int) error + ServiceSchemaRegistrySubjectVersionGet(ctx context.Context, project string, serviceName string, subjectName string, versionId int) (*ServiceSchemaRegistrySubjectVersionGetOut, error) // ServiceSchemaRegistrySubjectVersionPost register a new Schema in Schema Registry // POST /v1/project/{project}/service/{service_name}/kafka/schema/subjects/{subject_name}/versions @@ -222,10 +222,18 @@ func (h *KafkaSchemaRegistryHandler) ServiceSchemaRegistrySubjectVersionDelete(c _, err := h.doer.Do(ctx, "ServiceSchemaRegistrySubjectVersionDelete", "DELETE", path, nil) return err } -func (h *KafkaSchemaRegistryHandler) ServiceSchemaRegistrySubjectVersionGet(ctx context.Context, project string, serviceName string, subjectName string, versionId int) error { +func (h *KafkaSchemaRegistryHandler) ServiceSchemaRegistrySubjectVersionGet(ctx context.Context, project string, serviceName string, subjectName string, versionId int) (*ServiceSchemaRegistrySubjectVersionGetOut, error) { path := fmt.Sprintf("/v1/project/%s/service/%s/kafka/schema/subjects/%s/versions/%d", url.PathEscape(project), url.PathEscape(serviceName), url.PathEscape(subjectName), versionId) - _, err := h.doer.Do(ctx, "ServiceSchemaRegistrySubjectVersionGet", "GET", path, nil) - return err + b, err := h.doer.Do(ctx, "ServiceSchemaRegistrySubjectVersionGet", "GET", path, nil) + if err != nil { + return nil, err + } + out := new(serviceSchemaRegistrySubjectVersionGetOut) + err = json.Unmarshal(b, out) + if err != nil { + return nil, err + } + return &out.Version, nil } func (h *KafkaSchemaRegistryHandler) ServiceSchemaRegistrySubjectVersionPost(ctx context.Context, project string, serviceName string, subjectName string, in *ServiceSchemaRegistrySubjectVersionPostIn) (int, error) { path := fmt.Sprintf("/v1/project/%s/service/%s/kafka/schema/subjects/%s/versions", url.PathEscape(project), url.PathEscape(serviceName), url.PathEscape(subjectName)) @@ -310,6 +318,11 @@ type ReferenceIn struct { Subject string `json:"subject"` Version int `json:"version"` } +type ReferenceOut struct { + Name string `json:"name"` + Subject string `json:"subject"` + Version int `json:"version"` +} type SchemaType string const ( @@ -337,12 +350,22 @@ type ServiceSchemaRegistryCompatibilityIn struct { // ServiceSchemaRegistryGlobalConfigPutIn ServiceSchemaRegistryGlobalConfigPutRequestBody type ServiceSchemaRegistryGlobalConfigPutIn struct { - Compatibility CompatibilityType `json:"compatibility"` // Configuration + Compatibility CompatibilityType `json:"compatibility"` // Compatibility level } // ServiceSchemaRegistrySubjectConfigPutIn ServiceSchemaRegistrySubjectConfigPutRequestBody type ServiceSchemaRegistrySubjectConfigPutIn struct { - Compatibility CompatibilityType `json:"compatibility"` // Configuration + Compatibility CompatibilityType `json:"compatibility"` // Compatibility level +} + +// ServiceSchemaRegistrySubjectVersionGetOut Version +type ServiceSchemaRegistrySubjectVersionGetOut struct { + Id int `json:"id"` // Schema Id + References []ReferenceOut `json:"references,omitempty"` // Schema references + Schema string `json:"schema"` + SchemaType SchemaType `json:"schemaType"` // Schema type + Subject string `json:"subject"` + Version int `json:"version"` } // ServiceSchemaRegistrySubjectVersionPostIn ServiceSchemaRegistrySubjectVersionPostRequestBody @@ -374,27 +397,32 @@ type serviceSchemaRegistryCompatibilityOut struct { // serviceSchemaRegistryGlobalConfigGetOut ServiceSchemaRegistryGlobalConfigGetResponse type serviceSchemaRegistryGlobalConfigGetOut struct { - CompatibilityLevel CompatibilityType `json:"compatibilityLevel"` // Configuration + CompatibilityLevel CompatibilityType `json:"compatibilityLevel"` // Compatibility level } // serviceSchemaRegistryGlobalConfigPutOut ServiceSchemaRegistryGlobalConfigPutResponse type serviceSchemaRegistryGlobalConfigPutOut struct { - Compatibility CompatibilityType `json:"compatibility"` // Configuration + Compatibility CompatibilityType `json:"compatibility"` // Compatibility level } // serviceSchemaRegistrySubjectConfigGetOut ServiceSchemaRegistrySubjectConfigGetResponse type serviceSchemaRegistrySubjectConfigGetOut struct { - CompatibilityLevel CompatibilityType `json:"compatibilityLevel"` // Configuration + CompatibilityLevel CompatibilityType `json:"compatibilityLevel"` // Compatibility level } // serviceSchemaRegistrySubjectConfigPutOut ServiceSchemaRegistrySubjectConfigPutResponse type serviceSchemaRegistrySubjectConfigPutOut struct { - Compatibility CompatibilityType `json:"compatibility"` // Configuration + Compatibility CompatibilityType `json:"compatibility"` // Compatibility level +} + +// serviceSchemaRegistrySubjectVersionGetOut ServiceSchemaRegistrySubjectVersionGetResponse +type serviceSchemaRegistrySubjectVersionGetOut struct { + Version ServiceSchemaRegistrySubjectVersionGetOut `json:"version"` // Version } // serviceSchemaRegistrySubjectVersionPostOut ServiceSchemaRegistrySubjectVersionPostResponse type serviceSchemaRegistrySubjectVersionPostOut struct { - Id int `json:"id"` // Version + Id int `json:"id"` // Schema Id } // serviceSchemaRegistrySubjectVersionsGetOut ServiceSchemaRegistrySubjectVersionsGetResponse