Skip to content

Commit

Permalink
feat: remove error for partial path templating (#262)
Browse files Browse the repository at this point in the history
Purpose:
- Partial path templating is not disallowed in OAS3, so although partial path templating may not be ideal style, do not want it to be an error.

Changes:
- Remove code that checks for partial path templating.

Tests:
- Remove tests that test partial path template validation code.
  • Loading branch information
barrett-schonefeld committed Mar 26, 2021
1 parent 311982d commit 2838875
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 63 deletions.
17 changes: 0 additions & 17 deletions src/plugins/validation/2and3/semantic-validators/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
// Paths must have unique (name + in combination) parameters

// Assertation 5:
// Paths cannot have partial templates. (/path/abc{123} is illegal)

// Assertation 6:
// Paths cannot have literal query strings in them.
// Handled by the Spectral rule, path-not-include-query

Expand Down Expand Up @@ -43,20 +40,6 @@ module.exports.validate = function({ resolvedSpec }) {
return;
}

pathName.split('/').map(substr => {
// Assertation 5
if (
templateRegex.test(substr) &&
substr.replace(templateRegex, '').length > 0
) {
messages.addMessage(
`paths.${pathName}`,
'Partial path templating is not allowed.',
'error'
);
}
});

const parametersFromPath = path.parameters ? path.parameters.slice() : [];

const availableParameters = parametersFromPath.map((param, i) => {
Expand Down
46 changes: 0 additions & 46 deletions test/plugins/validation/2and3/paths.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,28 +203,6 @@ describe('validation plugin - semantic - paths', function() {
});

describe('Paths cannot have partial templates', () => {
it('should return one problem for an illegal partial path template', function() {
const spec = {
paths: {
'/CoolPath/user{id}': {
parameters: [
{
name: 'id',
in: 'path'
}
]
}
}
};

const res = validate({ resolvedSpec: spec });
expect(res.errors.length).toEqual(1);
expect(res.errors[0].message).toEqual(
'Partial path templating is not allowed.'
);
expect(res.errors[0].path).toEqual('paths./CoolPath/user{id}');
});

it('should return no problems for a correct path template', function() {
const spec = {
paths: {
Expand Down Expand Up @@ -267,30 +245,6 @@ describe('validation plugin - semantic - paths', function() {
});

describe('Integrations', () => {
it('should return one problem for an illegal query string in a path string', function() {
const spec = {
paths: {
'/report?rdate={relative_date}': {
parameters: [
{
name: 'relative_date',
in: 'path'
}
]
}
}
};

const res = validate({ resolvedSpec: spec });
expect(res.errors.length).toEqual(1);
expect(res.errors[0].message).toEqual(
'Partial path templating is not allowed.'
);
expect(res.errors[0].path).toEqual(
'paths./report?rdate={relative_date}'
);
});

it.skip('should return two problems for an equivalent path string missing a parameter definition', function() {
const spec = {
paths: {
Expand Down

0 comments on commit 2838875

Please sign in to comment.