prism icon indicating copy to clipboard operation
prism copied to clipboard

Auto-reloading not triggered when $ref files changed

Open SeMuell opened this issue 3 years ago • 2 comments

Describe the bug

The auto-reloading feature of prism only triggers a restart of the server when the main spec file is changed. Whenever the spec file is using references to other files with the $ref keyword, then the server will not trigger a restart in case such file is changed.

To Reproduce

  1. Given this OpenAPI document (testapi.yaml)
openapi: '3.1.0'
paths:
  /path:
    post:
      responses:
        200:
          content:
            text/plain:
              example: 
                $ref: "example.yaml"
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                id:
                  type: integer
              required:
                - id
  1. Given this example (example.yaml): referenced example
  2. Run this CLI command .\prism-cli-win.exe mock -h 127.0.0.1 .\testapi.yaml
  3. Perform post request on http://127.0.0.1/path the response will be referenced example
  4. Change the example.yaml to example
  5. Perform post request on http://127.0.0.1/path the response is still referenced example
  6. Restart mock server
  7. Perform post request on http://127.0.0.1/path the response will be example

Expected behavior

A change on example.yaml would also trigger a restart of the mock server so that the spec including examples are updated.

SeMuell avatar Mar 11 '22 09:03 SeMuell

Had the same thing happen to me the project is setup using docker so I added a watcher script... not ideal but it gets the job done.

lyatziv avatar May 20 '22 22:05 lyatziv

@SeMuell , thank you for the bug report. We've got this in our backlog. In the meantime, one workaround you might consider is using a tool like entr to restart Prism when any file that contributes to your OpenAPI spec has changed.

For example, given the two files you mentioned in your initial report, testapi.yaml and example.yaml, you may be able to a command similar to the following to restart Prism when example.yaml changes.

find ./OpenApiDirectory -name "*.yaml" | entr -r prism-cli mock testapi.yaml

EdVinyard avatar May 23 '22 21:05 EdVinyard

@SeMuell

You could use nodemon to watch the desired folders / files and restart prism like this:

package.json

{
    "scripts": {
        "mock:serve": "nodemon --watch ./src/definitions --exec \"prism mock ./src/definitions/root.openapi.json\"",
    }
}

This is OS-independent so would satisfy the majority of Prism users.

WhereJuly avatar Mar 30 '23 07:03 WhereJuly

I don't think we're going to be able to address this functionality any time soon, so I'm going to close this ticket and update our documentation with the suggestions mentioned above.

ryotrellim avatar Mar 31 '23 18:03 ryotrellim