/** * Handles the given {@code request} and {@code response}, producing documentation * snippets for them using the given {@code configuration}. * @param request the request * @param response the request * @param configuration the configuration * @throws RestDocumentationGenerationException if a failure occurs during handling */ public void handle(REQ request, RESP response, Map<String, Object> configuration) { Map<String, Object> attributes = new HashMap<>(configuration); OperationRequest operationRequest = preprocessRequest( this.requestConverter.convert(request), attributes); OperationResponse operationResponse = preprocessResponse( this.responseConverter.convert(response), attributes); Operation operation = new StandardOperation(this.identifier, operationRequest, operationResponse, attributes); try { for (Snippet snippet : getSnippets(attributes)) { snippet.document(operation); } } catch (IOException ex) { throw new RestDocumentationGenerationException(ex); } }
public Operation build() { if (this.attributes.get(TemplateEngine.class.getName()) == null) { Map<String, Object> templateContext = new HashMap<>(); templateContext.put("tableCellContent", new AsciidoctorTableCellContentLambda()); this.attributes.put(TemplateEngine.class.getName(), new MustacheTemplateEngine( new StandardTemplateResourceResolver(this.templateFormat), Mustache.compiler().escapeHTML(false), templateContext)); } RestDocumentationContext context = createContext(); this.attributes.put(RestDocumentationContext.class.getName(), context); this.attributes.put(WriterResolver.class.getName(), new StandardWriterResolver( new RestDocumentationContextPlaceholderResolverFactory(), "UTF-8", this.templateFormat)); return new StandardOperation(this.name, ((this.requestBuilder == null) ? new OperationRequestBuilder("http://localhost/").buildRequest() : this.requestBuilder.buildRequest()), (this.responseBuilder == null) ? new OperationResponseBuilder().buildResponse() : this.responseBuilder.buildResponse(), this.attributes); }