OpenAPI Test Templates (oatts)
++ +OpenAPI Test Templates (oatts)
+-Generate basic unit test scaffolding for your OpenAPI specification.
Disclaimer
This is not an officially supported Google product.
+Disclaimer
+This is not an officially supported Google product.
oattsis based off of the swagger-test-templates module and the lessons learned during its development.This is a work in progress.
-Goal
The goal of
+oattsis to provide a standalone module for generating Node.js unit test code scaffolding based on a given OpenAPI specification.Goal
+The goal of
oattsis to provide a standalone module for generating Node.js unit test code scaffolding based on a given OpenAPI specification.The hope is that by providing such a tool, API developers will be encouraged to test the contract between their spec and backend early, often and continuously as the project grows.
-Usage
There are a couple ways to use
-oatts.Module
Install via
-npmnpm install --save oattsThen use it in code
+Usage
+There are a couple ways to use
+oatts.Module
+Install via
+npm+npm install --save oatts +Then use it in code
var oatts = require('oatts'); var options = { @@ -66,8 +73,13 @@Module
Install via
var tests = oatts.generate('/path/to/openapi.yaml', options); -console.log(tests)npmCommand line interface
Install globally via
-npmnpm install -g oattsThen use in your command line
+console.log(tests) + +Command line interface
+Install globally via
+npm+npm install -g oatts +Then use in your command line
> oatts generate --help Usage: generate [options] @@ -93,7 +105,10 @@Module
Install via
> oatts generate -s ./path/to/openapi.yaml -w ./output/dir > ls ./output/dir pet-test.js pet-{petId}-uploadImage-test.js user-test.js -. . .npmUsing the result
The resulting test files are built using the mocha testing framework and chakram API testing framework. Thus, you will need both of these dependencies installed in order to run your newly generated tests.
+. . . + +Using the result
+The resulting test files are built using the mocha testing framework and chakram API testing framework. Thus, you will need both of these dependencies installed in order to run your newly generated tests.
After installing these, you can run the tests with mocha:
# start your API server to test against!! > mocha --recursive <test directory> @@ -108,9 +123,13 @@Module
Install via
✓ should respond 200 for "Success" - 2 passing (82ms)npmCustom Values
Custom values can be supplied through both the command line and a JSON file. The in-line, command line supplied JSON will take precedent.
+ 2 passing (82ms) + +Custom Values
+Custom values can be supplied through both the command line and a JSON file. The in-line, command line supplied JSON will take precedent.
An example custom values JSON file can be found here.
-Custom Templates
Custom templates can be supplied via the
+templatesoption. The directory pointed to by the option must contain 4 Handlebars templates named the same way as those found in./templates.Custom Templates
+Custom templates can be supplied via the
templatesoption. The directory pointed to by the option must contain 4 Handlebars templates named the same way as those found in./templates.
topLevel.handlebars: the top level template for a single test file- @@ -119,7 +138,8 @@
pathLevel.handlebars: the path level template, usually the beginning of a test suite for a specific pathCustom Templates
Custom templates can be supplied via the
templThe data available to be used in the templates is specified in the
ProcessedSpectype.There are also a few helpers available to be used in the Handlebars templates, which can be found in the
-templateHelpersdocumentation namespace. Use the default templates as examples of how to use them.Options
The following options can be passed to the generation function, some/all are exposed in the accompanying CLI:
+Options
+The following options can be passed to the generation function, some/all are exposed in the accompanying CLI:
-
@@ -169,14 +189,14 @@ Options
The following options can be passed to the generation functio
consumes- --consumes -c+ operation.consumes[0]| |spec.conumes[0]operation.consumes[0]| |spec.conumes[0]falseConsumes header to use in a request when applicable @@ -215,14 +235,49 @@ produces- --produces -o+ operation.produces[0]| |spec.produces[0]operation.produces[0]| |spec.produces[0]falseProduces header to use in a request when applicable Options
The following options can be passed to the generation functio
falsecomma separated list of status codes to explicity generate tests for ++ ++ jsonRefs+ n/a ++ false(See JsonRefs~JsonRefsOptions) ++ ++ customFormats+ n/a ++ falseThe key/value pair of custom formats (The keys are the format name and the values are async functions. See ZSchema Custom Formats) ++ ++ customFormatGenerators+ n/a ++ falseThe key/value pair of custom format generators (The keys are the format name and the values are functions. See json-schema-mocker Custom Format) ++ + customValidators+ n/a ++ falseThe custom validators. See DocumentValidationFunction +Testing
To test this module simply use the
-npmscriptnpm testDiscussion
If you have a question or a topic you'd like to discuss, please feel free to open +
Testing
+To test this module simply use the
+npmscript+npm test +Discussion
+If you have a question or a topic you'd like to discuss, please feel free to open a discussion on our Google Group oatts-users.
-Contributing
Contributors are welcome! Please see CONTRIBUTING.md.
-Copyright
Copyright 2018, Google Inc.
-License
See LICENSE file.
Contributing
+Contributors are welcome! Please see CONTRIBUTING.md.
+Copyright
+Copyright 2018, Google Inc.
+License
+See LICENSE file.