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 <dblock@amazon.com>
  • Loading branch information
dblock committed Jul 12, 2024
1 parent 188413c commit 8115fa7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fixed `/_data_stream` health status and required fields ([#401](https://github.com/opensearch-project/opensearch-api-specification/pull/401))
- Fixed query DSL `match` that supports a field name and value ([#405](https://github.com/opensearch-project/opensearch-api-specification/pull/405))
- Fixed `/_mapping` with `index` in query ([#385](https://github.com/opensearch-project/opensearch-api-specification/pull/385))
- Fixed duplicate `/_nodes/{node_id}` path ([#416](https://github.com/opensearch-project/opensearch-api-specification/pull/416))

### Security

Expand Down
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,
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))
return this.error(`Duplicate path${dup_paths.length > 1 ? 's' : ''} ${_.join(dup_paths, ', ')} found in namespace${dup_namespaces.length > 1 ? 's' : ''}: ${_.join(dup_namespaces, ', ')}.`)
}
}).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 8115fa7

Please sign in to comment.