Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 'any' examples in JSON schema #2289

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

ilyakuz-db
Copy link
Contributor

@ilyakuz-db ilyakuz-db commented Feb 4, 2025

Changes

  1. Allow any examples in json-schema type since we have many of them in open api spec
  2. Fix issue with missing overrides annotations when re-generating the schema

Tests

@@ -79,7 +79,7 @@ type Schema struct {

// Examples of the value for properties in the schema.
// https://json-schema.org/understanding-json-schema/reference/annotations
Examples []any `json:"examples,omitempty"`
Examples any `json:"examples,omitempty"`
Copy link
Contributor Author

@ilyakuz-db ilyakuz-db Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also probably we could remove this field and add some custom field instead to use in docsgen. Currently it doesn't get any examples from doc and used only to keep this annotation example linked with particular json schema node

@@ -122,7 +124,11 @@ func (p *openapiParser) extractAnnotations(typ reflect.Type, outputPath, overrid
if err != nil {
return err
}
err = yaml.Unmarshal(b, &overrides)
overridesDyn, err := yamlloader.LoadYAML(overridesPath, bytes.NewBuffer(b))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced marshaller with our custom loader because it was expecting "yaml" tags in structure while we use "json" everywhere

@pietern pietern changed the title Allow 'any' examples in json-schema Allow 'any' examples in JSON schema Feb 4, 2025
Copy link
Contributor

@pietern pietern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain where/how the examples field is not an array?

github.com/databricks/databricks-sdk-go/service/apps.AppResource:
"job":
github.com/databricks/databricks-sdk-go/service/apps.AppDeployment:
"create_time":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did the reordering happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that previously there lines were added manually but now it was auto-sorted after regenerating

Will keep an eye in it to see if there are any issues with ordering

return ""
}
return examples[0].(string)
return examples[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can call getExamples to avoid duplicate type casts.

@pietern
Copy link
Contributor

pietern commented Feb 4, 2025

The docs state that examples must be an array (ref).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants