Skip to content

Commit

Permalink
Disallowed characters are replaced with ___.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Nov 6, 2024
1 parent d1a1bac commit 359e6f8
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 84 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Fixed
- Spec passes OpenAPI 3.1.0 validations ([#646](https://github.com/opensearch-project/opensearch-api-specification/pull/646))
- Key names containing invalid `::`, `@`, and `:` are renamed to `___`, `__`, and `_` respectively on merge ([#646](https://github.com/opensearch-project/opensearch-api-specification/pull/646))
- Disallowed characters (`::`, `@`, and `:`) in key names are replaced with `___` on merge ([#646](https://github.com/opensearch-project/opensearch-api-specification/pull/646))
- Added missing `required` to `path` parameters ([#646](https://github.com/opensearch-project/opensearch-api-specification/pull/646))
- Added missing `schema` parent to response types ([#646](https://github.com/opensearch-project/opensearch-api-specification/pull/646))
- Removed invalid `externalDocs` from `flow_framework.create/update::query.use_case` ([#646](https://github.com/opensearch-project/opensearch-api-specification/pull/646))
Expand Down
8 changes: 4 additions & 4 deletions tools/src/linter/SchemasValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export default class SchemasValidator {
const message = this.json_validator.validate_schema(_schema)
if (message == null) return

const file = `schemas/${key.split('_')[0]}.yaml`
const location = `#/components/schemas/${key.split('_')[1]}`
const file = `schemas/${key.split('___')[0]}.yaml`
const location = `#/components/schemas/${key.split('___')[1]}`
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
4 changes: 2 additions & 2 deletions tools/src/merger/OpenApiMerger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ export default class OpenApiMerger {
#normalize_key(key: string): string {
return key
.replaceAll('::', '___')
.replaceAll('@', '__')
.replaceAll(':', '_')
.replaceAll('@', '___')
.replaceAll(':', '___')
}

#normalize_fields(obj: any = this._spec): void {
Expand Down
52 changes: 26 additions & 26 deletions tools/tests/merger/fixtures/extractor/opensearch/expected_1.3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@ paths:
- $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,7 +47,7 @@ paths:
operationId: nodes.0
responses:
'200':
$ref: '#/components/responses/nodes.info__200'
$ref: '#/components/responses/nodes.info___200'
parameters: []
components:
parameters:
Expand All @@ -60,20 +60,20 @@ components:
type: string
requestBodies: {}
responses:
info__200:
info___200:
content:
application/json:
schema:
type: object
properties:
_type:
$ref: '#/components/schemas/_common_Type'
$ref: '#/components/schemas/_common___Type'
tagline:
type: string
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,35 +107,35 @@ 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:
- $ref: '#/components/schemas/_common___Type'
- $ref: '#/components/schemas/_common___OldId'
nodes.info___200:
description: All nodes.
content:
application/json:
schema:
type: object
schemas:
_common_OldId:
_common___OldId:
type: string
_common_Type:
_common___Type:
type: string
x-version-removed: '2.0'
56 changes: 28 additions & 28 deletions tools/tests/merger/fixtures/extractor/opensearch/expected_2.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ paths:
- $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
Expand All @@ -28,9 +28,9 @@ paths:
$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,7 +69,7 @@ paths:
operationId: nodes.0
responses:
'200':
$ref: '#/components/responses/nodes.info__200'
$ref: '#/components/responses/nodes.info___200'
parameters: []
components:
parameters:
Expand Down Expand Up @@ -98,11 +98,11 @@ components:
_all:
type: boolean
ids:
$ref: '#/components/schemas/_common_Ids'
$ref: '#/components/schemas/_common___Ids'
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,39 +147,39 @@ 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:
- $ref: '#/components/schemas/_common___OldId'
nodes.info___200:
description: All nodes.
content:
application/json:
schema:
type: object
nodes.info__201:
nodes.info___201:
description: All nodes.
content:
application/json:
schema:
type: object
schemas:
_common_Ids:
_common___Ids:
oneOf:
- $ref: '#/components/schemas/_common_OldId'
- $ref: '#/components/schemas/_common___OldId'
- type: array
items:
$ref: '#/components/schemas/_common_Ids'
_common_OldId:
$ref: '#/components/schemas/_common___Ids'
_common___OldId:
type: string
Loading

0 comments on commit 359e6f8

Please sign in to comment.