Skip to content

requestFields example is not reflected as requestBody example, so Swagger UI "Edit Value" does not show the expected example #287

@zeromok

Description

@zeromok

1. Problem Summary

  • When I use .attributes(key("example").value(...)) in requestFields(...) to specify an example for each field,
    the OpenAPI 3 output only includes the example at the schema/properties/field level.
  • The OpenAPI requestBody does not get an overall example (singular) generated automatically.
  • As a result, the Swagger UI "Edit Value" tab does not show the expected example JSON by default.

2. Expected Behavior

  • I expect that the field examples from requestFields would be combined and used to generate a top-level example in the OpenAPI requestBody, like this:
"requestBody": {
  "content": {
    "application/json": {
      "schema": { ... },
      "example": { "targetDate": "yyyy-MM-dd" }
    }
  }
}
  • The Swagger UI "Edit Value" tab should then automatically show:
    { "targetDate": "yyyy-MM-dd" }

3. Actual Behavior

  • Each field’s example is present in the OpenAPI schema/properties,
    but there is no top-level example in the requestBody.
  • The Swagger UI "Edit Value" tab is empty or just shows {} by default.

4. Minimal Reproducible Example

.requestFields(
    fieldWithPath("targetDate").type(JsonFieldType.STRING)
        .description("Settlement base date (e.g., 2025-06-23)")
        .attributes(key("example").value("yyyy-MM-dd"))
)

5. Environment

  • restdocs-api-spec version: (e.g., 0.19.4)
  • Spring REST Docs version: (e.g., 3.x)
  • Swagger UI version: (e.g., 4.x)
  • JDK: (e.g., 17)

6. Additional Notes

  • As a workaround, I can post-process the generated openapi3.json to add the top-level example, but it would be great if this was supported natively.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions