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

Get field mapping api should honour pretty flag #8806

Closed
wants to merge 5 commits into from

Conversation

johtani
Copy link
Contributor

@johtani johtani commented Dec 7, 2014

Use builder.field method instead of XContentHelper#writeRawField

Closes #6552

responseBuilder.endObject();
String responseStrings = responseBuilder.string();

String expectedStrings ="{\n"+
Copy link
Member

Choose a reason for hiding this comment

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

This seems fragile, since any slight change in the format/structure would cause the test to break. Could we just check the output contains some newlines (which non pretty results would not)?

@bleskes
Copy link
Contributor

bleskes commented Dec 8, 2014

@johtani left one comment. I also agree @rjernst comment.

Change assertion more simple
Use writeRawField if pretty off

Closes elastic#6552
@johtani
Copy link
Contributor Author

johtani commented Dec 8, 2014

@rjernst @bleskes Thanks for reviewing.
I change the assertion and using writeRawField if pretty off.

Does it make sense?


assertTrue(responseStrings.contains("\"mapping\" : {\n"));

// pretty=false
Copy link
Member

Choose a reason for hiding this comment

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

This comment doesn't add any value

@rjernst
Copy link
Member

rjernst commented Dec 8, 2014

LGTM, just a couple suggestions.

@@ -81,7 +82,8 @@ public RestResponse buildResponse(GetFieldMappingsResponse response, XContentBui
status = NOT_FOUND;
}
builder.startObject();
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
Map<String, String> param = Maps.newHashMap();
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 be simplified to response.toXContent(builder,request);

@bleskes
Copy link
Contributor

bleskes commented Dec 8, 2014

Thx @johtani . Left one comment about the implementation.

@johtani
Copy link
Contributor Author

johtani commented Dec 9, 2014

Fix all comments

responseBuilder.endObject();
String responseStrings = responseBuilder.string();

assertFalse(responseStrings.contains(":{"));
Copy link
Member

Choose a reason for hiding this comment

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

I think checking for newline is better than relying on pretty printing having space between key/object...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rjernst I see...
I have no idea for good assertion.
Do you have any other idea?

Output without pretty

{
  "index" : {
    "mappings" : {
      "type" : {
        "obj.subfield" : {
          "full_name" : "obj.subfield",
          "mapping":{"subfield":{"type":"string","index":"not_analyzed"}}
        },
        "field1" : {
          "full_name" : "field1",
          "mapping":{"field1":{"type":"string"}}
        }
      }
    }
  }
}

Output with pretty

{
  "index" : {
    "mappings" : {
      "type" : {
        "obj.subfield" : {
          "full_name" : "obj.subfield",
          "mapping" : {
            "subfield" : {
              "type" : "string",
              "index" : "not_analyzed"
            }
          }
        },
        "field1" : {
          "full_name" : "field1",
          "mapping" : {
            "field1" : {
              "type" : "string"
            }
          }
        }
      }
    }
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe just take the output you get from the API and re-feed it to a builder you know is pretty printing and make sure the output is identical to the input?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thx @bleskes ! I changed the assertion and pushed. Does it make sense?

@bleskes
Copy link
Contributor

bleskes commented Dec 9, 2014

LGTM (note that @rjernst had a comment)

Change an assertion using re-parse pretty printing

Closes elastic#6552

XContentBuilder prettyJsonBuilder = XContentFactory.jsonBuilder().prettyPrint();
prettyJsonBuilder.copyCurrentStructure(XContentFactory.xContent(responseStrings).createParser(responseStrings));
assertThat(responseStrings, equalTo(prettyJsonBuilder.string()));
Copy link
Contributor

Choose a reason for hiding this comment

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

great. Thx.

@bleskes
Copy link
Contributor

bleskes commented Dec 10, 2014

LGTM :)


prettyJsonBuilder = XContentFactory.jsonBuilder().prettyPrint();
prettyJsonBuilder.copyCurrentStructure(XContentFactory.xContent(responseStrings).createParser(responseStrings));
assertThat(responseStrings,not(equalTo(prettyJsonBuilder.string())));
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be equal to the jsonBuilder().string() above, without adding .prettyPrint()? And a nitpick: please add a space after the comma..

@rjernst
Copy link
Member

rjernst commented Dec 10, 2014

@johtani Thanks, LGTM. I left one minor comment. No need for another review regardless of if/how that is addressed.

@johtani johtani added the v1.5.0 label Dec 11, 2014
@johtani
Copy link
Contributor Author

johtani commented Dec 12, 2014

Merged 80bd698

@johtani johtani closed this Dec 12, 2014
@clintongormley clintongormley added :Core/Infra/Transport API Transport client API >bug and removed review labels Mar 19, 2015
@clintongormley clintongormley added the :Core/Infra/REST API REST infrastructure and utilities label Jun 7, 2015
@clintongormley clintongormley removed the :Core/Infra/Transport API Transport client API label Jun 7, 2015
@clintongormley clintongormley changed the title Mappings: Fix Get field mapping api with pretty flag Get field mapping api should honour pretty flag Jun 7, 2015
@johtani johtani deleted the fix/pretty_get_field_mapping branch April 25, 2016 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get field mapping api doesn't honor pretty flag
4 participants