Skip to content

Commit 709aaae

Browse files
authored
Merge pull request #250 from jellydn/246-withswagger-doesnt-include-schema-stored-in-non-pages-folder-to-serve-in-vercel
Support load yaml/json files on public folder
2 parents ecbcbb9 + bd186fd commit 709aaae

24 files changed

+2999
-112
lines changed

.changes/header.tpl.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
7+
and is generated by [Changie](https://github.com/miniscruff/changie).

.changes/unreleased/.gitkeep

Whitespace-only changes.

.changie.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
changesDir: .changes
2+
unreleasedDir: unreleased
3+
headerPath: header.tpl.md
4+
versionHeaderPath: ""
5+
versionFooterPath: ""
6+
changelogPath: CHANGELOG.md
7+
versionExt: md
8+
versionFormat: '## {{.Version}} - {{.Time.Format "2006-01-02"}}'
9+
kindFormat: '### {{.Kind}}'
10+
changeFormat: '* {{.Body}}'
11+
headerFormat: ""
12+
footerFormat: ""
13+
kinds:
14+
- label: Added
15+
- label: Changed
16+
- label: Deprecated
17+
- label: Removed
18+
- label: Fixed
19+
- label: Security

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
7+
and is generated by [Changie](https://github.com/miniscruff/changie).
8+
9+
No releases yet, this file will be updated when generating your first release.

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Welcome to next-swagger-doc 👋
22

33
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4+
45
[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-)
6+
57
<!-- ALL-CONTRIBUTORS-BADGE:END -->
68

79
[![Version](https://img.shields.io/npm/v/next-swagger-doc.svg)](https://npmjs.org/package/next-swagger-doc)
@@ -44,25 +46,29 @@ yarn add next-swagger-doc swagger-ui-react
4446

4547
```typescript
4648
import { GetStaticProps, InferGetStaticPropsType } from 'next';
47-
4849
import { createSwaggerSpec } from 'next-swagger-doc';
49-
import SwaggerUI from 'swagger-ui-react';
50+
import dynamic from 'next/dynamic';
5051
import 'swagger-ui-react/swagger-ui.css';
5152

52-
const ApiDoc = ({ spec }: InferGetStaticPropsType<typeof getStaticProps>) => {
53+
const SwaggerUI = dynamic<{
54+
spec: any;
55+
}>(import('swagger-ui-react'), { ssr: false });
56+
57+
function ApiDoc({ spec }: InferGetStaticPropsType<typeof getStaticProps>) {
5358
return <SwaggerUI spec={spec} />;
54-
};
59+
}
5560

56-
export const getStaticProps: GetStaticProps = async ctx => {
61+
export const getStaticProps: GetStaticProps = async () => {
5762
const spec: Record<string, any> = createSwaggerSpec({
5863
definition: {
5964
openapi: '3.0.0',
6065
info: {
61-
title: 'NextJS Swagger',
62-
version: '0.1.0',
66+
title: 'Next Swagger API Example',
67+
version: '1.0',
6368
},
6469
},
6570
});
71+
6672
return {
6773
props: {
6874
spec,

example/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
22

3+
## Link package
4+
5+
```sh
6+
npx link
7+
```
8+
39
## Getting Started
410

511
First, run the development server:

example/link.config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"packages": [
3+
"../"
4+
]
5+
}

example/next.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
compiler: {
3+
// ssr and displayName are configured by default
4+
styledComponents: true,
5+
removeConsole: true,
6+
swcMinify: true,
7+
},
8+
};

example/package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,35 @@
44
"private": true,
55
"scripts": {
66
"build": "next build",
7+
"postbuild": "cpy 'models/**/*.swagger.yaml' public/openapi --flat",
78
"dev": "next dev",
89
"openapi:yaml": "typeconv -f ts -t oapi --oapi-format yaml --output-extension 'swagger.yaml' --output-directory 'models/openapi' 'models/*.ts'",
910
"start": "next start"
1011
},
1112
"dependencies": {
13+
"@stoplight/elements": "7.5.18",
14+
"@xstyled/styled-components": "^3.6.0",
15+
"@xstyled/system": "^3.6.0",
1216
"isarray": "2.0.5",
1317
"next": "12.1.5",
14-
"next-swagger-doc": "0.3.0",
18+
"next-swagger-doc": "*",
1519
"react": "18.1.0",
1620
"react-dom": "18.1.0",
21+
"styled-components": "^5.3.5",
1722
"swagger-ui-react": "latest"
1823
},
1924
"devDependencies": {
2025
"@trivago/prettier-plugin-sort-imports": "3.2.0",
2126
"@types/node": "16.11.31",
2227
"@types/react": "18.0.8",
23-
"@types/react-dom": "18.0.2",
28+
"@types/react-dom": "18.0.3",
2429
"@types/swagger-jsdoc": "6.0.1",
2530
"@typescript-eslint/eslint-plugin": "5.21.0",
31+
"cpy-cli": "^4.1.0",
2632
"eslint": "8.14.0",
2733
"eslint-config-next": "12.1.5",
2834
"prettier": "2.6.2",
2935
"typeconv": "1.7.0",
30-
"typescript": "4.6.3"
36+
"typescript": "4.6.4"
3137
}
32-
}
38+
}

example/pages/_app.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import '../styles/globals.css';
2-
31
function MyApp({ Component, pageProps }) {
42
return <Component {...pageProps} />;
53
}

0 commit comments

Comments
 (0)