@scalar/nuxt 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/module.d.mts +9 -0
- package/dist/module.d.ts +9 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +52 -9
- package/dist/runtime/components/ScalarApiReference.vue +54 -0
- package/dist/runtime/components/nuxt-theme.css +1 -0
- package/dist/runtime/pages/ScalarPage.vue +21 -0
- package/dist/runtime/plugins/hydrateClient.d.ts +2 -0
- package/dist/runtime/plugins/hydrateClient.mjs +13 -0
- package/dist/types.d.mts +2 -11
- package/dist/types.d.ts +2 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/@scalar/nuxt)
|
|
6
6
|
[](https://discord.gg/8HeZcRGPFS)
|
|
7
7
|
|
|
8
|
+
This plugin provides an easy way to render a beautiful API reference based on a OpenAPI/Swagger file with Nuxt.
|
|
9
|
+
|
|
10
|
+
[](https://docs.scalar.com/swagger-editor)
|
|
11
|
+
|
|
8
12
|
## Quick Setup
|
|
9
13
|
|
|
10
14
|
Install the module to your Nuxt application with one command:
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { ReferenceConfiguration } from '@scalar/api-reference';
|
|
3
|
+
|
|
4
|
+
type Configuration = Omit<ReferenceConfiguration, 'layout' | 'isEditable' | 'onSpecUpdate'>;
|
|
5
|
+
|
|
6
|
+
type ModuleOptions = Configuration;
|
|
7
|
+
declare const _default: _nuxt_schema.NuxtModule<Configuration>;
|
|
8
|
+
|
|
9
|
+
export { type ModuleOptions, _default as default };
|
package/dist/module.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { ReferenceConfiguration } from '@scalar/api-reference';
|
|
3
|
+
|
|
4
|
+
type Configuration = Omit<ReferenceConfiguration, 'layout' | 'isEditable' | 'onSpecUpdate'>;
|
|
5
|
+
|
|
6
|
+
type ModuleOptions = Configuration;
|
|
7
|
+
declare const _default: _nuxt_schema.NuxtModule<Configuration>;
|
|
8
|
+
|
|
9
|
+
export { type ModuleOptions, _default as default };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,12 +1,55 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { defineNuxtModule, createResolver, addComponent, extendPages, addPlugin } from '@nuxt/kit';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
const module = defineNuxtModule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "@scalar/nuxt",
|
|
6
|
+
configKey: "scalarConfig"
|
|
7
|
+
},
|
|
8
|
+
// Default configuration options of the Nuxt module
|
|
9
|
+
defaults: {
|
|
10
|
+
darkMode: true,
|
|
11
|
+
metaData: {
|
|
12
|
+
title: "API Documentation by Scalar"
|
|
13
|
+
},
|
|
14
|
+
pathRouting: {
|
|
15
|
+
basePath: "/docs"
|
|
16
|
+
},
|
|
17
|
+
showSidebar: true
|
|
18
|
+
},
|
|
19
|
+
setup(_options, _nuxt) {
|
|
20
|
+
const resolver = createResolver(import.meta.url);
|
|
21
|
+
let isOpenApiEnabled = false;
|
|
22
|
+
_nuxt.options.build.transpile.push("@scalar/api-reference");
|
|
23
|
+
_nuxt.options.vite.optimizeDeps ||= {};
|
|
24
|
+
_nuxt.options.vite.optimizeDeps.include ||= [];
|
|
25
|
+
_nuxt.options.vite.optimizeDeps.include.push(
|
|
26
|
+
"debug",
|
|
27
|
+
"extend",
|
|
28
|
+
"stringify-object",
|
|
29
|
+
"rehype-highlight"
|
|
30
|
+
);
|
|
31
|
+
_nuxt.hook("nitro:config", (config) => {
|
|
32
|
+
if (config.experimental?.openAPI)
|
|
33
|
+
isOpenApiEnabled = true;
|
|
34
|
+
});
|
|
35
|
+
addComponent({
|
|
36
|
+
name: "ScalarApiReference",
|
|
37
|
+
export: "default",
|
|
38
|
+
filePath: resolver.resolve("./runtime/components/ScalarApiReference.vue")
|
|
39
|
+
});
|
|
40
|
+
extendPages((pages) => {
|
|
41
|
+
pages.push({
|
|
42
|
+
name: "scalar",
|
|
43
|
+
path: _options.pathRouting?.basePath + ":pathMatch(.*)*",
|
|
44
|
+
meta: {
|
|
45
|
+
configuration: _options,
|
|
46
|
+
isOpenApiEnabled
|
|
47
|
+
},
|
|
48
|
+
file: resolver.resolve("./runtime/pages/ScalarPage.vue")
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
addPlugin(resolver.resolve("./runtime/plugins/hydrateClient"));
|
|
9
52
|
}
|
|
10
|
-
})
|
|
53
|
+
});
|
|
11
54
|
|
|
12
|
-
export default
|
|
55
|
+
export { module as default };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { useHead, useRequestURL, useSeoMeta } from '#imports'
|
|
3
|
+
import { ModernLayout, parse } from '@scalar/api-reference'
|
|
4
|
+
import '@scalar/api-reference/index.css'
|
|
5
|
+
import { reactive, ref, toRaw } from 'vue'
|
|
6
|
+
import type { Configuration } from '~/src/types'
|
|
7
|
+
|
|
8
|
+
import './nuxt-theme.css'
|
|
9
|
+
|
|
10
|
+
const props = defineProps<{
|
|
11
|
+
configuration: Configuration
|
|
12
|
+
}>()
|
|
13
|
+
|
|
14
|
+
const isDark = ref(props.configuration.darkMode)
|
|
15
|
+
|
|
16
|
+
// Grab spec if we can
|
|
17
|
+
const content: unknown = props.configuration.spec?.content
|
|
18
|
+
? toRaw(props.configuration.spec.content)
|
|
19
|
+
: props.configuration.spec?.url
|
|
20
|
+
? await $fetch(props.configuration.spec?.url)
|
|
21
|
+
: await $fetch('/_nitro/openapi.json')
|
|
22
|
+
|
|
23
|
+
// Check for empty spec
|
|
24
|
+
if (!content)
|
|
25
|
+
throw new Error('You must provide a spec for Scalar API References')
|
|
26
|
+
|
|
27
|
+
const parsedSpec = reactive(await parse(content))
|
|
28
|
+
const rawSpec = JSON.stringify(content)
|
|
29
|
+
|
|
30
|
+
// Load up the metadata
|
|
31
|
+
if (props.configuration?.metaData) useSeoMeta(props.configuration.metaData)
|
|
32
|
+
|
|
33
|
+
useHead({
|
|
34
|
+
bodyAttrs: {
|
|
35
|
+
class: () => (isDark.value ? 'dark-mode' : 'light-mode'),
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
// Add baseServerURL
|
|
40
|
+
const { origin } = useRequestURL()
|
|
41
|
+
const config = {
|
|
42
|
+
baseServerURL: origin,
|
|
43
|
+
...props.configuration,
|
|
44
|
+
}
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<template>
|
|
48
|
+
<ModernLayout
|
|
49
|
+
:configuration="config"
|
|
50
|
+
:isDark="isDark"
|
|
51
|
+
:parsedSpec="parsedSpec"
|
|
52
|
+
:rawSpec="rawSpec"
|
|
53
|
+
@toggleDarkMode="isDark = !isDark" />
|
|
54
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.light-mode{--scalar-background-1:#fff;--scalar-background-2:#f8fafc;--scalar-background-3:#e7e7e7;--scalar-background-accent:#8ab4f81f;--scalar-color-1:#000;--scalar-color-2:#6b7280;--scalar-color-3:#9ca3af;--scalar-color-accent:#00c16a;--scalar-border-color:#e5e7eb;--scalar-color-green:#069061;--scalar-color-red:#ef4444;--scalar-color-yellow:#f59e0b;--scalar-color-blue:#1d4ed8;--scalar-color-orange:#fb892c;--scalar-color-purple:#6d28d9;--scalar-button-1:#000;--scalar-button-1-hover:rgba(0,0,0,.9);--scalar-button-1-color:#fff}.dark-mode{--scalar-background-1:#020420;--scalar-background-2:#121a31;--scalar-background-3:#1e293b;--scalar-background-accent:#8ab4f81f;--scalar-color-1:#fff;--scalar-color-2:#cbd5e1;--scalar-color-3:#94a3b8;--scalar-color-accent:#00dc82;--scalar-border-color:#1e293b;--scalar-color-green:#069061;--scalar-color-red:#f87171;--scalar-color-yellow:#fde68a;--scalar-color-blue:#60a5fa;--scalar-color-orange:#fb892c;--scalar-color-purple:#ddd6fe;--scalar-button-1:hsla(0,0%,100%,.9);--scalar-button-1-hover:hsla(0,0%,100%,.8);--scalar-button-1-color:#000}.dark-mode .t-doc__sidebar,.light-mode .t-doc__sidebar{--scalar-sidebar-background-1:var(--scalar-background-1);--scalar-sidebar-color-1:var(--scalar-color-1);--scalar-sidebar-color-2:var(--scalar-color-3);--scalar-sidebar-border-color:var(--scalar-border-color);--scalar-sidebar-item-hover-background:transparent;--scalar-sidebar-item-hover-color:var(--scalar-color-1);--scalar-sidebar-item-active-background:transparent;--scalar-sidebar-color-active:var(--scalar-color-accent);--scalar-sidebar-search-background:transparent;--scalar-sidebar-search-color:var(--scalar-color-3);--scalar-sidebar-search-border-color:var(--scalar-border-color);--scalar-sidebar-indent-border:var(--scalar-border-color);--scalar-sidebar-indent-border-hover:var(--scalar-color-1);--scalar-sidebar-indent-border-active:var(--scalar-color-accent)}.scalar-card .request-card-footer{--scalar-background-3:var(--scalar-background-2);--scalar-button-1:#0f172a;--scalar-button-1-hover:rgba(30,41,59,.5);--scalar-button-1-color:#fff}.scalar-card .show-api-client-button{border:1px solid #334155!important}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { useRoute } from '#imports'
|
|
3
|
+
import type { Meta } from '~/src/types'
|
|
4
|
+
|
|
5
|
+
const route = useRoute()
|
|
6
|
+
const meta = route.meta as Meta
|
|
7
|
+
|
|
8
|
+
// Ensure we have a spec
|
|
9
|
+
if (
|
|
10
|
+
!meta.isOpenApiEnabled &&
|
|
11
|
+
!meta.configuration?.spec?.url &&
|
|
12
|
+
!meta.configuration?.spec?.content
|
|
13
|
+
)
|
|
14
|
+
throw new Error(
|
|
15
|
+
'You must either provide a spec to scalarConfig, or enable experimental openApi in the Nitro config.',
|
|
16
|
+
)
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<ScalarApiReference :configuration="meta.configuration" />
|
|
21
|
+
</template>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineNuxtPlugin } from "#app";
|
|
2
|
+
import { useHead } from "#imports";
|
|
3
|
+
export default defineNuxtPlugin((_nuxtApp) => {
|
|
4
|
+
_nuxtApp.hook("app:rendered", ({ ssrContext }) => {
|
|
5
|
+
useHead({
|
|
6
|
+
script: [
|
|
7
|
+
{
|
|
8
|
+
children: `window.__SCALAR__ = ${JSON.stringify(ssrContext?.payload?.data ?? {})}`
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
});
|
package/dist/types.d.mts
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
|
|
2
|
-
import type { ModuleOptions
|
|
2
|
+
import type { ModuleOptions } from './module.js'
|
|
3
3
|
|
|
4
|
-
declare module '#app' {
|
|
5
|
-
interface RuntimeNuxtHooks extends RuntimeModuleHooks, ModuleRuntimeHooks {}
|
|
6
|
-
}
|
|
7
4
|
|
|
8
5
|
declare module '@nuxt/schema' {
|
|
9
6
|
interface NuxtConfig { ['scalarConfig']?: Partial<ModuleOptions> }
|
|
10
7
|
interface NuxtOptions { ['scalarConfig']?: ModuleOptions }
|
|
11
|
-
interface NuxtHooks extends ModuleHooks {}
|
|
12
|
-
interface RuntimeConfig extends ModuleRuntimeConfig {}
|
|
13
|
-
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
|
|
14
8
|
}
|
|
15
9
|
|
|
16
10
|
declare module 'nuxt/schema' {
|
|
17
11
|
interface NuxtConfig { ['scalarConfig']?: Partial<ModuleOptions> }
|
|
18
12
|
interface NuxtOptions { ['scalarConfig']?: ModuleOptions }
|
|
19
|
-
interface NuxtHooks extends ModuleHooks {}
|
|
20
|
-
interface RuntimeConfig extends ModuleRuntimeConfig {}
|
|
21
|
-
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
|
|
22
13
|
}
|
|
23
14
|
|
|
24
15
|
|
|
25
|
-
export type { default } from './module.js'
|
|
16
|
+
export type { ModuleOptions, default } from './module.js'
|
package/dist/types.d.ts
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
|
|
2
|
-
import type { ModuleOptions
|
|
2
|
+
import type { ModuleOptions } from './module'
|
|
3
3
|
|
|
4
|
-
declare module '#app' {
|
|
5
|
-
interface RuntimeNuxtHooks extends RuntimeModuleHooks, ModuleRuntimeHooks {}
|
|
6
|
-
}
|
|
7
4
|
|
|
8
5
|
declare module '@nuxt/schema' {
|
|
9
6
|
interface NuxtConfig { ['scalarConfig']?: Partial<ModuleOptions> }
|
|
10
7
|
interface NuxtOptions { ['scalarConfig']?: ModuleOptions }
|
|
11
|
-
interface NuxtHooks extends ModuleHooks {}
|
|
12
|
-
interface RuntimeConfig extends ModuleRuntimeConfig {}
|
|
13
|
-
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
|
|
14
8
|
}
|
|
15
9
|
|
|
16
10
|
declare module 'nuxt/schema' {
|
|
17
11
|
interface NuxtConfig { ['scalarConfig']?: Partial<ModuleOptions> }
|
|
18
12
|
interface NuxtOptions { ['scalarConfig']?: ModuleOptions }
|
|
19
|
-
interface NuxtHooks extends ModuleHooks {}
|
|
20
|
-
interface RuntimeConfig extends ModuleRuntimeConfig {}
|
|
21
|
-
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
|
|
22
13
|
}
|
|
23
14
|
|
|
24
15
|
|
|
25
|
-
export type { default } from './module'
|
|
16
|
+
export type { ModuleOptions, default } from './module'
|