Closed otrosien closed 8 years ago
@otrosien Thanks for opening this and for sharing the current state of things.
I've prototyped a new OutputFileResolver
abstraction in this branch. However, having now taken a look at your current implementation, I'm not sure that it's necessary. Unless I've missed a subtlety in JsonWriterResolver
, I think you can use StandardWriterResolver
by doing something like this:
private static final TemplateFormat TEMPLATE_FORMAT = new TemplateFormat() {
@Override
public String getId() {
return "json";
}
@Override
public String getFileExtension() {
return "json";
}
};
…
@Override
public void document(Operation operation) throws IOException {
RestDocumentationContext context = (RestDocumentationContext) operation
.getAttributes().get(RestDocumentationContext.class.getName());
WriterResolver writerResolver = new StandardWriterResolver(
new RestDocumentationContextPlaceholderResolver(context), "UTF-8", TEMPLATE_FORMAT);
try (Writer writer = writerResolver.resolve(operation.getName(), SNIPPET_NAME, context)) {
writer.append(toJsonString(operation));
}
}
thanks for your feedback. I'll try immediately.
Yay, it works. :-) BTW I'm at the moment trying to place a slot on springio.net in Barcelona for presenting this topic...
Awesome, on both counts. I've submitted a general Spring REST Docs talk. I haven't heard whether or not it's been accepted yet.
Alright, would be nice meeting in Barcelona then. :+1:
So, regarding this issue, I think it can be closed - the integration is actually simple enough. I'll be fiddling some more with improving how to autowire a wiremock on a dynamic port on the client-side, but that's a different issue. And maybe publish the existing integration on bintray.
Would you consider integrating such a feature into spring restdocs core?
Alright, would be nice meeting in Barcelona then. :+1:
It would indeed. Fingers crossed.
Would you consider integrating such a feature into spring restdocs core?
Absolutely. As I think I said in another issue, I consider Wiremock JSON to be another form of documentation, just one that's not normally consumed by a person.
As mentioned before, I am working on wiring spring restdocs and wiremock, so I uploaded a small project that demonstrates the current state: https://github.com/otrosien/restdocs-wiremock
From my point of view quite some boilerplate code is needed for this:
JsonWriterResolver
is mostly copy&paste from StandardWriterResolver (only because I need a .json suffix, instead of .adoc!)WireMockJsonSnippet
has some copy&paste fromHttpRequestSnippet
andHttpResponseSnippet
, which is okay because it does similar things with the data provided.