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

Reload mock server on example changes #1083

Closed
lehphyro opened this issue Apr 10, 2020 · 6 comments
Closed

Reload mock server on example changes #1083

lehphyro opened this issue Apr 10, 2020 · 6 comments

Comments

@lehphyro
Copy link
Contributor

User story.
As a developer, I can change a referenced example file, so that I can see the changes after a request to prism.

Is your feature request related to a problem?
Prism only watches the spec file for changes and even if it changes, it doesn't reload referenced examples. This is useful because spec files can get extremely big so $ref usage is a must to keep it manageable.

Describe the solution you'd like
Given a spec like this:

/test:
  get:
    ...
    responses:
      '200':
        ...
        examples:
          example1:
            value:
              $ref: examples/test1.json

Prism should watch examples/test1.json for changes and reload it or restart itself so that the changes are returned by it in the next request.

@XVincentX
Copy link
Contributor

Oh ok I understand your use case. I'm not too sure wether we can make it happen with the current architecture.

The CLI does not resolve the file content, making a little bit hard to track all the files on the disk and react accordingly. I do see the value in the feature though. I'm going to try to have a look at it.

@philsturgeon
Copy link
Contributor

@lehphyro I would love to see this, great idea!

@XVincentX The new ref resolver is working on a way to keep track of what the old files were pre-resolve. APIDevTools/json-schema-ref-parser#173

When we switch to that ref resolver, maybe we can use this new feature in order to keep track of the initial files, then place a watch on all of them to look for changes and reload?

@XVincentX
Copy link
Contributor

@philsturgeon Prism is already using the new resolved, it would just probably matter of using the feature correctly in it. At the moment Prism-Http is making the assumption that the document is fully resolved, and that prevents us in general to take care of references after it has started.

In order to make this correctly we will probably have to rethink this concept and make the http package a little bit smarter.

@InfoSec812
Copy link

I too would like to see this, and further it would be great if Prism would update on ANY change to a local Spec file.

@InfoSec812
Copy link

Oh hey! I just found a nice workaround for this... Try this:

{​​​​​​​
  "name": "angular-openapi-prism",
  "version": "0.0.1",
  "scripts": {​​​​​​​
    "prism": "nodemon -w openapi.yml --exec 'prism mock -d --cors openapi.yml'",
    "openapi": "openapi-generator-cli generate -g typescript-angular -i openapi.yml -o src/sdk/"
  }​​​​​​​,
  "watch": {​​​​​​​
    "openapi": "openapi.yml"
  }​​​​​​​,
  "devDependencies": {​​​​​​​
    "nodemon": "^2.0.7",
    "npm-watch": "^0.7.0",
    "@openapitools/openapi-generator-cli": "^2.1.25",
    "@stoplight/prism-cli": "^4.1.2",
  }​​​​​​​
}​​​​​​​

This will use nodemon to "watch" the OpenAPI Spec and restart prism when there is a change.

@philsturgeon
Copy link
Contributor

Autoreload on change was added in #689.

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

No branches or pull requests

5 participants