Validate schemas without relying on source filenames
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user