org.springframework.restdocs.snippet.RestDocumentationContextPlaceholderResolverFactory Java Examples

The following examples show how to use org.springframework.restdocs.snippet.RestDocumentationContextPlaceholderResolverFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OperationBuilder.java    From restdocs-raml with MIT License 6 votes vote down vote up
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);
}
 
Example #2
Source File: OperationBuilder.java    From restdocs-wiremock with Apache License 2.0 6 votes vote down vote up
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.buildResponse(), this.attributes);
}
 
Example #3
Source File: RamlResourceSnippet.java    From restdocs-raml with MIT License 5 votes vote down vote up
private void documentSnippet(Operation operation) throws IOException {

        WriterResolver writerResolver = new StandardWriterResolver(new RestDocumentationContextPlaceholderResolverFactory(), DEFAULT_SNIPPET_ENCODING, new RamlTemplateFormat());
        try (Writer writer = writerResolver.resolve(operation.getName(), SNIPPET_NAME,
                (RestDocumentationContext) operation.getAttributes().get(RestDocumentationContext.class.getName()))) {
            Map<String, Object> model = createModel(operation);
            TemplateEngine templateEngine = new MustacheTemplateEngine(new StandardTemplateResourceResolver(new RamlTemplateFormat()));
            writer.append(templateEngine.compileTemplate(SNIPPET_NAME).render(model));
        }
    }
 
Example #4
Source File: WireMockJsonSnippet.java    From restdocs-wiremock with Apache License 2.0 5 votes vote down vote up
@Override
public void document(Operation operation) throws IOException {
	RestDocumentationContext context = (RestDocumentationContext) operation.getAttributes()
			.get(RestDocumentationContext.class.getName());
	WriterResolver writerResolver = new StandardWriterResolver(
			new RestDocumentationContextPlaceholderResolverFactory(), "UTF-8", TEMPLATE_FORMAT);
	try (Writer writer = writerResolver.resolve(operation.getName(), SNIPPET_NAME, context)) {
		writer.append(toJsonString(operation));
	}
}