MCPcopy Create free account
hub / github.com/github/gh-aw / CompileSchema

Function CompileSchema

pkg/parser/schema_compiler.go:121–145  ·  view source on GitHub ↗

CompileSchema compiles a JSON schema from a JSON string.

(schemaJSON, schemaURL string)

Source from the content-addressed store, hash-verified

119
120// CompileSchema compiles a JSON schema from a JSON string.
121func CompileSchema(schemaJSON, schemaURL string) (*jsonschema.Schema, error) {
122 schemaCompilerLog.Printf("Compiling JSON schema: %s", schemaURL)
123
124 // Create a new compiler
125 compiler := jsonschema.NewCompiler()
126
127 // Parse the schema JSON first
128 var schemaDoc any
129 if err := json.Unmarshal([]byte(schemaJSON), &schemaDoc); err != nil {
130 return nil, fmt.Errorf("failed to parse schema JSON: %w", err)
131 }
132
133 // Add the schema as a resource
134 if err := compiler.AddResource(schemaURL, schemaDoc); err != nil {
135 return nil, fmt.Errorf("failed to add schema resource: %w", err)
136 }
137
138 // Compile the schema
139 schema, err := compiler.Compile(schemaURL)
140 if err != nil {
141 return nil, fmt.Errorf("failed to compile schema: %w", err)
142 }
143
144 return schema, nil
145}
146
147// compileSchema preserves existing package-local call sites.
148func compileSchema(schemaJSON, schemaURL string) (*jsonschema.Schema, error) {

Callers 3

compileSchemaFunction · 0.92
TestCompileSchemaFunction · 0.85
compileSchemaFunction · 0.85

Calls 3

CompileMethod · 0.80
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by 1

TestCompileSchemaFunction · 0.68