Skip to content

Disallow dotted fields#591

Merged
mrodm merged 5 commits intoelastic:mainfrom
mrodm:disallow_dotted_fields
Sep 12, 2023
Merged

Disallow dotted fields#591
mrodm merged 5 commits intoelastic:mainfrom
mrodm:disallow_dotted_fields

Conversation

@mrodm
Copy link
Copy Markdown
Contributor

@mrodm mrodm commented Sep 12, 2023

What does this PR do?

This PR disallows to use fields with dots. For instance:

conditions:
  kibana.version: ^8.8.0

Those files should be updated to:

conditions:
  kibana:
    version: ^8.8.0

Why is it important?

Allowing dotted fields leads to ambiguous specifications.

Checklist

Related issues

@mrodm mrodm self-assigned this Sep 12, 2023
@mrodm mrodm marked this pull request as ready for review September 12, 2023 08:46
@mrodm mrodm requested a review from a team as a code owner September 12, 2023 08:46
jsoriano
jsoriano previously approved these changes Sep 12, 2023
Copy link
Copy Markdown
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Looks good, added a couple of nitpicks.

}

func loadItemSchema(fsys fs.FS, path string, contentType *spectypes.ContentType) ([]byte, error) {
func loadItemSchema(fsys fs.FS, path string, contentType *spectypes.ContentType, specVersion *semver.Version) ([]byte, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to pass by pointer here, right?

Suggested change
func loadItemSchema(fsys fs.FS, path string, contentType *spectypes.ContentType, specVersion *semver.Version) ([]byte, error) {
func loadItemSchema(fsys fs.FS, path string, contentType *spectypes.ContentType, specVersion semver.Version) ([]byte, error) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

True, it can be passed by value. I'll change it

}
if contentType != nil && contentType.MediaType == "application/x-yaml" {
return convertYAMLToJSON(data)
return convertYAMLToJSON(data, specVersion.LessThan(semver.MustParse("3.0.0")))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit. Consider extracting the parsed version to a constant.

@elasticmachine
Copy link
Copy Markdown

💚 Build Succeeded

History

cc @mrodm

Copy link
Copy Markdown
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

@mrodm mrodm merged commit 6bbaece into elastic:main Sep 12, 2023
@mrodm mrodm deleted the disallow_dotted_fields branch September 12, 2023 14:35
@andrewkroh
Copy link
Copy Markdown
Member

Awesome! 🏆

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.

[Proposal] Disallow dotted YAML key names

4 participants