Spring Boot 3 with RESTDOCS

781 Views Asked by At

I was using spring-restdocs with SB2.7.9

Now we migrated to SB3.0.6. I am using gradle plugin (kotlin DSL) id("org.asciidoctor.jvm.convert") version "3.3.2"

Libraries are versions:

spring-restdocs-asciidoctor-3.0.0.jar

spring-restdocs-core-3.0.0.jar

spring-restdocs-mockmvc-3.0.0.jar

I have my custom template under <project_path>/src/test/resources/org/springframework/restdocs/templates/request-parameters.snippet

During execution of gradle task asciidoctor i am getting WARNING: rest/my_complex_adoc_file.adoc: line 9: Snippet request-parameters not found at <project_path>/build/generated-snippets/zip-cities-find/request-parameters.adoc for operation zip-cities-find (and yes, they are not really there)

And in <project_path>/documentation/rest/my_complex_adoc_file.adoc i have it like

operation::zip-cities-find[snippets='http-request,request-parameters,http-response,response-fields,links']

Gradle looks like:

    val documentationDir = file("documentation")
    val documentationSnippetsDir = file("build/generated-snippets")
    "asciidoctor"(AsciidoctorTask::class) {
        setConfigurations(listOf("asciidoctorExtensions"))
        setOutputDir(file("build/documentation"))
        inputs.dir(documentationSnippetsDir)
        setSourceDir(documentationDir)
        setBaseDir(documentationDir)
        attributes(mapOf("snippets" to documentationSnippetsDir))
        baseDirFollowsSourceFile()
        asciidoctorj {
            fatalWarnings(listOf(missingIncludes()))
        }
    }

With SB2.7.9 was working correctly, now I can't find where is the problem.

Any help is appreciated

1

There are 1 best solutions below

0
Andy Wilkinson On

Support for documenting request parameters has been removed in Spring REST Docs 3.0 and replaced with support for documenting form and query parameters separately:

Request Parameters Support Removed

Support for documenting request parameters has been removed. Request parameters are a server-side construct of the Servlet API that mix form and query parameters together. To provide accurate, client-focussed documentation, form and query parameters should be documented separately.

As a result of this change, when using Spring Framework’s MockMvc, you may have to update how your tests send parameters to your API. Instead of using param to populate the server-side map of request parameters, queryParam (for query parameters) or application/x-www-form-urlencoded body content (for form parameters) should be used instead.

In addition to updating your tests to adapt to this change, you should also update your .adoc file to reference the query-parameters and/or form-parameters snippet in place of the request-parameters snippet.