Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Fix tags path

Kiran K4ba49e4f025f
diff --git a/apps/web/app/api/projects/[slug]/tags/route.ts b/apps/web/app/api/projects/[slug]/tags/route.ts
index 22d4e5d3d3..b9f9b630ca 100644
--- a/apps/web/app/api/projects/[slug]/tags/route.ts
+++ b/apps/web/app/api/projects/[slug]/tags/route.ts
@@ -4,7 +4,7 @@ import prisma from "@/lib/prisma";
import { randomBadgeColor } from "@/ui/links/tag-badge";
import { NextResponse } from "next/server";
import { DubApiError, handleAndReturnErrorResponse } from "@/lib/errors";
-import { CreateTagSchema } from "@/lib/zod/schemas/tags";
+import { CreateTagBodySchema } from "@/lib/zod/schemas/tags";
// GET /api/projects/[slug]/tags - get all tags for a project
export const GET = withAuth(async ({ project, headers }) => {
@@ -48,7 +48,7 @@ export const POST = withAuth(async ({ req, project, headers }) => {
});
}
- const { tag } = CreateTagSchema.parse(await req.json());
+ const { tag } = CreateTagBodySchema.parse(await req.json());
const existingTag = await prisma.tag.findFirst({
where: {
diff --git a/apps/web/lib/openapi/index.ts b/apps/web/lib/openapi/index.ts
index 44ce76bc55..be52a41e3f 100644
--- a/apps/web/lib/openapi/index.ts
+++ b/apps/web/lib/openapi/index.ts
@@ -1,9 +1,9 @@
import { createDocument } from "zod-openapi";
-import { linkPaths } from "./links";
+import { linksPaths } from "./links";
+import { tagsPaths } from "./tags";
import { LinkSchema } from "@/lib/zod/schemas/links";
-import { TagSchemaOpenApi, tagPaths } from "@/lib/zod/schemas/tags";
-import { ProjectSchemaOpenApi, projectPaths } from "@/lib/zod/schemas/projects";
+import { TagSchema } from "@/lib/zod/schemas/tags";
export const openAPIDocument = createDocument({
openapi: "3.0.3",
@@ -29,15 +29,14 @@ export const openAPIDocument = createDocument({
},
],
paths: {
- ...linkPaths,
- // ...tagPaths,
+ ...linksPaths,
+ ...tagsPaths,
// ...projectPaths,
},
components: {
schemas: {
LinkSchema,
- TagSchemaOpenApi,
- ProjectSchemaOpenApi,
+ TagSchema,
},
},
});
diff --git a/apps/web/lib/openapi/links/index.ts b/apps/web/lib/openapi/links/index.ts
index 13300de59c..8514d056b2 100644
--- a/apps/web/lib/openapi/links/index.ts
+++ b/apps/web/lib/openapi/links/index.ts
@@ -7,7 +7,7 @@ import { deleteLink } from "./delete-link";
import { editLink } from "./edit-link";
import { createBulkLink } from "./create-bulk-link";
-export const linkPaths: ZodOpenApiPathsObject = {
+export const linksPaths: ZodOpenApiPathsObject = {
"/links": {
post: createLink,
get: getLinks,
diff --git a/apps/web/lib/openapi/tags/create-tag.ts b/apps/web/lib/openapi/tags/create-tag.ts
new file mode 100644
index 0000000000..d01e98ff91
--- /dev/null
+++ b/apps/web/lib/openapi/tags/create-tag.ts
@@ -0,0 +1,37 @@
+import { ZodOpenApiOperationObject } from "zod-openapi";
+
+import z from "@/lib/zod";
+import { CreateTagBodySchema, TagSchema } from "@/lib/zod/schemas/tags";
+
+export const createTag: ZodOpenApiOperationObject = {
+ operationId: "createTag",
+ summary: "Create a new tag",
+ description: "Create a new tag for the authenticated project.",
+ requestParams: {
+ path: z.object({
+ projectSlug: z
+ .string()
+ .describe(
+ "The slug for the project to create tags for. E.g. for `app.dub.co/acme`, the `projectSlug` is `acme`.",
+ ),
+ }),
+ },
+ requestBody: {
+ content: {
+ "application/json": {
+ schema: CreateTagBodySchema,
+ },
+ },
+ },
+ responses: {
+ "201": {
+ description: "The created tag",
+ content: {
+ "application/json": {
+ schema: TagSchema
+ },
+ },
+ },
+ },
+ tags: ["Tags"],
+};
diff --git a/apps/web/lib/openapi/tags/get-tags.ts b/apps/web/lib/openapi/tags/get-tags.ts
new file mode 100644
index 0000000000..54fbc016ee
--- /dev/null
+++ b/apps/web/lib/openapi/tags/get-tags.ts
@@ -0,0 +1,30 @@
+import { ZodOpenApiOperationObject } from "zod-openapi";
+
+import z from "@/lib/zod";
+import { TagSchema } from "@/lib/zod/schemas/tags";
+
+export const getTags: ZodOpenApiOperationObject = {
+ operationId: "getTags",
+ summary: "Retrieve a list of tags",
+ description: "Retrieve a list of tags for the authenticated project.",
+ requestParams: {
+ path: z.object({
+ projectSlug: z
+ .string()
+ .describe(
+ "The slug for the project to retrieve tags for. E.g. for `app.dub.co/acme`, the `projectSlug` is `acme`.",
+ ),
+ }),
+ },
+ responses: {
+ "200": {
+ description: "A list of tags",
+ content: {
+ "application/json": {
+ schema: z.array(TagSchema),
+ },
+ },
+ },
+ },
+ tags: ["Tags"],
+};
diff --git a/apps/web/lib/openapi/tags/index.ts b/apps/web/lib/openapi/tags/index.ts
new file mode 100644
index 0000000000..222029caa2
--- /dev/null
+++ b/apps/web/lib/openapi/tags/index.ts
@@ -0,0 +1,11 @@
+import { ZodOpenApiPathsObject } from "zod-openapi";
+
+import { createTag } from "./create-tag";
+import { getTags } from "./get-tags";
+
+export const tagsPaths: ZodOpenApiPathsObject = {
+ "/projects/{projectSlug}/tags": {
+ post: createTag,
+ get: getTags,
+ },
+};
diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.ts
index 4cd5b23396..b53f312e9c 100644
--- a/apps/web/lib/zod/schemas/links.ts
+++ b/apps/web/lib/zod/schemas/links.ts
@@ -165,4 +165,4 @@ export const BulkCreateLinksBodySchema = z
// TODO: Add proper type for geo
export const LinkSchema = Link.extend({
geo: z.record(z.string()).optional().nullable(),
-});
+}).openapi({ title: "Link" });
diff --git a/apps/web/lib/zod/schemas/tags.ts b/apps/web/lib/zod/schemas/tags.ts
index 2830177986..1ecf239dae 100644
--- a/apps/web/lib/zod/schemas/tags.ts
+++ b/apps/web/lib/zod/schemas/tags.ts
@@ -1,95 +1,15 @@
import z from "@/lib/zod";
-import { TagSchema } from "prisma/zod";
-import { ZodOpenApiOperationObject, ZodOpenApiPathsObject } from "zod-openapi";
-export const TagSchemaOpenApi = TagSchema.pick({
- id: true,
- name: true,
- color: true,
-}).openapi({
- title: "Tag",
- properties: {
- id: {
- description: "The unique ID of the tag.",
- },
- name: {
- description: "The name of the tag.",
- },
- color: {
- description: "The color of the tag.",
- },
- },
+export const CreateTagBodySchema = z.object({
+ tag: z.string().min(1).describe("The name of the tag to create."),
});
-export const CreateTagSchema = z.object({
- tag: z.string().min(1).openapi({
- description: "The name of the tag to create.",
- example: "news",
- }),
-});
-
-export type Tag = z.infer<typeof TagSchemaOpenApi>;
-
-export const createTag: ZodOpenApiOperationObject = {
- operationId: "createTag",
- summary: "Create a new tag",
- description: "Create a new tag for the authenticated project.",
- requestParams: {
- path: z.object({
- projectSlug: z.string().min(1).openapi({
- description:
- "The slug for the project to retrieve tags for. E.g. for `app.dub.co/acme`, the `projectSlug` is `acme`.",
- example: "acme",
- }),
- }),
- },
- requestBody: {
- content: {
- "application/json": {
- schema: CreateTagSchema,
- },
- },
- },
- responses: {
- "201": {
- description: "The tag was created",
- content: {
- "application/json": {
- schema: TagSchemaOpenApi,
- },
- },
- },
- },
-};
-
-export const getTags: ZodOpenApiOperationObject = {
- operationId: "getTags",
- summary: "Retrieve a list of tags",
- description: "Retrieve a list of tags for the authenticated project.",
- requestParams: {
- path: z.object({
- projectSlug: z.string().min(1).openapi({
- description:
- "The slug for the project to retrieve tags for. E.g. for `app.dub.co/acme`, the `projectSlug` is `acme`.",
- example: "acme",
- }),
- }),
- },
- responses: {
- "200": {
- description: "The tags were found",
- content: {
- "application/json": {
- schema: z.array(TagSchemaOpenApi),
- },
- },
- },
- },
-};
-
-export const tagPaths: ZodOpenApiPathsObject = {
- "/projects/{projectSlug}/tags": {
- post: createTag,
- get: getTags,
- },
-};
+export const TagSchema = z
+ .object({
+ id: z.string().describe("The unique ID of the tag."),
+ name: z.string().describe("The name of the tag."),
+ color: z.string().describe("The color of the tag."),
+ })
+ .openapi({
+ title: "Tag",
+ });