Skip to content

Make restApiVersion on XContentBuilder final #70878

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

Merged

Conversation

pgomulka
Copy link
Contributor

@pgomulka pgomulka commented Mar 25, 2021

When passing in restApiVersion during creation of XContentBuilder
it makes it more clear that this field is final.
This prevents accidental change of the version during the xcontent
creation.
The withCompatibleVersion method can also be removed, since the field
only needs to be set in constructor.

relates #51816

When passing in restApiVersion during creation of XContentBuilder
it makes it more clear that this field is final.
This prevents accidental change of the version during the xcontent
creation.
The withCompatibleVersion method can also be removed, since the field
only needs to be set in constructor.
@pgomulka pgomulka self-assigned this Mar 26, 2021
@pgomulka pgomulka added :Core/Infra/REST API REST infrastructure and utilities v8.0.0 labels Mar 26, 2021
@pgomulka pgomulka marked this pull request as ready for review March 26, 2021 08:57
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Mar 26, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@pgomulka pgomulka requested review from joegallo and jakelandis March 26, 2021 08:58
@pgomulka
Copy link
Contributor Author

@elasticmachine update branch

Copy link
Contributor

@jakelandis jakelandis left a comment

Choose a reason for hiding this comment

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

Changes look good, I like that you were able to find an non-intrusrive solution here.

One nitpick about java doc, and I would have (very) minor preference to expose an additional constructor (i.e. preserve the original and default current API version) so that the cases that don't care about REST API compatibility can remain blissfully ignorant of it.

@@ -188,13 +198,15 @@ public XContentBuilder(XContentType xContentType, OutputStream bos, Set<String>
* @param includes the inclusive filters: only fields and objects that match the inclusive filters will be written to the output.
* @param excludes the exclusive filters: only fields and objects that don't match the exclusive filters will be written to the output.
* @param responseContentType a content-type header value to be send back on a response
* @param restApiVersion
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: javadoc

@@ -511,7 +512,7 @@ public static InputStream filterToXContent(HttpRequest request, XContentType xCo
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
XContentBuilder filteredBuilder = new XContentBuilder(xContentType.xContent(), bos,
Collections.emptySet(), Collections.singleton(excludeField),
xContentType.toParsedMediaType())) {
xContentType.toParsedMediaType(), RestApiVersion.current())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I hate the idea of more constructors ... but I wonder if it makes sense here to de-emphasize that RestApiVersion is non-consequential.

The additional constructor, would be the original constructor prior to the PR that would set RestAPIVersion to current(). That way use cases like this (and enrich) that don't care about REST API compatibility don't need to concern themselves here.

…omulka/elasticsearch into compat/remove_with_compatible_version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/REST API REST infrastructure and utilities >refactoring Team:Core/Infra Meta label for core/infra team v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants