Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add schema folder options #196

Merged
merged 4 commits into from
Mar 4, 2022
Merged

Conversation

pahrizal
Copy link
Contributor

@pahrizal pahrizal commented Mar 4, 2022

adding schemaFolder option in makeSwagger to get swagger component schemas spec from an entity file.

example (using TypeORM):

// /models/organization.model.ts
import {
  Column,
  Entity,
  Generated,
  ManyToOne,
  OneToMany,
  PrimaryColumn,
} from "typeorm";

/**
 * @swagger
 * components:
 *  schemas:
 *    Organization:
 *      type: object
 *      properties:
 *        id:
 *          type: string
 *          format: uuid
 *        name:
 *          type: string
 *        parent:
 *          type: string
 *        createdAt:
 *          type: string
 *          format: date-time
 *        updatedAt:
 *          type: string
 *          format: date-time
 */

@Entity()
export class Organization {
  @PrimaryColumn({ type: "uuid" })
  @Generated("uuid")
  id!: string;

  @Column() name!: string;

  @Column({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
  createdAt?: Date;

  @Column({
    type: "timestamp",
    default: () => "CURRENT_TIMESTAMP",
    onUpdate: "CURRENT_TIMESTAMP",
  })
  updatedAt?: Date;
}

and then, we can use this schema in our api route file:

// page/api/org/index.ts
...
/**
 * @swagger
 * /api/org:
 *   get:
 *     tags: [Organization]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: Organization
 *         content:
 *           application/json:
 *             schema:
 *               type: array
 *               items:
 *                 type: object
 *                 $ref: '#/components/schemas/Organization'
 */
....

@changeset-bot
Copy link

changeset-bot bot commented Mar 4, 2022

⚠️ No Changeset found

Latest commit: 384298c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Mar 4, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

next-swagger-doc – ./

🔍 Inspect: https://vercel.com/dunghd/next-swagger-doc/Dv1vXxn5Nrks4xUiBfo5pqBXQKBL
✅ Preview: https://next-swagger-doc-git-fork-pahrizal-add-schema-fol-689afd-dunghd.vercel.app

next-swagger-doc-demo – ./example

🔍 Inspect: https://vercel.com/dunghd/next-swagger-doc-demo/7K7az2TMde9i2b4ZWo2DY3Qmp8QZ
✅ Preview: https://next-swagger-doc-demo-git-fork-pahrizal-add-schem-03e8d0-dunghd.vercel.app

@jellydn
Copy link
Owner

jellydn commented Mar 4, 2022

Nice. Thanks. I will adjust a little bit and release new version soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants