Skip to content

Commit

Permalink
oas-validate; add explicit mediatype option
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeRalphson committed Jun 27, 2018
1 parent 7a918c6 commit e9a2ebb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion packages/oas-validator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions packages/swagger2openapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions packages/swagger2openapi/docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions packages/swagger2openapi/testRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit e9a2ebb

Please sign in to comment.