mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-05-09 17: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
|
@ -8,12 +8,12 @@ import (
|
||||||
|
|
||||||
// ResourceType is the Type of a Resource
|
// ResourceType is the Type of a Resource
|
||||||
type ResourceType struct {
|
type ResourceType struct {
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
Slug string `json:"slug,omitempty"`
|
Slug string `json:"slug,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Definition string `json:"definition,omitempty"`
|
Definition json.RawMessage `json:"definition,omitempty"`
|
||||||
Created *Time `json:"created,omitempty"`
|
Created *Time `json:"created,omitempty"`
|
||||||
Modified *Time `json:"modified,omitempty"`
|
Modified *Time `json:"modified,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResourceTypeSchema struct {
|
type ResourceTypeSchema struct {
|
||||||
|
|
|
@ -41,7 +41,22 @@ func validateSecretData(rType *api.ResourceType, secretData string) error {
|
||||||
var schemaDefinition api.ResourceTypeSchema
|
var schemaDefinition api.ResourceTypeSchema
|
||||||
err := json.Unmarshal([]byte(rType.Definition), &schemaDefinition)
|
err := json.Unmarshal([]byte(rType.Definition), &schemaDefinition)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unmarshal Json Schema: %w", err)
|
// 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()
|
comp := jsonschema.NewCompiler()
|
||||||
|
|
Loading…
Add table
Reference in a new issue