fix(app,manifest): manifest serialization
arcad/edge/pipeline/head This commit looks good
Details
arcad/edge/pipeline/head This commit looks good
Details
This commit is contained in:
parent
98ebd7a168
commit
f5283b86ed
|
@ -5,3 +5,8 @@ version: 0.0.0
|
|||
description: |
|
||||
Suite de tests pour le SDK client
|
||||
tags: ["test"]
|
||||
|
||||
metadata:
|
||||
paths:
|
||||
icon: /icon.png
|
||||
minimumRole: visitor
|
Binary file not shown.
After Width: | Height: | Size: 77 KiB |
|
@ -4,6 +4,7 @@
|
|||
<meta charset="utf-8" />
|
||||
<title>Client SDK Test suite</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="icon" type="image/png" href="/icon.png">
|
||||
<link rel="stylesheet" href="/vendor/mocha.css" />
|
||||
<style>
|
||||
body {
|
||||
|
|
|
@ -17,7 +17,7 @@ type Manifest struct {
|
|||
Title string `yaml:"title" json:"title"`
|
||||
Description string `yaml:"description" json:"description"`
|
||||
Tags []string `yaml:"tags" json:"tags"`
|
||||
Metadata map[string]any `yaml:"metadata" json:"metadata"`
|
||||
Metadata MapStr `yaml:"metadata" json:"metadata"`
|
||||
}
|
||||
|
||||
type MetadataValidator func(map[string]any) (bool, error)
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type MapStr map[string]interface{}
|
||||
|
||||
func MapStrUnion(dict1 MapStr, dict2 MapStr) MapStr {
|
||||
dict := MapStr{}
|
||||
|
||||
for k, v := range dict1 {
|
||||
dict[k] = v
|
||||
}
|
||||
|
||||
for k, v := range dict2 {
|
||||
dict[k] = v
|
||||
}
|
||||
return dict
|
||||
}
|
||||
|
||||
func (ms *MapStr) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var result map[interface{}]interface{}
|
||||
err := unmarshal(&result)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
*ms = cleanUpInterfaceMap(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
func cleanUpInterfaceArray(in []interface{}) []interface{} {
|
||||
result := make([]interface{}, len(in))
|
||||
for i, v := range in {
|
||||
result[i] = cleanUpMapValue(v)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func cleanUpInterfaceMap(in map[interface{}]interface{}) MapStr {
|
||||
result := make(MapStr)
|
||||
for k, v := range in {
|
||||
result[fmt.Sprintf("%v", k)] = cleanUpMapValue(v)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func cleanUpMapValue(v interface{}) interface{} {
|
||||
switch v := v.(type) {
|
||||
case []interface{}:
|
||||
return cleanUpInterfaceArray(v)
|
||||
case map[interface{}]interface{}:
|
||||
return cleanUpInterfaceMap(v)
|
||||
case string:
|
||||
return v
|
||||
default:
|
||||
return fmt.Sprintf("%v", v)
|
||||
}
|
||||
}
|
|
@ -26,28 +26,23 @@ func WithNamedPathsValidator(names ...NamedPath) app.MetadataValidator {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
paths, ok := rawPaths.(map[any]any)
|
||||
paths, ok := rawPaths.(app.MapStr)
|
||||
if !ok {
|
||||
return false, errors.Errorf("metadata['paths']: unexpected named path value type '%T'", rawPaths)
|
||||
}
|
||||
|
||||
for n, p := range paths {
|
||||
name, ok := n.(string)
|
||||
if !ok {
|
||||
return false, errors.Errorf("metadata['paths']: unexpected named path type '%T'", n)
|
||||
}
|
||||
|
||||
if _, exists := set[NamedPath(name)]; !exists {
|
||||
return false, errors.Errorf("metadata['paths']: unexpected named path '%s'", name)
|
||||
if _, exists := set[NamedPath(n)]; !exists {
|
||||
return false, errors.Errorf("metadata['paths']: unexpected named path '%s'", n)
|
||||
}
|
||||
|
||||
path, ok := p.(string)
|
||||
if !ok {
|
||||
return false, errors.Errorf("metadata['paths']['%s']: unexpected named path value type '%T'", name, path)
|
||||
return false, errors.Errorf("metadata['paths']['%s']: unexpected named path value type '%T'", n, path)
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(path, "/") {
|
||||
return false, errors.Errorf("metadata['paths']['%s']: named path value should start with a '/'", name)
|
||||
return false, errors.Errorf("metadata['paths']['%s']: named path value should start with a '/'", n)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ type gojaManifest struct {
|
|||
Title string `goja:"title" json:"title"`
|
||||
Description string `goja:"description" json:"description"`
|
||||
Tags []string `goja:"tags" json:"tags"`
|
||||
Metadata map[string]any `goja:"metadata" json:"metadata"`
|
||||
}
|
||||
|
||||
func toGojaManifest(manifest *app.Manifest) *gojaManifest {
|
||||
|
@ -28,6 +29,7 @@ func toGojaManifest(manifest *app.Manifest) *gojaManifest {
|
|||
Title: manifest.Title,
|
||||
Description: manifest.Description,
|
||||
Tags: manifest.Tags,
|
||||
Metadata: manifest.Metadata,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue