Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/algolia-index.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Index API Reference to Algolia

on:
workflow_dispatch:

jobs:
index:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Install dependencies
run: yarn install --immutable
working-directory: www
- name: Run Algolia indexing
run: node scripts/index-algolia.mjs
working-directory: www/apps/api-reference
env:
NEXT_PUBLIC_ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
ALGOLIA_WRITE_API_KEY: ${{ secrets.ALGOLIA_WRITE_API_KEY }}
NEXT_PUBLIC_API_ALGOLIA_INDEX_NAME: ${{ secrets.API_ALGOLIA_INDEX_NAME }}
NEXT_PUBLIC_SITE_URL: ${{ secrets.API_REFERENCE_URL }}
NEXT_PUBLIC_BASE_PATH: /v1/api
3 changes: 2 additions & 1 deletion www/apps/api-reference/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ specs/admin.oas.json
specs/store.oas.json

# analyzer
analyze
analyze
public/specs
152 changes: 0 additions & 152 deletions www/apps/api-reference/app/algolia/route.ts

This file was deleted.

7 changes: 0 additions & 7 deletions www/apps/api-reference/app/assets/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import { MetadataRoute } from "next"
import OpenAPIParser from "@readme/openapi-parser"
import path from "path"
import type { ExpandedDocument, Operation } from "../../types/openapi"
import getUrl from "../../utils/get-url"
import getSectionId from "../../utils/get-section-id"
import getPathsOfTag from "../../utils/get-paths-of-tag"
import { config } from "../../config"

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
return []
Expand Down
50 changes: 50 additions & 0 deletions www/apps/api-reference/app/base-specs/[area]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { NextResponse } from "next/server"

export const runtime = "edge"

type RouteParams = { params: { area: string } }

export async function GET(request: Request, { params }: RouteParams) {
const { searchParams, origin } = new URL(request.url)
const { area } = params
const expand = searchParams.get("expand")
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ""

if (area !== "admin" && area !== "store") {
return NextResponse.json(
{
success: false,
message: `area ${area} is not allowed`,
},
{
status: 400,
}
)
}

const baseSpecsRes = await fetch(
`${origin}${basePath}/specs/${area}/base.json`
)
if (!baseSpecsRes.ok) {
return NextResponse.json({ success: false }, { status: 500 })
}

const baseSpecs = await baseSpecsRes.json()

if (expand) {
const tagRes = await fetch(
`${origin}${basePath}/specs/${area}/tags/${expand}.json`
)
if (tagRes.ok) {
const paths = await tagRes.json()
if (paths) {
baseSpecs.expandedTags = {}
baseSpecs.expandedTags[expand] = paths.paths
}
}
}

return NextResponse.json(baseSpecs, {
status: 200,
})
}
37 changes: 0 additions & 37 deletions www/apps/api-reference/app/base-specs/route.ts

This file was deleted.

18 changes: 10 additions & 8 deletions www/apps/api-reference/app/download/[area]/route.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import { existsSync, readFileSync } from "fs"
import { NextResponse } from "next/server"
import path from "path"

export const runtime = "edge"

type DownloadParams = {
params: {
area: string
}
}

export function GET(request: Request, { params }: DownloadParams) {
export async function GET(request: Request, { params }: DownloadParams) {
const { area } = params
const filePath = path.join(process.cwd(), "specs", area, "openapi.full.yaml")
const { origin } = new URL(request.url)
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ""

if (!existsSync(filePath)) {
const specRes = await fetch(
`${origin}${basePath}/specs/${area}/openapi.full.yaml`
)
if (!specRes.ok) {
return new NextResponse(null, {
status: 404,
})
}

const fileContent = readFileSync(filePath)

return new Response(fileContent, {
return new Response(specRes.body, {
headers: {
"Content-Type": "application/x-yaml",
"Content-Disposition": `attachment; filename="openapi.yaml"`,
Expand Down
45 changes: 45 additions & 0 deletions www/apps/api-reference/app/tag/[area]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { NextResponse } from "next/server"

export const runtime = "edge"

type RouteParams = { params: { area: string } }

export async function GET(request: Request, { params }: RouteParams) {
const { searchParams, origin } = new URL(request.url)
const { area } = params
const tagName = searchParams.get("tagName") || ""
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ""

if (area !== "admin" && area !== "store") {
return NextResponse.json(
{
success: false,
message: `area ${area} is not allowed`,
},
{
status: 400,
}
)
}

const tagRes = await fetch(
`${origin}${basePath}/specs/${area}/tags/${tagName}.json`
)
if (!tagRes.ok) {
return NextResponse.json(
{ success: false, message: `tag ${tagName} not found` },
{ status: 404 }
)
}

const paths = await tagRes.json()

return NextResponse.json(
{
paths: paths.paths,
},
{
status: 200,
}
)
}
Loading
Loading