Skip to content

Commit d899935

Browse files
committed
update
1 parent 02fb4bd commit d899935

File tree

456 files changed

+3701
-4049
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

456 files changed

+3701
-4049
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,7 @@ docs/
123123

124124
[wiki](https://github.com/on-org/nuxt-openapi-docs-module/wiki/Development)
125125

126+
### Custom pages
127+
128+
[wiki](https://github.com/on-org/nuxt-openapi-docs-module/wiki/Custom-pages)
129+

changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.5.1]- 2023-04-14
9+
10+
### Added
11+
12+
- custom pagex
13+
14+
### Fixed
15+
16+
nuxt 3 auth
17+
818
## [3.4.3]- 2023-04-13
919

1020
### Removed

dist/module.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"name": "nuxt-open-api-docs",
33
"configKey": "openApiDocs",
4-
"version": "3.4.3"
4+
"version": "3.5.1"
55
}

dist/module.mjs

Lines changed: 99 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,98 @@ function filesCleanup(files) {
108108
}
109109
return result;
110110
}
111+
function processCustomPaths(custom, locales) {
112+
const pathsByTags = {};
113+
if (Object.keys(custom).length) {
114+
pathsByTags["custom"] = {
115+
name: custom.name ?? "Custom",
116+
description: custom.description ?? "",
117+
isOpen: custom["x-tag-expanded"] ?? true,
118+
items: []
119+
};
120+
for (const i in locales) {
121+
if (custom[`x-summary-${i}`]) {
122+
pathsByTags[`x-description-${i}`] = custom[`x-summary-${i}`];
123+
}
124+
if (custom[`x-name-${i}`]) {
125+
pathsByTags[`x-name-${i}`] = custom[`x-name-${i}`];
126+
}
127+
}
128+
for (const path in custom.paths) {
129+
const item = {
130+
name: custom.paths[path].title ?? path,
131+
path,
132+
type: "custom",
133+
description: custom.paths[path].description ?? "",
134+
icon: custom.paths[path]["x-icon"] ?? null
135+
};
136+
for (const i in locales) {
137+
if (custom[`x-summary-${i}`]) {
138+
pathsByTags[`x-description-${i}`] = custom[`x-summary-${i}`];
139+
}
140+
if (custom[`x-name-${i}`]) {
141+
pathsByTags[`x-name-${i}`] = custom[`x-name-${i}`];
142+
}
143+
}
144+
pathsByTags["custom"].items.push(item);
145+
}
146+
}
147+
return pathsByTags;
148+
}
149+
function processOpenApiPaths(paths, locales) {
150+
const pathsByTags = {};
151+
for (const url in paths) {
152+
let routePath = url;
153+
if (routePath.startsWith("/"))
154+
routePath = routePath.substring(1);
155+
if (routePath.endsWith("/"))
156+
routePath = routePath.substring(-1);
157+
routePath = routePath.replace(/[/\\.?+=&{}]/gumi, "_").replace(/__+/, "_");
158+
for (const method in paths[url]) {
159+
const openapi_item = paths[url][method];
160+
if (!openapi_item.tags)
161+
openapi_item.tags = ["other"];
162+
openapi_item.tags.forEach((tag) => {
163+
if (method === "parameters")
164+
return;
165+
if (method === "servers")
166+
return;
167+
if (!pathsByTags[tag]) {
168+
const tagInfo = openapi_item.tags[tag] ?? {};
169+
const item2 = {
170+
name: tagInfo.name ?? tag,
171+
description: marked.parse(tagInfo.description ?? ""),
172+
isOpen: tagInfo["x-tag-expanded"] ?? true,
173+
items: []
174+
};
175+
for (const locale in locales) {
176+
if (tagInfo[`x-description-${locale}`]) {
177+
item2[`x-description-${locale}`] = marked.parse(tagInfo[`x-description-${locale}`]);
178+
}
179+
if (tagInfo[`x-name-${locale}`]) {
180+
item2[`x-name-${locale}`] = tagInfo[`x-name-${locale}`];
181+
}
182+
}
183+
pathsByTags[tag] = item2;
184+
}
185+
const item = {
186+
name: url,
187+
path: routePath,
188+
type: method,
189+
icon: openapi_item["x-icon"] ?? null,
190+
description: openapi_item.summary ?? null
191+
};
192+
for (const i in locales) {
193+
if (openapi_item[`x-summary-${i}`]) {
194+
item[`x-description-${i}`] = openapi_item[`x-summary-${i}`];
195+
}
196+
}
197+
pathsByTags[tag].items.push(item);
198+
});
199+
}
200+
}
201+
return pathsByTags;
202+
}
111203
const module = defineNuxtModule({
112204
meta: {
113205
name: "nuxt-open-api-docs",
@@ -158,60 +250,14 @@ const module = defineNuxtModule({
158250
if (openApiSpec.info["x-locales"]) {
159251
localoptions.locales = { ...{ en: "English" }, ...openApiSpec.info["x-locales"] };
160252
}
161-
const tags = (openApiSpec.tags ?? []).reduce((acc, tag) => {
253+
(openApiSpec.tags ?? []).reduce((acc, tag) => {
162254
acc[tag.name] = tag;
163255
return acc;
164256
}, {});
165-
const pathsByTags = {};
166-
for (const url in openApiSpec.paths) {
167-
let reUrl = url;
168-
if (reUrl.startsWith("/"))
169-
reUrl = reUrl.substring(1);
170-
if (reUrl.endsWith("/"))
171-
reUrl = reUrl.substring(-1);
172-
reUrl = reUrl.replace(/[/\\.?+=&{}]/gumi, "_").replace(/__+/, "_");
173-
for (const method in openApiSpec.paths[url]) {
174-
const openapi_item = openApiSpec.paths[url][method];
175-
if (!openapi_item.tags)
176-
openapi_item.tags = ["other"];
177-
openapi_item.tags.forEach((tag) => {
178-
if (method === "parameters")
179-
return;
180-
if (method === "servers")
181-
return;
182-
if (!pathsByTags[tag]) {
183-
const tagInfo = tags[tag] ?? {};
184-
const item2 = {
185-
name: tagInfo.name ?? tag,
186-
description: marked.parse(tagInfo.description ?? ""),
187-
isOpen: tagInfo["x-tag-expanded"] ?? true,
188-
items: []
189-
};
190-
for (const i in localoptions.locales) {
191-
if (tagInfo[`x-description-${i}`]) {
192-
item2[`x-description-${i}`] = marked.parse(tagInfo[`x-description-${i}`]);
193-
}
194-
if (tagInfo[`x-name-${i}`]) {
195-
item2[`x-name-${i}`] = tagInfo[`x-name-${i}`];
196-
}
197-
}
198-
pathsByTags[tag] = item2;
199-
}
200-
const item = {
201-
name: url,
202-
path: reUrl,
203-
type: method,
204-
description: openapi_item.summary ?? null
205-
};
206-
for (const i in localoptions.locales) {
207-
if (openapi_item[`x-summary-${i}`]) {
208-
item[`x-description-${i}`] = openapi_item[`x-summary-${i}`];
209-
}
210-
}
211-
pathsByTags[tag].items.push(item);
212-
});
213-
}
214-
}
257+
const pathsByTags = JSON.parse(JSON.stringify({
258+
...processCustomPaths(openApiSpec["x-custom-path"] ?? {}, localoptions.locales),
259+
...processOpenApiPaths(openApiSpec.paths, localoptions.locales)
260+
}));
215261
openApiSpec.definitions = replaceMarkdown(openApiSpec.definitions, openApiSpec.components, openApiSpec.definitions);
216262
openApiSpec.components = replaceMarkdown(openApiSpec.components, openApiSpec.components, openApiSpec.definitions);
217263
localoptions.doc = replaceMarkdown(openApiSpec, openApiSpec.components, openApiSpec.definitions);
@@ -261,6 +307,8 @@ const module = defineNuxtModule({
261307
}
262308
});
263309
for (let tag in pathsByTags) {
310+
if (tag === "custom")
311+
continue;
264312
for (let i in pathsByTags[tag].items) {
265313
const item = pathsByTags[tag].items[i];
266314
pages.push({

dist/runtime/OpenApiPlugin.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default class OpenApiPlugin {
2727
getLocaleText(lang: string, path: string): string;
2828
hasLocaleText(lang: string, path: string): boolean;
2929
hasAccess(file: string): boolean;
30-
setAccess(accessor: (file: string) => true): void;
30+
setAccess(accessor: (file: string) => boolean): void;
3131
getFooter(): string | null;
3232
setFooter(footer: null | string): void;
3333
getLogo(): string | null;

dist/runtime/components/OpenApiMenu.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
<nuxt-link :to="getSubRoute(route)" @click.native.stop.prevent class="block-btn py-2 px-4 hover:bg-gray-200 dark:hover:bg-gray-700">
3838
<div class="flex flex-col">
3939
<div class="font-semibold item-path">
40-
<span class="px-1 font-medium method-tag" :class="getTagColor(route.type)">{{ getRouteType(route.type) }} </span>
40+
<span class="px-1 font-medium method-icon" v-if="route.icon" v-html="route.icon"></span>
41+
<span class="px-1 font-medium method-tag" v-else-if="route.type !== 'custom'" :class="getTagColor(route.type)">{{ getRouteType(route.type) }} </span>
4142
{{ route.name }}
4243
</div>
4344
<div class="description text-sm text-gray-600 dark:text-gray-300/75 overflow-hidden overflow-ellipsis whitespace-nowrap">{{ tr(route, 'description', currentLocale) }}</div>
@@ -120,6 +121,10 @@ export default {
120121
getSubRoute(route) {
121122
const path = this.genUrl(route.path);
122123
const type = route.type;
124+
if (route.type === 'custom') {
125+
return `/${this.path}/${this.file}/${this.currentLocale}/${type}/${path}`
126+
}
127+
123128
return {name: `openapi-${this.path}/${this.file}/${this.currentLocale}-${type}-${path}`, meta: {locale: this.currentLocale, path: path, file: this.file, type: type}};
124129
},
125130
changeDoc(option) {
@@ -133,6 +138,10 @@ export default {
133138
</script>
134139

135140
<style scoped>
141+
.method-icon {
142+
width: 24px;
143+
display: inline-block;
144+
}
136145
.method-tag {
137146
width: 45px;
138147
display: inline-block;

dist/runtime/components/OpenApiMenu.vue.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ declare namespace _default {
5353
type: string;
5454
};
5555
};
56-
export function getSubRoute(route: any): {
56+
export function getSubRoute(route: any): string | {
5757
name: string;
5858
meta: {
5959
locale: any;

dist/runtime/components/OpenApiRoute.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
<OpenApiRequestBody v-if="route.requestBody" :requestBody="route.requestBody" :current-locale="currentLocale"
3737
:components="components"/>
3838

39-
<client-only v-if="route.path">
39+
<client-only v-if="url">
4040
<h2 class="text-lg font-bold mb-2">{{ $openapidoc.getLocaleText(currentLocale, 'Code simple') }}:</h2>
4141
<CodeSimples
42-
:url="route.path"
42+
:url="url"
4343
:baseUrl="server"
4444
:method="method"
4545
:mime-type="mimeType"
@@ -81,10 +81,6 @@ export default {
8181
subParams: {
8282
required: false,
8383
},
84-
url: {
85-
type: String,
86-
required: true,
87-
},
8884
path_doc: {
8985
type: String,
9086
required: true,

dist/runtime/components/OpenApiRoute.vue.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@ declare namespace _default {
1010
const required_1: boolean;
1111
export { required_1 as required };
1212
}
13-
export namespace url {
13+
export namespace path_doc {
1414
const type_1: StringConstructor;
1515
export { type_1 as type };
1616
const required_2: boolean;
1717
export { required_2 as required };
18-
const _default: string;
19-
export { _default as default };
2018
}
21-
export namespace path_doc {
19+
export namespace file {
2220
const type_2: StringConstructor;
2321
export { type_2 as type };
2422
const required_3: boolean;
2523
export { required_3 as required };
2624
}
27-
export namespace file {
25+
export namespace currentLocale {
2826
const type_3: StringConstructor;
2927
export { type_3 as type };
3028
const required_4: boolean;
3129
export { required_4 as required };
3230
}
33-
export namespace currentLocale {
31+
export namespace url {
3432
const type_4: StringConstructor;
3533
export { type_4 as type };
3634
const required_5: boolean;
3735
export { required_5 as required };
36+
const _default: string;
37+
export { _default as default };
3838
}
3939
export namespace server {
4040
const type_5: StringConstructor;

dist/runtime/layout/docs.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
<script>
4242
<% if (options.isNuxt3) {
43-
print('import {useNuxtApp} from "#app";');
43+
print('import {useNuxtApp, showError} from "#app";');
4444
} %>
4545
4646
@@ -56,7 +56,7 @@ export default {
5656
const { $openapidoc } = useNuxtApp()
5757
5858
if(!$openapidoc.hasAccess(file)) {
59-
throw createError({
59+
showError({
6060
statusCode: 404,
6161
message: 'page not found',
6262
})

0 commit comments

Comments
 (0)