Skip to content

Commit

Permalink
Convert TaskDuration into an alias type
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed Jul 8, 2024
1 parent 9949df4 commit b0b9af2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
8 changes: 8 additions & 0 deletions typespec/common.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions typespec/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "@typespec/versioning";

import "./common.tsp";

using TypeSpec.OpenAPI;
using TypeSpec.Http;
using TypeSpec.Versioning;

Expand Down Expand Up @@ -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")
Expand Down
13 changes: 9 additions & 4 deletions typespec/tsp-output/@typespec/openapi3/openapi.v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,14 @@ security:
- ApiKeyAuth: []
components:
schemas:
DurationString:
type: string
enum:
- ''
- < 1
x-enum-varnames:
- Empty
- LowerThanOne
Error:
type: object
required:
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit b0b9af2

Please sign in to comment.