Skip to content

Commit

Permalink
fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Simun17 committed Jan 9, 2025
1 parent a5a63d3 commit e55fb8a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions registry/server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"encoding/json"
"io"
"net/http"
"slices"
"strings"

"github.com/dataphos/schema-registry/registry"
Expand All @@ -29,7 +28,7 @@ type responseBodyAndCode struct {
Code int
}

var SupportedFormats = []string{"json", "avro", "xml", "csv", "protobuf"}
var supportedFormats = []string{"json", "avro", "xml", "csv", "protobuf"}

func writeResponse(w http.ResponseWriter, response responseBodyAndCode) {
w.Header().Set("Content-Type", "application/json")
Expand All @@ -55,13 +54,22 @@ func readSchemaRegisterRequest(body io.ReadCloser) (registry.SchemaRegistrationR

// check if format is unknown
format := strings.ToLower(schemaRegisterRequest.SchemaType)
if !slices.Contains(SupportedFormats, format) {
if !containsFormat(format) {
return registry.SchemaRegistrationRequest{}, registry.ErrUnknownFormat
}

return schemaRegisterRequest, nil
}

func containsFormat(format string) bool {
for _, supportedFormat := range supportedFormats {
if format == supportedFormat {
return true
}
}
return false
}

func readSchemaUpdateRequest(body io.ReadCloser) (registry.SchemaUpdateRequest, error) {
encoded, err := io.ReadAll(body)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static boolean checkValidity(String schemaType, String schema, String mod
case "full" -> ValidityLevel.FULL;
default -> ValidityLevel.NONE;
};
ContentValidator validator = ValidatorFactory.createValidator(schemaType);
ContentValidator validator = ValidatorFactory.createValidator(schemaType.toLowerCase());
if (validator == null) { // in case ValidatorFactory returns null
return false;
}
Expand Down

0 comments on commit e55fb8a

Please sign in to comment.