Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling reference-components-regex #28

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Changed
- `properties` rule will now ignore extensions, so `foo: 'a', x-bar: 'b'` is only 1 property.
### Fixed
- Disabled `reference-components-regex` rule until resolver can allow it to work

## [0.5.3] - 2018-03-29
### Fixed
Expand Down
28 changes: 15 additions & 13 deletions lib/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,21 @@ const lint = (objectName, object, options = {}) => {
const target = object[property]

let components = [];
if (split) {
components = target.split(split);
}
else {
components.push(target);
}
const re = new RegExp(value);
for (let component of components) {
if (omit) component = component.split(omit).join('');
if (component) {
ensure(rule, () => {
should(re.test(component)).be.exactly(true, rule.description);
});
if (target) {
if (split) {
components = target.split(split);
}
else {
components.push(target);
}
const re = new RegExp(value);
for (let component of components) {
if (omit) component = component.split(omit).join('');
if (component) {
ensure(rule, () => {
should(re.test(component)).be.exactly(true, rule.description);
});
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,9 @@ function checkPathItem(pathItem, path, openapi, options) {
op.should.not.have.property('produces');
op.should.not.have.property('schemes');
op.should.have.property('responses');
op.responses.should.not.be.empty();
if (!(typeof op.responses === 'object' && Object.keys(op.responses).length > 0)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but an empty responses was causing unclear errors.

should.fail(false,true,'Operation object responses must be a non-empty object');
}
if (op.summary) op.summary.should.have.type('string');
if (op.description) op.description.should.have.type('string');
if (typeof op.operationId !== 'undefined') {
Expand Down
4 changes: 2 additions & 2 deletions rules/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@
{
"name": "reference-components-regex",
"object": "reference",
"enabled": true,
"description": "reference components should all match spec. regex",
"enabled": false,
"description": "reference components should all match regex ^[a-zA-Z0-9\\.\\-_]+",
"pattern": { "property": "$ref", "omit": "#", "split": "/", "value": "^[a-zA-Z0-9\\.\\-_]+$" }
},
{
Expand Down
2 changes: 1 addition & 1 deletion test/linter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function testProfile(profile) {
else {
it(JSON.stringify(test.input) + ' is not valid', done => {
const actualRuleErrors = options.lintResults.map(result => result.rule.name);
test.expectedRuleErrors.should.deepEqual(actualRuleErrors);
actualRuleErrors.should.deepEqual(test.expectedRuleErrors);
done();
});
}
Expand Down
6 changes: 3 additions & 3 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('loader.js', () => {
"openapi-tags-alphabetical",
"reference-no-other-properties",
"example-value-or-externalValue",
"reference-components-regex",
// "reference-components-regex",
"no-script-tags-in-markdown",
"info-contact",
"license-apimatic-bug",
Expand Down Expand Up @@ -75,12 +75,12 @@ describe('loader.js', () => {

it('does not resolve references by default', async () => {
const spec = await loader.loadSpec(samplesDir + 'refs/openapi.yaml');
should(spec.paths.a).have.key('$ref');
should(spec.paths['/a']).have.key('$ref');
});

it('resolves refs when passed { resolve: true }', async () => {
const spec = await loader.loadSpec(samplesDir + 'refs/openapi.yaml', { resolve: true });
should(spec.paths.a.post.description).equal('Some operation object');
should(spec.paths['/a'].post.description).equal('Some operation object');
});

it('throws OpenError for non-existant file', async () => {
Expand Down
12 changes: 12 additions & 0 deletions test/profiles/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@
"expectedRuleErrors": [
"reference-no-other-properties"
]
},
{
"input": {
"$ref": "parameters.yml#/roomId"
},
"expectedRuleErrors": []
},
{
"input": {
"$ref": "./parameters.yml#/roomId"
},
"expectValid": true
}
]
},
Expand Down
Loading