Skip to content

Commit

Permalink
refactor: migrate to biome
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Apr 18, 2024
1 parent 22904cc commit bd2ce5a
Show file tree
Hide file tree
Showing 77 changed files with 15,975 additions and 15,107 deletions.
7 changes: 0 additions & 7 deletions .eslintrc.cjs

This file was deleted.

1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions .husky/pre-commit

This file was deleted.

12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v4.0.0-alpha.8" # Use the sha or tag you want to point at
hooks:
- id: prettier
# Those are not supported by biomejs yet, refer https://biomejs.dev/internals/language-support/
types_or: [html, css, markdown]
- repo: https://github.com/biomejs/pre-commit
rev: "v0.1.0" # Use the sha / tag you want to point at
hooks:
- id: biome-check
additional_dependencies: ["@biomejs/[email protected]"]
9 changes: 0 additions & 9 deletions .prettierrc.cjs

This file was deleted.

15 changes: 8 additions & 7 deletions .swm/dev-environment-setup.mcged.sw.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ To run your local dev environment you will need a few things on your machine. Fo

## Installations

* Install [Node JS](https://nodejs.org/en/download/), version `16.x`
- Install [Node JS](https://nodejs.org/en/download/), version `16.x`

* Install an IDE (preferably [VS Code](https://code.visualstudio.com/))
- Install an IDE (preferably [VS Code](https://code.visualstudio.com/))

* Install Git (if you don't already have it on your machine).
<br/>
- Install Git (if you don't already have it on your machine).
<br/>

## Getting the sources

Expand All @@ -26,17 +26,18 @@ git clone https://github.com/jellydn/next-swagger-doc.git

## Build

* Within the repository directory, run `yarn install` to install the project's dependencies.
- Within the repository directory, run `yarn install` to install the project's dependencies.

* Then, build the project by running `yarn build`.
- Then, build the project by running `yarn build`.

Here's what `yarn build` doing behind the scenes:

<br/>


<!-- NOTE-swimm-snippet: the lines below link your snippet to Swimm -->

### 📄 package.json

```json
34 "build": "pkgroll",
35 "coverage": "vitest run --coverage",
Expand Down
8 changes: 4 additions & 4 deletions .swm/swimm.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"repo_id": "Z2l0aHViJTNBJTNBbmV4dC1zd2FnZ2VyLWRvYyUzQSUzQWplbGx5ZG4=",
"configuration": {
"swmd": true
}
"repo_id": "Z2l0aHViJTNBJTNBbmV4dC1zd2FnZ2VyLWRvYyUzQSUzQWplbGx5ZG4=",
"configuration": {
"swmd": true
}
}
13 changes: 9 additions & 4 deletions .swm/testing-overview.b1r1n.sw.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ Use snapshot testing for make sure the output is the same.

<br/>


<!-- NOTE-swimm-snippet: the lines below link your snippet to Swimm -->

### 📄 test/index.test.ts

```typescript
7 expect(
8 createSwaggerSpec({
Expand All @@ -58,18 +59,22 @@ Test by file

<br/>


<!-- NOTE-swimm-snippet: the lines below link your snippet to Swimm -->

### 📄 test/index.test.ts

```typescript
5 describe('withSwagger', () => {
```
<br/>
Then we have all related use cases to the same group
<!-- NOTE-swimm-snippet: the lines below link your snippet to Swimm -->
### 📄 test/index.test.ts
```typescript
6 it('should create default swagger json option', () => {
7 expect(
Expand All @@ -84,7 +89,7 @@ Then we have all related use cases to the same group
16 }),
17 ).toMatchSnapshot();
18 });
19
19
20 it('should have Bearer Authentication', () => {
21 expect(
22 createSwaggerSpec({
Expand Down Expand Up @@ -113,7 +118,7 @@ Then we have all related use cases to the same group
45 }),
46 ).toMatchSnapshot();
47 });
48
48
49 it('should have support OAuth2 Authentication', () => {
50 expect(
51 createSwaggerSpec({
Expand Down
42 changes: 25 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ To incorporate `next-swagger-doc` with your Next.js 13 project, follow these ste
Next, create a new file `lib/swagger.ts`. This file uses the `next-swagger-doc` library to create a Swagger specification based on the API routes in your Next.js project.

```javascript
import { createSwaggerSpec } from 'next-swagger-doc';
import { createSwaggerSpec } from "next-swagger-doc";

export const getApiDocs = async () => {
const spec = createSwaggerSpec({
apiFolder: 'app/api', // define api folder under app folder
apiFolder: "app/api", // define api folder under app folder
definition: {
openapi: '3.0.0',
openapi: "3.0.0",
info: {
title: 'Next Swagger API Example',
version: '1.0',
title: "Next Swagger API Example",
version: "1.0",
},
components: {
securitySchemes: {
BearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
},
},
},
Expand Down Expand Up @@ -105,8 +105,8 @@ export default ReactSwagger;
Create a new file `app/api-doc/page.tsx`. This page imports the Swagger spec and the Swagger UI component to display the Swagger documentation.

```javascript
import { getApiDocs } from '@/lib/swagger';
import ReactSwagger from './react-swagger';
import { getApiDocs } from "@/lib/swagger";
import ReactSwagger from "./react-swagger";

export default async function IndexPage() {
const spec = await getApiDocs();
Expand Down Expand Up @@ -195,25 +195,25 @@ export default ApiDoc;
- Step 1: Create an api route on nextjs, e.g: `pages/api/doc.ts`

```typescript
import { withSwagger } from 'next-swagger-doc';
import { withSwagger } from "next-swagger-doc";

const swaggerHandler = withSwagger({
definition: {
openapi: '3.0.0',
openapi: "3.0.0",
info: {
title: 'NextJS Swagger',
version: '0.1.0',
title: "NextJS Swagger",
version: "0.1.0",
},
},
apiFolder: 'pages/api',
apiFolder: "pages/api",
});
export default swaggerHandler();
```

- Step 2: Add JSdoc to any NextJS API routes, for example: `pages/api/hello.ts`

```typescript
import { NextApiRequest, NextApiResponse } from 'next';
import { NextApiRequest, NextApiResponse } from "next";

/**
* @swagger
Expand All @@ -226,7 +226,7 @@ import { NextApiRequest, NextApiResponse } from 'next';
*/
const handler = (_req: NextApiRequest, res: NextApiResponse) => {
res.status(200).json({
result: 'hello world',
result: "hello world",
});
};

Expand Down Expand Up @@ -312,6 +312,14 @@ Create the custom rule in your eslint configuration file:
}
```

## Pre-commit hook

This project uses [pre-commit](https://pre-commit.com/) to enforce code quality. To install pre-commit hooks, run:

```sh
pre-commit install
```

## Author

👤 **Huynh Duc Dung**
Expand Down
Loading

0 comments on commit bd2ce5a

Please sign in to comment.