diff --git a/package.json b/package.json index b06032d..c42bf94 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "types:check": "tsc --noEmit --skipLibCheck" }, "dependencies": { + "@scalar/galaxy": "^0.1.0", "@scalar/mock-server": "^0.1.49", "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -23,10 +24,10 @@ "@hono/vite-cloudflare-pages": "^0.2.4", "@hono/vite-dev-server": "^0.12.0", "@originjs/vite-plugin-commonjs": "^1.0.3", + "@trivago/prettier-plugin-sort-imports": "^4.2.0", + "prettier": "^3.0.3", "vite": "^5.0.12", "vitest": "^1.5.3", - "wrangler": "^3.47.0", - "@trivago/prettier-plugin-sort-imports": "^4.2.0", - "prettier": "^3.0.3" + "wrangler": "^3.47.0" } } diff --git a/public/static/style.css b/public/static/style.css index bb73cbd..50969c8 100644 --- a/public/static/style.css +++ b/public/static/style.css @@ -1 +1,3 @@ -h1 { font-family: Arial, Helvetica, sans-serif; } \ No newline at end of file +h1 { + font-family: Arial, Helvetica, sans-serif; +} diff --git a/src/global.d.ts b/src/global.d.ts index 1137e63..900beeb 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,4 +1,4 @@ -import {} from 'hono' +import 'hono' declare module 'hono' { interface ContextRenderer { diff --git a/src/index.tsx b/src/index.tsx index f0f661a..5315d51 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,7 +1,7 @@ -import { renderer } from './renderer' - import { createMockServer } from '@scalar/mock-server' -import galaxy from './scalar-galaxy-3.1.json' + +import { renderer } from './renderer' +import galaxy from '@scalar/galaxy/latest.yaml?raw' // Create the mocked routes const app = await createMockServer({ diff --git a/src/renderer.tsx b/src/renderer.tsx index 45574ed..c9d1f23 100644 --- a/src/renderer.tsx +++ b/src/renderer.tsx @@ -4,7 +4,10 @@ export const renderer = jsxRenderer(({ children, title }) => { return ( - + {title} {children} diff --git a/src/scalar-galaxy-3.1.json b/src/scalar-galaxy-3.1.json deleted file mode 100644 index 23ac17f..0000000 --- a/src/scalar-galaxy-3.1.json +++ /dev/null @@ -1,803 +0,0 @@ -{ - "openapi": "3.1.0", - "info": { - "title": "Scalar Galaxy", - "description": "The Scalar Galaxy is an example OpenAPI specification to test OpenAPI tools and libraries. It’s a fictional universe with fictional planets and fictional data. Get all the data for all planets.\n\n## Resources\n\n* https://github.com/scalar/scalar\n* https://github.com/OAI/OpenAPI-Specification\n* https://scalar.com\n\n## Markdown Support\n\nAll descriptions *can* contain ~~tons of text~~ **Markdown**. [If GitHub supports the syntax](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax), chances are we’re supporting it, too.\n\n
\n Examples\n\n ### Blockquotes\n\n > I love OpenAPI. <3\n\n ### Tables\n\n | Feature | Availability |\n | ---------------- | ------------ |\n | Markdown Support | ✓ |\n\n ### Accordion\n\n ```html\n
\n Using Details Tags\n

HTML Example

\n
\n ```\n\n ### Images\n\n Yes, there’s support for images, too!\n\n ![Empty placeholder image showing the width/height](https://images.placeholders.dev/?width=1280&height=720)\n\n
\n", - "version": "1.0.0", - "contact": { - "name": "Marc from Scalar", - "url": "https://scalar.com", - "email": "marc@scalar.com" - } - }, - "servers": [ - { - "url": "https://galaxy.scalar.com" - } - ], - "security": [ - { - "bearerAuth": [] - }, - { - "basicAuth": [] - }, - { - "apiKeyQuery": [] - }, - { - "apiKeyHeader": [] - }, - { - "apiKeyCookie": [] - }, - { - "oauth2": [] - } - ], - "tags": [ - { - "name": "Authentication", - "description": "Some endpoints are public, but some require authentication. We provide all the required endpoints to create an account and authorize yourself." - }, - { - "name": "Planets", - "description": "Everything about planets" - } - ], - "paths": { - "/planets": { - "get": { - "tags": [ - "Planets" - ], - "summary": "Get all planets", - "description": "It’s easy to say you know them all, but do you really? Retrieve all the planets and check whether you missed one.", - "operationId": "getAllData", - "security": [ - {} - ], - "parameters": [ - { - "$ref": "#/components/parameters/limit" - }, - { - "$ref": "#/components/parameters/offset" - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "allOf": [ - { - "type": "object", - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Planet" - } - } - } - }, - { - "$ref": "#/components/schemas/PaginatedResource" - } - ] - } - } - } - } - } - }, - "post": { - "tags": [ - "Planets" - ], - "summary": "Create a planet", - "description": "Time to play god and create a new planet. What do you think? Ah, don’t think too much. What could go wrong anyway?", - "operationId": "createPlanet", - "requestBody": { - "description": "Planet", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Planet" - } - } - } - }, - "responses": { - "201": { - "description": "Created", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Planet" - } - } - } - }, - "400": { - "description": "Bad Request", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/responses/BadRequest" - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/responses/Forbidden" - } - } - } - } - } - } - }, - "/planets/{planetId}": { - "get": { - "tags": [ - "Planets" - ], - "summary": "Get a planet", - "description": "You’ll better learn a little bit more about the planets. It might come in handy once space travel is available for everyone.", - "operationId": "getPlanet", - "security": [ - {} - ], - "parameters": [ - { - "$ref": "#/components/parameters/planetId" - } - ], - "responses": { - "200": { - "description": "Planet Found", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Planet" - } - } - } - }, - "404": { - "description": "Planet Not Found", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/responses/NotFound" - } - } - } - } - } - }, - "put": { - "tags": [ - "Planets" - ], - "summary": "Update a planet", - "description": "Sometimes you make mistakes, that’s fine. No worries, you can update all planets.", - "operationId": "updatePlanet", - "requestBody": { - "description": "New information about the planet", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Planet" - } - } - } - }, - "parameters": [ - { - "$ref": "#/components/parameters/planetId" - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Planet" - } - } - } - }, - "400": { - "description": "Bad Request", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/responses/BadRequest" - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/responses/Forbidden" - } - } - } - }, - "404": { - "description": "Not Found", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/responses/NotFound" - } - } - } - } - } - }, - "delete": { - "tags": [ - "Planets" - ], - "summary": "Delete a planet", - "operationId": "deletePlanet", - "description": "This endpoint was used to delete planets. Unfortunately, that caused a lot of trouble for planets with life. So, this endpoint is now deprecated and should not be used anymore.", - "deprecated": true, - "parameters": [ - { - "$ref": "#/components/parameters/planetId" - } - ], - "responses": { - "204": { - "description": "No Content" - }, - "404": { - "description": "Not Found" - } - } - } - }, - "/planets/{planetId}/image": { - "post": { - "tags": [ - "Planets" - ], - "summary": "Upload an image to a planet", - "description": "Got a crazy good photo of a planet? Share it with the world!", - "operationId": "uploadImage", - "parameters": [ - { - "$ref": "#/components/parameters/planetId" - } - ], - "requestBody": { - "content": { - "multipart/form-data": { - "schema": { - "type": "object", - "properties": { - "image": { - "type": "string", - "format": "binary" - } - } - } - } - } - }, - "responses": { - "200": { - "description": "Image uploaded", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "message": { - "type": "string", - "examples": [ - "Image uploaded successfully" - ] - } - } - } - } - } - }, - "400": { - "description": "Bad Upload Request", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/responses/BadRequest" - } - } - } - }, - "403": { - "description": "Upload Forbidden", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/responses/Forbidden" - } - } - } - }, - "404": { - "description": "Failed to Upload Image, Planet Not Found", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/responses/NotFound" - } - } - } - } - } - } - }, - "/user/signup": { - "post": { - "tags": [ - "Authentication" - ], - "summary": "Create a user", - "description": "Time to create a user account, eh?", - "operationId": "createUser", - "security": [ - {} - ], - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/NewUser" - } - } - } - }, - "responses": { - "201": { - "description": "Created", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/User" - } - } - } - }, - "400": { - "description": "Bad Request", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/responses/BadRequest" - } - } - } - } - } - } - }, - "/auth/token": { - "post": { - "tags": [ - "Authentication" - ], - "summary": "Get a token", - "description": "Yeah, this is the boring security stuff. Just get your super secret token and move on.", - "operationId": "getToken", - "security": [ - {} - ], - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Credentials" - } - } - } - }, - "responses": { - "201": { - "description": "Token Created", - "content": { - "application/json": { - "schema": { - "ref": "#/components/schemas/Token" - } - } - } - } - } - } - }, - "/me": { - "get": { - "tags": [ - "Authentication" - ], - "summary": "Get authenticated user", - "description": "Find yourself they say. That’s what you can do here.", - "operationId": "getMe", - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/User" - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/responses/Forbidden" - } - } - } - } - } - } - } - }, - "webhooks": { - "newPlanet": { - "post": { - "tags": [ - "Planets" - ], - "requestBody": { - "description": "Information about a new planet", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Planet" - } - } - } - }, - "responses": { - "200": { - "description": "Return a 200 status to indicate that the data was received successfully" - } - } - } - } - }, - "components": { - "securitySchemes": { - "bearerAuth": { - "type": "http", - "scheme": "bearer" - }, - "basicAuth": { - "type": "http", - "scheme": "basic" - }, - "apiKeyHeader": { - "type": "apiKey", - "in": "header", - "name": "X-API-Key" - }, - "apiKeyQuery": { - "type": "apiKey", - "in": "query", - "name": "api_key" - }, - "apiKeyCookie": { - "type": "apiKey", - "in": "cookie", - "name": "api_key" - }, - "oauth2": { - "type": "oauth2", - "flows": { - "implicit": { - "authorizationUrl": "https://galaxy.scalar.com/oauth/authorize", - "scopes": { - "write:planets": "modify planets in your account", - "read:planets": "read your planets" - } - } - } - } - }, - "parameters": { - "planetId": { - "name": "planetId", - "in": "path", - "required": true, - "schema": { - "type": "integer", - "format": "int64", - "examples": [ - 1 - ] - } - }, - "limit": { - "name": "limit", - "in": "query", - "description": "The number of items to return", - "required": false, - "schema": { - "type": "integer", - "format": "int64", - "default": 10 - } - }, - "offset": { - "name": "offset", - "in": "query", - "description": "The number of items to skip before starting to collect the result set", - "required": false, - "schema": { - "type": "integer", - "format": "int64", - "default": 0 - } - } - }, - "responses": { - "BadRequest": { - "description": "Bad Request", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "Forbidden": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "NotFound": { - "description": "NotFound", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - } - }, - "schemas": { - "NewUser": { - "type": "object", - "required": [ - "name", - "email", - "password" - ], - "properties": { - "name": { - "type": "string", - "examples": [ - "Marc" - ] - }, - "email": { - "type": "string", - "format": "email", - "examples": [ - "marc@scalar.com" - ] - }, - "password": { - "type": "string", - "minLength": 8, - "examples": [ - "i-love-scalar" - ] - } - } - }, - "User": { - "type": "object", - "required": [ - "id", - "name", - "email" - ], - "properties": { - "id": { - "type": "integer", - "format": "int64", - "examples": [ - 1 - ] - }, - "name": { - "type": "string", - "examples": [ - "Marc" - ] - }, - "email": { - "type": "string", - "format": "email", - "examples": [ - "marc@scalar.com" - ] - } - } - }, - "Credentials": { - "type": "object", - "required": [ - "email", - "password" - ], - "properties": { - "email": { - "type": "string", - "format": "email", - "examples": [ - "marc@scalar.com" - ] - }, - "password": { - "type": "string", - "examples": [ - "i-love-scalar" - ] - } - } - }, - "Token": { - "type": "object", - "properties": { - "token": { - "type": "string", - "examples": [ - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" - ] - } - } - }, - "Planet": { - "type": "object", - "required": [ - "id", - "name" - ], - "properties": { - "id": { - "type": "integer", - "format": "int64", - "examples": [ - 1 - ] - }, - "name": { - "type": "string", - "examples": [ - "Mars" - ] - }, - "description": { - "type": [ - "string", - "null" - ], - "examples": [ - "The red planet" - ] - }, - "image": { - "type": "string", - "nullable": true, - "examples": [ - "https://cdn.scalar.com/photos/mars.jpg" - ] - }, - "creator": { - "$ref": "#/components/schemas/User" - } - } - }, - "PaginatedResource": { - "type": "object", - "properties": { - "meta": { - "type": "object", - "properties": { - "limit": { - "type": "integer", - "format": "int64", - "examples": [ - 10 - ] - }, - "offset": { - "type": "integer", - "format": "int64", - "examples": [ - 0 - ] - }, - "total": { - "type": "integer", - "format": "int64", - "examples": [ - 100 - ] - }, - "next": { - "type": [ - "string", - "null" - ], - "examples": [ - "/planets?limit=10&offset=10" - ] - } - } - } - } - }, - "Error": { - "type": "object", - "description": "RFC 7807 (https://datatracker.ietf.org/doc/html/rfc7807)", - "properties": { - "type": { - "type": "string", - "examples": [ - "https://example.com/errors/generic-error" - ] - }, - "title": { - "type": "string", - "examples": [ - "Something went wrong here." - ] - }, - "status": { - "type": "integer", - "format": "int64", - "examples": [ - 403 - ] - }, - "detail": { - "type": "string", - "examples": [ - "Unfortunately, we can’t provide further information." - ] - } - } - } - } - } - } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 64ea1d7..2da3888 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,14 +4,9 @@ "module": "ESNext", "moduleResolution": "Bundler", "strict": true, - "lib": [ - "ESNext" - ], - "types": [ - "@cloudflare/workers-types", - "vite/client" - ], + "lib": ["ESNext"], + "types": ["@cloudflare/workers-types", "vite/client"], "jsx": "react-jsx", "jsxImportSource": "hono/jsx" - }, -} \ No newline at end of file + } +} diff --git a/vite.config.ts b/vite.config.ts index 7fa7b72..9c39912 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -15,5 +15,5 @@ export default defineConfig({ ], build: { target: 'esnext', - } + }, })