diff --git a/.travis.yml b/.travis.yml index 0304eb54..68373b5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,5 +15,5 @@ script: - travis_wait node $nflags packages/swagger2openapi/testRunner -q -l openapi-directory/APIs/ - travis_wait node $nflags packages/swagger2openapi/testRunner -q openapi-definitions/ - travis_wait node $nflags packages/swagger2openapi/testRunner -q -n openapi3-examples/pass - - travis_wait node $nflags packages/swagger2openapi/testRunner -q -r -n -f openapi3-examples/fail . + - travis_wait node $nflags packages/swagger2openapi/testRunner -q -r -n -f openapi3-examples/fail bin - node $nflags packages/swagger2openapi/testRunner -q -r test/s2o-test diff --git a/packages/oas-validator/index.js b/packages/oas-validator/index.js index 18706caa..aed3f9de 100644 --- a/packages/oas-validator/index.js +++ b/packages/oas-validator/index.js @@ -348,7 +348,9 @@ function checkContent(content, contextServers, openapi, options) { for (let ct in content) { contextAppend(options, jptr.jpescape(ct)); // validate ct against https://tools.ietf.org/html/rfc6838#section-4.2 - should(/[a-zA-Z0-9!#$%^&\*_\-\+{}\|'.`~]+\/[a-zA-Z0-9!#$%^&\*_\-\+{}\|'.`~]+/.test(ct)).be.exactly(true,'media-type should match RFC6838 format'); // this is a SHOULD not MUST + if (options.mediatype) { + should(/[a-zA-Z0-9!#$%^&\*_\-\+{}\|'.`~]+\/[a-zA-Z0-9!#$%^&\*_\-\+{}\|'.`~]+/.test(ct)).be.exactly(true,'media-type should match RFC6838 format'); // this is a SHOULD not MUST + } let contentType = content[ct]; should(contentType).be.an.Object(); should(contentType).not.be.an.Array(); diff --git a/packages/swagger2openapi/README.md b/packages/swagger2openapi/README.md index 2f46c0a9..38790faf 100644 --- a/packages/swagger2openapi/README.md +++ b/packages/swagger2openapi/README.md @@ -92,6 +92,7 @@ Options: -f, --fail path to specs expected to fail [string] -j, --jsonschema path to alternative JSON schema [string] -l, --laxurls lax checking of empty urls [boolean] + -m, --mediatype check media-types against RFC pattern [boolean] -n, --nopatch do not patch minor errors in the source definition [boolean] -o, --output output conversion result [string] [default: "openapi.yaml"] -q, --quiet do not show test passes on console, for CI [boolean] diff --git a/packages/swagger2openapi/docs/options.md b/packages/swagger2openapi/docs/options.md index 50ffc6dd..80385e04 100644 --- a/packages/swagger2openapi/docs/options.md +++ b/packages/swagger2openapi/docs/options.md @@ -21,6 +21,7 @@ indent|String|Input|Command-line flag to control JSON indenting jsonschema|String|Input|Path to alternative JSON schema (in JSON or YAML) for validation laxRefs|Boolean|Input|**No longer has any effect as this is now the default** laxurls|Boolean|Input|Flag to validation step to ignore empty URLs +mediatype|Boolean|Input|Flag to validation step to check media-type strings against RFC pattern nopatch|Boolean|Input|Command-line flag by `testRunner` to unset `patch` openapi|Object|Output|The OpenApi 3.x definition returned from a conversion step operationIds|Array[string]|Output|Used by validation to track uniqueness of operationIds diff --git a/packages/swagger2openapi/testRunner.js b/packages/swagger2openapi/testRunner.js index 5bae9ceb..c091bf74 100755 --- a/packages/swagger2openapi/testRunner.js +++ b/packages/swagger2openapi/testRunner.js @@ -35,6 +35,9 @@ let argv = yargs .boolean('laxurls') .alias('l', 'laxurls') .describe('laxurls', 'lax checking of empty urls') + .boolean('mediatype') + .alias('m','mediatype') + .describe('mediatype','check media-types against RFC pattern') .boolean('lint') .describe('lint','lint the definition') .boolean('nopatch')