@@ -19,7 +19,9 @@ type resolvedSchemaBuildInput struct {
1919 ctx context.Context
2020 idx * index.SpecIndex
2121 valueNode * yaml.Node
22+ scopeNode * yaml.Node
2223 refNode * yaml.Node
24+ transformed * yaml.Node
2325 refLocation string
2426}
2527
@@ -41,7 +43,7 @@ func buildPropertyMap(ctx context.Context, parent *Schema, root *yaml.Node, idx
4143 propertyMap .Set (low.KeyReference [string ]{
4244 KeyNode : currentProp ,
4345 Value : currentProp .Value ,
44- }, buildSchemaProxy (resolved .ctx , resolved .idx , currentProp , resolved .valueNode , resolved .refNode , resolved .refLocation != "" , resolved .refLocation ))
46+ }, buildSchemaProxy (resolved .ctx , resolved .idx , currentProp , resolved .valueNode , resolved .scopeNode , resolved .refNode , resolved . transformed , resolved .refLocation ))
4547 }
4648
4749 return & low.NodeReference [* orderedmap.Map [low.KeyReference [string ], low.ValueReference [* SchemaProxy ]]]{
@@ -100,13 +102,9 @@ func (s *Schema) extractExtensions(root *yaml.Node) {
100102}
101103
102104// buildSchemaProxy builds out a SchemaProxy for a single node.
103- func buildSchemaProxy (ctx context.Context , idx * index.SpecIndex , kn , vn * yaml. Node , rf * yaml.Node , isRef bool , refLocation string ) low.ValueReference [* SchemaProxy ] {
105+ func buildSchemaProxy (ctx context.Context , idx * index.SpecIndex , kn , vn , scopeNode , rf , transformed * yaml.Node , refLocation string ) low.ValueReference [* SchemaProxy ] {
104106 sp := new (SchemaProxy )
105- if isRef {
106- sp .prepareForResolvedBuild (ctx , kn , vn , idx , refLocation , rf )
107- } else {
108- sp .prepareForResolvedBuild (ctx , kn , vn , idx , "" , nil )
109- }
107+ sp .prepareForResolvedBuild (ctx , kn , vn , scopeNode , idx , refLocation , rf , transformed )
110108 return low.ValueReference [* SchemaProxy ]{
111109 Value : sp ,
112110 ValueNode : sp .vn ,
@@ -130,7 +128,7 @@ func buildSchema(ctx context.Context, labelNode, valueNode *yaml.Node, idx *inde
130128 return low.ValueReference [* SchemaProxy ]{}, err
131129 }
132130
133- return buildSchemaProxy (resolved .ctx , resolved .idx , labelNode , resolved .valueNode , resolved .refNode , resolved .refLocation != "" , resolved .refLocation ), nil
131+ return buildSchemaProxy (resolved .ctx , resolved .idx , labelNode , resolved .valueNode , resolved .scopeNode , resolved .refNode , resolved . transformed , resolved .refLocation ), nil
134132}
135133
136134// buildSchemaList builds out child schemas for a parent schema. Expected to be an array of schema objects.
@@ -152,7 +150,7 @@ func buildSchemaList(ctx context.Context, labelNode, valueNode *yaml.Node, idx *
152150 if err != nil {
153151 return nil , err
154152 }
155- r := buildSchemaProxy (resolved .ctx , resolved .idx , resolved .valueNode , resolved .valueNode , resolved .refNode , resolved .refLocation != "" , resolved .refLocation )
153+ r := buildSchemaProxy (resolved .ctx , resolved .idx , resolved .valueNode , resolved .valueNode , resolved .scopeNode , resolved .refNode , resolved . transformed , resolved .refLocation )
156154 results = append (results , r )
157155 }
158156
@@ -190,17 +188,25 @@ func resolveSchemaBuildInput(ctx context.Context, valueNode *yaml.Node, idx *ind
190188 ctx : ctx ,
191189 idx : idx ,
192190 valueNode : valueNode ,
191+ scopeNode : valueNode ,
193192 }
194193
195194 if valueNode == nil {
196195 return resolved , nil
197196 }
198197
198+ if transformedValue , wasTransformed := transformSiblingRefNode (valueNode , idx ); wasTransformed {
199+ resolved .valueNode = transformedValue
200+ resolved .transformed = valueNode
201+ return resolved , nil
202+ }
203+
199204 if hasRef , _ , refLocation := utils .IsNodeRefValue (valueNode ); hasRef {
200205 ref , foundIdx , err , foundCtx := low .LocateRefNodeWithContext (ctx , valueNode , idx )
201206 if ref != nil {
202207 resolved .refNode = valueNode
203208 resolved .valueNode = ref
209+ resolved .scopeNode = ref
204210 resolved .refLocation = refLocation
205211 resolved .ctx = foundCtx
206212 resolved .idx = foundIdx
@@ -211,8 +217,16 @@ func resolveSchemaBuildInput(ctx context.Context, valueNode *yaml.Node, idx *ind
211217 resolved .refLocation = refLocation
212218 return resolved , nil
213219 }
214- return resolved , fmt . Errorf (errFormat , valueNode . Content [ 1 ]. Value , valueNode . Content [ 1 ]. Line , valueNode . Content [ 1 ]. Column )
220+ return resolved , schemaReferenceBuildError (errFormat , valueNode )
215221 }
216222
217223 return resolved , nil
218224}
225+
226+ func schemaReferenceBuildError (errFormat string , valueNode * yaml.Node ) error {
227+ refValue := valueNode .Content [1 ].Value
228+ if refValue == "" {
229+ refValue = "[empty]"
230+ }
231+ return fmt .Errorf (errFormat , refValue , valueNode .Content [1 ].Line , valueNode .Content [1 ].Column )
232+ }
0 commit comments