@redocly/openapi-core
Version:
See https://github.com/Redocly/openapi-cli
86 lines (76 loc) • 2.32 kB
text/typescript
import { outdent } from 'outdent';
import { lintDocument } from '../../../lint';
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
import { BaseResolver } from '../../../resolve';
describe('no-path-trailing-slash', () => {
it('should report on trailing slash in path', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
'/bad/':
get:
summary: List all pets
`,
'foobar.yaml',
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: makeConfig({ 'no-path-trailing-slash': 'error' }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
Array [
Object {
"location": Array [
Object {
"pointer": "#/paths/~1bad~1",
"reportOnKey": true,
"source": "foobar.yaml",
},
],
"message": "\`/bad/\` should not have a trailing slash.",
"ruleId": "no-path-trailing-slash",
"severity": "error",
"suggest": Array [],
},
]
`);
});
it('should not report on if no trailing slash in path', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
'/good':
get:
summary: List all pets
`,
'foobar.yaml',
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: makeConfig({ 'no-path-trailing-slash': 'error' }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
});
it('should not report on trailing slash in path if the path is root', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
'/':
get:
summary: List all pets
`,
'foobar.yaml',
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: makeConfig({ 'no-path-trailing-slash': 'error' }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
});
});