mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-05-09 09:48:20 +00:00
Add Workaround for inconsistent API Response
This commit is contained in:
parent
360cc3748e
commit
e13f484bcb
2 changed files with 22 additions and 7 deletions
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue