move schema to an internal package

This commit is contained in:
Joel Wetzell
2026-03-23 12:51:26 -05:00
parent 256eeac6a8
commit 9a50ca8cfe
12 changed files with 223 additions and 159 deletions

View File

@@ -50,49 +50,3 @@ var (
func CreateLogger(config config.ModuleConfig) *slog.Logger {
return slog.Default().With("component", "module", "id", config.Id, "type", config.Type)
}
func GetModulesSchema() *jsonschema.Schema {
moduleRegistryMu.RLock()
defer moduleRegistryMu.RUnlock()
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 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
}