Skip to content

Commit 14fb75a

Browse files
author
Phil Sturgeon
authored
Merge pull request #28 from wework/feature/regex
Disabling reference-components-regex
2 parents 31456aa + 1fcd638 commit 14fb75a

11 files changed

+758
-1085
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
### Changed
99
- `properties` rule will now ignore extensions, so `foo: 'a', x-bar: 'b'` is only 1 property.
10+
### Fixed
11+
- Disabled `reference-components-regex` rule until resolver can allow it to work
1012

1113
## [0.5.3] - 2018-03-29
1214
### Fixed

lib/linter.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,21 @@ const lint = (objectName, object, options = {}) => {
110110
const target = object[property]
111111

112112
let components = [];
113-
if (split) {
114-
components = target.split(split);
115-
}
116-
else {
117-
components.push(target);
118-
}
119-
const re = new RegExp(value);
120-
for (let component of components) {
121-
if (omit) component = component.split(omit).join('');
122-
if (component) {
123-
ensure(rule, () => {
124-
should(re.test(component)).be.exactly(true, rule.description);
125-
});
113+
if (target) {
114+
if (split) {
115+
components = target.split(split);
116+
}
117+
else {
118+
components.push(target);
119+
}
120+
const re = new RegExp(value);
121+
for (let component of components) {
122+
if (omit) component = component.split(omit).join('');
123+
if (component) {
124+
ensure(rule, () => {
125+
should(re.test(component)).be.exactly(true, rule.description);
126+
});
127+
}
126128
}
127129
}
128130
}

lib/validate.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,9 @@ function checkPathItem(pathItem, path, openapi, options) {
688688
op.should.not.have.property('produces');
689689
op.should.not.have.property('schemes');
690690
op.should.have.property('responses');
691-
op.responses.should.not.be.empty();
691+
if (!(typeof op.responses === 'object' && Object.keys(op.responses).length > 0)) {
692+
should.fail(false,true,'Operation object responses must be a non-empty object');
693+
}
692694
if (op.summary) op.summary.should.have.type('string');
693695
if (op.description) op.description.should.have.type('string');
694696
if (typeof op.operationId !== 'undefined') {

rules/default.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@
9292
{
9393
"name": "reference-components-regex",
9494
"object": "reference",
95-
"enabled": true,
96-
"description": "reference components should all match spec. regex",
95+
"enabled": false,
96+
"description": "reference components should all match regex ^[a-zA-Z0-9\\.\\-_]+",
9797
"pattern": { "property": "$ref", "omit": "#", "split": "/", "value": "^[a-zA-Z0-9\\.\\-_]+$" }
9898
},
9999
{

test/linter.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function testProfile(profile) {
2525
else {
2626
it(JSON.stringify(test.input) + ' is not valid', done => {
2727
const actualRuleErrors = options.lintResults.map(result => result.rule.name);
28-
test.expectedRuleErrors.should.deepEqual(actualRuleErrors);
28+
actualRuleErrors.should.deepEqual(test.expectedRuleErrors);
2929
done();
3030
});
3131
}

test/loader.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('loader.js', () => {
1717
"openapi-tags-alphabetical",
1818
"reference-no-other-properties",
1919
"example-value-or-externalValue",
20-
"reference-components-regex",
20+
// "reference-components-regex",
2121
"no-script-tags-in-markdown",
2222
"info-contact",
2323
"license-apimatic-bug",
@@ -75,12 +75,12 @@ describe('loader.js', () => {
7575

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

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

8686
it('throws OpenError for non-existant file', async () => {

test/profiles/default.json

+12
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@
139139
"expectedRuleErrors": [
140140
"reference-no-other-properties"
141141
]
142+
},
143+
{
144+
"input": {
145+
"$ref": "parameters.yml#/roomId"
146+
},
147+
"expectedRuleErrors": []
148+
},
149+
{
150+
"input": {
151+
"$ref": "./parameters.yml#/roomId"
152+
},
153+
"expectValid": true
142154
}
143155
]
144156
},

0 commit comments

Comments
 (0)