From 6f40a826a3086c81c2ceae05cd7a87c80045140c Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Fri, 8 Sep 2023 21:32:08 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Root=20resource=20and=20OpenAPI=20e?= =?UTF-8?q?mit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds the `Root` resource. Installs http, rest, and openapi TypeSpec packages. Emits Open API document. --- .gitignore | 1 + main.tsp | 28 +++++++++++++++-- package-lock.json | 76 ++++++++++++++++++++++++++++++++++++++++++++++- package.json | 9 ++++-- tspconfig.yaml | 7 +++++ 5 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 tspconfig.yaml diff --git a/.gitignore b/.gitignore index 40b878d..763301f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +dist/ node_modules/ \ No newline at end of file diff --git a/main.tsp b/main.tsp index 44b1694..3da0cef 100644 --- a/main.tsp +++ b/main.tsp @@ -1,2 +1,26 @@ -@service -namespace SWAPI; +import "@typespec/http"; +import "@typespec/rest"; + +using TypeSpec.Http; +using TypeSpec.Rest; + +@service({ + title: "SWAPI: The Star Wars API", + version: "v1", +}) +@server("https://swapi.dev/api/", "SWAPI server") +namespace SWAPI { + @route("/") + @get + op root(): Root; + + // https://swapi.dev/documentation#root + model Root { + films: string; + people: string; + planets: string; + species: string; + starships: string; + vehicles: string; + } +} diff --git a/package-lock.json b/package-lock.json index 911c89c..aa5806a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,10 @@ "version": "1.0.0-prerelease", "devDependencies": { "@typespec/compiler": "~0.47.1", - "@typespec/prettier-plugin-typespec": "^0.47.0", + "@typespec/http": "~0.47.0", + "@typespec/openapi3": "~0.47.0", + "@typespec/prettier-plugin-typespec": "~0.47.0", + "@typespec/rest": "~0.47.0", "husky": "^8.0.3", "is-ci": "^3.0.1", "lint-staged": "^14.0.1", @@ -115,6 +118,52 @@ "node": ">=16.0.0" } }, + "node_modules/@typespec/http": { + "version": "0.47.0", + "resolved": "https://registry.npmjs.org/@typespec/http/-/http-0.47.0.tgz", + "integrity": "sha512-HrVu5mGV+p3KGPtcNFHB5gXm9pU4rYRG3hJWZdLcN8fy+OuwbhmOgjOGN4AB7HLllnISmcFn6LtlqGnr0LpyfA==", + "dev": true, + "engines": { + "node": ">=16.0.0" + }, + "peerDependencies": { + "@typespec/compiler": "~0.47.0" + } + }, + "node_modules/@typespec/openapi": { + "version": "0.47.0", + "resolved": "https://registry.npmjs.org/@typespec/openapi/-/openapi-0.47.0.tgz", + "integrity": "sha512-p10NA5MQ1/z/yltTmK9g/RHgRQa+UPJg7ntcix8I9DIwX6u3yJReYwWBrKLeRNExd8ylNHNqjXTwiHJfptmR3w==", + "dev": true, + "peer": true, + "engines": { + "node": ">=16.0.0" + }, + "peerDependencies": { + "@typespec/compiler": "~0.47.0", + "@typespec/http": "~0.47.0", + "@typespec/rest": "~0.47.0" + } + }, + "node_modules/@typespec/openapi3": { + "version": "0.47.0", + "resolved": "https://registry.npmjs.org/@typespec/openapi3/-/openapi3-0.47.0.tgz", + "integrity": "sha512-N6TxfCKe1PmCyjFRnCH2+yHUyopEHzv8wjF71o7YLh9yWj4Qin51LmBa+Xr3OaRwyF6AJQedDDwB27uaRzIN7A==", + "dev": true, + "dependencies": { + "js-yaml": "~4.1.0" + }, + "engines": { + "node": ">=16.0.0" + }, + "peerDependencies": { + "@typespec/compiler": "~0.47.0", + "@typespec/http": "~0.47.0", + "@typespec/openapi": "~0.47.0", + "@typespec/rest": "~0.47.0", + "@typespec/versioning": "~0.47.0" + } + }, "node_modules/@typespec/prettier-plugin-typespec": { "version": "0.47.0", "resolved": "https://registry.npmjs.org/@typespec/prettier-plugin-typespec/-/prettier-plugin-typespec-0.47.0.tgz", @@ -124,6 +173,31 @@ "prettier": "~3.0.1" } }, + "node_modules/@typespec/rest": { + "version": "0.47.0", + "resolved": "https://registry.npmjs.org/@typespec/rest/-/rest-0.47.0.tgz", + "integrity": "sha512-sjxCY2dQ6Wc51W7NYDLgcZdeTI35vFJR0aK+tuYHMTwjhZJK20ezwb/c+RZQ8xyGIyX+vUj9yhTc7lBZGw4n1A==", + "dev": true, + "engines": { + "node": ">=16.0.0" + }, + "peerDependencies": { + "@typespec/compiler": "~0.47.0" + } + }, + "node_modules/@typespec/versioning": { + "version": "0.47.0", + "resolved": "https://registry.npmjs.org/@typespec/versioning/-/versioning-0.47.0.tgz", + "integrity": "sha512-j3NUBm61k40ZI5aljgqfVFvduoR+q7ijLpwt+lzXw/DecOgNWZX7R/GGzwCmUVyfJUZpMA/8zhuxmx4fB36P7g==", + "dev": true, + "peer": true, + "engines": { + "node": ">=16.0.0" + }, + "peerDependencies": { + "@typespec/compiler": "~0.47.0" + } + }, "node_modules/ajv": { "version": "8.12.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", diff --git a/package.json b/package.json index d625155..964bd30 100644 --- a/package.json +++ b/package.json @@ -5,17 +5,20 @@ "type": "module", "scripts": { "build": "tsp compile .", - "format": "prettier -l '**/*.{json,md,tsp}'", + "format": "prettier -l '**/*.{json,md,tsp,yaml}'", "format:fix": "npm run format -- -w", "prepare": "is-ci || husky install", "release": "npm run build && npm run format" }, "lint-staged": { - "**/*.{json,md,tsp}": "prettier -w" + "**/*.{json,md,tsp,yaml}": "prettier -w" }, "devDependencies": { "@typespec/compiler": "~0.47.1", - "@typespec/prettier-plugin-typespec": "^0.47.0", + "@typespec/http": "~0.47.0", + "@typespec/openapi3": "~0.47.0", + "@typespec/prettier-plugin-typespec": "~0.47.0", + "@typespec/rest": "~0.47.0", "husky": "^8.0.3", "is-ci": "^3.0.1", "lint-staged": "^14.0.1", diff --git a/tspconfig.yaml b/tspconfig.yaml new file mode 100644 index 0000000..9c56992 --- /dev/null +++ b/tspconfig.yaml @@ -0,0 +1,7 @@ +emit: + - "@typespec/openapi3" +options: + "@typespec/openapi3": + emitter-output-dir: "{project-root}/dist" + omit-unreachable-types: true + output-file: "swapi.openapi.yaml"