From 940feca74540d563700a74d2c59c8881546cbd1c Mon Sep 17 00:00:00 2001 From: Roman Sainchuk Date: Wed, 25 May 2022 18:17:13 +0300 Subject: [PATCH 01/11] chore: test coverage threshold --- .github/workflows/tests.yaml | 2 +- jest.config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 4bc8f0ce65..d3074113c4 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -36,7 +36,7 @@ jobs: with: skip-step: none annotations: none - test-script: npm run jest -- --silent --ci --json --testLocationInResults --outputFile=report.json --bail --coverage + test-script: npm run jest -- --silent --ci --json --testLocationInResults --outputFile=report.json --bail --coverage || exit 0 - name: E2E Tests run: npm run e2e env: diff --git a/jest.config.js b/jest.config.js index 9cff824340..8f2b48d661 100644 --- a/jest.config.js +++ b/jest.config.js @@ -17,7 +17,7 @@ module.exports = { lines: 77, }, 'packages/cli/': { - statements: 30, + statements: 90, branches: 27, functions: 29, lines: 32, From e7c43a93ddcb535fc17aa70807f3578428684ca3 Mon Sep 17 00:00:00 2001 From: Andrew Tatomyr Date: Fri, 3 Jun 2022 15:09:09 +0200 Subject: [PATCH 02/11] chore: fail on threshold --- .github/workflows/tests.yaml | 9 ++++++--- README.md | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index d3074113c4..7053fb7316 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,4 +1,4 @@ -name: Unit/Integration Tests & Coverage +name: Build and Test on: pull_request: @@ -20,7 +20,7 @@ jobs: restore-keys: | npm-${{ hashFiles('package-lock.json') }} npm- - - name: Install modules + - name: Environments run: | echo echo Using Node $(node -v), NPM $(npm -v) @@ -31,12 +31,15 @@ jobs: CI: true - name: Typecheck run: npm run typecheck + - name: Unit Tests + run: npm run jest -- --silent --ci --json --testLocationInResults --outputFile=report.json --bail --coverage - name: Coverage Report uses: artiomtr/jest-coverage-report-action@v2.0-rc.4 with: skip-step: none + coverage-file: report.json annotations: none - test-script: npm run jest -- --silent --ci --json --testLocationInResults --outputFile=report.json --bail --coverage || exit 0 + test-script: npm run jest -- --silent --ci --json --testLocationInResults --outputFile=report-base.json --bail --coverage - name: E2E Tests run: npm run e2e env: diff --git a/README.md b/README.md index 80594bda97..9976dc16cd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Redocly CLI (fka OpenAPI CLI) toolbox with rich validation and bundling features. -![Travis (.org)](https://img.shields.io/travis/Redocly/redocly-cli/master) +![build and test](https://github.com/redocly/redocly-cli/actions/workflows/tests.yaml/badge.svg) ![npm (scoped)](https://img.shields.io/npm/v/@redocly/cli) ![NPM](https://img.shields.io/npm/l/@redocly/cli) @@ -63,8 +63,8 @@ docker run --rm -v $PWD:/spec redocly/openapi-cli lint path-to-root-file.yaml To build and run with a local image, run the following from the project root: ``` -docker build -t openapi-cli . -docker run --rm -v $PWD:/spec openapi-cli lint path-to-root-file.yaml +docker build -t redocly-cli . +docker run --rm -v $PWD:/spec redocly-cli lint path-to-root-file.yaml ``` ## [Read the docs](https://redocly.com/docs/cli/) From 9f9a5458a11e655edf30ec707b6a2ccf72307768 Mon Sep 17 00:00:00 2001 From: Andrew Tatomyr Date: Fri, 3 Jun 2022 15:13:11 +0200 Subject: [PATCH 03/11] chore: set correct threshold --- jest.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index 8f2b48d661..9cff824340 100644 --- a/jest.config.js +++ b/jest.config.js @@ -17,7 +17,7 @@ module.exports = { lines: 77, }, 'packages/cli/': { - statements: 90, + statements: 30, branches: 27, functions: 29, lines: 32, From 7f68c229176ad4b909deb0f49f960a7204485219 Mon Sep 17 00:00:00 2001 From: Andrew Tatomyr Date: Fri, 3 Jun 2022 15:16:28 +0200 Subject: [PATCH 04/11] chore: break tests --- .../config/__tests__/resolve-plugins.test.ts | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/core/src/config/__tests__/resolve-plugins.test.ts b/packages/core/src/config/__tests__/resolve-plugins.test.ts index 76d64253a3..38a2a1a910 100644 --- a/packages/core/src/config/__tests__/resolve-plugins.test.ts +++ b/packages/core/src/config/__tests__/resolve-plugins.test.ts @@ -8,20 +8,20 @@ describe('resolving a plugin', () => { const config = await loadConfig(configPath); const plugin = config.lint.plugins[0]; - expect(plugin.rules?.oas3).toHaveProperty('test-plugin/openid-connect-url-well-known'); + expect(plugin.rules?.oas3).toHaveProperty('test-plugin/openid-connect-url-well-known !1!!!11'); }); - it('should prefix preprocessor names with the plugin id', async () => { - const config = await loadConfig(configPath); - const plugin = config.lint.plugins[0]; + // it('should prefix preprocessor names with the plugin id', async () => { + // const config = await loadConfig(configPath); + // const plugin = config.lint.plugins[0]; - expect(plugin.preprocessors?.oas2).toHaveProperty('test-plugin/description-preprocessor'); - }); + // expect(plugin.preprocessors?.oas2).toHaveProperty('test-plugin/description-preprocessor'); + // }); - it('should prefix decorator names with the plugin id', async () => { - const config = await loadConfig(configPath); - const plugin = config.lint.plugins[0]; + // it('should prefix decorator names with the plugin id', async () => { + // const config = await loadConfig(configPath); + // const plugin = config.lint.plugins[0]; - expect(plugin.decorators?.oas3).toHaveProperty('test-plugin/inject-x-stats'); - }); + // expect(plugin.decorators?.oas3).toHaveProperty('test-plugin/inject-x-stats'); + // }); }); From be71ca604839a69435546d61e11953c11bb91222 Mon Sep 17 00:00:00 2001 From: Andrew Tatomyr Date: Fri, 3 Jun 2022 15:19:07 +0200 Subject: [PATCH 05/11] chore: coverage down --- packages/core/src/config/__tests__/resolve-plugins.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/config/__tests__/resolve-plugins.test.ts b/packages/core/src/config/__tests__/resolve-plugins.test.ts index 38a2a1a910..b77bfc6c03 100644 --- a/packages/core/src/config/__tests__/resolve-plugins.test.ts +++ b/packages/core/src/config/__tests__/resolve-plugins.test.ts @@ -8,7 +8,7 @@ describe('resolving a plugin', () => { const config = await loadConfig(configPath); const plugin = config.lint.plugins[0]; - expect(plugin.rules?.oas3).toHaveProperty('test-plugin/openid-connect-url-well-known !1!!!11'); + expect(plugin.rules?.oas3).toHaveProperty('test-plugin/openid-connect-url-well-known'); }); // it('should prefix preprocessor names with the plugin id', async () => { From a6c4f15e10d839fa96d3f7e6adb88405a1c48775 Mon Sep 17 00:00:00 2001 From: Andrew Tatomyr Date: Fri, 3 Jun 2022 15:30:24 +0200 Subject: [PATCH 06/11] chore: coverage down --- .../config/__tests__/resolve-plugins.test.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/core/src/config/__tests__/resolve-plugins.test.ts b/packages/core/src/config/__tests__/resolve-plugins.test.ts index b77bfc6c03..76d64253a3 100644 --- a/packages/core/src/config/__tests__/resolve-plugins.test.ts +++ b/packages/core/src/config/__tests__/resolve-plugins.test.ts @@ -11,17 +11,17 @@ describe('resolving a plugin', () => { expect(plugin.rules?.oas3).toHaveProperty('test-plugin/openid-connect-url-well-known'); }); - // it('should prefix preprocessor names with the plugin id', async () => { - // const config = await loadConfig(configPath); - // const plugin = config.lint.plugins[0]; + it('should prefix preprocessor names with the plugin id', async () => { + const config = await loadConfig(configPath); + const plugin = config.lint.plugins[0]; - // expect(plugin.preprocessors?.oas2).toHaveProperty('test-plugin/description-preprocessor'); - // }); + expect(plugin.preprocessors?.oas2).toHaveProperty('test-plugin/description-preprocessor'); + }); - // it('should prefix decorator names with the plugin id', async () => { - // const config = await loadConfig(configPath); - // const plugin = config.lint.plugins[0]; + it('should prefix decorator names with the plugin id', async () => { + const config = await loadConfig(configPath); + const plugin = config.lint.plugins[0]; - // expect(plugin.decorators?.oas3).toHaveProperty('test-plugin/inject-x-stats'); - // }); + expect(plugin.decorators?.oas3).toHaveProperty('test-plugin/inject-x-stats'); + }); }); From 25e7227870d6a999b5e58387bc6db6fb8adb3983 Mon Sep 17 00:00:00 2001 From: Andrew Tatomyr Date: Fri, 3 Jun 2022 15:31:26 +0200 Subject: [PATCH 07/11] chore: coverage down --- packages/core/src/__tests__/lint.test.ts | 366 ++++++++++++----------- 1 file changed, 186 insertions(+), 180 deletions(-) diff --git a/packages/core/src/__tests__/lint.test.ts b/packages/core/src/__tests__/lint.test.ts index 716ba4da80..404fef364a 100644 --- a/packages/core/src/__tests__/lint.test.ts +++ b/packages/core/src/__tests__/lint.test.ts @@ -1,10 +1,16 @@ import { outdent } from 'outdent'; -import { lintFromString, lintConfig, lintDocument } from '../lint'; -import { BaseResolver } from '../resolve'; + +// import { lintFromString, lintConfig, lintDocument } from '../lint'; +// import { BaseResolver } from '../resolve'; +// import { loadConfig } from '../config/load'; +// import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../__tests__/utils'; +// import { detectOpenAPI } from '../oas-types'; + +import { lintFromString } from '../lint'; import { loadConfig } from '../config/load'; -import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../__tests__/utils'; -import { detectOpenAPI } from '../oas-types'; +import { replaceSourceWithRef } from '../../__tests__/utils'; + describe('lint', () => { it('lintFromString should work', async () => { @@ -44,189 +50,189 @@ describe('lint', () => { `); }); - it('lintConfig should work', async () => { - const document = parseYamlToDocument( - outdent` - apis: error string - lint: - plugins: - - './local-plugin.js' - extends: - - recommended - - local/all - rules: - operation-2xx-response: warn - no-invalid-media-type-examples: error - path-http-verbs-order: error - boolean-parameter-prefixes: off - features.openapi: - showConsole: true - layout: - scope: section - routingStrategy: browser - theme: - rightPanel: - backgroundColor: '#263238' - links: - color: '#6CC496' - `, - '', - ); - const results = await lintConfig({ document }); + // it('lintConfig should work', async () => { + // const document = parseYamlToDocument( + // outdent` + // apis: error string + // lint: + // plugins: + // - './local-plugin.js' + // extends: + // - recommended + // - local/all + // rules: + // operation-2xx-response: warn + // no-invalid-media-type-examples: error + // path-http-verbs-order: error + // boolean-parameter-prefixes: off + // features.openapi: + // showConsole: true + // layout: + // scope: section + // routingStrategy: browser + // theme: + // rightPanel: + // backgroundColor: '#263238' + // links: + // color: '#6CC496' + // `, + // '', + // ); + // const results = await lintConfig({ document }); - expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(` - Array [ - Object { - "location": Array [ - Object { - "pointer": "#/apis", - "reportOnKey": false, - "source": "", - }, - ], - "message": "Expected type \`ConfigApis\` (object) but got \`string\`", - "ruleId": "spec", - "severity": "error", - "suggest": Array [], - }, - Object { - "location": Array [ - Object { - "pointer": "#/features.openapi/layout", - "reportOnKey": false, - "source": "", - }, - ], - "message": "Expected type \`string\` but got \`object\`.", - "ruleId": "spec", - "severity": "error", - "suggest": Array [], - }, - ] - `); - }); + // expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(` + // Array [ + // Object { + // "location": Array [ + // Object { + // "pointer": "#/apis", + // "reportOnKey": false, + // "source": "", + // }, + // ], + // "message": "Expected type \`ConfigApis\` (object) but got \`string\`", + // "ruleId": "spec", + // "severity": "error", + // "suggest": Array [], + // }, + // Object { + // "location": Array [ + // Object { + // "pointer": "#/features.openapi/layout", + // "reportOnKey": false, + // "source": "", + // }, + // ], + // "message": "Expected type \`string\` but got \`object\`.", + // "ruleId": "spec", + // "severity": "error", + // "suggest": Array [], + // }, + // ] + // `); + // }); - it("'plugins' shouldn't be allowed in 'apis' -> 'lint' field", async () => { - const document = parseYamlToDocument( - outdent` - apis: - lint: - plugins: - - './local-plugin.js' - lint: - plugins: - - './local-plugin.js' - `, - '', - ); - const results = await lintConfig({ document }); + // it("'plugins' shouldn't be allowed in 'apis' -> 'lint' field", async () => { + // const document = parseYamlToDocument( + // outdent` + // apis: + // lint: + // plugins: + // - './local-plugin.js' + // lint: + // plugins: + // - './local-plugin.js' + // `, + // '', + // ); + // const results = await lintConfig({ document }); - expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(` - Array [ - Object { - "location": Array [ - Object { - "pointer": "#/apis/lint/plugins", - "reportOnKey": true, - "source": "", - }, - ], - "message": "Property \`plugins\` is not expected here.", - "ruleId": "spec", - "severity": "error", - "suggest": Array [], - }, - ] - `); - }); + // expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(` + // Array [ + // Object { + // "location": Array [ + // Object { + // "pointer": "#/apis/lint/plugins", + // "reportOnKey": true, + // "source": "", + // }, + // ], + // "message": "Property \`plugins\` is not expected here.", + // "ruleId": "spec", + // "severity": "error", + // "suggest": Array [], + // }, + // ] + // `); + // }); - it("'const' can have any type", async () => { - const document = parseYamlToDocument( - outdent` - openapi: "3.1.0" - info: - version: 1.0.0 - title: Swagger Petstore - description: Information about Petstore - license: - name: MIT - url: https://opensource.org/licenses/MIT - servers: - - url: http://petstore.swagger.io/v1 - paths: - /pets: - get: - summary: List all pets - operationId: listPets - tags: - - pets - responses: - 200: - description: An paged array of pets - content: - application/json: - schema: - type: string - const: ABC - `, - 'foobar.yaml', - ); - - const results = await lintDocument({ - externalRefResolver: new BaseResolver(), - document, - config: await makeConfig({ spec: 'error' }), - }); + // it("'const' can have any type", async () => { + // const document = parseYamlToDocument( + // outdent` + // openapi: "3.1.0" + // info: + // version: 1.0.0 + // title: Swagger Petstore + // description: Information about Petstore + // license: + // name: MIT + // url: https://opensource.org/licenses/MIT + // servers: + // - url: http://petstore.swagger.io/v1 + // paths: + // /pets: + // get: + // summary: List all pets + // operationId: listPets + // tags: + // - pets + // responses: + // 200: + // description: An paged array of pets + // content: + // application/json: + // schema: + // type: string + // const: ABC + // `, + // 'foobar.yaml', + // ); - expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`); - }); + // const results = await lintDocument({ + // externalRefResolver: new BaseResolver(), + // document, + // config: await makeConfig({ spec: 'error' }), + // }); - it('detect OpenAPI should throw an error when version is not string', () => { - const testDocument = parseYamlToDocument( - outdent` - openapi: 3.0 - `, - '', - ); - expect(() => detectOpenAPI(testDocument.parsed)).toThrow( - `Invalid OpenAPI version: should be a string but got "number"`, - ); - }); + // expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`); + // }); - it("spec rule shouldn't throw an error for named callback", async () => { - const document = parseYamlToDocument( - outdent` - openapi: 3.1.0 - info: - title: Callback test - version: 'alpha' - components: - callbacks: - resultCallback: - '{$url}': - post: - requestBody: - description: Callback payload - content: - 'application/json': - schema: - type: object - properties: - test: - type: string - responses: - '200': - description: callback successfully processed - `, - 'foobar.yaml', - ); + // it('detect OpenAPI should throw an error when version is not string', () => { + // const testDocument = parseYamlToDocument( + // outdent` + // openapi: 3.0 + // `, + // '', + // ); + // expect(() => detectOpenAPI(testDocument.parsed)).toThrow( + // `Invalid OpenAPI version: should be a string but got "number"`, + // ); + // }); - const results = await lintDocument({ - externalRefResolver: new BaseResolver(), - document, - config: await makeConfig({ spec: 'error' }), - }); + // it("spec rule shouldn't throw an error for named callback", async () => { + // const document = parseYamlToDocument( + // outdent` + // openapi: 3.1.0 + // info: + // title: Callback test + // version: 'alpha' + // components: + // callbacks: + // resultCallback: + // '{$url}': + // post: + // requestBody: + // description: Callback payload + // content: + // 'application/json': + // schema: + // type: object + // properties: + // test: + // type: string + // responses: + // '200': + // description: callback successfully processed + // `, + // 'foobar.yaml', + // ); - expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`); - }); + // const results = await lintDocument({ + // externalRefResolver: new BaseResolver(), + // document, + // config: await makeConfig({ spec: 'error' }), + // }); + + // expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`); + // }); }); From ee2696a5d07a26beaadfc01f70cf571145265cc2 Mon Sep 17 00:00:00 2001 From: Andrew Tatomyr Date: Fri, 3 Jun 2022 16:03:51 +0200 Subject: [PATCH 08/11] chore: coverage down --- .github/workflows/tests.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 7053fb7316..b79ee17eb8 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -31,13 +31,13 @@ jobs: CI: true - name: Typecheck run: npm run typecheck - - name: Unit Tests - run: npm run jest -- --silent --ci --json --testLocationInResults --outputFile=report.json --bail --coverage + # - name: Unit Tests + # run: npm run jest -- --silent --ci --json --testLocationInResults --outputFile=report.json --bail --coverage - name: Coverage Report uses: artiomtr/jest-coverage-report-action@v2.0-rc.4 with: skip-step: none - coverage-file: report.json + # coverage-file: report.json annotations: none test-script: npm run jest -- --silent --ci --json --testLocationInResults --outputFile=report-base.json --bail --coverage - name: E2E Tests From ca998ec1139a6aceef0c49ee0cbf88035e11adbe Mon Sep 17 00:00:00 2001 From: Andrew Tatomyr Date: Fri, 3 Jun 2022 16:09:01 +0200 Subject: [PATCH 09/11] chore: coverage down --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index b79ee17eb8..43ff12e179 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -39,7 +39,7 @@ jobs: skip-step: none # coverage-file: report.json annotations: none - test-script: npm run jest -- --silent --ci --json --testLocationInResults --outputFile=report-base.json --bail --coverage + test-script: npm run jest -- --silent --ci --json --testLocationInResults --outputFile=report.json --bail --coverage - name: E2E Tests run: npm run e2e env: From 4f75ee60708d4ce25032e5255af7ae49fc43fe1d Mon Sep 17 00:00:00 2001 From: Andrew Tatomyr Date: Fri, 3 Jun 2022 16:13:20 +0200 Subject: [PATCH 10/11] chore: coverage down --- .github/workflows/tests.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 43ff12e179..7da3bf0f0e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -31,13 +31,13 @@ jobs: CI: true - name: Typecheck run: npm run typecheck - # - name: Unit Tests - # run: npm run jest -- --silent --ci --json --testLocationInResults --outputFile=report.json --bail --coverage + - name: Unit Tests + run: npm run jest -- --silent --ci --json --testLocationInResults --outputFile=report-incoming.json --bail --coverage - name: Coverage Report uses: artiomtr/jest-coverage-report-action@v2.0-rc.4 with: skip-step: none - # coverage-file: report.json + coverage-file: report-incoming.json annotations: none test-script: npm run jest -- --silent --ci --json --testLocationInResults --outputFile=report.json --bail --coverage - name: E2E Tests From 8214f22911d02411a388442465ba8501329906d9 Mon Sep 17 00:00:00 2001 From: Andrew Tatomyr Date: Fri, 3 Jun 2022 16:19:19 +0200 Subject: [PATCH 11/11] chore: coverage up --- packages/core/src/__tests__/lint.test.ts | 366 +++++++++++------------ 1 file changed, 180 insertions(+), 186 deletions(-) diff --git a/packages/core/src/__tests__/lint.test.ts b/packages/core/src/__tests__/lint.test.ts index 404fef364a..716ba4da80 100644 --- a/packages/core/src/__tests__/lint.test.ts +++ b/packages/core/src/__tests__/lint.test.ts @@ -1,16 +1,10 @@ import { outdent } from 'outdent'; - -// import { lintFromString, lintConfig, lintDocument } from '../lint'; -// import { BaseResolver } from '../resolve'; -// import { loadConfig } from '../config/load'; -// import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../__tests__/utils'; -// import { detectOpenAPI } from '../oas-types'; - -import { lintFromString } from '../lint'; +import { lintFromString, lintConfig, lintDocument } from '../lint'; +import { BaseResolver } from '../resolve'; import { loadConfig } from '../config/load'; -import { replaceSourceWithRef } from '../../__tests__/utils'; - +import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../__tests__/utils'; +import { detectOpenAPI } from '../oas-types'; describe('lint', () => { it('lintFromString should work', async () => { @@ -50,189 +44,189 @@ describe('lint', () => { `); }); - // it('lintConfig should work', async () => { - // const document = parseYamlToDocument( - // outdent` - // apis: error string - // lint: - // plugins: - // - './local-plugin.js' - // extends: - // - recommended - // - local/all - // rules: - // operation-2xx-response: warn - // no-invalid-media-type-examples: error - // path-http-verbs-order: error - // boolean-parameter-prefixes: off - // features.openapi: - // showConsole: true - // layout: - // scope: section - // routingStrategy: browser - // theme: - // rightPanel: - // backgroundColor: '#263238' - // links: - // color: '#6CC496' - // `, - // '', - // ); - // const results = await lintConfig({ document }); - - // expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(` - // Array [ - // Object { - // "location": Array [ - // Object { - // "pointer": "#/apis", - // "reportOnKey": false, - // "source": "", - // }, - // ], - // "message": "Expected type \`ConfigApis\` (object) but got \`string\`", - // "ruleId": "spec", - // "severity": "error", - // "suggest": Array [], - // }, - // Object { - // "location": Array [ - // Object { - // "pointer": "#/features.openapi/layout", - // "reportOnKey": false, - // "source": "", - // }, - // ], - // "message": "Expected type \`string\` but got \`object\`.", - // "ruleId": "spec", - // "severity": "error", - // "suggest": Array [], - // }, - // ] - // `); - // }); + it('lintConfig should work', async () => { + const document = parseYamlToDocument( + outdent` + apis: error string + lint: + plugins: + - './local-plugin.js' + extends: + - recommended + - local/all + rules: + operation-2xx-response: warn + no-invalid-media-type-examples: error + path-http-verbs-order: error + boolean-parameter-prefixes: off + features.openapi: + showConsole: true + layout: + scope: section + routingStrategy: browser + theme: + rightPanel: + backgroundColor: '#263238' + links: + color: '#6CC496' + `, + '', + ); + const results = await lintConfig({ document }); - // it("'plugins' shouldn't be allowed in 'apis' -> 'lint' field", async () => { - // const document = parseYamlToDocument( - // outdent` - // apis: - // lint: - // plugins: - // - './local-plugin.js' - // lint: - // plugins: - // - './local-plugin.js' - // `, - // '', - // ); - // const results = await lintConfig({ document }); + expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(` + Array [ + Object { + "location": Array [ + Object { + "pointer": "#/apis", + "reportOnKey": false, + "source": "", + }, + ], + "message": "Expected type \`ConfigApis\` (object) but got \`string\`", + "ruleId": "spec", + "severity": "error", + "suggest": Array [], + }, + Object { + "location": Array [ + Object { + "pointer": "#/features.openapi/layout", + "reportOnKey": false, + "source": "", + }, + ], + "message": "Expected type \`string\` but got \`object\`.", + "ruleId": "spec", + "severity": "error", + "suggest": Array [], + }, + ] + `); + }); - // expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(` - // Array [ - // Object { - // "location": Array [ - // Object { - // "pointer": "#/apis/lint/plugins", - // "reportOnKey": true, - // "source": "", - // }, - // ], - // "message": "Property \`plugins\` is not expected here.", - // "ruleId": "spec", - // "severity": "error", - // "suggest": Array [], - // }, - // ] - // `); - // }); + it("'plugins' shouldn't be allowed in 'apis' -> 'lint' field", async () => { + const document = parseYamlToDocument( + outdent` + apis: + lint: + plugins: + - './local-plugin.js' + lint: + plugins: + - './local-plugin.js' + `, + '', + ); + const results = await lintConfig({ document }); - // it("'const' can have any type", async () => { - // const document = parseYamlToDocument( - // outdent` - // openapi: "3.1.0" - // info: - // version: 1.0.0 - // title: Swagger Petstore - // description: Information about Petstore - // license: - // name: MIT - // url: https://opensource.org/licenses/MIT - // servers: - // - url: http://petstore.swagger.io/v1 - // paths: - // /pets: - // get: - // summary: List all pets - // operationId: listPets - // tags: - // - pets - // responses: - // 200: - // description: An paged array of pets - // content: - // application/json: - // schema: - // type: string - // const: ABC - // `, - // 'foobar.yaml', - // ); + expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(` + Array [ + Object { + "location": Array [ + Object { + "pointer": "#/apis/lint/plugins", + "reportOnKey": true, + "source": "", + }, + ], + "message": "Property \`plugins\` is not expected here.", + "ruleId": "spec", + "severity": "error", + "suggest": Array [], + }, + ] + `); + }); - // const results = await lintDocument({ - // externalRefResolver: new BaseResolver(), - // document, - // config: await makeConfig({ spec: 'error' }), - // }); + it("'const' can have any type", async () => { + const document = parseYamlToDocument( + outdent` + openapi: "3.1.0" + info: + version: 1.0.0 + title: Swagger Petstore + description: Information about Petstore + license: + name: MIT + url: https://opensource.org/licenses/MIT + servers: + - url: http://petstore.swagger.io/v1 + paths: + /pets: + get: + summary: List all pets + operationId: listPets + tags: + - pets + responses: + 200: + description: An paged array of pets + content: + application/json: + schema: + type: string + const: ABC + `, + 'foobar.yaml', + ); + + const results = await lintDocument({ + externalRefResolver: new BaseResolver(), + document, + config: await makeConfig({ spec: 'error' }), + }); - // expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`); - // }); + expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`); + }); - // it('detect OpenAPI should throw an error when version is not string', () => { - // const testDocument = parseYamlToDocument( - // outdent` - // openapi: 3.0 - // `, - // '', - // ); - // expect(() => detectOpenAPI(testDocument.parsed)).toThrow( - // `Invalid OpenAPI version: should be a string but got "number"`, - // ); - // }); + it('detect OpenAPI should throw an error when version is not string', () => { + const testDocument = parseYamlToDocument( + outdent` + openapi: 3.0 + `, + '', + ); + expect(() => detectOpenAPI(testDocument.parsed)).toThrow( + `Invalid OpenAPI version: should be a string but got "number"`, + ); + }); - // it("spec rule shouldn't throw an error for named callback", async () => { - // const document = parseYamlToDocument( - // outdent` - // openapi: 3.1.0 - // info: - // title: Callback test - // version: 'alpha' - // components: - // callbacks: - // resultCallback: - // '{$url}': - // post: - // requestBody: - // description: Callback payload - // content: - // 'application/json': - // schema: - // type: object - // properties: - // test: - // type: string - // responses: - // '200': - // description: callback successfully processed - // `, - // 'foobar.yaml', - // ); + it("spec rule shouldn't throw an error for named callback", async () => { + const document = parseYamlToDocument( + outdent` + openapi: 3.1.0 + info: + title: Callback test + version: 'alpha' + components: + callbacks: + resultCallback: + '{$url}': + post: + requestBody: + description: Callback payload + content: + 'application/json': + schema: + type: object + properties: + test: + type: string + responses: + '200': + description: callback successfully processed + `, + 'foobar.yaml', + ); - // const results = await lintDocument({ - // externalRefResolver: new BaseResolver(), - // document, - // config: await makeConfig({ spec: 'error' }), - // }); + const results = await lintDocument({ + externalRefResolver: new BaseResolver(), + document, + config: await makeConfig({ spec: 'error' }), + }); - // expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`); - // }); + expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`); + }); });