Skip to content

Commit

Permalink
Normalize fields.
Browse files Browse the repository at this point in the history
      .replaceAll('::', '___')
      .replaceAll('@', '__')
      .replaceAll(':', '_')

Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Nov 5, 2024
1 parent acf7788 commit 50c3258
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 87 deletions.
8 changes: 4 additions & 4 deletions tools/src/linter/SchemasValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export default class SchemasValidator {
const message = this.json_validator.validate_schema(param.schema)
if (message == null) return

const namespace = this.group_to_namespace(key.split('__')[0])
const namespace = this.group_to_namespace(key.split('___')[0])
const file = namespace === '_global' ? '_global_parameters.yaml' : `namespaces/${namespace}.yaml`
const location = namespace === '_global' ? param.name as string : `#/components/parameters/${key}`.replace('__', '::')
const location = namespace === '_global' ? param.name as string : `#/components/parameters/${key}`.replace('___', '::')
return this.error(file, location, message)
}).filter((error) => error != null) as ValidationError[]
}
Expand All @@ -78,9 +78,9 @@ export default class SchemasValidator {

validate_response_schemas (): ValidationError[] {
return Object.entries(this.spec.responses as Record<string, any>).flatMap(([key, response]) => {
const namespace = this.group_to_namespace(key.split('.')[0])
const namespace = this.group_to_namespace(key.split('__')[0])
const file = `namespaces/${namespace}.yaml`
const location = `#/components/responses/${key}`.replace('.', '@')
const location = `#/components/responses/${key}`.replace('__', '@')
const content = response.content as Record<string, any>
return this.validate_content_schemas(file, location, content)
})
Expand Down
3 changes: 2 additions & 1 deletion tools/src/merger/OpenApiMerger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ export default class OpenApiMerger {

#normalize_key(key: string): string {
return key
.replaceAll('@', '.')
.replaceAll('::', '___')
.replaceAll('@', '__')
.replaceAll(':', '_')
}

Expand Down
46 changes: 23 additions & 23 deletions tools/tests/merger/fixtures/extractor/opensearch/expected_1.3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@ paths:
x-version-added: '1.0'
description: Returns information about nodes in the cluster.
parameters:
- $ref: '#/components/parameters/nodes.info__path.id'
- $ref: '#/components/parameters/nodes.info___path.id'
responses:
'200':
$ref: '#/components/responses/nodes.info.200'
$ref: '#/components/responses/nodes.info__200'
/index:
get:
operationId: get.0
responses:
'200':
$ref: '#/components/responses/info.200'
$ref: '#/components/responses/info__200'
'201':
$ref: '#/components/responses/info.201'
$ref: '#/components/responses/info__201'
'404':
$ref: '#/components/responses/info.404'
$ref: '#/components/responses/info__404'
'500':
$ref: '#/components/responses/info.500'
$ref: '#/components/responses/info__500'
'503':
$ref: '#/components/responses/info.503'
$ref: '#/components/responses/info__503'
removed-2.0:
$ref: '#/components/responses/info.removed-2.0'
$ref: '#/components/responses/info__removed-2.0'
x-version-removed: '2.0'
removed-2.0-refs:
$ref: '#/components/responses/info.removed-2.0-refs'
$ref: '#/components/responses/info__removed-2.0-refs'
added-1.3-removed-2.0:
$ref: '#/components/responses/info.added-1.3-removed-2.0'
$ref: '#/components/responses/info__added-1.3-removed-2.0'
distributed-excluded-amazon-serverless:
$ref: '#/components/responses/info.distributed-all'
$ref: '#/components/responses/info__distributed-all'
x-distributions-excluded:
- amazon-serverless
parameters: []
Expand All @@ -47,11 +47,11 @@ paths:
operationId: nodes.0
responses:
'200':
$ref: '#/components/responses/nodes.info.200'
$ref: '#/components/responses/nodes.info__200'
parameters: []
components:
parameters:
nodes.info__path.id:
nodes.info___path.id:
in: path
name: id
description: Node ID.
Expand All @@ -60,7 +60,7 @@ components:
type: string
requestBodies: {}
responses:
info.200:
info__200:
content:
application/json:
schema:
Expand All @@ -73,7 +73,7 @@ components:
required:
- tagline
description: ''
info.201:
info__201:
content:
application/json:
schema:
Expand All @@ -85,7 +85,7 @@ components:
- tagline
unevaluatedProperties: true
description: ''
info.404:
info__404:
content:
application/json:
schema:
Expand All @@ -98,7 +98,7 @@ components:
unevaluatedProperties:
type: object
description: ''
info.500:
info__500:
content:
application/json:
schema:
Expand All @@ -107,27 +107,27 @@ components:
tagline:
type: string
description: ''
info.503:
info__503:
content:
application/json:
schema:
type: object
description: ''
info.added-1.3-removed-2.0:
info__added-1.3-removed-2.0:
description: Added in 1.3, removed in 2.0 via attribute in response body.
x-version-added: '1.3'
x-version-removed: '2.0'
info.distributed-all:
info__distributed-all:
description: Distributed in opensearch.org, AOS and AOSS.
info.removed-2.0:
info__removed-2.0:
description: Removed in 2.0 via attribute next to ref.
info.removed-2.0-refs:
info__removed-2.0-refs:
description: One of the ref values removed in 2.0.
schema:
oneOf:
- $ref: '#/components/schemas/_common_Type'
- $ref: '#/components/schemas/_common_OldId'
nodes.info.200:
nodes.info__200:
description: All nodes.
content:
application/json:
Expand Down
54 changes: 27 additions & 27 deletions tools/tests/merger/fixtures/extractor/opensearch/expected_2.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ paths:
x-version-added: '1.0'
description: Returns information about nodes in the cluster.
parameters:
- $ref: '#/components/parameters/nodes.info__path.id'
- $ref: '#/components/parameters/nodes.info___path.id'
responses:
'200':
$ref: '#/components/responses/nodes.info.200'
$ref: '#/components/responses/nodes.info__200'
post:
operationId: nodes.info.1
x-operation-group: nodes.info
x-version-added: '2.0'
description: Returns information about nodes in the cluster.
parameters:
- $ref: '#/components/parameters/nodes.info__path.id'
- $ref: '#/components/parameters/nodes.info__query.flag'
- $ref: '#/components/parameters/nodes.info___path.id'
- $ref: '#/components/parameters/nodes.info___query.flag'
requestBody:
$ref: '#/components/requestBodies/nodes.info'
responses:
'200':
$ref: '#/components/responses/nodes.info.200'
$ref: '#/components/responses/nodes.info__200'
'201':
$ref: '#/components/responses/nodes.info.201'
$ref: '#/components/responses/nodes.info__201'
/cluster_manager:
get:
operationId: cluster_manager.0
Expand All @@ -45,22 +45,22 @@ paths:
operationId: get.0
responses:
'200':
$ref: '#/components/responses/info.200'
$ref: '#/components/responses/info__200'
'201':
$ref: '#/components/responses/info.201'
$ref: '#/components/responses/info__201'
'404':
$ref: '#/components/responses/info.404'
$ref: '#/components/responses/info__404'
'500':
$ref: '#/components/responses/info.500'
$ref: '#/components/responses/info__500'
'503':
$ref: '#/components/responses/info.503'
$ref: '#/components/responses/info__503'
added-2.0:
$ref: '#/components/responses/info.added-2.0'
$ref: '#/components/responses/info__added-2.0'
x-version-added: '2.0'
removed-2.0-refs:
$ref: '#/components/responses/info.removed-2.0-refs'
$ref: '#/components/responses/info__removed-2.0-refs'
distributed-excluded-amazon-serverless:
$ref: '#/components/responses/info.distributed-all'
$ref: '#/components/responses/info__distributed-all'
x-distributions-excluded:
- amazon-serverless
parameters: []
Expand All @@ -69,18 +69,18 @@ paths:
operationId: nodes.0
responses:
'200':
$ref: '#/components/responses/nodes.info.200'
$ref: '#/components/responses/nodes.info__200'
parameters: []
components:
parameters:
nodes.info__path.id:
nodes.info___path.id:
in: path
name: id
description: Node ID.
required: true
schema:
type: string
nodes.info__query.flag:
nodes.info___query.flag:
in: query
name: flag
description: Flag.
Expand All @@ -102,7 +102,7 @@ components:
x-version-added: '2.0'
description: Nodes options.
responses:
info.200:
info__200:
content:
application/json:
schema:
Expand All @@ -113,7 +113,7 @@ components:
required:
- tagline
description: ''
info.201:
info__201:
content:
application/json:
schema:
Expand All @@ -125,7 +125,7 @@ components:
- tagline
unevaluatedProperties: true
description: ''
info.404:
info__404:
content:
application/json:
schema:
Expand All @@ -138,7 +138,7 @@ components:
unevaluatedProperties:
type: object
description: ''
info.500:
info__500:
content:
application/json:
schema:
Expand All @@ -147,28 +147,28 @@ components:
tagline:
type: string
description: ''
info.503:
info__503:
content:
application/json:
schema:
type: object
description: ''
info.added-2.0:
info__added-2.0:
description: Added in 2.0 via attribute next to ref.
info.distributed-all:
info__distributed-all:
description: Distributed in opensearch.org, AOS and AOSS.
info.removed-2.0-refs:
info__removed-2.0-refs:
description: One of the ref values removed in 2.0.
schema:
oneOf:
- $ref: '#/components/schemas/_common_OldId'
nodes.info.200:
nodes.info__200:
description: All nodes.
content:
application/json:
schema:
type: object
nodes.info.201:
nodes.info__201:
description: All nodes.
content:
application/json:
Expand Down
Loading

0 comments on commit 50c3258

Please sign in to comment.