Skip to content

generateOpenApiSpec returns empty spec #20

@GorgeousPuree

Description

@GorgeousPuree
import { LicenceDTO, LicencePatchDTO, NewLicenseDTO } from "@/models/license";
import generateOpenApiSpec from "@omer-x/next-openapi-json-generator";

export async function GET() {
  console.log(LicenceDTO)

  const spec = await generateOpenApiSpec({
    LicenceDTO,
    NewLicenseDTO,
    LicencePatchDTO
  });

  return Response.json(spec);
}
import { createInsertSchema } from "drizzle-zod";
import { licenses } from "@/database/schema";

const baseSchema = createInsertSchema(licenses, {
  id: schema => schema.id.readonly().describe("Unique identifier of the license"),
  licenseNumber: schema => schema.licenseNumber.describe("Number of the license"),
  country: schema => schema.country.describe("Country where license was issued"),
});

export const LicenceDTO = baseSchema.required()
  .describe("Represents a license definition");

  console.log(LicenceDTO)

export const NewLicenseDTO = baseSchema.omit({
    id: true,
  }).describe("Data Transfer Object for creating a new license");
  
export const LicencePatchDTO = NewLicenseDTO.partial().omit({
}).describe("Data Transfer Object for updating an existing license");

Although my DTOs are not empty, when I go to localhost:3000/api/swagger I have
{"openapi":"3.1.0","info":{"title":"Aaa","version":"0.1.0"},"paths":{},"components":{"schemas":{}},"tags":[]} as a result.

My package.json seems to be fine:

{
  "name": "aaa",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "c": "^0.11.0",
    "@omer-x/next-openapi-json-generator": "^1.2.1",
    "@omer-x/next-openapi-route-handler": "^1.6.0",
    "dotenv": "^16.4.5",
    "drizzle-orm": "^0.36.1",
    "drizzle-zod": "^0.5.1",
    "next": "15.0.3",
    "pg": "^8.13.1",
    "react": "19.0.0-rc-66855b96-20241106",
    "react-dom": "19.0.0-rc-66855b96-20241106",
    "swagger-ui-react": "^5.18.2",
    "zod": "^3.23.8"
  },
  "devDependencies": {
    "@omer-x/openapi-types": "^1.1.0",
    "@types/node": "^20",
    "@types/pg": "^8.11.10",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "@types/swagger-ui-react": "^4.18.3",
    "drizzle-kit": "^0.28.0",
    "eslint": "^8",
    "eslint-config-next": "15.0.3",
    "postcss": "^8",
    "tailwindcss": "^3.4.1",
    "tsx": "^4.19.2",
    "typescript": "^5"
  }
}

I expected that the resulting schemas in spec would not be empty. What could be the reason for that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions