Spring REST Docs duplicates query parameter without value in curl and HTTP request snippets - spring-restdocs

I'm using Spring REST Docs (2.0.3.RELEASE) and Spring Auto Restdocs (2.0.6) to document a REST API.
When the request contains a query parameter that has no assigned value (empty string) the snippets produced by CliDocumentation.curlRequest() and HttpDocumentation.httpRequest() show the parameter duplicated. For example:
$ curl 'http://localhost:7001/my.app/books?code=&code=' -i -X
This happens whether I do
this.mockMvc.perform(
get("/my.app/books?code=")
...
or
this.mockMvc.perform(
get("/my.app/books").param("code", "")
...
This is similar to issue and duplicate, however this only happens for valueless parameters and the bug mentioned there was fixed in version 1.1.2.RELEASE of Spring REST Docs.
Note: I assume the issue is not with Spring Auto Restdocs since these are standard Spring REST Docs snippets.
Am I missing something?

As mentioned in the comments, this was a minor bug in Spring REST Docs that has been promptly fixed by #AndyWilkinson in this commit, to be released in version 2.0.5.RELEASE. Many thanks to #AndyWilkinson!

Related

Using Spring Cloud Contract Groovy DSL, how can I parameterize the response to include values from the request?

I am using Spring Cloud Contract to create stubs for a REST service so I can test with a REST client. I have the stub runner working within a Spring Boot application, and it all works as expected. The problem I am having is that I'd like to see elements of the requests in the responses, to better simulate the eventual behavior of the REST service. For example, in this contract, I'd like what is passed in the "code" field in the request to appear regurgitated in the response:
package contracts
org.springframework.cloud.contract.spec.Contract.make {
request {
method('POST')
url $("/resource")
body ([
code : $(client(regex('[a-zA-Z0-9]{5,32}')))
])
}
response {
status 200
body([
code: ???
])
}
}
Obviously the input "code" can be anything that matches the regular expression, and so the actual value is unknown until runtime. Is there anything i can put in place of "???" to return the code submitted in the request ? I tried accessing, for example:
request.body.serverValue['code']
but that value it seems is generated at compile time, perhaps to enable the auto-generation of tests in ContractVerifierTest.java under generated-test-sources.
Can this be done ? Is this an appropriate use of Spring Cloud Contract ?
Currently, it's not supported. We prefer an approach where you have simpler contracts. If you need in a response a value from the request just hard code both the request and the response parts of the contract.
You can, however, file an issue and we can try to think of something in the future releases.
UPDATE:
With version 1.1.0 that's already possible. Check out the docs for more info - http://cloud.spring.io/spring-cloud-static/spring-cloud-contract/1.1.0.RELEASE/#_referencing_request_from_response

Nutch REST api Results (limited)

I've just figured out how to complete a Nutch crawl via the REST api for the 2.3 version of Nutch. You can see my post here. So after running the crawl, I go to MongoVue to check out the results and there is no "status" or "baseUrl" fields, along with others. Now if I do a normal crawl through cygwin, I get all fields. Is there some parameter I'm missing from the POST request to UPDATEDB call?
Here is the last call I make for Updatedb.
{
"args":{
"crawlId":"crawl-01",
"batch":"1428526896161-4430"
},
"confId":"default",
"crawlId":"crawl-01",
"type":"UPDATEDB"
}
I figured it out. The timestamp used in the GenerateJob step was wrong. It needed to be in a particular format and my code wasn't supporting it. Found a work around.

How to get type names of elastic search index in internal java api or jest api

I have a index with the name of demo and it contains different types. I'm using elastic search java internal api and rest api jest both of them in my app. Basicly I want to make this request
curl -XGET 'http:localhost:9200/demo/_mapping'
Is there any way to do that especially in jest api? There seems to be no documentation to get mapping for rest client api. What should I do?
This should work, but it's really ugly:
GetMappingsResponse res = client.admin().indices().getMappings(new GetMappingsRequest().indices("demo")).get();
ImmutableOpenMap<String, MappingMetaData> mapping = res.mappings().get("demo");
for (ObjectObjectCursor<String, MappingMetaData> c : mapping) {
System.out.println(c.key+" = "+c.value.source());
}
I don't know if this is officially supported or not -- I just found this by playing around.

Grails REST API hide "class" in respond list

I'm using Grails 2.3.2 working on a REST API using the built in Grails REST support. I'm having trouble getting rid of the "class" element in the JSON response. Based on a tutorial by Bobby Warner, I have found adding the following to the resources.groovy file:
meterRenderer(JsonRenderer, Meter) {
excludes = ['class']
}
This works fine for show, but for the index controller function, I'm responding with a list of Meters. In this, the "class" doesn't go away. What does it take to get rid of this in the list response?
Edit: To clarify, I am looking for a way to leverage the Content Negotiation feature of Grails new respond functionality without locking myself down to render as JSON implementions.
I guess if you switch to using GSON (github) instead of JSON then you need not worry about that particular exclusion.
That is driven by a config setting provided by the plugin as grails.converters.gson.domain.include.class (default is false).
nickdos' SO link had the answer. I added the following to my BootStrap.groovy:
grails.converters.JSON.registerObjectMarshaller(Meter) {
return it.properties.findAll {k,v -> k != 'class'}
}
And the respond call results in no "class" item. Oddly enough, I lost the "id" item in the process, but I'll save that for another SO question. :)

Cannot use REST comments in Swagger

I have downloaded swagger ui and experimenting it locally. It works fine in scenarios like "path", "body" , and "query" . But most of my use cases use rest comments.
i.e /resourcePath/;tags
URI to retrieve the tags of a specific resource.
When I try this the the UI gets jumbled when adding the semi colon and malformed the sorted UI and cannot go beyond this.
So is this a known limitation ? Is there a workaround to accomplish this target ?
Appreciate any input to this..
Swagger is expecting you to specify path params in curly-brackets like {tags} and query params as comma-delimited, such as id=1,2,3,4. Some frameworks use semi-colons as delimiters but swagger likes commas.
Can you describe more what you're looking to do, with a more concrete example? Per design, comments on the api belong in the description and notes fields for operations, please see swagger-core wiki for details.
The Swagger codegen project has a validator which can be used to verify that your spec is properly formatted.