schema: expose InUse and Description.

This commit is contained in:
fiatjaf
2025-12-03 15:49:04 -03:00
parent 427e393460
commit 2502299e9c

View File

@@ -18,12 +18,12 @@ import (
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
const DefaultSchemaURL = "https://raw.githubusercontent.com/nostr-protocol/registry-of-kinds/daaa3a2a5573606aa0a4c4a98c25460ea9a1e388/schema.yaml" const DefaultSchemaURL = "https://raw.githubusercontent.com/nostr-protocol/registry-of-kinds/fa6e1bedc2d499eb01e716183089214e26a52877/schema.yaml"
// this is used by hex.Decode in the "hex" validator -- we don't care about data races // this is used by hex.Decode in the "hex" validator -- we don't care about data races
var hexdummydecoder = make([]byte, 128) var hexdummydecoder = make([]byte, 128)
func fetchSchemaFromURL(schemaURL string) (Schema, error) { func FetchSchemaFromURL(schemaURL string) (Schema, error) {
resp, err := http.Get(schemaURL) resp, err := http.Get(schemaURL)
if err != nil { if err != nil {
return Schema{}, fmt.Errorf("failed to fetch schema from URL: %w", err) return Schema{}, fmt.Errorf("failed to fetch schema from URL: %w", err)
@@ -50,9 +50,11 @@ type Schema struct {
} }
type KindSchema struct { type KindSchema struct {
Content nextSpec `yaml:"content"` Description string `yaml:"description"`
Required []string `yaml:"required"` InUse bool `yaml:"in_use"`
Tags []tagSpec `yaml:"tags"` Content nextSpec `yaml:"content"`
Required []string `yaml:"required"`
Tags []tagSpec `yaml:"tags"`
} }
type tagSpec struct { type tagSpec struct {
@@ -187,7 +189,7 @@ func NewValidatorFromFile(filename string) (Validator, error) {
} }
func NewValidatorFromURL(schemaURL string) (Validator, error) { func NewValidatorFromURL(schemaURL string) (Validator, error) {
schema, err := fetchSchemaFromURL(schemaURL) schema, err := FetchSchemaFromURL(schemaURL)
if err != nil { if err != nil {
return Validator{}, err return Validator{}, err
} }