RapiPdf icon indicating copy to clipboard operation
RapiPdf copied to clipboard

when 2 operations have the same input schema definitions, the requests in the PDF output are not displayed

Open akamarvin opened this issue 5 years ago • 3 comments

Hi, RapiPdf is very good, and would really fit my simple need, but I have one showstopper.

Just imagine a sligthly modified petstore example with just an added operation, POST /store/backOrder, the same as POST /store/order, with the same input, but a supposedly different business logic. (#/definitions/Order) petstore_plus_backorder.txt

...
    "/store/order": {
      "post": {
        "tags": [
          "store"
        ],
        "summary": "Place an order for a pet",
        "description": "",
        "operationId": "placeOrder",
        "produces": [
          "application/xml",
          "application/json"
        ],
        "parameters": [
          {
            "in": "body",
            "name": "body",
            "description": "order placed for purchasing the pet",
            "required": true,
            "schema": {
              "$ref": "#/definitions/Order"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "successful operation",
            "schema": {
              "$ref": "#/definitions/Order"
            }
          },
          "400": {
            "description": "Invalid Order"
          }
        }
      }
    },
    "/store/backorder": {
        "post": {
          "tags": [
            "store"
          ],
          "summary": "Place an back order for a pet",
          "description": "",
          "operationId": "placeBackOrder",
          "produces": [
            "application/xml",
            "application/json"
          ],
          "parameters": [
            {
              "in": "body",
              "name": "body",
              "description": "order placed for purchasing the pet",
              "required": true,
              "schema": {
                "$ref": "#/definitions/Order"
              }
            }
          ],
          "responses": {
            "200": {
              "description": "successful operation",
              "schema": {
                "$ref": "#/definitions/Order"
              }
            },
            "400": {
              "description": "Invalid Order"
            }
          }
        }
      },
...

if you do that, and this would happen a lot in real life, reusing the same schema for input on different operations, then in the PDF, the two request sections content just disappear, only leaving the REQUEST title right before RESPONSE image

To retrieve the desired output, the only solution I found is to duplicate the Order definition with another name. which beats the purpose of openApi definitions reusability.

In our case, we may have for instance a definition called UserTokenInput, used in 15 different operations, this would mean we'd have to duplicate it from UserTokenInput1 to UserTokenInput15 ... and amend each operation accordingly.

RapiDoc does not have the same issue. It displays the 2 requests content correctly.

Can this be solved easily ?

Best regards, David

akamarvin avatar Nov 16 '20 09:11 akamarvin

+1 -- I believe I see this same issue with responses, as well as requests.

bplus avatar Mar 05 '21 19:03 bplus

Still facing it. Anyone looking into this issue?

vaibhavkhulbe-nferx avatar Mar 15 '22 11:03 vaibhavkhulbe-nferx

I have fixed it manually for now. You can add the following code at line 132 in src/spec-parser.js

The issue is: in such cases it needs to pick the schema from requestBodies which it is not doing. Check swagger2openapi for more info

if (fullPath.requestBody && fullPath.requestBody.$ref) { const ref = fullPath.requestBody.$ref.split('/'); const refName = ref[ref.length - 1]; const refObj = openApiSpec.components.requestBodies[refName]; if (refObj) { fullPath.requestBody = refObj; } }

vaibhavkhulbe avatar Mar 15 '22 20:03 vaibhavkhulbe