Validate schemas without relying on source filenames

This commit is contained in:
2026-11-05 15:59:30 +00:00
parent ff57dbf8b3
commit ac1e150168
5 changed files with 86 additions and 1 deletions

View File

@@ -424,6 +424,20 @@ func (l externalSchemaLoader) Load(resourceURL string) (any, error) {
}
func compileSchemaDocument(ctx context.Context, resourceURL string, document any) (*jsonschema.Schema, error) {
root, err := compileSchemaAt(ctx, resourceURL, document)
if err != nil {
return nil, err
}
// File and private-FS retrieval URLs are never available to the provider.
// Compiling again under an unrelated HTTPS base detects reliance on those
// aliases without rewriting references or duplicating URI resolution rules.
if _, err := compileSchemaAt(ctx, "https://promptkit.invalid/submitted-schema", document); err != nil {
return nil, fmt.Errorf("schema is not independent of its source location; use fragment references or explicit schema IDs: %w", err)
}
return root, nil
}
func compileSchemaAt(ctx context.Context, resourceURL string, document any) (*jsonschema.Schema, error) {
if err := ctx.Err(); err != nil {
return nil, err
}