Skip to content

Commit

Permalink
Removed one of the duplicate '/_nodes/{metric}' and '/_nodes/{node_id…
Browse files Browse the repository at this point in the history
…}' paths.

Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Jul 12, 2024
1 parent 188413c commit 9dd01d3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
17 changes: 1 addition & 16 deletions spec/namespaces/nodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -253,24 +253,9 @@ paths:
responses:
'200':
$ref: '#/components/responses/nodes.usage@200'
/_nodes/{metric}:
get:
operationId: nodes.info.1
x-operation-group: nodes.info
x-version-added: '1.0'
description: Returns information about nodes in the cluster.
externalDocs:
url: https://opensearch.org/docs/latest/api-reference/nodes-apis/nodes-info/
parameters:
- $ref: '#/components/parameters/nodes.info::path.metric'
- $ref: '#/components/parameters/nodes.info::query.flat_settings'
- $ref: '#/components/parameters/nodes.info::query.timeout'
responses:
'200':
$ref: '#/components/responses/nodes.info@200'
/_nodes/{node_id}:
get:
operationId: nodes.info.2
operationId: nodes.info.1
x-operation-group: nodes.info
x-version-added: '1.0'
description: Returns information about nodes in the cluster.
Expand Down
23 changes: 18 additions & 5 deletions tools/src/linter/components/NamespacesFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import NamespaceFile from './NamespaceFile'
import { type ValidationError } from 'types'
import FolderValidator from './base/FolderValidator'
import _ from 'lodash'

export default class NamespacesFolder extends FolderValidator<NamespaceFile> {
constructor (folder_path: string) {
Expand All @@ -21,16 +22,28 @@ export default class NamespacesFolder extends FolderValidator<NamespaceFile> {
}

validate_duplicate_paths (): ValidationError[] {
const paths: Record<string, string[]> = {}
const paths: Record<string, [{ path: string, namespace: string }]> = {}
for (const file of this.files) {
if (file.spec().paths == null) continue
Object.keys(file.spec().paths).sort().forEach((path) => {
if (paths[path] == null) paths[path] = [file.namespace]
else paths[path].push(file.namespace)
const normalized_path = path.replaceAll(/\{[^}]+}/g, '{}')
const path_entry = {
path: path,

Check failure on line 31 in tools/src/linter/components/NamespacesFolder.ts

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand
namespace: file.namespace
}
if (paths[normalized_path] == null) {
paths[normalized_path] = [path_entry]
} else {
paths[normalized_path].push(path_entry)
}
})
}
return Object.entries(paths).map(([path, namespaces]) => {
if (namespaces.length > 1) { return this.error(`Duplicate path '${path}' found in namespaces: ${namespaces.sort().join(', ')}.`) }
return Object.entries(paths).map(([_normalized_path, namespaces]) => {
if (namespaces.length > 1) {
const dup_paths = _.uniq(_.map(namespaces, (entry) => { return `'${entry.path}'` }))
const dup_namespaces = _.uniq(_.map(namespaces, (entry) => entry.namespace ))

Check failure on line 44 in tools/src/linter/components/NamespacesFolder.ts

View workflow job for this annotation

GitHub Actions / lint

There should be no space before this paren
return this.error(`Duplicate path${dup_paths.length > 1 ? 's' : ''} ${_.join(dup_paths, ', ')} found in namespace${dup_namespaces.length > 1 ? 's' : ''}: ${_.join(dup_namespaces, ', ')}.`)

Check failure on line 45 in tools/src/linter/components/NamespacesFolder.ts

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
}
}).filter((e) => e) as ValidationError[]
}
}
5 changes: 5 additions & 0 deletions tools/tests/linter/NamespacesFolder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ describe('validate()', () => {
file: 'invalid_folder/',
location: 'Folder',
message: "Duplicate path '/{index}/_rollover' found in namespaces: dup_path_a, dup_path_b, dup_path_c."
},
{
file: 'invalid_folder/',
location: 'Folder',
message: "Duplicate paths '/nodes/{metric}', '/nodes/{node_id}' found in namespace: dup_path_d."
}
])
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
paths:
'/nodes/{metric}': {}
'/nodes/{node_id}': {}

0 comments on commit 9dd01d3

Please sign in to comment.