MCPcopy Create free account
hub / github.com/rilldata/rill / JSONSchemaForResourceType

Function JSONSchemaForResourceType

runtime/parser/schema.go:59–82  ·  view source on GitHub ↗

JSONSchemaForResourceType returns a JSON schema for validating the properties of a given resource type. Note: You can use ParseResourceKind to get the ResourceKind from a string.

(resourceType ResourceKind)

Source from the content-addressed store, hash-verified

57// JSONSchemaForResourceType returns a JSON schema for validating the properties of a given resource type.
58// Note: You can use ParseResourceKind to get the ResourceKind from a string.
59func JSONSchemaForResourceType(resourceType ResourceKind) (*jsonschema.Schema, error) {
60 // Ensure the schema is parsed
61 parsedResourceYAMLSchemaOnce.Do(func() {
62 var err error
63 parsedResourceYAMLSchema, err = parseSchemaFromYAML(resourceYAMLSchema)
64 if err != nil {
65 panic(fmt.Sprintf("failed to parse schema: %v", err))
66 }
67 })
68
69 // Look up the definition key for this resource type
70 defKey, ok := resourceKindToDefinitionKey[resourceType]
71 if !ok {
72 return nil, fmt.Errorf("no schema definition for resource type %v", resourceType)
73 }
74
75 // Get the definition from the schema
76 defSchema, ok := parsedResourceYAMLSchema.Definitions[defKey]
77 if !ok {
78 return nil, fmt.Errorf("schema definition %q not found", defKey)
79 }
80
81 return defSchema, nil
82}
83
84// parseSchemaFromYAML parses a JSON schema from YAML content.
85func parseSchemaFromYAML(yamlContent string) (*jsonschema.Schema, error) {

Callers 2

jsonSchemaForResourceFunction · 0.92

Calls 3

parseSchemaFromYAMLFunction · 0.85
DoMethod · 0.80
ErrorfMethod · 0.65

Tested by 1