diff --git a/tools/src/linter/SchemasValidator.ts b/tools/src/linter/SchemasValidator.ts index 008095f99..3ec6b94b2 100644 --- a/tools/src/linter/SchemasValidator.ts +++ b/tools/src/linter/SchemasValidator.ts @@ -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[] } @@ -78,9 +78,9 @@ export default class SchemasValidator { validate_response_schemas (): ValidationError[] { return Object.entries(this.spec.responses as Record).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 return this.validate_content_schemas(file, location, content) }) diff --git a/tools/src/merger/OpenApiMerger.ts b/tools/src/merger/OpenApiMerger.ts index 38c9527c6..5e588f6da 100644 --- a/tools/src/merger/OpenApiMerger.ts +++ b/tools/src/merger/OpenApiMerger.ts @@ -154,7 +154,8 @@ export default class OpenApiMerger { #normalize_key(key: string): string { return key - .replaceAll('@', '.') + .replaceAll('::', '___') + .replaceAll('@', '__') .replaceAll(':', '_') } diff --git a/tools/tests/merger/fixtures/extractor/opensearch/expected_1.3.yaml b/tools/tests/merger/fixtures/extractor/opensearch/expected_1.3.yaml index 3ff090046..4eb448c2a 100644 --- a/tools/tests/merger/fixtures/extractor/opensearch/expected_1.3.yaml +++ b/tools/tests/merger/fixtures/extractor/opensearch/expected_1.3.yaml @@ -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: [] @@ -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. @@ -60,7 +60,7 @@ components: type: string requestBodies: {} responses: - info.200: + info__200: content: application/json: schema: @@ -73,7 +73,7 @@ components: required: - tagline description: '' - info.201: + info__201: content: application/json: schema: @@ -85,7 +85,7 @@ components: - tagline unevaluatedProperties: true description: '' - info.404: + info__404: content: application/json: schema: @@ -98,7 +98,7 @@ components: unevaluatedProperties: type: object description: '' - info.500: + info__500: content: application/json: schema: @@ -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: diff --git a/tools/tests/merger/fixtures/extractor/opensearch/expected_2.0.yaml b/tools/tests/merger/fixtures/extractor/opensearch/expected_2.0.yaml index c41475513..044981da9 100644 --- a/tools/tests/merger/fixtures/extractor/opensearch/expected_2.0.yaml +++ b/tools/tests/merger/fixtures/extractor/opensearch/expected_2.0.yaml @@ -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 @@ -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: [] @@ -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. @@ -102,7 +102,7 @@ components: x-version-added: '2.0' description: Nodes options. responses: - info.200: + info__200: content: application/json: schema: @@ -113,7 +113,7 @@ components: required: - tagline description: '' - info.201: + info__201: content: application/json: schema: @@ -125,7 +125,7 @@ components: - tagline unevaluatedProperties: true description: '' - info.404: + info__404: content: application/json: schema: @@ -138,7 +138,7 @@ components: unevaluatedProperties: type: object description: '' - info.500: + info__500: content: application/json: schema: @@ -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: diff --git a/tools/tests/merger/fixtures/merger/animals/expected.yaml b/tools/tests/merger/fixtures/merger/animals/expected.yaml index 733d22a8b..17a0c6993 100644 --- a/tools/tests/merger/fixtures/merger/animals/expected.yaml +++ b/tools/tests/merger/fixtures/merger/animals/expected.yaml @@ -7,54 +7,54 @@ paths: /{index}: post: parameters: - - $ref: '#/components/parameters/indices.create__path.index' - - $ref: '#/components/parameters/indices.create__query.pretty' - - $ref: '#/components/parameters/indices.create__query.wait_for_active_shards' - - $ref: '#/components/parameters/_global__query.human' + - $ref: '#/components/parameters/indices.create___path.index' + - $ref: '#/components/parameters/indices.create___query.pretty' + - $ref: '#/components/parameters/indices.create___query.wait_for_active_shards' + - $ref: '#/components/parameters/_global___query.human' requestBody: $ref: '#/components/requestBodies/indices.create' responses: '200': - $ref: '#/components/responses/indices.create.200' + $ref: '#/components/responses/indices.create__200' '201': - $ref: '#/components/responses/indices.create.201' + $ref: '#/components/responses/indices.create__201' x-version-added: '2.0' /adopt/{animal}/dockets/{docket}: get: operationId: adopt.0 parameters: - - $ref: '#/components/parameters/adopt__path.animal' - - $ref: '#/components/parameters/adopt__path.docket' - - $ref: '#/components/parameters/_global__query.human' + - $ref: '#/components/parameters/adopt___path.animal' + - $ref: '#/components/parameters/adopt___path.docket' + - $ref: '#/components/parameters/_global___query.human' responses: '200': - $ref: '#/components/responses/adopt.200' + $ref: '#/components/responses/adopt__200' post: operationId: adopt.1 parameters: - - $ref: '#/components/parameters/adopt__path.animal' - - $ref: '#/components/parameters/adopt__path.docket' - - $ref: '#/components/parameters/_global__query.human' + - $ref: '#/components/parameters/adopt___path.animal' + - $ref: '#/components/parameters/adopt___path.docket' + - $ref: '#/components/parameters/_global___query.human' requestBody: $ref: '#/components/requestBodies/adopt' responses: '200': - $ref: '#/components/responses/adopt.200' + $ref: '#/components/responses/adopt__200' /replaced/adopting/{animal}/something/{docket}: get: operationId: adopt.0_superseded parameters: - - $ref: '#/components/parameters/adopt__path.animal' - - $ref: '#/components/parameters/adopt__path.docket' - - $ref: '#/components/parameters/_global__query.human' + - $ref: '#/components/parameters/adopt___path.animal' + - $ref: '#/components/parameters/adopt___path.docket' + - $ref: '#/components/parameters/_global___query.human' responses: '200': - $ref: '#/components/responses/adopt.200' + $ref: '#/components/responses/adopt__200' deprecated: true x-ignorable: true components: parameters: - _global__query.human: + _global___query.human: name: human in: query description: Whether to return human readable values for statistics. @@ -62,27 +62,27 @@ components: type: boolean default: true x-global: true - adopt__path.animal: + adopt___path.animal: name: animal in: path schema: $ref: '#/components/schemas/animals_Animal' - adopt__path.docket: + adopt___path.docket: name: docket in: path schema: type: number - indices.create__path.index: + indices.create___path.index: name: index in: path schema: type: string - indices.create__query.pretty: + indices.create___query.pretty: name: pretty in: query schema: type: boolean - indices.create__query.wait_for_active_shards: + indices.create___query.wait_for_active_shards: name: pretty in: query x-version-added: '2.0' @@ -94,17 +94,17 @@ components: name: type: string responses: - adopt.200: + adopt__200: application/json: schema: type: object description: '' - indices.create.200: + indices.create__200: application/json: schema: type: object description: '' - indices.create.201: + indices.create__201: description: Added in 2.0. application/json: schema: diff --git a/tools/tests/tester/MergedOpenApiSpec.test.ts b/tools/tests/tester/MergedOpenApiSpec.test.ts index 83868142b..8871a2174 100644 --- a/tools/tests/tester/MergedOpenApiSpec.test.ts +++ b/tools/tests/tester/MergedOpenApiSpec.test.ts @@ -40,27 +40,27 @@ describe('merged API spec', () => { const responses: any = spec.spec().components?.responses test('is added with required fields', () => { - const schema = responses['info.200'].content['application/json'].schema + const schema = responses.info__200.content['application/json'].schema expect(schema.unevaluatedProperties).toEqual({ not: true, errorMessage: 'property is not defined in the spec' }) }) test('is added when no required fields', () => { - const schema = responses['info.500'].content['application/json'].schema + const schema = responses.info__500.content['application/json'].schema expect(schema.unevaluatedProperties).toEqual({ not: true, errorMessage: 'property is not defined in the spec' }) }) test('is not added to empty object schema', () => { - const schema = responses['info.503'].content['application/json'].schema + const schema = responses.info__503.content['application/json'].schema expect(schema.unevaluatedProperties).toBeUndefined() }) test('is not added when true', () => { - const schema = responses['info.201'].content['application/json'].schema + const schema = responses.info__201.content['application/json'].schema expect(schema.unevaluatedProperties).toEqual(true) }) test('is not added when object', () => { - const schema = responses['info.404'].content['application/json'].schema + const schema = responses.info__404.content['application/json'].schema expect(schema.unevaluatedProperties).toEqual({ type: 'object' }) }) })