@@ -61,8 +61,9 @@ type DereferenceOptions struct {
6161
6262// relativeFilePathPattern only accepts relative file path prefixes "./" and "../"
6363var relativeFilePathPattern = regexp .MustCompile (`^(\.\/|\.\.\/)` )
64- var massdriverDefinitionPattern = regexp .MustCompile (`^[a-zA-Z0-9] ` )
64+ var massdriverDefinitionPattern = regexp .MustCompile (`^[a-zA-Z0-9-]+\/[a-zA-Z0-9-]+$ ` )
6565var httpPattern = regexp .MustCompile (`^(http|https)://` )
66+ var fragmentPattern = regexp .MustCompile (`^#` )
6667
6768func DereferenceSchema (anyVal any , opts DereferenceOptions ) (any , error ) {
6869 val := getValue (anyVal )
@@ -89,7 +90,7 @@ func DereferenceSchema(anyVal any, opts DereferenceOptions) (any, error) {
8990
9091 var err error
9192 if relativeFilePathPattern .MatchString (schemaRefValue ) { //nolint:gocritic
92- // this is a local file ref
93+ // this is a relative file ref
9394 // build up the path from where the dir current schema was read
9495 hydratedSchema , err = dereferenceFilePathRef (hydratedSchema , schema , schemaRefValue , opts )
9596 } else if httpPattern .MatchString (schemaRefValue ) {
@@ -98,6 +99,9 @@ func DereferenceSchema(anyVal any, opts DereferenceOptions) (any, error) {
9899 } else if massdriverDefinitionPattern .MatchString (schemaRefValue ) {
99100 // this must be a published schema, so fetch from massdriver
100101 hydratedSchema , err = dereferenceMassdriverRef (hydratedSchema , schema , schemaRefValue , opts )
102+ } else if fragmentPattern .MatchString (schemaRefValue ) {
103+ // this is a fragment, so we do nothing and leave the schema as is
104+ // since fragments are not dereferenced in the same way as full schemas
101105 } else {
102106 return nil , fmt .Errorf ("unable to resolve ref: %s" , schemaRefValue )
103107 }
0 commit comments