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

Add Optic for documentation #375

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .optic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

captures/
optic-temp-*
1 change: 1 addition & 0 deletions .optic/api/specification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
16 changes: 16 additions & 0 deletions .optic/ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Default Ignore Rules
# Learn to configure your own at http://localhost:4000/docs/using/advanced-configuration#ignoring-api-paths
OPTIONS (.*)
HEAD (.*)
GET (.*).htm
GET (.*).html
GET (.*).ico
GET (.*).css
GET (.*).js
GET (.*).woff
GET (.*).woff2
GET (.*).png
GET (.*).jpg
GET (.*).jpeg
GET (.*).svg
GET (.*).gif
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ Note that we are overriding the environment variable set in `.env` file because

Note: The difference between exec and run is that, exec executes the command within the running container and run will spin up a new container to run that command. So if you want to run only the tests without docker-compose up, you may do so by running `docker-compose run -e MONGODB_URL=mongodb://mongo:27017/noobjs_test node npm test`

## API Documentation

To simplify documenting your API, we have included [Optic](https://useoptic.com). To use it, you will need to [install the CLI tool](https://useoptic.com/document/#add-an-optic-specification-to-your-api-project), and then you can use `api exec "npm start"` to start capturing your endpoints as you create them. Once you want to review and add them to your API specification run: `api status -- review`.

## License

MIT
4 changes: 4 additions & 0 deletions config/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const compression = require('compression');
const morgan = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const { OpticMiddleware } = require('@useoptic/express-middleware');
const methodOverride = require('method-override');
const csrf = require('csurf');
const cors = require('cors');
Expand Down Expand Up @@ -107,6 +108,9 @@ module.exports = function(app, passport) {
})
);

// auto document API endpoints
app.use(OpticMiddleware({ enabled: !!(env !== 'production') }));

// use passport session
app.use(passport.initialize());
app.use(passport.session());
Expand Down
13 changes: 13 additions & 0 deletions optic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "nodejs-express-mongoose-demo"
# Start your api with Optic by running 'api run <taskname>'
tasks:
start:
command: "npm start"
inboundUrl: http://localhost:4000

# Capture traffic from a deployed api by running 'api intercept <environment-name>'
# pass '--chrome' to capture from your browser's network tab
environments:
production:
host: https://api.github.com # the hostname of the API we should record traffic from
webUI: https://api.github.com/repos/opticdev/optic # the url that should open when a browser flag is passed
Loading