Example usage for org.springframework.restdocs.operation Operation getName

List of usage examples for org.springframework.restdocs.operation Operation getName

Introduction

In this page you can find the example usage for org.springframework.restdocs.operation Operation getName.

Prototype

String getName();

Source Link

Document

Returns the name of the operation.

Usage

From source file:io.spring.initializr.web.test.ResponseFieldSnippet.java

@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(), file, context)) {
        Map<String, Object> model = createModel(operation);
        model.putAll(getAttributes());//  ww  w .  ja v a2 s  .c o  m
        TemplateEngine templateEngine = (TemplateEngine) operation.getAttributes()
                .get(TemplateEngine.class.getName());
        writer.append(templateEngine.compileTemplate(getSnippetName()).render(model));
    }
}

From source file:capital.scalable.restdocs.section.SectionSnippet.java

@Override
protected Map<String, Object> createModel(Operation operation) {
    HandlerMethod handlerMethod = getHandlerMethod(operation);
    final String title;
    if (handlerMethod != null) {
        title = join(splitByCharacterTypeCamelCase(capitalize(handlerMethod.getMethod().getName())), ' ');
    } else {//from ww w  .  ja v a2s  .c o  m
        title = "";
    }

    // resolve path
    String path = propertyPlaceholderHelper.replacePlaceholders(operation.getName(),
            placeholderResolverFactory.create(getDocumentationContext(operation)));

    Map<String, Object> model = new HashMap<>();
    model.put("title", title);
    model.put("link", delimit(path));
    model.put("path", path);
    List<SectionSupport> sections = new ArrayList<>();
    model.put("sections", sections);

    for (String sectionName : sectionNames) {
        SectionSupport section = getSectionSnippet(operation, sectionName);
        if (section != null) {
            if (!skipEmpty || section.hasContent(operation)) {
                sections.add(section);
            }
        } else {
            System.out.println("Section snippet '" + sectionName + "' is configured to be "
                    + "included in the section but no such snippet is present in configuration");
        }
    }

    return model;
}