org.springframework.restdocs.templates.TemplateEngine Java Examples

The following examples show how to use org.springframework.restdocs.templates.TemplateEngine. 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: ContractDslSnippet.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Override
public void document(Operation operation) throws IOException {
	TemplateEngine templateEngine = (TemplateEngine) operation.getAttributes()
			.get(TemplateEngine.class.getName());
	String renderedContract = templateEngine
			.compileTemplate("default-dsl-contract-only")
			.render(createModelForContract(operation));
	this.model.put("contract", renderedContract);
	storeDslContract(operation, renderedContract);
	super.document(operation);
}
 
Example #5
Source File: ResponseFieldSnippet.java    From initializr 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 = (WriterResolver) operation.getAttributes().get(WriterResolver.class.getName());
	try (Writer writer = writerResolver.resolve(operation.getName() + "/" + getSnippetName(), this.file, context)) {
		Map<String, Object> model = createModel(operation);
		model.putAll(getAttributes());
		TemplateEngine templateEngine = (TemplateEngine) operation.getAttributes()
				.get(TemplateEngine.class.getName());
		writer.append(templateEngine.compileTemplate(getSnippetName()).render(model));
	}
}