From b0b9af2072acfa316fc37d7d28ad3edb48e99c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Garc=C3=ADa=20Crespo?= Date: Mon, 8 Jul 2024 10:09:25 +0000 Subject: [PATCH] Convert TaskDuration into an alias type --- typespec/common.tsp | 8 ++++++++ typespec/main.tsp | 5 ++--- .../tsp-output/@typespec/openapi3/openapi.v1.yaml | 13 +++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/typespec/common.tsp b/typespec/common.tsp index 971c749..ff763a4 100644 --- a/typespec/common.tsp +++ b/typespec/common.tsp @@ -17,6 +17,14 @@ scalar exitCode extends uint8; @doc("E.g.: \"2020-01-17T00:44:37\".") scalar timestamp extends string; +alias TaskDuration = DurationString | int64; + +@extension("x-enum-varnames", ["Empty", "LowerThanOne"]) // Used to solve name clash in oapi-codegen. +enum DurationString { + Empty: ""; + LowerThanOne: "< 1"; +} + enum UnitStatus { USER_INPUT, FAILED, diff --git a/typespec/main.tsp b/typespec/main.tsp index 62960bb..6e58193 100644 --- a/typespec/main.tsp +++ b/typespec/main.tsp @@ -6,6 +6,7 @@ import "@typespec/versioning"; import "./common.tsp"; +using TypeSpec.OpenAPI; using TypeSpec.Http; using TypeSpec.Versioning; @@ -404,10 +405,8 @@ namespace Service { time_ended?: timestamp; @doc("Task duration in seconds (integer). If the duration is less than a second, this will be a \"< 1\" string.") - duration: "< 1" | "" | int64; + duration: TaskDuration; } - - } @route("/validate") diff --git a/typespec/tsp-output/@typespec/openapi3/openapi.v1.yaml b/typespec/tsp-output/@typespec/openapi3/openapi.v1.yaml index 30b723c..ce32c14 100644 --- a/typespec/tsp-output/@typespec/openapi3/openapi.v1.yaml +++ b/typespec/tsp-output/@typespec/openapi3/openapi.v1.yaml @@ -992,6 +992,14 @@ security: - ApiKeyAuth: [] components: schemas: + DurationString: + type: string + enum: + - '' + - < 1 + x-enum-varnames: + - Empty + - LowerThanOne Error: type: object required: @@ -1289,10 +1297,7 @@ components: $ref: '#/components/schemas/timestamp' duration: anyOf: - - type: string - enum: - - < 1 - - '' + - $ref: '#/components/schemas/DurationString' - type: integer format: int64 description: Task duration in seconds (integer). If the duration is less than a second, this will be a "< 1" string.