ePages-de / restdocs-api-spec

Adds API specification support to Spring REST Docs
MIT License
376 stars 100 forks source link

OpenApi2 SwaggerUI execute POST sends empty body #166

Open dschulten opened 3 years ago

dschulten commented 3 years ago

The OpenApi2 SwaggerUI Try Out for POST request appears to be broken, it sends an empty request body. (OpenApi3 works).

This is the resource.json:

{
  "operationId" : "birthCertificate",
  "summary" : null,
  "description" : null,
  "privateResource" : false,
  "deprecated" : false,
  "request" : {
    "path" : "/example",
    "method" : "POST",
    "contentType" : "application/json;charset=UTF-8",
    "schema" : null,
    "headers" : [ ],
    "pathParameters" : [ ],
    "requestParameters" : [ ],
    "requestFields" : [ ],
    "example" : "{\"some\": \"json\"}",
    "securityRequirements" : null
  },
  "response" : {
    "status" : 200,
    "contentType" : "text/xml",
    "schema" : null,
    "headers" : [ ],
    "responseFields" : [ ],
    "example" : "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<root/>"
  },
  "tags" : [ "sometag" ]
}

Below is the resulting openapi2.yml. It has an empty parameter name for the body, and I suspect that this causes the problem, see https://github.com/swagger-api/swagger-ui/issues/965

swagger: "2.0"
info:
  description: xmaproutes Service
  version: 1.0-SNAPSHOT
  title: xmaproutes
host: localhost:8090
tags: []
schemes:
- http
paths:
  /example:
    post:
      tags:
      - sometag
      operationId: birthCertificate
      consumes:
      - application/json;charset=UTF-8
      produces:
      - text/xml
      parameters:
      - in: body
        name: ""    # I suspect that the empty name might cause the empty body
        required: false
        schema:
          $ref: '#/definitions/myrequest3530607'
        x-examples:
          application/json;charset=UTF-8: "{"\some\": \"json\"}"
      responses:
        "200":
          description: ""
          examples:
            text/xml: |-
              <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
              <root/>
definitions:
  myrequest3530607:
    example: "{\"some\": \"json\"}"
ozscheyge commented 3 years ago

Hey @dschulten ,

thanks for reaching out! Would you mind posting the produced OpenAPI3 yml? In your test, are you using a Spring Restdocs field descriptor to document some?

"requestFields" : [ ],

Looks weird to me, rest seems to be fine (example is documented, definition is derived from example, although no real schema since field value/name is not there).