mw-apigee-apiproxy v1.0.0-alpha.0
mw-apigee-apiproxy
1. Installation
To install mw-apigee-apiproxy, run:
$ npm install mw-apigee-apiproxy --global2. Usage
mw-apigee-apiproxywill generate files in the current working directory, so be sure to change to a new directory first if you don't want to overwrite existing files.
mw-apigee-apiproxy supports CD workflows that can be executed in a command-line interface.
2.1. Generate a new API Proxy project
To scaffold a new API Proxy project, open a terminal and create a new, empty directory:
# Create a new directory
$ mkdir foo-proxy
# Enter your new directory
$ cd foo-proxyRun the app generator:
# Scaffold a new API Proxy project
$ yo apiproxy
# Answer the prompts till done3. Automating API Proxy CI/CD workflows
Projects created with mw-apigee-apiproxy include npm-scripts that facilitate automated API Proxy design, builds, linting, testing, documentation, version control, semantic versioning, CHANGELOG generation, packaging, and deployment to Apigee EDGE.
Here's a recommended sequence of tasks and commands you can incorporate into your CI/CD value streams.
3.1. Design your API with Swagger UI
- Go to the online Swagger Editor.
- Create a well-formed Swagger document.
- Copy the Swagger document to your clipboard.
- Open an IDE and paste the Swagger's YAML into a new file.
- Save the file to
openapidirectory.
3.2. Build, lint, test, document, and push to Git
If you're a lazy programmer (like me), you can run:
$ npm run build-test-pushOr, if that's too many characters for you, run the abbreviated command:
$ npm run btpThis will execute a:
- :factory: Build. If the build passes, then it will execute
:100: Test, which includes these quality gates:
:bathtub: Lint the
- Swagger documents and the
- Javascript callout source code (if any exists). If all's good, then it will
:school: Test with
jest. If all tests pass within the coverage threshold, it will check:lock: Security (with
nsp). If prelimary security checks pass, it'll:page_facing_up: Document your
- Swagger spec and
- Javascript callout code (both of which you'll find in the
docsdirectory). Finally, it'll
- :arrow_up: Commit and push to Git.
:warning:
npm run btpgenerates an automated commit messageThe
prepend-header.shshell script will use the default message "docs(api): auto-generate api docs and complexity report". The script can accept an alternate commit message, but that's not available from thenpm-script btp, yet. If you want add that, submit a pull request :v:.
3.3. Package all apiproxy artifacts
Finally, you can update the repository's apiproxy -- your final build -- by running:
$ npm run apigee:apiproxy:updateThis uses openapi2apigee behind the scenes to update the apiproxy artifacts and generate an apiproxy.zip file in your project's root directory.
3.4. Deploy the apiproxy package to Apigee EDGE
Run:
$ npm run apigee:apiproxy:deployThis not only generates apiproxy artifacts, but also deploys to an Apigee EDGE host of your choosing.
4. Quality gates, reports, and documentation
mw-apigee-apiproxy creates a consistent repository with tools that enforce Swagger quality; Javascript quality; and Javascript unit tests and code coverage.
4.1. Validate Swagger documentation
:trophy:
mw-apigee-apiproxyvalidates Swagger docs withswagger-cli.
swagger-cli validation runs before every test execution:
$ npm testswagger-api/validator-badges display whether there are syntactic issues with you Swagger/OpenAPI 2.0 document:
4.2. Analyze Javascript callout source code
:closed_lock_with_key: :bath: :ocean:
mw-apigee-apiproxylints source code; checks for vulnerabilities; assesses dependency drift; and executes quality gates withBitHound,eslint,nsp, andSonarQube/sonarcloud.The results are displayed real-time with README badges.
Code quality analysis runs before every test execution:
$ npm testIf you'd like an eslint report in HTML (with links to errors and warnings), run the following command to generate a eslint-report.html:
$ npm run eslint:html4.3. Test Javascript callouts
:100:
mw-apigee-apiproxyusesjestfor BDD spec execution and code coverage analysis.The results are displayed real-time with README badges.
Run:
$ npm testThis generates:
- Detailed code coverage reports at
coverage/lcov-report/index.html, as well as lcov.infoandclover.xmlfiles, which you can send to CI test coverage services like Coveralls.- Static markdown API documentation with complexity reports in the
docs/directory.
4.4. Generate API documentation and complexity reports
:page_facing_up:
mw-apigee-apiproxycomes withjsdoc-to-markdown,complexity-report, andswagger-markdownthat generate static markdown documentation.
To generate API docs, Swagger docs, and complexity reports in the docs directory, run:
$ npm run docs4.4.1. Only generate OpenAPI/Swagger docs
If you want to inspect your static OpenAPI docs before you push to source control or before you release your apiproxy to Apigee EDGE, run:
# Only generate static Swagger API docs (as markdown)
$ npm run docs:swagger:apis
# Generate static Swagger API docs with custom parameters
$ npm run docs:swagger-markdown -- -i /path/to/swagger.yml -o /path/to/swagger-api.md4.4.2. Only generate jsc API docs and complexity reports
If your apiproxy has Javascript callouts, you can preview your callouts' documentation and complexity reports in the docs directory by running:
$ npm run docs:jsc
# Access jsdoc2md directly, e.g.,
$ npm run docs:jsdoc2md -- --partial .assets/jsdoc2md/*.hbs --files lib/*.js > docs/README.md5. Release management automation
If you and your team write commit messages that comply with the the Conventional Commit Message Specification, mw-apigee-apiproxy can use standard-version to automate
- Semantic versioning (with Git tags), and
- CHANGELOG generation
When you're ready to release, run:
$ npm run release6 years ago