Skip to content

Commit

Permalink
revert: "feat(schema): supports x-nullable for OAS2 (stoplightio#1378)"
Browse files Browse the repository at this point in the history
This reverts commit 45c9cd2.
  • Loading branch information
P0lip committed Nov 2, 2020
1 parent 4e667f9 commit 621c025
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 148 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"node": ">=10.18"
},
"scripts": {
"postinstall": "patch-package",
"build.binary": "pkg . --output ./binaries/spectral",
"build.clean": "rimraf ./coverage && rimraf ./dist && rimraf ./rulesets && rimraf ./__karma__/__fixtures__",
"build.functions": "rollup -c",
Expand Down Expand Up @@ -129,7 +128,6 @@
"lint-staged": "^10.2.11",
"nock": "~12.0.2",
"node-html-parser": "^1.2.20",
"patch-package": "^6.2.2",
"pkg": "^4.4.8",
"prettier": "^2.0.5",
"recast": "^0.19.1",
Expand Down
25 changes: 0 additions & 25 deletions patches/ajv+6.12.5.patch

This file was deleted.

32 changes: 0 additions & 32 deletions src/functions/__tests__/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,36 +376,4 @@ describe('schema', () => {
expect(runSchema({}, { $ref: '#/bar' }, void 0, { rule: { resolved: true } })).toEqual([]);
});
});

test('given OAS2, supports x-nullable', () => {
const testSchema: JSONSchema4 = {
type: 'string',
'x-nullable': true,
};

expect(runSchema('cxz', testSchema, 2)).toEqual([]);
expect(runSchema(null, testSchema, 2)).toEqual([]);
expect(runSchema(2, testSchema, 2)).toEqual([
{
message: 'Value type should be string,null',
path: [],
},
]);
});

test('given OAS3, supports nullable', () => {
const testSchema: JSONSchema4 = {
type: 'string',
nullable: true,
};

expect(runSchema('cxz', testSchema, 3)).toEqual([]);
expect(runSchema(null, testSchema, 3)).toEqual([]);
expect(runSchema(2, testSchema, 3)).toEqual([
{
message: 'Value type should be string,null',
path: [],
},
]);
});
});
1 change: 0 additions & 1 deletion src/functions/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ function getAjv(oasVersion: Optional<number>, allErrors: Optional<boolean>): AJV
jsonPointers: true,
unknownFormats: 'ignore',
nullable: oasVersion === 3, // Support nullable for OAS3
xNullable: oasVersion === 2, // Support x-nullable for OAS2
logger,
};

Expand Down
17 changes: 0 additions & 17 deletions src/rulesets/oas/__tests__/typed-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,5 @@ describe('typed-enum', () => {

expect(results).toEqual([]);
});

test('supports x-nullable', async () => {
const doc = {
swagger: '2.0.0',
definitions: {
Test: {
type: 'string',
'x-nullable': true,
enum: ['OK', 'FAILED', null],
},
},
};

const results = await s.run(doc);

expect(results).toEqual([]);
});
});
});
9 changes: 2 additions & 7 deletions src/rulesets/oas/functions/typedEnum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,10 @@ export const typedEnum: IFunction = function (this: IFunctionContext, targetVal,
}

const isOAS3 = otherValues.documentInventory.document.formats?.includes('oas3') === true;
const isOAS2 = otherValues.documentInventory.document.formats?.includes('oas2') === true;

let innerSchema;
if ((isOAS3 && targetVal.nullable === true) || (isOAS2 && targetVal['x-nullable'] === true)) {
const type = Array.isArray(initialSchema.type)
? [...initialSchema.type]
: initialSchema.type !== void 0
? [initialSchema.type]
: [];
if (isOAS3 && targetVal.nullable === true) {
const type = Array.isArray(initialSchema.type) ? [...initialSchema.type] : [initialSchema.type];
if (!type.includes('null')) {
type.push('null');
}
Expand Down
84 changes: 20 additions & 64 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
dependencies:
"@babel/helper-plugin-utils" "^7.8.0"

"@babel/runtime@^7.9.2":
"@babel/runtime@^7.6.3", "@babel/runtime@^7.9.2":
version "7.10.3"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.10.3.tgz#670d002655a7c366540c67f6fd3342cd09500364"
integrity sha512-RzGO0RLSdokm9Ipe/YD+7ww8X2Ro79qiXZF3HU9ljrM+qnJmH1Vqth+hbiQZy761LnMJTMitHDuKVYTk3k4dLw==
Expand Down Expand Up @@ -937,11 +937,6 @@
semver "^7.3.2"
tsutils "^3.17.1"

"@yarnpkg/lockfile@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31"
integrity sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==

abab@^2.0.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.2.tgz#a2fba1b122c69a85caa02d10f9270c7219709a9d"
Expand Down Expand Up @@ -1029,7 +1024,7 @@ [email protected]:
dependencies:
decimal.js "^10.2.0"

[email protected], ajv@^6.10.0, ajv@^6.10.2, ajv@^6.5.5:
[email protected]:
version "6.12.5"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.5.tgz#19b0e8bae8f476e5ba666300387775fb1a00a4da"
integrity sha512-lRF8RORchjpKG50/WFf8xmg7sgCLFiYNNnqdKflk63whMQcWR5ngGjiSXkL9bjxy6B2npOK2HSMN49jEBMSkag==
Expand All @@ -1039,6 +1034,16 @@ [email protected], ajv@^6.10.0, ajv@^6.10.2, ajv@^6.5.5:
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

ajv@^6.10.0, ajv@^6.10.2, ajv@^6.5.5:
version "6.12.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.2.tgz#c629c5eced17baf314437918d2da88c99d5958cd"
integrity sha512-k+V+hzjm5q/Mr8ef/1Y9goCmlsK4I6Sm74teeyGvFk1XrOsbsKLjEdrvny42CZ+a8sXbk8KWpY/bDwS+FLL2UQ==
dependencies:
fast-deep-equal "^3.1.1"
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

ansi-colors@^3.2.1:
version "3.2.4"
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-3.2.4.tgz#e3a3da4bfbae6c86a9c285625de124a234026fbf"
Expand Down Expand Up @@ -1673,7 +1678,7 @@ chalk@*, [email protected], chalk@^4.0.0:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.4.2:
chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0:
version "2.4.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
Expand Down Expand Up @@ -2997,14 +3002,6 @@ find-versions@^3.2.0:
dependencies:
semver-regex "^2.0.0"

find-yarn-workspace-root@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-1.2.1.tgz#40eb8e6e7c2502ddfaa2577c176f221422f860db"
integrity sha512-dVtfb0WuQG+8Ag2uWkbG79hOUzEsRrhBzgfn86g2sJPkzmcpGdghbNTfUKGTxymFrY/tLIodDzLoW9nOJ4FY8Q==
dependencies:
fs-extra "^4.0.3"
micromatch "^3.1.4"

findup-sync@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/findup-sync/-/findup-sync-1.0.0.tgz#6f7e4b57b6ee3a4037b4414eaedea3f58f71e0ec"
Expand Down Expand Up @@ -3105,24 +3102,6 @@ [email protected], fs-extra@^8.1.0:
jsonfile "^4.0.0"
universalify "^0.1.0"

fs-extra@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94"
integrity sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg==
dependencies:
graceful-fs "^4.1.2"
jsonfile "^4.0.0"
universalify "^0.1.0"

fs-extra@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9"
integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==
dependencies:
graceful-fs "^4.1.2"
jsonfile "^4.0.0"
universalify "^0.1.0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
Expand Down Expand Up @@ -3359,7 +3338,7 @@ globby@^11.0.0:
merge2 "^1.3.0"
slash "^3.0.0"

graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4:
graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4:
version "4.2.4"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==
Expand Down Expand Up @@ -4765,13 +4744,6 @@ kind-of@^6.0.0, kind-of@^6.0.2:
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.2.tgz#01146b36a6218e64e58f3a8d66de5d7fc6f6d051"
integrity sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==

klaw-sync@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-6.0.0.tgz#1fd2cfd56ebb6250181114f0a581167099c2b28c"
integrity sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ==
dependencies:
graceful-fs "^4.1.11"

kleur@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
Expand Down Expand Up @@ -5621,24 +5593,6 @@ pascalcase@^0.1.1:
resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14"
integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=

patch-package@^6.2.2:
version "6.2.2"
resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-6.2.2.tgz#71d170d650c65c26556f0d0fbbb48d92b6cc5f39"
integrity sha512-YqScVYkVcClUY0v8fF0kWOjDYopzIM8e3bj/RU1DPeEF14+dCGm6UeOYm4jvCyxqIEQ5/eJzmbWfDWnUleFNMg==
dependencies:
"@yarnpkg/lockfile" "^1.1.0"
chalk "^2.4.2"
cross-spawn "^6.0.5"
find-yarn-workspace-root "^1.2.1"
fs-extra "^7.0.1"
is-ci "^2.0.0"
klaw-sync "^6.0.0"
minimist "^1.2.0"
rimraf "^2.6.3"
semver "^5.6.0"
slash "^2.0.0"
tmp "^0.0.33"

path-browserify@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-1.0.0.tgz#40702a97af46ae00b0ea6fa8998c0b03c0af160d"
Expand Down Expand Up @@ -6413,7 +6367,7 @@ semver-regex@^2.0.0:
resolved "https://registry.yarnpkg.com/semver-regex/-/semver-regex-2.0.0.tgz#a93c2c5844539a770233379107b38c7b4ac9d338"
integrity sha512-mUdIBBvdn0PLOeP3TEkMH7HHeUP3GjsXCwKarjv/kGmUFOYg1VqEemKhoQpWMu6X2I8kHeuVdGibLGkVK+/5Qw==

"semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.5.0, semver@^5.6.0:
"semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.5.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
Expand Down Expand Up @@ -7577,9 +7531,11 @@ yallist@^3.0.2:
integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==

yaml@^1.7.2:
version "1.10.0"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e"
integrity sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==
version "1.7.2"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.7.2.tgz#f26aabf738590ab61efaca502358e48dc9f348b2"
integrity sha512-qXROVp90sb83XtAoqE8bP9RwAkTTZbugRUTm5YeFCBfNRPEp2YzTeqWiz7m5OORHzEvrA/qcGS8hp/E+MMROYw==
dependencies:
"@babel/runtime" "^7.6.3"

[email protected], yargs-parser@^18.1.1:
version "18.1.3"
Expand Down

0 comments on commit 621c025

Please sign in to comment.