From c192cdc37b6c75a114ea6ec7114a8893f5e4fc02 Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Wed, 24 May 2023 11:50:13 +1200 Subject: [PATCH] Use `x-data-type` extension Signed-off-by: Thomas Farr --- src/ApiGenerator/Generator/ApiEndpointFactory.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ApiGenerator/Generator/ApiEndpointFactory.cs b/src/ApiGenerator/Generator/ApiEndpointFactory.cs index 1b2abab45c..1b78e2722c 100644 --- a/src/ApiGenerator/Generator/ApiEndpointFactory.cs +++ b/src/ApiGenerator/Generator/ApiEndpointFactory.cs @@ -140,11 +140,12 @@ private static string GetOpenSearchType(JsonSchema schema) { while (schema.HasReference) schema = schema.Reference; + if (schema.GetExtension("x-data-type") is string dataType) + return dataType; + return schema.Type switch { JsonObjectType.String when schema.Enumeration is { Count: > 0 } => "enum", - JsonObjectType.String when schema.Pattern is "^([0-9]+)(?:d|h|m|s|ms|micros|nanos)$" => "time", - JsonObjectType.String when schema.GetExtension("x-comma-separated-list") is "true" => "list", JsonObjectType.Integer => "number", JsonObjectType.Array => "list", var t => t.ToString().ToLowerInvariant()