Add Workaround for inconsistent API Response

This commit is contained in:
Samuel Lorch 2023-11-24 13:32:47 +01:00
parent 360cc3748e
commit e13f484bcb
2 changed files with 22 additions and 7 deletions

View file

@ -11,7 +11,7 @@ type ResourceType struct {
ID string `json:"id,omitempty"`
Slug string `json:"slug,omitempty"`
Description string `json:"description,omitempty"`
Definition string `json:"definition,omitempty"`
Definition json.RawMessage `json:"definition,omitempty"`
Created *Time `json:"created,omitempty"`
Modified *Time `json:"modified,omitempty"`
}

View file

@ -41,8 +41,23 @@ func validateSecretData(rType *api.ResourceType, secretData string) error {
var schemaDefinition api.ResourceTypeSchema
err := json.Unmarshal([]byte(rType.Definition), &schemaDefinition)
if err != nil {
// Workaround for inconsistant API Responses where sometime the Schema is embedded directly and sometimes it's escaped as a string
if err.Error() == "json: cannot unmarshal string into Go value of type api.ResourceTypeSchema" {
var tmp string
err = json.Unmarshal([]byte(rType.Definition), &tmp)
if err != nil {
return fmt.Errorf("Workaround Unmarshal Json Schema String: %w", err)
}
err = json.Unmarshal([]byte(tmp), &schemaDefinition)
if err != nil {
return fmt.Errorf("Workaround Unmarshal Json Schema: %w", err)
}
} else {
return fmt.Errorf("Unmarshal Json Schema: %w", err)
}
}
comp := jsonschema.NewCompiler()