Skip to content

Commit

Permalink
fix(ls): fix condition for server URL linting
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Jul 26, 2023
1 parent 434bd38 commit 42f7575
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const urlFormatURILint: LinterMeta = {
data: {},
conditions: [
{
targets: [{ path: 'url' }],
function: 'apilintValueRegex',
params: ['^(?!.*\\{\\S+?\\}).*$'], // validate as URI only if variables in brackets not present
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
openapi: 3.1.0
info:
title: test
version: 1.0.0
servers:
- url: https://{host}:{port}/{basePath}
description: Live Bookstore dynamic servers
variables:
host:
default: test.book.com
enum:
- test.book.com
- staging.book.com
- sandbox.book.com
- production.book.com
port:
default: '443'
enum:
- '443'
- '8443'
- '80'
basePath:
default: v1.3
enum:
- v1.0
- v1.1
- v1.2
- v1.3
paths:
/a:
get:
operationId: aget
28 changes: 28 additions & 0 deletions packages/apidom-ls/test/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3175,4 +3175,32 @@ describe('apidom-ls-validate', function () {

languageService.terminate();
});

it('oas / yaml - test server with variable URL', async function () {
const validationContext: ValidationContext = {
comments: DiagnosticSeverity.Error,
maxNumberOfProblems: 100,
relatedInformation: false,
};

const spec = fs
.readFileSync(
path.join(__dirname, 'fixtures', 'validation', 'oas', 'server-variables-url.yaml'),
)
.toString();
const doc: TextDocument = TextDocument.create(
'foo://bar/server-variables-url.yaml',
'yaml',
0,
spec,
);

const languageService: LanguageService = getLanguageService(contextNoSchema);

const result = await languageService.doValidation(doc, validationContext);
const expected: Diagnostic[] = [];
assert.deepEqual(result, expected as Diagnostic[]);

languageService.terminate();
});
});

0 comments on commit 42f7575

Please sign in to comment.