generate json-schema dynamically in Go

This commit is contained in:
Joel Wetzell
2026-03-23 12:11:10 -05:00
parent 0922ece656
commit 842495f010
77 changed files with 1319 additions and 1659 deletions

28
internal/config/api.go Normal file
View File

@@ -0,0 +1,28 @@
package config
import (
"encoding/json"
"github.com/google/jsonschema-go/jsonschema"
)
type ApiConfig struct {
Enabled bool `json:"enabled"`
Port int `json:"port"`
}
var ApiConfigSchema = jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"enabled": {
Type: "boolean",
Description: "Whether the API server is enabled",
Default: json.RawMessage(`false`),
},
"port": {
Type: "integer",
Description: "Port for the API server to listen on",
},
},
Required: []string{"port"},
}

View File

@@ -1,27 +1,28 @@
package config
import (
"github.com/google/jsonschema-go/jsonschema"
)
type Config struct {
Api ApiConfig `json:"api"`
Modules []ModuleConfig `json:"modules"`
Routes []RouteConfig `json:"routes"`
}
type ApiConfig struct {
Enabled bool `json:"enabled"`
Port int `json:"port"`
}
type ModuleConfig struct {
Id string `json:"id"`
Type string `json:"type"`
Params Params `json:"params,omitempty"`
}
type RouteConfig struct {
Input string `json:"input"`
Processors []ProcessorConfig `json:"processors"`
}
type ProcessorConfig struct {
Type string `json:"type"`
Params Params `json:"params,omitempty"`
var ConfigSchema = jsonschema.Schema{
Schema: "https://json-schema.org/draft/2020-12/schema",
ID: "https://showbridge.io/config.schema.json",
Title: "Config",
Description: "showbridge configuration",
Type: "object",
Properties: map[string]*jsonschema.Schema{
"api": &ApiConfigSchema,
"modules": {
Ref: "https://showbridge.io/modules.schema.json",
},
"routes": {
Ref: "https://showbridge.io/routes.schema.json",
},
},
}

View File

@@ -0,0 +1,7 @@
package config
type ModuleConfig struct {
Id string `json:"id"`
Type string `json:"type"`
Params Params `json:"params,omitempty"`
}

View File

@@ -0,0 +1,6 @@
package config
type ProcessorConfig struct {
Type string `json:"type"`
Params Params `json:"params,omitempty"`
}

29
internal/config/route.go Normal file
View File

@@ -0,0 +1,29 @@
package config
import "github.com/google/jsonschema-go/jsonschema"
type RouteConfig struct {
Input string `json:"input"`
Processors []ProcessorConfig `json:"processors"`
}
var RoutesConfigSchema = jsonschema.Schema{
Schema: "https://json-schema.org/draft/2020-12/schema",
ID: "https://showbridge.io/routes.schema.json",
Title: "Routes",
Description: "route configurations",
Type: "array",
Items: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"input": {
Type: "string",
MinLength: jsonschema.Ptr(1),
},
"processors": {
Ref: "https://showbridge.io/processors.schema.json",
},
},
Required: []string{"input"},
},
}