mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
move schema to an internal package
This commit is contained in:
50
internal/schema/modules.go
Normal file
50
internal/schema/modules.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"github.com/google/jsonschema-go/jsonschema"
|
||||
"github.com/jwetzell/showbridge-go/internal/module"
|
||||
)
|
||||
|
||||
func GetModulesSchema() *jsonschema.Schema {
|
||||
|
||||
schema := &jsonschema.Schema{
|
||||
Schema: "https://json-schema.org/draft/2020-12/schema",
|
||||
ID: "https://showbridge.io/modules.schema.json",
|
||||
Title: "Modules",
|
||||
Description: "module configurations",
|
||||
Type: "array",
|
||||
}
|
||||
|
||||
moduleDefinitionSchemas := []*jsonschema.Schema{}
|
||||
for _, mod := range module.ModuleRegistry {
|
||||
moduleSchema := &jsonschema.Schema{
|
||||
Type: "object",
|
||||
Properties: map[string]*jsonschema.Schema{
|
||||
"id": {
|
||||
Type: "string",
|
||||
MinLength: jsonschema.Ptr(1),
|
||||
},
|
||||
"type": {
|
||||
Const: jsonschema.Ptr[any](mod.Type),
|
||||
},
|
||||
},
|
||||
Required: []string{"id", "type"},
|
||||
AdditionalProperties: nil,
|
||||
}
|
||||
if mod.Title != "" {
|
||||
moduleSchema.Title = mod.Title
|
||||
}
|
||||
if mod.Description != "" {
|
||||
moduleSchema.Description = mod.Description
|
||||
}
|
||||
if mod.ParamsSchema != nil {
|
||||
moduleSchema.Properties["params"] = mod.ParamsSchema
|
||||
moduleSchema.Required = append(moduleSchema.Required, "params")
|
||||
}
|
||||
moduleDefinitionSchemas = append(moduleDefinitionSchemas, moduleSchema)
|
||||
}
|
||||
schema.Items = &jsonschema.Schema{
|
||||
OneOf: moduleDefinitionSchemas,
|
||||
}
|
||||
return schema
|
||||
}
|
||||
Reference in New Issue
Block a user