Skip to content

Commit

Permalink
- fix token pattern
Browse files Browse the repository at this point in the history
- add tests to have more code coverage
  • Loading branch information
Mairu committed Feb 6, 2020
1 parent 2a83557 commit 00b1fb8
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/node_modules
/coverage
/.nyc_output
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* add support for "invalid" method - `joi.string().invalid('A','B','C')`
* add add support for "uuid" format for string type
* add support for ES6 default import syntax
* fix string token pattern

3.3.0 / 2019-10-18
==================
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ J2S returns a result object containing `swagger` and `components` properties. `s

- `any.example()` sets the `"example"` or `"examples"`.
- `.example('hi')` -> `"example": "hi"`
- joi < v14: `.example('hi').example('hey')` -> `"examples": ["hi", "hey"]`
- joi v14: `.example('hi', 'hey')` -> `"examples": ["hi", "hey"]`
- `.example('hi', 'hey')` -> `"examples": ["hi", "hey"]`

- `joi.any()`
- `.meta({ swaggerType: 'file' }).description('simpleFile')` add a file to the swagger structure
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const patterns = {
alphanum: '^[a-zA-Z0-9]*$',
alphanumLower: '^[a-z0-9]*$',
alphanumUpper: '^[A-Z0-9]*$',
token: '^[a-zA-Z0-9_]*$',
};

function meta (schema, key) {
Expand Down Expand Up @@ -151,7 +152,7 @@ const parseAsType = {
}

if (find(schema._rules, { name: 'token' })) {
swagger.pattern = patterns[`alphanum${getCaseSuffix(schema)}`];
swagger.pattern = patterns.token;
}

if (find(schema._rules, { name: 'email' })) {
Expand Down Expand Up @@ -329,7 +330,6 @@ function parse (schema, existingComponents) {
return { swagger: refDef(metaDefType, metaDefName) };
}

// TODO: test forbidden
if (get(schema, '_flags.presence') === 'forbidden') {
return false;
}
Expand Down
55 changes: 29 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"types": "index.d.ts",
"scripts": {
"test": "tap tests.js",
"test:debug": "tap --node-arg=--inspect --no-timeout tests.js",
"test:travis": "tap --reporter=tap tests.js",
"lint": "eslint ./"
},
Expand All @@ -31,12 +32,12 @@
"eslint-config-twipped": "~3.3.0",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-promise": "^4.2.1",
"@hapi/joi": "^16.1.7",
"@hapi/joi": "^17.1.0",
"tap": "^14.7.2",
"tapsuite": "^2.0.1"
},
"peerDependencies": {
"@hapi/joi": "*"
"@hapi/joi": ">=16"
},
"files": [
"index.js",
Expand Down
Loading

0 comments on commit 00b1fb8

Please sign in to comment.