diff --git a/CHANGELOG.md b/CHANGELOG.md index d520d3f8c..3d4e347b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Replaced the deprecated fs.rmdirSync with fs.rmSync ([#359](https://github.com/opensearch-project/opensearch-api-specification/pull/359)) - Tester tool now provides better context for non-2XX responses when --verbose is used ([#359](https://github.com/opensearch-project/opensearch-api-specification/pull/359)) - Lock testing for next release of OpenSearch to a specific SHA ([#431](https://github.com/opensearch-project/opensearch-api-specification/pull/431)) +- Replace nullable with null type ([#436](https://github.com/opensearch-project/opensearch-api-specification/pull/436)) ### Deprecated diff --git a/spec/schemas/_common.aggregations.yaml b/spec/schemas/_common.aggregations.yaml index f2c25a65f..3313b096b 100644 --- a/spec/schemas/_common.aggregations.yaml +++ b/spec/schemas/_common.aggregations.yaml @@ -113,21 +113,14 @@ components: KeyedPercentiles: type: object additionalProperties: - oneOf: - - type: string - - type: number - - nullable: true - type: string + type: ['null', number, string] ArrayPercentilesItem: type: object properties: key: type: string value: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] value_as_string: type: string required: @@ -162,10 +155,7 @@ components: description: |- The metric value. A missing value generally means that there was no data to aggregate, unless specified otherwise. - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] value_as_string: type: string required: @@ -226,20 +216,11 @@ components: count: type: number min: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] max: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] avg: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] sum: type: number min_as_string: @@ -266,40 +247,19 @@ components: - type: object properties: sum_of_squares: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] variance: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] variance_population: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] variance_sampling: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] std_deviation: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] std_deviation_population: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] std_deviation_sampling: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] std_deviation_bounds: $ref: '#/components/schemas/StandardDeviationBounds' sum_of_squares_as_string: @@ -326,35 +286,17 @@ components: type: object properties: upper: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] lower: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] upper_population: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] lower_population: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] upper_sampling: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] lower_sampling: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] required: - lower - lower_population @@ -1426,32 +1368,20 @@ components: count: type: number min_length: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] max_length: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] avg_length: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] entropy: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] distribution: oneOf: + - type: 'null' - type: object additionalProperties: type: number - - nullable: true - type: string + - type: string min_length_as_string: type: string max_length_as_string: @@ -1522,17 +1452,11 @@ components: sort: type: array items: - oneOf: - - $ref: '_common.yaml#/components/schemas/FieldValue' - - nullable: true - type: string + $ref: '_common.yaml#/components/schemas/FieldValue' metrics: type: object additionalProperties: - oneOf: - - $ref: '_common.yaml#/components/schemas/FieldValue' - - nullable: true - type: string + $ref: '_common.yaml#/components/schemas/FieldValue' required: - metrics - sort @@ -1542,10 +1466,7 @@ components: - type: object properties: value: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] value_as_string: type: string required: @@ -2544,21 +2465,13 @@ components: properties: from: description: Start of the range (inclusive). - oneOf: - - type: number - - type: string - - nullable: true - type: string + type: ['null', number, string] key: description: Custom key to return the range with. type: string to: description: End of the range (exclusive). - oneOf: - - type: number - - type: string - - nullable: true - type: string + type: ['null', number, string] GeoHashGridAggregation: allOf: - $ref: '#/components/schemas/BucketAggregationBase' @@ -2726,19 +2639,13 @@ components: properties: from: description: Start of the range. - oneOf: - - type: string - - nullable: true - type: string + type: ['null', string] mask: description: IP range defined as a CIDR mask. type: string to: description: End of the range. - oneOf: - - type: string - - nullable: true - type: string + type: ['null', string] IpPrefixAggregation: allOf: - $ref: '#/components/schemas/BucketAggregationBase' @@ -3113,8 +3020,8 @@ components: - type: array items: type: number - - nullable: true - type: string + - type: 'null' + - type: string hdr: $ref: '#/components/schemas/HdrMethod' tdigest: diff --git a/spec/schemas/_common.query_dsl.yaml b/spec/schemas/_common.query_dsl.yaml index 3fab6cef8..df09be4fd 100644 --- a/spec/schemas/_common.query_dsl.yaml +++ b/spec/schemas/_common.query_dsl.yaml @@ -1417,13 +1417,11 @@ components: from: oneOf: - $ref: '_common.yaml#/components/schemas/DateMath' - - nullable: true - type: string + - type: 'null' to: oneOf: - $ref: '_common.yaml#/components/schemas/DateMath' - - nullable: true - type: string + - type: 'null' format: $ref: '_common.yaml#/components/schemas/DateFormat' time_zone: @@ -1459,15 +1457,9 @@ components: description: Less than or equal to. type: number from: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] to: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] RankFeatureQuery: allOf: - $ref: '#/components/schemas/QueryBase' diff --git a/spec/schemas/_common.yaml b/spec/schemas/_common.yaml index b080de313..365c8826d 100644 --- a/spec/schemas/_common.yaml +++ b/spec/schemas/_common.yaml @@ -146,14 +146,12 @@ components: type: string FieldValue: description: A field value. - oneOf: - - type: number - - type: number - - type: string - - type: boolean - - nullable: true - type: string - - type: object + type: + - boolean + - 'null' + - number + - object + - string Void: description: |- The absence of any type. This is commonly used in APIs that don't return a body. @@ -1282,8 +1280,7 @@ components: licensed: type: boolean custom_foldername: - nullable: true - type: string + type: ['null', string] opensearch_version: $ref: '#/components/schemas/VersionString' required: @@ -2014,8 +2011,7 @@ components: relocating_node: oneOf: - $ref: '#/components/schemas/NodeId' - - nullable: true - type: string + - type: 'null' relocation_failure_info: $ref: '#/components/schemas/RelocationFailureInfo' required: diff --git a/spec/schemas/_core.bulk.yaml b/spec/schemas/_core.bulk.yaml index a4e03fd19..9006cfe23 100644 --- a/spec/schemas/_core.bulk.yaml +++ b/spec/schemas/_core.bulk.yaml @@ -116,10 +116,7 @@ components: x-version-removed: '2.0' _id: description: The document ID associated with the operation. - anyOf: - - type: string - - nullable: true - type: string + type: ['null', string] _index: description: |- Name of the index associated with the operation. diff --git a/spec/schemas/_core.rank_eval.yaml b/spec/schemas/_core.rank_eval.yaml index 171f44789..4527f0c05 100644 --- a/spec/schemas/_core.rank_eval.yaml +++ b/spec/schemas/_core.rank_eval.yaml @@ -156,10 +156,7 @@ components: hit: $ref: '#/components/schemas/RankEvalHit' rating: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] required: - hit RankEvalHit: diff --git a/spec/schemas/_core.search.yaml b/spec/schemas/_core.search.yaml index c6e65d005..87a2e01ef 100644 --- a/spec/schemas/_core.search.yaml +++ b/spec/schemas/_core.search.yaml @@ -19,10 +19,7 @@ components: items: $ref: '#/components/schemas/Hit' max_score: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] required: - hits TotalHits: @@ -50,10 +47,7 @@ components: _id: $ref: '_common.yaml#/components/schemas/Id' _score: - oneOf: - - type: number - - nullable: true - type: string + type: ['null', number, string] _explanation: $ref: '_core.explain.yaml#/components/schemas/Explanation' fields: diff --git a/spec/schemas/cat.allocation.yaml b/spec/schemas/cat.allocation.yaml index cfb016e91..ba6c82026 100644 --- a/spec/schemas/cat.allocation.yaml +++ b/spec/schemas/cat.allocation.yaml @@ -18,8 +18,7 @@ components: IMPORTANT: This metric double-counts disk space for hard-linked files, such as those created when shrinking, splitting, or cloning an index. anyOf: - $ref: '_common.yaml#/components/schemas/ByteSize' - - nullable: true - type: string + - type: 'null' disk.used: description: |- Total disk space in use. @@ -28,8 +27,7 @@ components: Unlike `disk.indices`, this metric does not double-count disk space for hard-linked files. anyOf: - $ref: '_common.yaml#/components/schemas/ByteSize' - - nullable: true - type: string + - type: 'null' disk.avail: description: |- Free disk space available to OpenSearch. @@ -37,32 +35,27 @@ components: Disk-based shard allocation uses this metric to assign shards to nodes based on available disk space. anyOf: - $ref: '_common.yaml#/components/schemas/ByteSize' - - nullable: true - type: string + - type: 'null' disk.total: description: Total disk space for the node, including in-use and available space. anyOf: - $ref: '_common.yaml#/components/schemas/ByteSize' - - nullable: true - type: string + - type: 'null' disk.percent: description: Total percentage of disk space in use. Calculated as `disk.used / disk.total`. anyOf: - $ref: '_common.yaml#/components/schemas/Percentage' - - nullable: true - type: string + - type: 'null' host: description: Network host for the node. Set using the `network.host` setting. anyOf: - $ref: '_common.yaml#/components/schemas/Host' - - nullable: true - type: string + - type: 'null' ip: description: IP address and port for the node. anyOf: - $ref: '_common.yaml#/components/schemas/Ip' - - nullable: true - type: string + - type: 'null' node: description: Name for the node. Set using the `node.name` setting. type: string diff --git a/spec/schemas/cat.indices.yaml b/spec/schemas/cat.indices.yaml index 974f4cbfc..32e50795c 100644 --- a/spec/schemas/cat.indices.yaml +++ b/spec/schemas/cat.indices.yaml @@ -29,16 +29,10 @@ components: type: string docs.count: description: available docs - anyOf: - - type: string - - nullable: true - type: string + type: ['null', string] docs.deleted: description: deleted docs - anyOf: - - type: string - - nullable: true - type: string + type: ['null', string] creation.date: description: index creation date (millisecond value) type: string @@ -47,16 +41,10 @@ components: type: string store.size: description: store size of primaries & replicas - anyOf: - - type: string - - nullable: true - type: string + type: ['null', string] pri.store.size: description: store size of primaries - anyOf: - - type: string - - nullable: true - type: string + type: ['null', string] completion.size: description: size of completion type: string diff --git a/spec/schemas/cat.shards.yaml b/spec/schemas/cat.shards.yaml index 65c9e94d2..4bb492c13 100644 --- a/spec/schemas/cat.shards.yaml +++ b/spec/schemas/cat.shards.yaml @@ -29,31 +29,19 @@ components: type: string docs: description: The number of documents in the shard. - anyOf: - - type: string - - nullable: true - type: string + type: ['null', string] store: description: The disk space used by the shard. - anyOf: - - type: string - - nullable: true - type: string + type: ['null', string] ip: description: The IP address of the node. - anyOf: - - type: string - - nullable: true - type: string + type: ['null', string] id: description: The unique identifier for the node. type: string node: description: The name of node. - anyOf: - - type: string - - nullable: true - type: string + type: ['null', string] sync_id: description: The sync identifier. type: string diff --git a/spec/schemas/cat.templates.yaml b/spec/schemas/cat.templates.yaml index 81c048955..ebc269250 100644 --- a/spec/schemas/cat.templates.yaml +++ b/spec/schemas/cat.templates.yaml @@ -21,8 +21,7 @@ components: description: The template version. anyOf: - $ref: '_common.yaml#/components/schemas/VersionString' - - nullable: true - type: string + - type: 'null' composed_of: description: The component templates that comprise the index template. type: string diff --git a/spec/schemas/cat.thread_pool.yaml b/spec/schemas/cat.thread_pool.yaml index bc91a875e..3d14b730a 100644 --- a/spec/schemas/cat.thread_pool.yaml +++ b/spec/schemas/cat.thread_pool.yaml @@ -60,25 +60,13 @@ components: type: string core: description: The core number of active threads allowed in a scaling thread pool. - anyOf: - - type: string - - nullable: true - type: string + type: ['null', string] max: description: The maximum number of active threads allowed in a scaling thread pool. - anyOf: - - type: string - - nullable: true - type: string + type: ['null', string] size: description: The number of active threads allowed in a fixed thread pool. - anyOf: - - type: string - - nullable: true - type: string + type: ['null', string] keep_alive: description: The thread keep alive time. - anyOf: - - type: string - - nullable: true - type: string + type: ['null', string] diff --git a/spec/schemas/indices.stats.yaml b/spec/schemas/indices.stats.yaml index 45076740f..d3301fcd0 100644 --- a/spec/schemas/indices.stats.yaml +++ b/spec/schemas/indices.stats.yaml @@ -255,10 +255,7 @@ components: primary: type: boolean relocating_node: - oneOf: - - type: string - - nullable: true - type: string + type: ['null', string] state: $ref: '#/components/schemas/ShardRoutingState' required: diff --git a/tools/src/_utils/JsonSchemaValidator.ts b/tools/src/_utils/JsonSchemaValidator.ts index e72b5654b..ff33dbc1f 100644 --- a/tools/src/_utils/JsonSchemaValidator.ts +++ b/tools/src/_utils/JsonSchemaValidator.ts @@ -22,7 +22,8 @@ interface JsonSchemaValidatorOpts { const DEFAULT_AJV_OPTS = { strict: true, - allErrors: true + allErrors: true, + allowUnionTypes: true } // Wrapper for AJV @@ -58,4 +59,4 @@ export default class JsonSchemaValidator { const errors = is_schema ? this.ajv.errors : validate_func.errors return valid ? undefined : this.errors_parser.parse(errors) } -} \ No newline at end of file +}