-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from CiscoDevNet/new-rules
add rule for multi-version and operation-id-required-uniq-verb-noun
- Loading branch information
Showing
21 changed files
with
1,979 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright 2022 Cisco Systems, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import { isObject } from '../util/funcUtils.js'; | ||
|
||
/** | ||
* Checks if there is only one version in server urls and paths. | ||
* @param {string} targetVal The string to lint | ||
* @param {object} opts checks to do | ||
*/ | ||
export default function (targetVal) { | ||
if (!isObject(targetVal)) { | ||
return; | ||
} | ||
|
||
const results = []; | ||
|
||
for (const key in targetVal) { | ||
if (targetVal[key].enum && targetVal[key].default) { | ||
if (!targetVal[key].enum.includes(targetVal[key].default)) { | ||
results.push({ | ||
message: 'default not in enum', | ||
}); | ||
} | ||
} | ||
} | ||
|
||
return results; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Copyright 2022 Cisco Systems, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import defaultInEnum from './defaultInEnum.js'; | ||
|
||
describe('defaultInEnum', () => { | ||
const targetVal = { | ||
'port': { | ||
'enum': [ | ||
8443, | ||
443, | ||
], | ||
'default': 8443, | ||
}, | ||
}; | ||
|
||
test('should pass when default in enum', () => { | ||
const res = defaultInEnum(targetVal); | ||
|
||
expect(res).toEqual([]); | ||
}); | ||
|
||
|
||
test('should pass if no default field in enum', () => { | ||
const targetVal = { | ||
'port': { | ||
'enum': [ | ||
8443, | ||
443, | ||
], | ||
}, | ||
}; | ||
|
||
const res = defaultInEnum(targetVal); | ||
|
||
expect(res).toEqual([]); | ||
}); | ||
|
||
test('should fail if default in not in enum', () => { | ||
const targetVal = { | ||
'port': { | ||
'enum': [ | ||
8443, | ||
443, | ||
], | ||
'default': 1443, | ||
}, | ||
}; | ||
|
||
const res = defaultInEnum(targetVal); | ||
|
||
expect(res).toEqual([ | ||
{ | ||
message: 'default not in enum', | ||
}, | ||
]); | ||
}); | ||
|
||
}); |
Oops, something went wrong.