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

[content management / maps] Content management / Saved object schema abstraction #155342

Merged
merged 37 commits into from
Apr 27, 2023

Conversation

mattkime
Copy link
Contributor

@mattkime mattkime commented Apr 20, 2023

Summary

Abstract schema definitions for using Saved Objects with the content management api. For most schema types, this will reduce creation to only the attributes specific to a saved object. For Option types (create options, update options, search options) the saved object api is more complex and its likely that most SO types will only need to use a portion of it. In these cases we recommend using the provided schema definitions as a pattern for creating simpler schemas.

Follow up to - #154985 - expresses types in schema form

@mattkime mattkime changed the title Content management code abstraction [content management / maps] schema abstraction Apr 20, 2023
@mattkime mattkime changed the title [content management / maps] schema abstraction [content management / maps] Content management / Saved object schema abstraction Apr 25, 2023
@mattkime mattkime added Feature:Content Management User generated content (saved objects) management Feature:Maps Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. release_note:skip Skip the PR/issue when compiling release notes labels Apr 25, 2023
@mattkime mattkime marked this pull request as ready for review April 25, 2023 02:18
@mattkime mattkime requested review from a team as code owners April 25, 2023 02:18
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@mattkime mattkime requested a review from sebelga April 25, 2023 02:18
Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

Code-only review, schemas LGTM 👍

Copy link
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

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

LGTM

Out of scope for the work of this PR but I wonder if we don't want to leave the mapAttributesSchema (which is the main schema for a SO type) loose.

Only for the "result -> out" (so createResultSchema and objectTypeToGetResultSchema). Not for what comes "in" which should be strict.

Basically changing the { unknowns: 'forbid' } to { unknowns: 'allow / ignore' }. This would allow adding new fields without throwing when validating the schema. New fields are not breaking change and should also be fine in the UI. WDYT?

export const schemaAndOr = schema.oneOf([schema.literal('AND'), schema.literal('OR')]);

// its recommended to create a subset of this schema for stricter validation
export const searchOptionsSchema = schema.object({
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better then to expose the properties separately for composing the schema then?

export const searchOptionsSchemaProperties = {
  page: schema.maybe(schema.number()),
  perPage: schema.maybe(schema.number()),
  sortField: schema.maybe(schema.string()),
  ...
}

// consumer side
const { sortField } = searchOptionsSchemaProperties;

const mySearchOptionsSchema = schema.object({
  sortField
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thats a good idea, will do.

@mattkime
Copy link
Contributor Author

@sebelga

New fields are not breaking change and should also be fine in the UI. WDYT?

I agree that its not necessary to have strict validation regarding new fields however it seems to me that we should have well defined schemas if possible. I think its the same as having good types with typescript code.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/content-management-utils 15 57 +42
Unknown metric groups

API count

id before after diff
@kbn/content-management-utils 64 106 +42

ESLint disabled line counts

id before after diff
enterpriseSearch 17 19 +2
securitySolution 399 402 +3
total +5

Total ESLint disabled count

id before after diff
enterpriseSearch 18 20 +2
securitySolution 479 482 +3
total +5

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @mattkime

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

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

kibana-gis changes LGTM
code review

@mattkime mattkime merged commit 0c8f38b into elastic:main Apr 27, 2023
@kibanamachine kibanamachine added v8.9.0 backport:skip This commit does not require backporting labels Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Content Management User generated content (saved objects) management Feature:Maps release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v8.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants