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

Expose Sway-Options #20

Merged
merged 2 commits into from
May 28, 2019
Merged
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ The following options can be passed to the generation function, some/all are exp
| `scheme` | `--scheme -m` | `spec.schemes[0]` | `false` | Override for multiple scheme present in a spec |
| `templates` | `--templates -t` | `'./templates'` | `false` | Path to directory containing custom templates |
| `statusCodes` |`--status-codes -S` | `operation.responses` | `false` | comma separated list of status codes to explicity generate tests for |
| `jsonRefs` | | n/a | `false` | *(See [JsonRefs~JsonRefsOptions](https://github.com/whitlockjc/json-refs/blob/master/docs/API.md#module_JsonRefs..JsonRefsOptions))* |
| `customFormats` | | n/a | `false` | The key/value pair of custom formats *(The keys are the format name and the values are async functions. See [ZSchema Custom Formats](https://github.com/zaggino/z-schema#register-a-custom-format))* |
| `customFormatGenerators` | | n/a | `false` | The key/value pair of custom format generators *(The keys are the format name and the values are functions. See [json-schema-mocker Custom Format](https://github.com/json-schema-faker/json-schema-faker#custom-formats))* |
| `customValidators` | | n/a | `false` | The custom validators. See [DocumentValidationFunction](https://github.com/apigee-127/sway/blob/master/docs/API.md#module_sway.DocumentValidationFunction) |

## Testing

Expand Down
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ module.exports = {
* @return {Promise<GenerationResults>}
*/
function generate(specPath, options) {
return sway.create({'definition': specPath})
return sway.create({
'definition': specPath,
'jsonRefs': options && options.jsonRefs,
'customFormats': options && options.customFormats,
'customFormatGenerators': options && options.customFormatGenerators,
'customValidators': options && options.customValidators
})
.then(function (api) {
if (options.customValues) {
options.customValues = JSON.parse(options.customValues);
Expand Down Expand Up @@ -75,4 +81,4 @@ function generate(specPath, options) {
console.error(err.stack);
return err
});
}
}