80 lines
2.3 KiB
Plaintext
80 lines
2.3 KiB
Plaintext
import { outdent } from 'outdent';
|
|
import { lintDocument } from '../../../lint';
|
|
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
|
|
import { BaseResolver } from '../../../resolve';
|
|
|
|
describe('Oas3 oas3-no-server-trailing-slash', () => {
|
|
it('oas3-no-server-trailing-slash: should report on server object with trailing slash', async () => {
|
|
const document = parseYamlToDocument(
|
|
outdent`
|
|
openapi: 3.0.0
|
|
servers:
|
|
- url: https://somedomain.com/
|
|
`,
|
|
'foobar.yaml'
|
|
);
|
|
|
|
const results = await lintDocument({
|
|
externalRefResolver: new BaseResolver(),
|
|
document,
|
|
config: await makeConfig({ rules: { 'no-server-trailing-slash': 'error' } }),
|
|
});
|
|
|
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
[
|
|
{
|
|
"location": [
|
|
{
|
|
"pointer": "#/servers/0/url",
|
|
"reportOnKey": false,
|
|
"source": "foobar.yaml",
|
|
},
|
|
],
|
|
"message": "Server \`url\` should not have a trailing slash.",
|
|
"ruleId": "no-server-trailing-slash",
|
|
"severity": "error",
|
|
"suggest": [],
|
|
},
|
|
]
|
|
`);
|
|
});
|
|
|
|
it('oas3-no-server-trailing-slash: should not report on server object with no trailing slash', async () => {
|
|
const document = parseYamlToDocument(
|
|
outdent`
|
|
openapi: 3.0.0
|
|
servers:
|
|
- url: https://somedomain.com
|
|
`,
|
|
'foobar.yaml'
|
|
);
|
|
|
|
const results = await lintDocument({
|
|
externalRefResolver: new BaseResolver(),
|
|
document,
|
|
config: await makeConfig({ rules: { 'no-server-trailing-slash': 'error' } }),
|
|
});
|
|
|
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
|
|
});
|
|
|
|
it('oas3-no-server-trailing-slash: should not report on server object with no trailing slash if the url is root', async () => {
|
|
const document = parseYamlToDocument(
|
|
outdent`
|
|
openapi: 3.0.0
|
|
servers:
|
|
- url: /
|
|
`,
|
|
'foobar.yaml'
|
|
);
|
|
|
|
const results = await lintDocument({
|
|
externalRefResolver: new BaseResolver(),
|
|
document,
|
|
config: await makeConfig({ rules: { 'no-server-trailing-slash': 'error' } }),
|
|
});
|
|
|
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
|
|
});
|
|
});
|