简体   繁体   English

Spring Rest Docs代码段模板被忽略

[英]Spring Rest Docs snippet template is ignored

I am attempting to be able to create custom snippet template for Spring Rest Docs documentation purposes. 我试图能够为Spring Rest Docs文档目的创建自定义代码段模板。 I have been following the reference guide 我一直在遵循参考指南

My first problem I ran into was in IntelliJ when creating a .snippet file in src/test/resources/org/springframework/restdocs/templates/asciidoctor/path-parameters.snippet as instructed by the guide. 我遇到的第一个问题是在src/test/resources/org/springframework/restdocs/templates/asciidoctor/path-parameters.snippet根据指南创建.snippet文件时遇到的问题。 IntelliJ registers it as a jShell snippet file which from a quick glance is not the same as a AsciiDoc snippet. IntelliJ将其注册为jShell片段文件,从一眼看就与AsciiDoc片段不同。 So I went into Settings -> Editor -> File Types and changed jShell Snippet from *.snippet to *.snippetOld. 所以我进入Settings -> Editor -> File Types ,并将jShell代码段从* .snippet更改为* .snippetOld。 I then created a file type called Snippet and put it's pattern as *.snippet. 然后,我创建了一个名为Snippet的文件类型,并将其模式设置为* .snippet。 This now fixes the problem that the snippet template is read as a jShell file. 现在,这解决了将片段模板读取为jShell文件的问题。 So the .snippet template I created no longer gets compile/validation errors. 因此,我创建的.snippet模板不再遇到编译/验证错误。

But now when I run my mockMvc test after deleting the previous existing adoc files. 但是现在,当我在删除先前的现有adoc文件之后运行我的嘲笑Mvc测试时。 The path-perameters.adoc file which should had used my custom template, if not use the default template , is now not generated at all. 现在,即使没有使用默认模板 ,本来应该使用我的自定义模板的path-perameters.adoc文件也不会生成。

In my mockMvc test I have the following 在我的嘲笑Mvc测试中,我有以下内容

//Given
RestDocumentationResultHandler document = makeDocument("name-of-method");
document.document(
    pathParameters(//do path parameters)
    requestParameters(
        parameterWithName("Month").description("The month requested").attributes(
        key("type").value("integer"), key("constraints").value("more than 0 & less than 13.")
        ),
        parameterWithName("Year").description("The year requested").attributes(
            key("type").value("integer"), key("constraints").value("more than 1970 and less than current year")
        )
    ),
    responseField(//Do response fields)
);

// When
mvc.perform(get(REQUEST_PATH, USERID)
          .contentType(MediaType.APPLICATION_JSON)
          .param("month", "8")
          .param("year", "2018"))

          // Then
          .andExpect(status().isOk())
          .andDo(document);

And my snippet template is the following: 我的代码段模板如下:

   |===
   |Parameter|Description|Type|Constraints

   |{{parameter}}
   |{{description}}
   |{{type}}
   |{{constraints}}

Could somebody point out what I've done wrong/different from the reference guide and how I could fix it to have my template working? 有人可以指出我做错了什么/与参考指南有所不同,以及如何修复它以使模板正常工作?

I suspect the reason you did not get output is that you confused path-parameters with request-parameters . 我怀疑您未获得输出的原因是您将path-parametersrequest-parameters混淆了。 Your documentation config specifies request parameters, but you customized path-parameters template 您的文档配置指定了请求参数,但是您自定义了路径参数模板

Here is the complete list of snippet templates: 以下是摘要模板的完整列表:

  • curl-request.snippet 卷曲request.snippet
  • http-request.snippet HTTP-request.snippet
  • http-response.snippet HTTP-response.snippet
  • httpie-request.snippet httpie-request.snippet
  • links.snippet links.snippet
  • path-parameters.snippet 路径parameters.snippet
  • request-body.snippet 请求body.snippet
  • request-fields.snippet 请求fields.snippet
  • request-headers.snippet 请求headers.snippet
  • request-parameters.snippet 请求parameters.snippet
  • request-part-body.snippet 请求部分body.snippet
  • request-part-fields.snippet 请求部分fields.snippet
  • request-parts.snippet 请求parts.snippet
  • response-body.snippet 响应body.snippet
  • response-fields.snippet 响应fields.snippet
  • response-headers.snippet 响应headers.snippet

Source: 资源:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM