Test your API Changes with Optic's DSL
Optic Rulesets are written in Typescript using Optic's SDK. If you have written Spectral rules, the first thing you will notice is that Optic does not rely on JSON Path. Instead, rules are attached to OpenAPI entities i.e.
operation. Specific patterns in the spec can be matched using a predicate
matches: (...) => true | false, and rules can be triggered when parts of the spec are
changed. We will go into examples soon, but first let's set up a project:
Use the ruleset init command to Bootstrap a Typescript project with the correct test, build and publish scripts already configured:
optic ruleset init
You will need to have the
optic CLI installed to run this command. Install Instructions
Optic will write the following files:
├── README.md ├── jest.config.js ├── package.json ├── src │ ├── __tests__ │ │ └── main.test.ts │ └── main.ts └── tsconfig.json
If you use
yarn install. If you use
yarn run buildbundles all the rules and dependencies into a single
.jsfile for simple distribution.
yarn run testruns any tests you have written to ensure your rules work as expected
yarn run uploaddeploys your ruleset to Optic Cloud. In the dashboard you will have the option to run this ruleset whenever a tracked API changes.
🪜 Explore examples:
- Snyk's V3 API Standards (opens in a new tab)
- Breaking change standards (opens in a new tab)
- Casing and Naming standards (opens in a new tab)
- Examples must match schema standard (opens in a new tab)
👋 Book a call
Need help getting started? Book a call with our team and we can write some rules together. (opens in a new tab)