Skip to content

Commit

Permalink
Merge pull request #28 from wework/feature/regex
Browse files Browse the repository at this point in the history
Disabling reference-components-regex
  • Loading branch information
Phil Sturgeon authored Apr 3, 2018
2 parents 31456aa + 1fcd638 commit 14fb75a
Show file tree
Hide file tree
Showing 11 changed files with 758 additions and 1,085 deletions.
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)) {
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

0 comments on commit 14fb75a

Please sign in to comment.