mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 04:20:17 +00:00
added context to schema buildout
model was failing on subschemas with refs, needed context Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
@@ -827,56 +827,56 @@ func (s *Schema) Build(ctx context.Context, root *yaml.Node, idx *index.SpecInde
|
|||||||
countSubSchemaItems(prefixItemsValue)
|
countSubSchemaItems(prefixItemsValue)
|
||||||
|
|
||||||
if allOfValue != nil {
|
if allOfValue != nil {
|
||||||
go buildSchema(allOfChan, allOfLabel, allOfValue, errorChan, idx)
|
go buildSchema(ctx, allOfChan, allOfLabel, allOfValue, errorChan, idx)
|
||||||
}
|
}
|
||||||
if anyOfValue != nil {
|
if anyOfValue != nil {
|
||||||
go buildSchema(anyOfChan, anyOfLabel, anyOfValue, errorChan, idx)
|
go buildSchema(ctx, anyOfChan, anyOfLabel, anyOfValue, errorChan, idx)
|
||||||
}
|
}
|
||||||
if oneOfValue != nil {
|
if oneOfValue != nil {
|
||||||
go buildSchema(oneOfChan, oneOfLabel, oneOfValue, errorChan, idx)
|
go buildSchema(ctx, oneOfChan, oneOfLabel, oneOfValue, errorChan, idx)
|
||||||
}
|
}
|
||||||
if prefixItemsValue != nil {
|
if prefixItemsValue != nil {
|
||||||
go buildSchema(prefixItemsChan, prefixItemsLabel, prefixItemsValue, errorChan, idx)
|
go buildSchema(ctx, prefixItemsChan, prefixItemsLabel, prefixItemsValue, errorChan, idx)
|
||||||
}
|
}
|
||||||
if notValue != nil {
|
if notValue != nil {
|
||||||
totalBuilds++
|
totalBuilds++
|
||||||
go buildSchema(notChan, notLabel, notValue, errorChan, idx)
|
go buildSchema(ctx, notChan, notLabel, notValue, errorChan, idx)
|
||||||
}
|
}
|
||||||
if containsValue != nil {
|
if containsValue != nil {
|
||||||
totalBuilds++
|
totalBuilds++
|
||||||
go buildSchema(containsChan, containsLabel, containsValue, errorChan, idx)
|
go buildSchema(ctx, containsChan, containsLabel, containsValue, errorChan, idx)
|
||||||
}
|
}
|
||||||
if !itemsIsBool && itemsValue != nil {
|
if !itemsIsBool && itemsValue != nil {
|
||||||
totalBuilds++
|
totalBuilds++
|
||||||
go buildSchema(itemsChan, itemsLabel, itemsValue, errorChan, idx)
|
go buildSchema(ctx, itemsChan, itemsLabel, itemsValue, errorChan, idx)
|
||||||
}
|
}
|
||||||
if sifValue != nil {
|
if sifValue != nil {
|
||||||
totalBuilds++
|
totalBuilds++
|
||||||
go buildSchema(ifChan, sifLabel, sifValue, errorChan, idx)
|
go buildSchema(ctx, ifChan, sifLabel, sifValue, errorChan, idx)
|
||||||
}
|
}
|
||||||
if selseValue != nil {
|
if selseValue != nil {
|
||||||
totalBuilds++
|
totalBuilds++
|
||||||
go buildSchema(elseChan, selseLabel, selseValue, errorChan, idx)
|
go buildSchema(ctx, elseChan, selseLabel, selseValue, errorChan, idx)
|
||||||
}
|
}
|
||||||
if sthenValue != nil {
|
if sthenValue != nil {
|
||||||
totalBuilds++
|
totalBuilds++
|
||||||
go buildSchema(thenChan, sthenLabel, sthenValue, errorChan, idx)
|
go buildSchema(ctx, thenChan, sthenLabel, sthenValue, errorChan, idx)
|
||||||
}
|
}
|
||||||
if propNamesValue != nil {
|
if propNamesValue != nil {
|
||||||
totalBuilds++
|
totalBuilds++
|
||||||
go buildSchema(propNamesChan, propNamesLabel, propNamesValue, errorChan, idx)
|
go buildSchema(ctx, propNamesChan, propNamesLabel, propNamesValue, errorChan, idx)
|
||||||
}
|
}
|
||||||
if unevalItemsValue != nil {
|
if unevalItemsValue != nil {
|
||||||
totalBuilds++
|
totalBuilds++
|
||||||
go buildSchema(unevalItemsChan, unevalItemsLabel, unevalItemsValue, errorChan, idx)
|
go buildSchema(ctx, unevalItemsChan, unevalItemsLabel, unevalItemsValue, errorChan, idx)
|
||||||
}
|
}
|
||||||
if !unevalIsBool && unevalPropsValue != nil {
|
if !unevalIsBool && unevalPropsValue != nil {
|
||||||
totalBuilds++
|
totalBuilds++
|
||||||
go buildSchema(unevalPropsChan, unevalPropsLabel, unevalPropsValue, errorChan, idx)
|
go buildSchema(ctx, unevalPropsChan, unevalPropsLabel, unevalPropsValue, errorChan, idx)
|
||||||
}
|
}
|
||||||
if !addPropsIsBool && addPropsValue != nil {
|
if !addPropsIsBool && addPropsValue != nil {
|
||||||
totalBuilds++
|
totalBuilds++
|
||||||
go buildSchema(addPropsChan, addPropsLabel, addPropsValue, errorChan, idx)
|
go buildSchema(ctx, addPropsChan, addPropsLabel, addPropsValue, errorChan, idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
completeCount := 0
|
completeCount := 0
|
||||||
@@ -1125,7 +1125,7 @@ func (s *Schema) extractExtensions(root *yaml.Node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// build out a child schema for parent schema.
|
// build out a child schema for parent schema.
|
||||||
func buildSchema(schemas chan schemaProxyBuildResult, labelNode, valueNode *yaml.Node, errors chan error, idx *index.SpecIndex) {
|
func buildSchema(ctx context.Context, schemas chan schemaProxyBuildResult, labelNode, valueNode *yaml.Node, errors chan error, idx *index.SpecIndex) {
|
||||||
if valueNode != nil {
|
if valueNode != nil {
|
||||||
type buildResult struct {
|
type buildResult struct {
|
||||||
res *low.ValueReference[*SchemaProxy]
|
res *low.ValueReference[*SchemaProxy]
|
||||||
@@ -1135,7 +1135,7 @@ func buildSchema(schemas chan schemaProxyBuildResult, labelNode, valueNode *yaml
|
|||||||
syncChan := make(chan buildResult)
|
syncChan := make(chan buildResult)
|
||||||
|
|
||||||
// build out a SchemaProxy for every sub-schema.
|
// build out a SchemaProxy for every sub-schema.
|
||||||
build := func(kn *yaml.Node, vn *yaml.Node, schemaIdx int, c chan buildResult,
|
build := func(pctx context.Context, kn *yaml.Node, vn *yaml.Node, schemaIdx int, c chan buildResult,
|
||||||
isRef bool, refLocation string,
|
isRef bool, refLocation string,
|
||||||
) {
|
) {
|
||||||
// a proxy design works best here. polymorphism, pretty much guarantees that a sub-schema can
|
// a proxy design works best here. polymorphism, pretty much guarantees that a sub-schema can
|
||||||
@@ -1148,6 +1148,7 @@ func buildSchema(schemas chan schemaProxyBuildResult, labelNode, valueNode *yaml
|
|||||||
sp.kn = kn
|
sp.kn = kn
|
||||||
sp.vn = vn
|
sp.vn = vn
|
||||||
sp.idx = idx
|
sp.idx = idx
|
||||||
|
sp.ctx = pctx
|
||||||
if isRef {
|
if isRef {
|
||||||
sp.referenceLookup = refLocation
|
sp.referenceLookup = refLocation
|
||||||
sp.isReference = true
|
sp.isReference = true
|
||||||
@@ -1164,13 +1165,15 @@ func buildSchema(schemas chan schemaProxyBuildResult, labelNode, valueNode *yaml
|
|||||||
|
|
||||||
isRef := false
|
isRef := false
|
||||||
refLocation := ""
|
refLocation := ""
|
||||||
|
foundCtx := ctx
|
||||||
if utils.IsNodeMap(valueNode) {
|
if utils.IsNodeMap(valueNode) {
|
||||||
h := false
|
h := false
|
||||||
if h, _, refLocation = utils.IsNodeRefValue(valueNode); h {
|
if h, _, refLocation = utils.IsNodeRefValue(valueNode); h {
|
||||||
isRef = true
|
isRef = true
|
||||||
ref, _, _ := low.LocateRefNode(valueNode, idx)
|
ref, _, _, fctx := low.LocateRefNodeWithContext(ctx, valueNode, idx)
|
||||||
if ref != nil {
|
if ref != nil {
|
||||||
valueNode = ref
|
valueNode = ref
|
||||||
|
foundCtx = fctx
|
||||||
} else {
|
} else {
|
||||||
errors <- fmt.Errorf("build schema failed: reference cannot be found: %s, line %d, col %d",
|
errors <- fmt.Errorf("build schema failed: reference cannot be found: %s, line %d, col %d",
|
||||||
valueNode.Content[1].Value, valueNode.Content[1].Line, valueNode.Content[1].Column)
|
valueNode.Content[1].Value, valueNode.Content[1].Line, valueNode.Content[1].Column)
|
||||||
@@ -1179,7 +1182,7 @@ func buildSchema(schemas chan schemaProxyBuildResult, labelNode, valueNode *yaml
|
|||||||
|
|
||||||
// this only runs once, however to keep things consistent, it makes sense to use the same async method
|
// this only runs once, however to keep things consistent, it makes sense to use the same async method
|
||||||
// that arrays will use.
|
// that arrays will use.
|
||||||
go build(labelNode, valueNode, -1, syncChan, isRef, refLocation)
|
go build(foundCtx, labelNode, valueNode, -1, syncChan, isRef, refLocation)
|
||||||
select {
|
select {
|
||||||
case r := <-syncChan:
|
case r := <-syncChan:
|
||||||
schemas <- schemaProxyBuildResult{
|
schemas <- schemaProxyBuildResult{
|
||||||
@@ -1199,9 +1202,10 @@ func buildSchema(schemas chan schemaProxyBuildResult, labelNode, valueNode *yaml
|
|||||||
h := false
|
h := false
|
||||||
if h, _, refLocation = utils.IsNodeRefValue(vn); h {
|
if h, _, refLocation = utils.IsNodeRefValue(vn); h {
|
||||||
isRef = true
|
isRef = true
|
||||||
ref, _, _ := low.LocateRefNode(vn, idx)
|
ref, _, _, fctx := low.LocateRefNodeWithContext(ctx, vn, idx)
|
||||||
if ref != nil {
|
if ref != nil {
|
||||||
vn = ref
|
vn = ref
|
||||||
|
foundCtx = fctx
|
||||||
} else {
|
} else {
|
||||||
err := fmt.Errorf("build schema failed: reference cannot be found: %s, line %d, col %d",
|
err := fmt.Errorf("build schema failed: reference cannot be found: %s, line %d, col %d",
|
||||||
vn.Content[1].Value, vn.Content[1].Line, vn.Content[1].Column)
|
vn.Content[1].Value, vn.Content[1].Line, vn.Content[1].Column)
|
||||||
@@ -1210,7 +1214,7 @@ func buildSchema(schemas chan schemaProxyBuildResult, labelNode, valueNode *yaml
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
refBuilds++
|
refBuilds++
|
||||||
go build(vn, vn, i, syncChan, isRef, refLocation)
|
go build(foundCtx, vn, vn, i, syncChan, isRef, refLocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
completedBuilds := 0
|
completedBuilds := 0
|
||||||
|
|||||||
@@ -601,7 +601,6 @@ func ExtractMapExtensions[PT Buildable[N], N any](
|
|||||||
idx *index.SpecIndex,
|
idx *index.SpecIndex,
|
||||||
extensions bool,
|
extensions bool,
|
||||||
) (map[KeyReference[string]]ValueReference[PT], *yaml.Node, *yaml.Node, error) {
|
) (map[KeyReference[string]]ValueReference[PT], *yaml.Node, *yaml.Node, error) {
|
||||||
//var isReference bool
|
|
||||||
var referenceValue string
|
var referenceValue string
|
||||||
var labelNode, valueNode *yaml.Node
|
var labelNode, valueNode *yaml.Node
|
||||||
var circError error
|
var circError error
|
||||||
@@ -612,7 +611,6 @@ func ExtractMapExtensions[PT Buildable[N], N any](
|
|||||||
if ref != nil {
|
if ref != nil {
|
||||||
valueNode = ref
|
valueNode = ref
|
||||||
labelNode = rl
|
labelNode = rl
|
||||||
//isReference = true
|
|
||||||
referenceValue = rv
|
referenceValue = rv
|
||||||
if err != nil {
|
if err != nil {
|
||||||
circError = err
|
circError = err
|
||||||
@@ -629,7 +627,6 @@ func ExtractMapExtensions[PT Buildable[N], N any](
|
|||||||
ref, fIdx, err, nCtx := LocateRefNodeWithContext(ctx, valueNode, idx)
|
ref, fIdx, err, nCtx := LocateRefNodeWithContext(ctx, valueNode, idx)
|
||||||
if ref != nil {
|
if ref != nil {
|
||||||
valueNode = ref
|
valueNode = ref
|
||||||
//isReference = true
|
|
||||||
referenceValue = rvt
|
referenceValue = rvt
|
||||||
idx = fIdx
|
idx = fIdx
|
||||||
ctx = nCtx
|
ctx = nCtx
|
||||||
@@ -662,9 +659,7 @@ func ExtractMapExtensions[PT Buildable[N], N any](
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//isRef := false
|
|
||||||
if ref != "" {
|
if ref != "" {
|
||||||
//isRef = true
|
|
||||||
SetReference(n, ref)
|
SetReference(n, ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -676,7 +671,6 @@ func ExtractMapExtensions[PT Buildable[N], N any](
|
|||||||
v: ValueReference[PT]{
|
v: ValueReference[PT]{
|
||||||
Value: n,
|
Value: n,
|
||||||
ValueNode: value,
|
ValueNode: value,
|
||||||
//IsReference: isRef,
|
|
||||||
Reference: ref,
|
Reference: ref,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user