From 39072ed9b4180b1ba224975447820e47d8ecdcf1 Mon Sep 17 00:00:00 2001 From: shiron Date: Tue, 28 May 2024 13:28:52 +0900 Subject: [PATCH 1/2] fix: namespace --- specs/admin.tsp | 2 +- specs/algorithm.tsp | 2 +- specs/main.tsp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/admin.tsp b/specs/admin.tsp index 01b49b9..537c212 100644 --- a/specs/admin.tsp +++ b/specs/admin.tsp @@ -7,7 +7,7 @@ import "./algorithm.tsp"; using TypeSpec.Http; using TypeSpec.Rest; -namespace AlgorithmServer; +namespace BeLifelineServer; @route("/admin") @tag("Admin") diff --git a/specs/algorithm.tsp b/specs/algorithm.tsp index 57aed3a..a650b72 100644 --- a/specs/algorithm.tsp +++ b/specs/algorithm.tsp @@ -5,7 +5,7 @@ import "@typespec/openapi3"; using TypeSpec.Http; using TypeSpec.Rest; -namespace AlgorithmServer; +namespace BeLifelineServer; alias algorithm_id = string; diff --git a/specs/main.tsp b/specs/main.tsp index 0429618..6d6d967 100644 --- a/specs/main.tsp +++ b/specs/main.tsp @@ -4,4 +4,4 @@ import "./admin.tsp"; @service({ title: "BeLifeline Server API", }) -namespace AlgorithmServer; +namespace BeLifelineServer; From 3f1370987d3ccca4e0e86dd92246b1bb4c3bc0d9 Mon Sep 17 00:00:00 2001 From: shiron Date: Tue, 28 May 2024 13:29:02 +0900 Subject: [PATCH 2/2] feat: add versioning --- package.json | 5 +- pnpm-lock.yaml | 3 + schema/@typespec/openapi3/openapi.v0.1.0.yaml | 315 ++++++++++++++++++ schema/@typespec/openapi3/openapi.yaml | 312 +---------------- scripts/compile.sh | 13 + specs/main.tsp | 7 + 6 files changed, 342 insertions(+), 313 deletions(-) create mode 100644 schema/@typespec/openapi3/openapi.v0.1.0.yaml mode change 100644 => 120000 schema/@typespec/openapi3/openapi.yaml create mode 100644 scripts/compile.sh diff --git a/package.json b/package.json index 94014c8..bd92137 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "type": "module", "scripts": { "dev": "tsp compile specs --watch & pnpm run _doc", - "compile": "tsp compile specs", + "compile": "tsp compile specs && source ./scripts/compile.sh", "_doc": "redocly preview-docs schema/@typespec/openapi3/openapi.yaml", "bundle": "pnpm run compile && redocly build-docs schema/@typespec/openapi3/openapi.yaml --output bundled/index.html", "format": "tsp format specs" @@ -13,7 +13,8 @@ "@typespec/compiler": "latest", "@typespec/http": "latest", "@typespec/openapi3": "latest", - "@typespec/rest": "latest" + "@typespec/rest": "latest", + "@typespec/versioning": "latest" }, "private": true, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b9f7732..75f6f9a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ dependencies: '@typespec/rest': specifier: latest version: 0.56.0(@typespec/compiler@0.56.0)(@typespec/http@0.56.0) + '@typespec/versioning': + specifier: latest + version: 0.56.0(@typespec/compiler@0.56.0) devDependencies: '@redocly/cli': diff --git a/schema/@typespec/openapi3/openapi.v0.1.0.yaml b/schema/@typespec/openapi3/openapi.v0.1.0.yaml new file mode 100644 index 0000000..e9dba77 --- /dev/null +++ b/schema/@typespec/openapi3/openapi.v0.1.0.yaml @@ -0,0 +1,315 @@ +openapi: 3.0.0 +info: + title: BeLifeline Server API + version: v0.1.0 +tags: + - name: Algorithm + - name: Admin +paths: + /admin/algorithm: + post: + tags: + - Admin + operationId: Algorithm_create + parameters: [] + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + type: object + properties: + algorithm_id: + type: string + description: From Admin API + algorithm_name: + type: string + algorithm_description: + type: string + need_external: + type: array + items: + type: string + first_entry_at: + type: string + format: date-time + last_entry_at: + type: string + format: date-time + last_updated_at: + type: string + format: date-time + bearer_token: + type: string + required: + - algorithm_id + - algorithm_name + - algorithm_description + - need_external + - first_entry_at + - last_entry_at + - last_updated_at + - bearer_token + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + algorithm: + $ref: '#/components/schemas/AlgorithmInfomationCreate' + required: + - algorithm + security: + - BearerAuth: [] + /admin/algorithm/{algorithm_id}: + delete: + tags: + - Admin + operationId: Algorithm_delete + parameters: + - name: algorithm_id + in: path + required: true + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + type: object + properties: + delete_algorithm_id: + type: string + required: + - delete_algorithm_id + security: + - BearerAuth: [] + /algorithm: + get: + tags: + - Algorithm + operationId: Algorithm_list + parameters: + - name: limit + in: query + required: false + schema: + type: integer + format: int32 + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/AlgorithmInfomation' + security: + - BearerAuth: [] + post: + tags: + - Algorithm + operationId: Algorithm_create + parameters: [] + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/AlgorithmInfomation' + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + algorithm: + $ref: '#/components/schemas/AlgorithmInfomationCreate' + required: + - algorithm + security: + - BearerAuth: [] + /algorithm/{algorithm_id}: + put: + tags: + - Algorithm + operationId: EachAlgorithm_update + parameters: + - name: algorithm_id + in: path + required: true + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/AlgorithmInfomation' + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + update_algorithm: + $ref: '#/components/schemas/AlgorithmInfomationCreateOrUpdate' + required: + - update_algorithm + security: + - BearerAuth: [] + get: + tags: + - Algorithm + operationId: EachAlgorithm_get + parameters: + - name: algorithm_id + in: path + required: true + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + $ref: '#/components/schemas/AlgorithmInfomation' + security: + - BearerAuth: [] + delete: + tags: + - Algorithm + operationId: EachAlgorithm_delete + parameters: + - name: algorithm_id + in: path + required: true + schema: + type: string + responses: + '200': + description: The request has succeeded. + content: + application/json: + schema: + type: object + properties: + delete_algorithm_id: + type: string + required: + - delete_algorithm_id + security: + - BearerAuth: [] +components: + schemas: + AlgorithmInfomation: + type: object + required: + - algorithm_id + - algorithm_name + - algorithm_description + - need_external + - first_entry_at + - last_entry_at + - last_updated_at + properties: + algorithm_id: + type: string + description: From Admin API + algorithm_name: + type: string + algorithm_description: + type: string + need_external: + type: array + items: + type: string + first_entry_at: + type: string + format: date-time + last_entry_at: + type: string + format: date-time + last_updated_at: + type: string + format: date-time + AlgorithmInfomationCreate: + type: object + required: + - algorithm_name + - algorithm_description + - need_external + properties: + algorithm_name: + type: string + algorithm_description: + type: string + need_external: + type: array + items: + type: string + AlgorithmInfomationCreateOrUpdate: + type: object + required: + - algorithm_id + - algorithm_name + - algorithm_description + - need_external + properties: + algorithm_id: + type: string + description: From Admin API + algorithm_name: + type: string + algorithm_description: + type: string + need_external: + type: array + items: + type: string + ExternalInfomation: + type: object + required: + - external_id + - external_name + - external_description + - first_entry_at + - last_updated_at + - updated_history + properties: + external_id: + type: string + external_name: + type: string + external_description: + type: string + first_entry_at: + type: string + format: date-time + last_updated_at: + type: string + format: date-time + updated_history: + type: array + items: + type: string + format: date-time + Versions: + type: string + enum: + - v0.1.0 + securitySchemes: + BearerAuth: + type: http + scheme: bearer diff --git a/schema/@typespec/openapi3/openapi.yaml b/schema/@typespec/openapi3/openapi.yaml deleted file mode 100644 index 46af45d..0000000 --- a/schema/@typespec/openapi3/openapi.yaml +++ /dev/null @@ -1,311 +0,0 @@ -openapi: 3.0.0 -info: - title: BeLifeline Server API - version: 0.0.0 -tags: - - name: Algorithm - - name: Admin -paths: - /admin/algorithm: - post: - tags: - - Admin - operationId: Algorithm_create - parameters: [] - responses: - '200': - description: The request has succeeded. - content: - application/json: - schema: - type: object - properties: - algorithm_id: - type: string - description: From Admin API - algorithm_name: - type: string - algorithm_description: - type: string - need_external: - type: array - items: - type: string - first_entry_at: - type: string - format: date-time - last_entry_at: - type: string - format: date-time - last_updated_at: - type: string - format: date-time - bearer_token: - type: string - required: - - algorithm_id - - algorithm_name - - algorithm_description - - need_external - - first_entry_at - - last_entry_at - - last_updated_at - - bearer_token - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - algorithm: - $ref: '#/components/schemas/AlgorithmInfomationCreate' - required: - - algorithm - security: - - BearerAuth: [] - /admin/algorithm/{algorithm_id}: - delete: - tags: - - Admin - operationId: Algorithm_delete - parameters: - - name: algorithm_id - in: path - required: true - schema: - type: string - responses: - '200': - description: The request has succeeded. - content: - application/json: - schema: - type: object - properties: - delete_algorithm_id: - type: string - required: - - delete_algorithm_id - security: - - BearerAuth: [] - /algorithm: - get: - tags: - - Algorithm - operationId: Algorithm_list - parameters: - - name: limit - in: query - required: false - schema: - type: integer - format: int32 - responses: - '200': - description: The request has succeeded. - content: - application/json: - schema: - type: array - items: - $ref: '#/components/schemas/AlgorithmInfomation' - security: - - BearerAuth: [] - post: - tags: - - Algorithm - operationId: Algorithm_create - parameters: [] - responses: - '200': - description: The request has succeeded. - content: - application/json: - schema: - $ref: '#/components/schemas/AlgorithmInfomation' - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - algorithm: - $ref: '#/components/schemas/AlgorithmInfomationCreate' - required: - - algorithm - security: - - BearerAuth: [] - /algorithm/{algorithm_id}: - put: - tags: - - Algorithm - operationId: EachAlgorithm_update - parameters: - - name: algorithm_id - in: path - required: true - schema: - type: string - responses: - '200': - description: The request has succeeded. - content: - application/json: - schema: - $ref: '#/components/schemas/AlgorithmInfomation' - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - update_algorithm: - $ref: '#/components/schemas/AlgorithmInfomationCreateOrUpdate' - required: - - update_algorithm - security: - - BearerAuth: [] - get: - tags: - - Algorithm - operationId: EachAlgorithm_get - parameters: - - name: algorithm_id - in: path - required: true - schema: - type: string - responses: - '200': - description: The request has succeeded. - content: - application/json: - schema: - $ref: '#/components/schemas/AlgorithmInfomation' - security: - - BearerAuth: [] - delete: - tags: - - Algorithm - operationId: EachAlgorithm_delete - parameters: - - name: algorithm_id - in: path - required: true - schema: - type: string - responses: - '200': - description: The request has succeeded. - content: - application/json: - schema: - type: object - properties: - delete_algorithm_id: - type: string - required: - - delete_algorithm_id - security: - - BearerAuth: [] -components: - schemas: - AlgorithmInfomation: - type: object - required: - - algorithm_id - - algorithm_name - - algorithm_description - - need_external - - first_entry_at - - last_entry_at - - last_updated_at - properties: - algorithm_id: - type: string - description: From Admin API - algorithm_name: - type: string - algorithm_description: - type: string - need_external: - type: array - items: - type: string - first_entry_at: - type: string - format: date-time - last_entry_at: - type: string - format: date-time - last_updated_at: - type: string - format: date-time - AlgorithmInfomationCreate: - type: object - required: - - algorithm_name - - algorithm_description - - need_external - properties: - algorithm_name: - type: string - algorithm_description: - type: string - need_external: - type: array - items: - type: string - AlgorithmInfomationCreateOrUpdate: - type: object - required: - - algorithm_id - - algorithm_name - - algorithm_description - - need_external - properties: - algorithm_id: - type: string - description: From Admin API - algorithm_name: - type: string - algorithm_description: - type: string - need_external: - type: array - items: - type: string - ExternalInfomation: - type: object - required: - - external_id - - external_name - - external_description - - first_entry_at - - last_updated_at - - updated_history - properties: - external_id: - type: string - external_name: - type: string - external_description: - type: string - first_entry_at: - type: string - format: date-time - last_updated_at: - type: string - format: date-time - updated_history: - type: array - items: - type: string - format: date-time - securitySchemes: - BearerAuth: - type: http - scheme: bearer diff --git a/schema/@typespec/openapi3/openapi.yaml b/schema/@typespec/openapi3/openapi.yaml new file mode 120000 index 0000000..b8a26b6 --- /dev/null +++ b/schema/@typespec/openapi3/openapi.yaml @@ -0,0 +1 @@ +./openapi.v0.1.0.yaml \ No newline at end of file diff --git a/scripts/compile.sh b/scripts/compile.sh new file mode 100644 index 0000000..7967c2b --- /dev/null +++ b/scripts/compile.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +base_dir="schema/@typespec/openapi3" + +sorted_files=($(cd "$base_dir" && find . -maxdepth 1 -type f -name "*.yaml" 2>/dev/null | sort )) + +if [ ${#sorted_files[@]} -eq 0 ]; then + echo "No .yaml files found in ${base_dir}" +else + top_file="${sorted_files[0]}" + + cd ${base_dir} && ln -sf "${top_file}" "openapi.yaml" +fi diff --git a/specs/main.tsp b/specs/main.tsp index 6d6d967..a7ff840 100644 --- a/specs/main.tsp +++ b/specs/main.tsp @@ -1,7 +1,14 @@ +import "@typespec/versioning"; + import "./algorithm.tsp"; import "./admin.tsp"; @service({ title: "BeLifeline Server API", }) +@Versioning.versioned(BeLifelineServer.Versions) namespace BeLifelineServer; + +enum Versions { + v0: "v0.1.0", +}