Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
akamarvin opened this issue Nov 16, 2020 · 3 comments

Comments

@akamarvin
Copy link

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 akamarvin changed the title when 2 operations have the same input schema definitions, the requests in the output are not displayed when 2 operations have the same input schema definitions, the requests in the PDF output are not displayed Nov 16, 2020
@bplus
Copy link

bplus commented Mar 5, 2021

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

@vaibhavkhulbe-nferx
Copy link

Still facing it. Anyone looking into this issue?

@vaibhavkhulbe
Copy link

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; } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants