Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #80 from AtomLinter/arcanemagus/no-required-quotes
Browse files Browse the repository at this point in the history
Don't require quotes around version
  • Loading branch information
Arcanemagus authored Feb 6, 2019
2 parents 2c3a009 + 2f02da2 commit 0ed5d7f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let populateRangesForErrors;
const idleCallbacks = new Set();

function canValidate(text) {
return text.length > 8 && /"?(swagger|openapi)"?\s*:\s*['"]\d+\.\d+(.\d+)?['"]/g.test(text);
return text.length > 8 && /"?(swagger|openapi)"?\s*:\s*['"]?\d+\.\d+(.\d+)?['"]?/g.test(text);
}

function errorsToLinterMessages(err, path, text) {
Expand Down
21 changes: 21 additions & 0 deletions spec/fixtures/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
openapi: 3.0.0
info:
title: Open API Sample
version: 1.0.0
paths:
/todos:
get:
description: "Returns all todo items"
responses:
200:
description: "A list of todo items"
schema:
type: array
items:
type: object
properties:
id:
type: strin
format: uuid
name:
type: string
24 changes: 24 additions & 0 deletions spec/yaml-files-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@ describe('Linting YAML files', () => {
await atom.packages.activatePackage('linter-swagger');
});

it('Handles no quotes around version', async () => {
const OPENAPI = join(__dirname, 'fixtures', 'openapi.yaml');
const editor = await atom.workspace.open(OPENAPI);
const messages = await lint(editor);

expect(messages.length).toEqual(2);
expect(messages[0]).toEqual({
severity: 'error',
excerpt: 'Additional properties not allowed: schema',
location: {
file: OPENAPI,
position: [[11, 10], [11, 16]],
},
});
expect(messages[1]).toEqual({
severity: 'error',
excerpt: 'Missing required property: $ref',
location: {
file: OPENAPI,
position: [[11, 10], [11, 16]],
},
});
});

it('Handles correct input with no errors', async () => {
const PETSTORE = join(__dirname, 'fixtures', 'petstore.yaml');
const editor = await atom.workspace.open(PETSTORE);
Expand Down

0 comments on commit 0ed5d7f

Please sign in to comment.