mirror of
https://github.com/Kong/insomnia
synced 2024-11-07 22:30:15 +00:00
Update Spectral to latest release (#3179)
This commit is contained in:
parent
837cadebaf
commit
c24d08ad66
12
packages/insomnia-app/app/common/spectral.ts
Normal file
12
packages/insomnia-app/app/common/spectral.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { IRuleResult, isOpenApiv2, isOpenApiv3, Spectral } from '@stoplight/spectral';
|
||||
|
||||
export const initializeSpectral = () => {
|
||||
const spectral = new Spectral();
|
||||
spectral.registerFormat('oas2', isOpenApiv2);
|
||||
spectral.registerFormat('oas3', isOpenApiv3);
|
||||
spectral.loadRuleset('spectral:oas');
|
||||
|
||||
return spectral;
|
||||
};
|
||||
|
||||
export const isLintError = (result: IRuleResult) => result.severity === 0;
|
@ -1,10 +1,11 @@
|
||||
import CodeMirror from 'codemirror';
|
||||
import { Spectral } from '@stoplight/spectral';
|
||||
import { isLintError, initializeSpectral } from '../../../../common/spectral';
|
||||
|
||||
const spectral = new Spectral();
|
||||
const spectral = initializeSpectral();
|
||||
|
||||
CodeMirror.registerHelper('lint', 'openapi', async function(text) {
|
||||
const results = await spectral.run(text);
|
||||
const results = (await spectral.run(text)).filter(isLintError);
|
||||
|
||||
return results.map(result => ({
|
||||
from: CodeMirror.Pos(result.range.start.line, result.range.start.character),
|
||||
to: CodeMirror.Pos(result.range.end.line, result.range.end.character),
|
||||
|
@ -6,7 +6,6 @@ import { Button, NoticeTable } from 'insomnia-components';
|
||||
import ErrorBoundary from './error-boundary';
|
||||
import SpecEditorSidebar from './spec-editor/spec-editor-sidebar';
|
||||
import CodeEditor from './codemirror/code-editor';
|
||||
import { Spectral } from '@stoplight/spectral';
|
||||
import SwaggerUI from 'swagger-ui-react';
|
||||
import type { ApiSpec } from '../../models/api-spec';
|
||||
import previewIcon from '../images/icn-eye.svg';
|
||||
@ -15,8 +14,9 @@ import { parseApiSpec, ParsedApiSpec } from '../../common/api-specs';
|
||||
import type { GlobalActivity } from '../../common/constants';
|
||||
import { ACTIVITY_HOME, AUTOBIND_CFG } from '../../common/constants';
|
||||
import WorkspacePageHeader from './workspace-page-header';
|
||||
import { initializeSpectral, isLintError } from '../../common/spectral';
|
||||
|
||||
const spectral = new Spectral();
|
||||
const spectral = initializeSpectral();
|
||||
|
||||
interface Props {
|
||||
gitSyncDropdown: ReactNode;
|
||||
@ -110,7 +110,7 @@ class WrapperDesign extends PureComponent<Props, State> {
|
||||
|
||||
// Lint only if spec has content
|
||||
if (activeApiSpec && activeApiSpec.contents.length !== 0) {
|
||||
const results = await spectral.run(activeApiSpec.contents);
|
||||
const results = (await spectral.run(activeApiSpec.contents)).filter(isLintError);
|
||||
this.setState({
|
||||
lintMessages: results.map(r => ({
|
||||
type: r.severity === 0 ? 'error' : 'warning',
|
||||
|
@ -76,7 +76,6 @@ import { importRaw } from '../../common/import';
|
||||
import GitSyncDropdown from './dropdowns/git-sync-dropdown';
|
||||
import { DropdownButton } from './base/dropdown';
|
||||
import type { GlobalActivity } from '../../common/constants';
|
||||
import { Spectral } from '@stoplight/spectral';
|
||||
import ProtoFilesModal from './modals/proto-files-modal';
|
||||
import { GrpcDispatchModalWrapper } from '../context/grpc';
|
||||
import WrapperMigration from './wrapper-migration';
|
||||
@ -86,8 +85,9 @@ import { HandleGetRenderContext, HandleRender } from '../../common/render';
|
||||
import { RequestGroup } from '../../models/request-group';
|
||||
import SpaceSettingsModal from './modals/space-settings-modal';
|
||||
import { AppProps } from '../containers/app';
|
||||
import { initializeSpectral, isLintError } from '../../common/spectral';
|
||||
|
||||
const spectral = new Spectral();
|
||||
const spectral = initializeSpectral();
|
||||
|
||||
export type WrapperProps = AppProps & {
|
||||
handleActivateRequest: (activeRequestId: string) => void;
|
||||
@ -259,8 +259,7 @@ class Wrapper extends PureComponent<WrapperProps, State> {
|
||||
// Handle switching away from the spec design activity. For this, we want to generate
|
||||
// requests that can be accessed from debug or test.
|
||||
// If there are errors in the spec, show the user a warning first
|
||||
const results = await spectral.run(activeApiSpec.contents);
|
||||
|
||||
const results = (await spectral.run(activeApiSpec.contents)).filter(isLintError);
|
||||
if (activeApiSpec.contents && results && results.length) {
|
||||
showModal(AlertModal, {
|
||||
title: 'Error Generating Configuration',
|
||||
|
796
packages/insomnia-app/package-lock.json
generated
796
packages/insomnia-app/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -75,7 +75,7 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"@hot-loader/react-dom": "^16.8.6",
|
||||
"@stoplight/spectral": "^4.1.1",
|
||||
"@stoplight/spectral": "^5.9.0",
|
||||
"analytics-node": "^4.0.1",
|
||||
"aws4": "^1.9.0",
|
||||
"axios": "^0.21.1",
|
||||
|
729
packages/insomnia-inso/package-lock.json
generated
729
packages/insomnia-inso/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -58,7 +58,7 @@
|
||||
"webpack-node-externals": "^1.7.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@stoplight/spectral": "^5.4.0",
|
||||
"@stoplight/spectral": "^5.9.0",
|
||||
"commander": "^5.1.0",
|
||||
"consola": "^2.15.0",
|
||||
"cosmiconfig": "^6.0.0",
|
||||
|
@ -2,6 +2,9 @@ openapi: '3.0.2'
|
||||
info:
|
||||
title: Sample Spec
|
||||
version: '1.2'
|
||||
description: A sample API specification
|
||||
contact:
|
||||
email: support@insomnia.rest
|
||||
servers:
|
||||
- url: https://200.insomnia.rest
|
||||
tags:
|
||||
@ -9,6 +12,8 @@ tags:
|
||||
paths:
|
||||
/global:
|
||||
get:
|
||||
description: Global
|
||||
operationId: get_global
|
||||
tags:
|
||||
- Folder
|
||||
responses:
|
||||
@ -16,6 +21,10 @@ paths:
|
||||
description: OK
|
||||
/override:
|
||||
get:
|
||||
description: Override
|
||||
operationId: get_override
|
||||
tags:
|
||||
- Folder
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Spectral } from '@stoplight/spectral';
|
||||
import { Spectral, isOpenApiv2, isOpenApiv3 } from '@stoplight/spectral';
|
||||
import type { GlobalOptions } from '../get-options';
|
||||
import { loadDb } from '../db';
|
||||
import { loadApiSpec, promptApiSpec } from '../db/models/api-spec';
|
||||
@ -48,7 +48,13 @@ export async function lintSpecification(
|
||||
}
|
||||
|
||||
const spectral = new Spectral();
|
||||
const results = await spectral.run(specContent);
|
||||
spectral.registerFormat('oas2', isOpenApiv2);
|
||||
spectral.registerFormat('oas3', isOpenApiv3);
|
||||
await spectral.loadRuleset('spectral:oas');
|
||||
|
||||
const results = (await spectral.run(specContent)).filter(result => (
|
||||
result.severity === 0 // filter for errors only
|
||||
));
|
||||
|
||||
if (results.length) {
|
||||
logger.log(`${results.length} lint errors found. \n`);
|
||||
|
@ -5,6 +5,9 @@ contents: |
|
||||
info:
|
||||
title: Sample Spec
|
||||
version: '1.2'
|
||||
description: A sample API specification
|
||||
contact:
|
||||
email: support@insomnia.rest
|
||||
servers:
|
||||
- url: https://200.insomnia.rest
|
||||
tags:
|
||||
@ -12,6 +15,8 @@ contents: |
|
||||
paths:
|
||||
/global:
|
||||
get:
|
||||
description: Global
|
||||
operationId: get_global
|
||||
tags:
|
||||
- Folder
|
||||
responses:
|
||||
@ -19,6 +24,10 @@ contents: |
|
||||
description: OK
|
||||
/override:
|
||||
get:
|
||||
description: Override
|
||||
operationId: get_override
|
||||
tags:
|
||||
- Folder
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
|
833
packages/insomnia-send-request/package-lock.json
generated
833
packages/insomnia-send-request/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,7 @@
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/send-request/index.d.ts",
|
||||
"dependencies": {
|
||||
"@stoplight/spectral": "^5.4.0",
|
||||
"@stoplight/spectral": "^5.9.0",
|
||||
"analytics-node": "^4.0.1",
|
||||
"aws4": "^1.10.0",
|
||||
"axios": "^0.21.1",
|
||||
|
Loading…
Reference in New Issue
Block a user