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
|
@ -4,4 +4,9 @@ title: SDK Test
|
||||||
version: 0.0.0
|
version: 0.0.0
|
||||||
description: |
|
description: |
|
||||||
Suite de tests pour le SDK client
|
Suite de tests pour le SDK client
|
||||||
tags: ["test"]
|
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" />
|
<meta charset="utf-8" />
|
||||||
<title>Client SDK Test suite</title>
|
<title>Client SDK Test suite</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<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" />
|
<link rel="stylesheet" href="/vendor/mocha.css" />
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
|
|
|
@ -12,12 +12,12 @@ import (
|
||||||
type ID string
|
type ID string
|
||||||
|
|
||||||
type Manifest struct {
|
type Manifest struct {
|
||||||
ID ID `yaml:"id" json:"id"`
|
ID ID `yaml:"id" json:"id"`
|
||||||
Version string `yaml:"version" json:"version"`
|
Version string `yaml:"version" json:"version"`
|
||||||
Title string `yaml:"title" json:"title"`
|
Title string `yaml:"title" json:"title"`
|
||||||
Description string `yaml:"description" json:"description"`
|
Description string `yaml:"description" json:"description"`
|
||||||
Tags []string `yaml:"tags" json:"tags"`
|
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)
|
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
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
paths, ok := rawPaths.(map[any]any)
|
paths, ok := rawPaths.(app.MapStr)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false, errors.Errorf("metadata['paths']: unexpected named path value type '%T'", rawPaths)
|
return false, errors.Errorf("metadata['paths']: unexpected named path value type '%T'", rawPaths)
|
||||||
}
|
}
|
||||||
|
|
||||||
for n, p := range paths {
|
for n, p := range paths {
|
||||||
name, ok := n.(string)
|
if _, exists := set[NamedPath(n)]; !exists {
|
||||||
if !ok {
|
return false, errors.Errorf("metadata['paths']: unexpected named path '%s'", n)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
path, ok := p.(string)
|
path, ok := p.(string)
|
||||||
if !ok {
|
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, "/") {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,12 @@ type Module struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type gojaManifest struct {
|
type gojaManifest struct {
|
||||||
ID string `goja:"id" json:"id"`
|
ID string `goja:"id" json:"id"`
|
||||||
Version string `goja:"version" json:"version"`
|
Version string `goja:"version" json:"version"`
|
||||||
Title string `goja:"title" json:"title"`
|
Title string `goja:"title" json:"title"`
|
||||||
Description string `goja:"description" json:"description"`
|
Description string `goja:"description" json:"description"`
|
||||||
Tags []string `goja:"tags" json:"tags"`
|
Tags []string `goja:"tags" json:"tags"`
|
||||||
|
Metadata map[string]any `goja:"metadata" json:"metadata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func toGojaManifest(manifest *app.Manifest) *gojaManifest {
|
func toGojaManifest(manifest *app.Manifest) *gojaManifest {
|
||||||
|
@ -28,6 +29,7 @@ func toGojaManifest(manifest *app.Manifest) *gojaManifest {
|
||||||
Title: manifest.Title,
|
Title: manifest.Title,
|
||||||
Description: manifest.Description,
|
Description: manifest.Description,
|
||||||
Tags: manifest.Tags,
|
Tags: manifest.Tags,
|
||||||
|
Metadata: manifest.Metadata,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue