Skip `for_each_task` when generating the bundle schema (#1204)

## Changes
Bundle schema generation does not support recursive API fields. This PR
skips generation for for_each_task until we add proper support for
recursive types in the bundle schema.

## Tests
Manually. This fixes the generation of the CLI and the bundle schema
command works as expected, with the sub-schema for `for_each_task` being
set to null in the output.
```
"for_each_task": null,
```
This commit is contained in:
shreyas-goenka 2024-02-13 19:43:47 +05:30 committed by GitHub
parent aa0c715930
commit 52b813bd8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View File

@ -71,6 +71,13 @@ func (reader *OpenapiReader) safeResolveRefs(root *jsonschema.Schema, tracker *t
return reader.traverseSchema(root, tracker) return reader.traverseSchema(root, tracker)
} }
key := *root.Reference key := *root.Reference
// HACK to unblock CLI release (13th Feb 2024). This is temporary until proper
// support for recursive types is added to the docs generator. PR: https://github.com/databricks/cli/pull/1204
if strings.Contains(key, "ForEachTask") {
return root, nil
}
if tracker.hasCycle(key) { if tracker.hasCycle(key) {
// self reference loops can be supported however the logic is non-trivial because // self reference loops can be supported however the logic is non-trivial because
// cross refernce loops are not allowed (see: http://json-schema.org/understanding-json-schema/structuring.html#recursion) // cross refernce loops are not allowed (see: http://json-schema.org/understanding-json-schema/structuring.html#recursion)

View File

@ -92,6 +92,12 @@ func jsonSchemaType(golangType reflect.Type) (jsonschema.Type, error) {
// //
// - tracker: Keeps track of types / traceIds seen during recursive traversal // - tracker: Keeps track of types / traceIds seen during recursive traversal
func safeToSchema(golangType reflect.Type, docs *Docs, traceId string, tracker *tracker) (*jsonschema.Schema, error) { func safeToSchema(golangType reflect.Type, docs *Docs, traceId string, tracker *tracker) (*jsonschema.Schema, error) {
// HACK to unblock CLI release (13th Feb 2024). This is temporary until proper
// support for recursive types is added to the schema generator. PR: https://github.com/databricks/cli/pull/1204
if traceId == "for_each_task" {
return nil, nil
}
// WE ERROR OUT IF THERE ARE CYCLES IN THE JSON SCHEMA // WE ERROR OUT IF THERE ARE CYCLES IN THE JSON SCHEMA
// There are mechanisms to deal with cycles though recursive identifiers in json // There are mechanisms to deal with cycles though recursive identifiers in json
// schema. However if we use them, we would need to make sure we are able to detect // schema. However if we use them, we would need to make sure we are able to detect