Skip to content

Commit

Permalink
Merge c177e91 into d9eaba1
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-zakharchenko committed Jul 18, 2019
2 parents d9eaba1 + c177e91 commit 5416ded
Show file tree
Hide file tree
Showing 19 changed files with 301 additions and 2,436 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -8,5 +8,6 @@ cov.*
.nyc_output

# List specific to .gitignore
build
node_modules
.idea/
1 change: 1 addition & 0 deletions .npmignore
Expand Up @@ -10,6 +10,7 @@ cov.*
# List specific to .npmignore
.travis.yml
.npmignore
lib
docs/
img/
test/
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -14,6 +14,7 @@ install:
- 'npm install --no-save'
script:
- 'npm run ci:lint'
- 'npm run ci:build'
- 'npm run ci:test'
after_success:
- 'npm run ci:release'
15 changes: 8 additions & 7 deletions appveyor.yml
@@ -1,14 +1,15 @@
environment:
nodejs_version: "10"
nodejs_version: '10'
cache:
- "node_modules"
- 'node_modules'
install:
- ps: Install-Product node 10
- "npm -g install npm@6"
- 'npm -g install npm@6'
- "set PATH=%APPDATA%\\npm;%PATH%"
- "npm install"
- 'npm install'
build: off
test_script:
- "node --version"
- "npm --version"
- "npm test"
- 'node --version'
- 'npm --version'
- 'npm run build'
- 'npm test'
14 changes: 7 additions & 7 deletions lib/units/normalize/normalizeHeaders.js
Expand Up @@ -20,13 +20,13 @@ const normalizeHeaders = (headers) => {
}

return Object.keys(headers).reduce(
(normalizedHeaders, name) => ({
...normalizedHeaders,
[name.toLowerCase()]:
typeof headers[name] === 'string'
? normalizeStringValue(headers[name])
: headers[name]
}),
(normalizedHeaders, name) =>
Object.assign({}, normalizedHeaders, {
[name.toLowerCase()]:
typeof headers[name] === 'string'
? normalizeStringValue(headers[name])
: headers[name]
}),
{}
);
};
Expand Down
8 changes: 4 additions & 4 deletions lib/units/validateBody.js
@@ -1,10 +1,10 @@
const jph = require('json-parse-helpfulerror');
const mediaTyper = require('media-typer');
const contentTypeUtils = require('content-type');

const { isValidField } = require('./isValid');
const { TextDiff, JsonExample, JsonSchema } = require('../validators');
const isset = require('../utils/isset');
const { isValidField } = require('./isValid');
const parseJson = require('../utils/parseJson');

function isPlainText(mediaType) {
return mediaType.type === 'text' && mediaType.subtype === 'plain';
Expand Down Expand Up @@ -69,7 +69,7 @@ function getBodyType(body, contentType, httpMessageOrigin) {
const hasJsonContentType = isJsonContentType(contentType);

try {
jph.parse(body);
parseJson(body);
const bodyMediaType = parseContentType(
hasJsonContentType ? contentType : 'application/json'
);
Expand Down Expand Up @@ -101,7 +101,7 @@ function getBodySchemaType(bodySchema) {
}

try {
jph.parse(bodySchema);
parseJson(bodySchema);
return [null, jsonSchemaType];
} catch (error) {
// Gavel must throw when given malformed JSON Schema.
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/evolve.js
Expand Up @@ -38,7 +38,9 @@ const evolve = (schema, { strict = false } = {}) => (data) => {
: value;
/* eslint-enable no-nested-ternary */

return isArray ? acc.concat(nextValue) : { ...acc, [key]: nextValue };
return isArray
? acc.concat(nextValue)
: Object.assign({}, acc, { [key]: nextValue });
};

const nextData = Object.keys(data).reduce(reducer, result);
Expand Down
11 changes: 11 additions & 0 deletions lib/utils/parseJson.js
@@ -0,0 +1,11 @@
const { parse } = require('jju/lib/parse');

const parseJson = (json, revivew) => {
try {
return parse(json, revivew);
} catch (error) {
throw error;
}
};

module.exports = parseJson;

0 comments on commit 5416ded

Please sign in to comment.