prism
prism copied to clipboard
Auto-reloading not triggered when $ref files changed
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
- 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
- Given this example (example.yaml):
referenced example - Run this CLI command
.\prism-cli-win.exe mock -h 127.0.0.1 .\testapi.yaml - Perform post request on
http://127.0.0.1/paththe response will bereferenced example - Change the example.yaml to
example - Perform post request on
http://127.0.0.1/paththe response is stillreferenced example - Restart mock server
- Perform post request on
http://127.0.0.1/paththe response will beexample
Expected behavior
A change on example.yaml would also trigger a restart of the mock server so that the spec including examples are updated.
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.
@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
@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.
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.