Skip to content

Commit b34d3c7

Browse files
committed
improve openapi meta
1 parent 70555b8 commit b34d3c7

16 files changed

Lines changed: 229 additions & 0 deletions

File tree

routes/_health.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
defineRouteMeta({
2+
openAPI: {
3+
description: "Service health check endpoint (should return 200 OK).",
4+
},
5+
});
6+
17
export default eventHandler(() => {
28
// const runtimeConfig = useRuntimeConfig();
39
// const res = await $fetch.raw("/meta", {

routes/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { renderHTML } from "openapi-renderer";
22

3+
defineRouteMeta({
4+
openAPI: {
5+
description: "API documentation for Ungh.",
6+
},
7+
});
8+
39
export default eventHandler(
410
() =>
511
renderHTML({

routes/orgs/[owner]/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import type { GithubOrg } from "~types";
22

3+
defineRouteMeta({
4+
openAPI: {
5+
description: "GitHub organization information.",
6+
parameters: [
7+
{
8+
name: "owner",
9+
in: "path",
10+
required: true,
11+
schema: { type: "string", example: "unjs" },
12+
},
13+
],
14+
},
15+
});
16+
317
export default eventHandler(async (event) => {
418
const org = await ghFetch(`orgs/${event.context.params.owner}`);
519

routes/orgs/[owner]/repos.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import type { GithubRepo } from "~types";
22

3+
defineRouteMeta({
4+
openAPI: {
5+
description: "GitHub organization repositories overview.",
6+
parameters: [
7+
{
8+
name: "owner",
9+
in: "path",
10+
required: true,
11+
schema: { type: "string", example: "unjs" },
12+
},
13+
],
14+
},
15+
});
16+
317
export default eventHandler(async (event) => {
418
// TODO: Do pagination
519
const rawRepos = await ghFetch(

routes/repos/[owner]/[repo]/branches/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
import type { GitHubBranches } from "~types";
22

3+
defineRouteMeta({
4+
openAPI: {
5+
description: "Get all the branches of a repository.",
6+
parameters: [
7+
{
8+
name: "owner",
9+
in: "path",
10+
required: true,
11+
schema: { type: "string", example: "unjs" },
12+
},
13+
{
14+
name: "repo",
15+
in: "path",
16+
required: true,
17+
schema: { type: "string", example: "ofetch" },
18+
},
19+
],
20+
},
21+
});
22+
323
export default eventHandler(async (event) => {
424
const repo = `${event.context.params.owner}/${event.context.params.repo}`;
525
const res = await ghFetch(`/repos/${repo}/branches`);

routes/repos/[owner]/[repo]/contributors.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
import type { GithubContributor } from "~types";
22

3+
defineRouteMeta({
4+
openAPI: {
5+
description: "Get repository contributors.",
6+
parameters: [
7+
{
8+
name: "owner",
9+
in: "path",
10+
required: true,
11+
schema: { type: "string", example: "unjs" },
12+
},
13+
{
14+
name: "repo",
15+
in: "path",
16+
required: true,
17+
schema: { type: "string", example: "ofetch" },
18+
},
19+
],
20+
},
21+
});
22+
323
export default eventHandler(async (event) => {
424
const res = await ghRepoContributors(
525
`${event.context.params.owner}/${event.context.params.repo}`,

routes/repos/[owner]/[repo]/files/[branch]/[...path].ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// import { hash } from "ohash";
22
// import type { GithubFileData } from "~types";
33

4+
defineRouteMeta({
5+
openAPI: {
6+
description: "(disabled - redirects to raw.githubusercontent.com)",
7+
},
8+
});
9+
410
export default eventHandler(async (event) => {
511
const repo = `${event.context.params.owner}/${event.context.params.repo}`;
612
const ref = `${event.context.params.branch}/${event.context.params.path}`;

routes/repos/[owner]/[repo]/files/[branch]/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import type { GithubFile } from "~types";
22

3+
defineRouteMeta({
4+
openAPI: {
5+
description: "(disabled - redirects to raw.githubusercontent.com)",
6+
},
7+
});
8+
39
export default eventHandler(async (event) => {
410
const repo = `${event.context.params.owner}/${event.context.params.repo}`;
511
const res = await ghRepoFiles(repo, event.context.params.branch);

routes/repos/[owner]/[repo]/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
import type { GithubRepo } from "~types";
22

3+
defineRouteMeta({
4+
openAPI: {
5+
description: "Get repository readme file on main branch (not cached).",
6+
parameters: [
7+
{
8+
name: "owner",
9+
in: "path",
10+
required: true,
11+
schema: { type: "string", example: "unjs" },
12+
},
13+
{
14+
name: "repo",
15+
in: "path",
16+
required: true,
17+
schema: { type: "string", example: "ofetch" },
18+
},
19+
],
20+
},
21+
});
22+
323
export default eventHandler(async (event) => {
424
const rawRepo = await ghRepo(
525
`${event.context.params.owner}/${event.context.params.repo}`,

routes/repos/[owner]/[repo]/readme.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
const GH_RAW_URL = "https://raw.githubusercontent.com";
22

3+
defineRouteMeta({
4+
openAPI: {
5+
description: "Get repository readme file on main branch (not cached).",
6+
parameters: [
7+
{
8+
name: "owner",
9+
in: "path",
10+
required: true,
11+
schema: { type: "string", example: "unjs" },
12+
},
13+
{
14+
name: "repo",
15+
in: "path",
16+
required: true,
17+
schema: { type: "string", example: "ofetch" },
18+
},
19+
],
20+
},
21+
});
22+
323
export default cachedEventHandler(
424
async (event) => {
525
const repo = `${event.context.params.owner}/${event.context.params.repo}`;

0 commit comments

Comments
 (0)