@scalar/nuxt 0.0.1
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/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/module.cjs +5 -0
- package/dist/module.d.mts +9 -0
- package/dist/module.d.ts +9 -0
- package/dist/module.json +5 -0
- package/dist/module.mjs +46 -0
- package/dist/runtime/components/ScalarApiReference.vue +53 -0
- package/dist/runtime/components/nuxt-theme.css +1 -0
- package/dist/runtime/pages/ScalarPage.vue +20 -0
- package/dist/runtime/plugins/hydrateClient.d.ts +2 -0
- package/dist/runtime/plugins/hydrateClient.mjs +12 -0
- package/dist/types.d.mts +16 -0
- package/dist/types.d.ts +16 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Scalar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Scalar API Reference Nuxt Module
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@scalar/nuxt)
|
|
4
|
+
[](https://www.npmjs.com/package/@scalar/nuxt)
|
|
5
|
+
[](https://www.npmjs.com/package/@scalar/nuxt)
|
|
6
|
+
[](https://discord.gg/8HeZcRGPFS)
|
|
7
|
+
|
|
8
|
+
## Quick Setup
|
|
9
|
+
|
|
10
|
+
Install the module to your Nuxt application with one command:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npx nuxi module add @scalar/nuxt
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
That's it! You can now use @scalar/nuxt in your Nuxt app ✨
|
|
17
|
+
|
|
18
|
+
## Configuration
|
|
19
|
+
|
|
20
|
+
If you are using nuxt server routes you can enable scalar simply by enabling openAPI in the nitro
|
|
21
|
+
config in your nuxt.config.ts
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
export default defineNuxtConfig({
|
|
25
|
+
modules: ['@scalar/nuxt'],
|
|
26
|
+
nitro: {
|
|
27
|
+
experimental: {
|
|
28
|
+
openAPI: true,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
If you would like to add your own OpenAPI spec file you can do so with the following minimal config
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
export default defineNuxtConfig({
|
|
38
|
+
modules: ['@scalar/nuxt'],
|
|
39
|
+
scalarConfig: {
|
|
40
|
+
spec: {
|
|
41
|
+
url: 'https://cdn.scalar.com/spec/openapi_petstore.json',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
By default the docs will be hosted at `/scalar` but you an easily customize that, here's a more in
|
|
48
|
+
depth config example.
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
export default defineNuxtConfig({
|
|
52
|
+
modules: ['@scalar/nuxt'],
|
|
53
|
+
scalarConfig: {
|
|
54
|
+
darkMode: true,
|
|
55
|
+
hideModals: false,
|
|
56
|
+
hideDownloadButton: false,
|
|
57
|
+
metaData: {
|
|
58
|
+
title: 'API Documentation by Scalar',
|
|
59
|
+
},
|
|
60
|
+
proxy: 'https://api.scalar.com/request-proxy',
|
|
61
|
+
searchHotKey: 'k',
|
|
62
|
+
showSidebar: true,
|
|
63
|
+
pathRouting: {
|
|
64
|
+
basePath: '/scalar',
|
|
65
|
+
},
|
|
66
|
+
spec: {
|
|
67
|
+
url: 'https://cdn.scalar.com/spec/openapi_petstore.json',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
```
|
package/dist/module.cjs
ADDED
|
@@ -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
ADDED
|
@@ -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.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { defineNuxtModule, createResolver, addComponent, extendPages, addPlugin } from '@nuxt/kit';
|
|
2
|
+
|
|
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: "/scalar"
|
|
16
|
+
},
|
|
17
|
+
showSidebar: true
|
|
18
|
+
},
|
|
19
|
+
setup(_options, _nuxt) {
|
|
20
|
+
const resolver = createResolver(import.meta.url);
|
|
21
|
+
let isOpenApiEnabled = false;
|
|
22
|
+
_nuxt.hook("nitro:config", (config) => {
|
|
23
|
+
if (config.experimental?.openAPI)
|
|
24
|
+
isOpenApiEnabled = true;
|
|
25
|
+
});
|
|
26
|
+
addComponent({
|
|
27
|
+
name: "ScalarApiReference",
|
|
28
|
+
export: "default",
|
|
29
|
+
filePath: resolver.resolve("./runtime/components/ScalarApiReference.vue")
|
|
30
|
+
});
|
|
31
|
+
extendPages((pages) => {
|
|
32
|
+
pages.push({
|
|
33
|
+
name: "scalar",
|
|
34
|
+
path: _options.pathRouting?.basePath + ":pathMatch(.*)*",
|
|
35
|
+
meta: {
|
|
36
|
+
configuration: _options,
|
|
37
|
+
isOpenApiEnabled
|
|
38
|
+
},
|
|
39
|
+
file: resolver.resolve("./runtime/pages/ScalarPage.vue")
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
addPlugin(resolver.resolve("./runtime/plugins/hydrateClient"));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export { module as default };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { ModernLayout, parse } from '@scalar/api-reference'
|
|
3
|
+
import '@scalar/api-reference/index.css'
|
|
4
|
+
import { reactive, ref, toRaw } from 'vue'
|
|
5
|
+
import type { Configuration } from '~/src/types'
|
|
6
|
+
|
|
7
|
+
import './nuxt-theme.css'
|
|
8
|
+
|
|
9
|
+
const props = defineProps<{
|
|
10
|
+
configuration: Configuration
|
|
11
|
+
}>()
|
|
12
|
+
|
|
13
|
+
const isDark = ref(props.configuration.darkMode)
|
|
14
|
+
|
|
15
|
+
// Grab spec if we can
|
|
16
|
+
const content: unknown = props.configuration.spec?.content
|
|
17
|
+
? toRaw(props.configuration.spec.content)
|
|
18
|
+
: props.configuration.spec?.url
|
|
19
|
+
? await $fetch(props.configuration.spec?.url)
|
|
20
|
+
: await $fetch('/_nitro/openapi.json')
|
|
21
|
+
|
|
22
|
+
// Check for empty spec
|
|
23
|
+
if (!content)
|
|
24
|
+
throw new Error('You must provide a spec for Scalar API References')
|
|
25
|
+
|
|
26
|
+
const parsedSpec = reactive(await parse(content))
|
|
27
|
+
const rawSpec = JSON.stringify(content)
|
|
28
|
+
|
|
29
|
+
// Load up the metadata
|
|
30
|
+
if (props.configuration?.metaData) useSeoMeta(props.configuration.metaData)
|
|
31
|
+
|
|
32
|
+
useHead({
|
|
33
|
+
bodyAttrs: {
|
|
34
|
+
class: () => (isDark.value ? 'dark-mode' : 'light-mode'),
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
// Add baseServerURL
|
|
39
|
+
const { origin } = useRequestURL()
|
|
40
|
+
const config = {
|
|
41
|
+
baseServerURL: origin,
|
|
42
|
+
...props.configuration,
|
|
43
|
+
}
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<template>
|
|
47
|
+
<ModernLayout
|
|
48
|
+
:configuration="config"
|
|
49
|
+
:isDark="isDark"
|
|
50
|
+
:parsedSpec="parsedSpec"
|
|
51
|
+
:rawSpec="rawSpec"
|
|
52
|
+
@toggleDarkMode="isDark = !isDark" />
|
|
53
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.light-mode{--theme-background-1:#fff;--theme-background-2:#f8fafc;--theme-background-3:#e7e7e7;--theme-background-accent:#8ab4f81f;--theme-color-1:#000;--theme-color-2:#6b7280;--theme-color-3:#9ca3af;--theme-color-accent:#00c16a;--theme-border-color:#e5e7eb;--theme-color-green:#069061;--theme-color-red:#ef4444;--theme-color-yellow:#f59e0b;--theme-color-blue:#1d4ed8;--theme-color-orange:#fb892c;--theme-color-purple:#6d28d9;--theme-button-1:#000;--theme-button-1-hover:rgba(0,0,0,.9);--theme-button-1-color:#fff}.dark-mode{--theme-background-1:#020420;--theme-background-2:#121a31;--theme-background-3:#1e293b;--theme-background-accent:#8ab4f81f;--theme-color-1:#fff;--theme-color-2:#cbd5e1;--theme-color-3:#94a3b8;--theme-color-accent:#00dc82;--theme-border-color:#1e293b;--theme-color-green:#069061;--theme-color-red:#f87171;--theme-color-yellow:#fde68a;--theme-color-blue:#60a5fa;--theme-color-orange:#fb892c;--theme-color-purple:#ddd6fe;--theme-button-1:hsla(0,0%,100%,.9);--theme-button-1-hover:hsla(0,0%,100%,.8);--theme-button-1-color:#000}.dark-mode .t-doc__sidebar,.light-mode .t-doc__sidebar{--sidebar-background-1:var(--theme-background-1);--sidebar-color-1:var(--theme-color-1);--sidebar-color-2:var(--theme-color-3);--sidebar-border-color:var(--theme-border-color);--sidebar-item-hover-background:transparent;--sidebar-item-hover-color:var(--theme-color-1);--sidebar-item-active-background:transparent;--sidebar-color-active:var(--theme-color-accent);--sidebar-search-background:transparent;--sidebar-search-color:var(--theme-color-3);--sidebar-search-border-color:var(--theme-border-color);--sidebar-indent-border:var(--theme-border-color);--sidebar-indent-border-hover:var(--theme-color-1);--sidebar-indent-border-active:var(--theme-color-accent)}.scalar-card .request-card-footer{--theme-background-3:var(--theme-background-2);--theme-button-1:#0f172a;--theme-button-1-hover:rgba(30,41,59,.5);--theme-button-1-color:#fff}.scalar-card .show-api-client-button{border:1px solid #334155!important}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import type { Meta } from '~/src/types'
|
|
3
|
+
|
|
4
|
+
const route = useRoute()
|
|
5
|
+
const meta = route.meta as Meta
|
|
6
|
+
|
|
7
|
+
// Ensure we have a spec
|
|
8
|
+
if (
|
|
9
|
+
!meta.isOpenApiEnabled &&
|
|
10
|
+
!meta.configuration?.spec?.url &&
|
|
11
|
+
!meta.configuration?.spec?.content
|
|
12
|
+
)
|
|
13
|
+
throw new Error(
|
|
14
|
+
'You must either provide a spec to scalarConfig, or enable experimental openApi in the Nitro config.',
|
|
15
|
+
)
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<template>
|
|
19
|
+
<ScalarApiReference :configuration="meta.configuration" />
|
|
20
|
+
</template>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineNuxtPlugin } from "#app";
|
|
2
|
+
export default defineNuxtPlugin((_nuxtApp) => {
|
|
3
|
+
_nuxtApp.hook("app:rendered", ({ ssrContext }) => {
|
|
4
|
+
useHead({
|
|
5
|
+
script: [
|
|
6
|
+
{
|
|
7
|
+
children: `window.__SCALAR__ = ${JSON.stringify(ssrContext?.payload?.data ?? {})}`
|
|
8
|
+
}
|
|
9
|
+
]
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
});
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
import type { ModuleOptions } from './module.js'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
declare module '@nuxt/schema' {
|
|
6
|
+
interface NuxtConfig { ['scalarConfig']?: Partial<ModuleOptions> }
|
|
7
|
+
interface NuxtOptions { ['scalarConfig']?: ModuleOptions }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare module 'nuxt/schema' {
|
|
11
|
+
interface NuxtConfig { ['scalarConfig']?: Partial<ModuleOptions> }
|
|
12
|
+
interface NuxtOptions { ['scalarConfig']?: ModuleOptions }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export type { ModuleOptions, default } from './module.js'
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
import type { ModuleOptions } from './module'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
declare module '@nuxt/schema' {
|
|
6
|
+
interface NuxtConfig { ['scalarConfig']?: Partial<ModuleOptions> }
|
|
7
|
+
interface NuxtOptions { ['scalarConfig']?: ModuleOptions }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare module 'nuxt/schema' {
|
|
11
|
+
interface NuxtConfig { ['scalarConfig']?: Partial<ModuleOptions> }
|
|
12
|
+
interface NuxtOptions { ['scalarConfig']?: ModuleOptions }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export type { ModuleOptions, default } from './module'
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@scalar/nuxt",
|
|
3
|
+
"description": "Nuxt integration for Scalar API references",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Scalar (https://github.com/scalar)",
|
|
6
|
+
"homepage": "https://github.com/scalar/scalar",
|
|
7
|
+
"bugs": "https://github.com/scalar/scalar/issues/new/choose",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"api",
|
|
10
|
+
"references",
|
|
11
|
+
"nuxt",
|
|
12
|
+
"docs",
|
|
13
|
+
"postman alternative",
|
|
14
|
+
"rest",
|
|
15
|
+
"testing",
|
|
16
|
+
"vue"
|
|
17
|
+
],
|
|
18
|
+
"version": "0.0.1",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18"
|
|
21
|
+
},
|
|
22
|
+
"main": "./dist/module.cjs",
|
|
23
|
+
"types": "./dist/types.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/types.d.ts",
|
|
27
|
+
"import": "./dist/module.mjs",
|
|
28
|
+
"require": "./dist/module.cjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@nuxt/kit": "^3.11.2",
|
|
36
|
+
"@scalar/api-reference": "1.20.30"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@nuxt/devtools": "^1.1.5",
|
|
40
|
+
"@nuxt/eslint-config": "^0.3.4",
|
|
41
|
+
"@nuxt/module-builder": "^0.5.5",
|
|
42
|
+
"@nuxt/schema": "^3.11.2",
|
|
43
|
+
"@nuxt/test-utils": "^3.12.0",
|
|
44
|
+
"@types/node": "^20.8.4",
|
|
45
|
+
"changelogen": "^0.5.5",
|
|
46
|
+
"eslint": "^8.56.0",
|
|
47
|
+
"nuxt": "^3.11.2",
|
|
48
|
+
"vitest": "^1.2.2"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "nuxt-module-build build",
|
|
52
|
+
"dev": "nuxi dev playground",
|
|
53
|
+
"dev:build": "nuxi build playground",
|
|
54
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
55
|
+
"lint:check": "eslint .",
|
|
56
|
+
"lint:fix": "eslint . --fix",
|
|
57
|
+
"postinstall": "pnpm dev:prepare",
|
|
58
|
+
"toist": "vitest run",
|
|
59
|
+
"test:watch": "vitest watch",
|
|
60
|
+
"types:check": "nuxi typecheck"
|
|
61
|
+
}
|
|
62
|
+
}
|