diff --git a/docs/package.json b/docs/package.json index 3e8f0fc..6f976db 100644 --- a/docs/package.json +++ b/docs/package.json @@ -17,7 +17,6 @@ "@astrojs/starlight": "0.19.0", "astro": "4.2.7", "sharp": "0.33.2", - "shiki": "0.14.4", "starlight-openapi": "workspace:*", "starlight-package-managers": "0.1.0" }, diff --git a/docs/src/content/docs/guides/getting-started.mdx b/docs/src/content/docs/guides/getting-started.mdx index 56f3e01..87de423 100644 --- a/docs/src/content/docs/guides/getting-started.mdx +++ b/docs/src/content/docs/guides/getting-started.mdx @@ -20,12 +20,6 @@ Install the Starlight OpenAPI integration using your favorite package manager: -:::note -When using a [strict package manager](https://pnpm.io/pnpm-vs-npm#npms-flat-tree) like pnpm, you will also need to install the [Shiki](https://shiki.matsu.io/) syntax highlighter so it can be found during builds: - - -::: - Update your [Astro configuration](https://docs.astro.build/en/guides/configuring-astro/#supported-config-file-types) to generate documentation from your OpenAPI/Swagger specification: ```ts diff --git a/packages/starlight-openapi/components/example/Example.astro b/packages/starlight-openapi/components/example/Example.astro index 5b7dd51..806b194 100644 --- a/packages/starlight-openapi/components/example/Example.astro +++ b/packages/starlight-openapi/components/example/Example.astro @@ -1,4 +1,6 @@ --- +import { Code } from '@astrojs/starlight/components' + import type { ExampleV3 } from '../../libs/example' import Md from '../Md.astro' import Text from '../Text.astro' @@ -6,13 +8,14 @@ import Text from '../Text.astro' interface Props { example?: ExampleV3 raw?: ExampleV3['value'] + type?: string } -const { example, raw } = Astro.props +const { example, raw, type } = Astro.props const exampleToRender = raw === undefined ? example : { value: raw } -function getExampleValue(value: unknown): string { +function getExampleValue(value: unknown): string { switch (typeof value) { case 'string': { return value @@ -26,6 +29,17 @@ function getExampleValue(value: unknown): string { } } } + +function getExampleLang(type: string | undefined) { + switch (type) { + case 'application/json': { + return 'json' + } + default: { + return 'plaintext' + } + } +} --- { @@ -38,12 +52,7 @@ function getExampleValue(value: unknown): string { {exampleToRender.externalValue} )} - - {exampleToRender.value && - // eslint-disable-next-line astro/jsx-a11y/no-noninteractive-tabindex - (
{getExampleValue(exampleToRender.value)}
) - } - + {exampleToRender.value && } ) } diff --git a/packages/starlight-openapi/components/example/Examples.astro b/packages/starlight-openapi/components/example/Examples.astro index 41bb1dc..a0b70ba 100644 --- a/packages/starlight-openapi/components/example/Examples.astro +++ b/packages/starlight-openapi/components/example/Examples.astro @@ -20,7 +20,7 @@ const { example, examples } = Astro.props {Object.entries(examples).map(([type, data], index) => ( ))} diff --git a/packages/starlight-openapi/components/response/ResponseExamples.astro b/packages/starlight-openapi/components/response/ResponseExamples.astro index 7fa51b0..0a77912 100644 --- a/packages/starlight-openapi/components/response/ResponseExamples.astro +++ b/packages/starlight-openapi/components/response/ResponseExamples.astro @@ -17,7 +17,7 @@ const examples = Object.entries(Astro.props.examples) {examples.map(([type, data], index) => ( ))} diff --git a/packages/starlight-openapi/tests/requestBody.test.ts b/packages/starlight-openapi/tests/requestBody.test.ts index 4329f1a..0174c4b 100644 --- a/packages/starlight-openapi/tests/requestBody.test.ts +++ b/packages/starlight-openapi/tests/requestBody.test.ts @@ -80,11 +80,7 @@ test('supports schema object `oneOf` property', async ({ docPage }) => { await requestBody.getByRole('tab', { name: 'object' }).click() - await expect( - requestBody.getByText(`{ - "name": "Harley" -}`), - ).toBeVisible() + await expect(requestBody.getByText(`{ "name": "Harley"}`)).toBeVisible() }) test('supports schema object `anyOf` property', async ({ docPage }) => { diff --git a/packages/starlight-openapi/tests/response.test.ts b/packages/starlight-openapi/tests/response.test.ts index 2bac10a..84daa88 100644 --- a/packages/starlight-openapi/tests/response.test.ts +++ b/packages/starlight-openapi/tests/response.test.ts @@ -50,33 +50,11 @@ test('display the examples for a v2.0 schema', async ({ docPage }) => { await examples.getByRole('combobox').selectOption('application/json') - await expect( - examples.getByText(`[ - { - "id": 1, - "name": "Bessy" - }, - { - "id": 2, - "name": "Hazel" - } -]`), - ).toBeVisible() + await expect(examples.getByText(`[ { "id": 1, "name": "Bessy" }, { "id": 2, "name": "Hazel" }]`)).toBeVisible() await examples.getByRole('combobox').selectOption('application/xml') - await expect( - examples.getByText(`[ - { - "id": 3, - "name": "Cleo" - }, - { - "id": 4, - "name": "Daisy" - } -]`), - ).toBeVisible() + await expect(examples.getByText(`[ { "id": 3, "name": "Cleo" }, { "id": 4, "name": "Daisy" }]`)).toBeVisible() }) test('displays nested objects collapsed by default', async ({ docPage }) => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 99ceb98..a58fdf4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -46,13 +46,10 @@ importers: version: 0.19.0(astro@4.2.7) astro: specifier: 4.2.7 - version: 4.2.7(@types/node@18.17.3)(typescript@5.1.6) + version: 4.2.7 sharp: specifier: 0.33.2 version: 0.33.2 - shiki: - specifier: 0.14.4 - version: 0.14.4 starlight-openapi: specifier: workspace:* version: link:../packages/starlight-openapi @@ -150,7 +147,7 @@ packages: '@astrojs/markdown-remark': 4.2.1 '@mdx-js/mdx': 3.0.1 acorn: 8.11.3 - astro: 4.2.7(@types/node@18.17.3)(typescript@5.1.6) + astro: 4.2.7 es-module-lexer: 1.4.1 estree-util-visit: 2.0.0 github-slugger: 2.0.0 @@ -188,7 +185,7 @@ packages: '@pagefind/default-ui': 1.0.3 '@types/hast': 3.0.3 '@types/mdast': 4.0.3 - astro: 4.2.7(@types/node@18.17.3)(typescript@5.1.6) + astro: 4.2.7 astro-expressive-code: 0.32.4(astro@4.2.7) bcp-47: 2.1.0 hast-util-select: 6.0.2 @@ -1537,10 +1534,6 @@ packages: resolution: {integrity: sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==} engines: {node: '>=12'} - /ansi-sequence-parser@1.1.1: - resolution: {integrity: sha512-vJXt3yiaUL4UU546s3rPXlsry/RnM730G1+HkpKE012AN0sx1eOrxSu95oKDIonskeLTijMgqWZ3uDEe3NFvyg==} - dev: false - /ansi-styles@3.2.1: resolution: {integrity: sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==} engines: {node: '>=4'} @@ -1681,10 +1674,92 @@ packages: peerDependencies: astro: ^3.3.0 || ^4.0.0-beta dependencies: - astro: 4.2.7(@types/node@18.17.3)(typescript@5.1.6) + astro: 4.2.7 hast-util-to-html: 8.0.4 remark-expressive-code: 0.32.4 + /astro@4.2.7: + resolution: {integrity: sha512-m2zGL6JVwcxAV9IwwAXMHAchd8sJukW/hmskYSkIO5D4gVE9oh1SG7HA71BBxl1lJfI1j+RPAgjXQsSuGjLUjA==} + engines: {node: '>=18.14.1', npm: '>=6.14.0'} + hasBin: true + dependencies: + '@astrojs/compiler': 2.5.3 + '@astrojs/internal-helpers': 0.2.1 + '@astrojs/markdown-remark': 4.2.1 + '@astrojs/telemetry': 3.0.4 + '@babel/core': 7.23.9 + '@babel/generator': 7.23.6 + '@babel/parser': 7.23.9 + '@babel/plugin-transform-react-jsx': 7.22.5(@babel/core@7.23.9) + '@babel/traverse': 7.23.9 + '@babel/types': 7.23.9 + '@types/babel__core': 7.20.5 + acorn: 8.11.3 + aria-query: 5.3.0 + axobject-query: 4.0.0 + boxen: 7.1.1 + chokidar: 3.5.3 + ci-info: 4.0.0 + clsx: 2.0.0 + common-ancestor-path: 1.0.1 + cookie: 0.6.0 + cssesc: 3.0.0 + debug: 4.3.4 + deterministic-object-hash: 2.0.2 + devalue: 4.3.2 + diff: 5.1.0 + dlv: 1.1.3 + dset: 3.1.3 + es-module-lexer: 1.4.1 + esbuild: 0.19.12 + estree-walker: 3.0.3 + execa: 8.0.1 + fast-glob: 3.3.2 + flattie: 1.1.0 + github-slugger: 2.0.0 + gray-matter: 4.0.3 + html-escaper: 3.0.3 + http-cache-semantics: 4.1.1 + js-yaml: 4.1.0 + kleur: 4.1.5 + magic-string: 0.30.3 + mdast-util-to-hast: 13.0.2 + mime: 3.0.0 + ora: 7.0.1 + p-limit: 5.0.0 + p-queue: 8.0.1 + path-to-regexp: 6.2.1 + preferred-pm: 3.1.2 + probe-image-size: 7.2.3 + prompts: 2.4.2 + rehype: 13.0.1 + resolve: 1.22.6 + semver: 7.5.4 + server-destroy: 1.0.1 + shikiji: 0.9.19 + string-width: 7.1.0 + strip-ansi: 7.1.0 + tsconfck: 3.0.2 + unist-util-visit: 5.0.0 + vfile: 6.0.1 + vite: 5.1.3 + vitefu: 0.2.5(vite@5.1.3) + which-pm: 2.1.1 + yargs-parser: 21.1.1 + zod: 3.22.4 + optionalDependencies: + sharp: 0.32.6 + transitivePeerDependencies: + - '@types/node' + - less + - lightningcss + - sass + - stylus + - sugarss + - supports-color + - terser + - typescript + /astro@4.2.7(@types/node@18.17.3)(typescript@5.1.6): resolution: {integrity: sha512-m2zGL6JVwcxAV9IwwAXMHAchd8sJukW/hmskYSkIO5D4gVE9oh1SG7HA71BBxl1lJfI1j+RPAgjXQsSuGjLUjA==} engines: {node: '>=18.14.1', npm: '>=6.14.0'} @@ -1766,6 +1841,7 @@ packages: - supports-color - terser - typescript + dev: true /astrojs-compiler-sync@0.3.5(@astrojs/compiler@2.5.3): resolution: {integrity: sha512-y420rhIIJ2HHDkYeqKArBHSdJNIIGMztLH90KGIX3zjcJyt/cr9Z2wYA8CP5J1w6KE7xqMh0DAkhfjhNDpQb2Q==} @@ -3803,6 +3879,7 @@ packages: /jsonc-parser@3.2.0: resolution: {integrity: sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==} + dev: true /jsonpointer@5.0.1: resolution: {integrity: sha512-p/nXbhSEcu3pZRdkW1OfJhpsVtW1gd4Wa1fnQc9YLiTfAjn0312eMKimbdIQzuZl9aa9xUGaRlP9T/CJE/ditQ==} @@ -5542,15 +5619,6 @@ packages: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} - /shiki@0.14.4: - resolution: {integrity: sha512-IXCRip2IQzKwxArNNq1S+On4KPML3Yyn8Zzs/xRgcgOWIr8ntIK3IKzjFPfjy/7kt9ZMjc+FItfqHRBg8b6tNQ==} - dependencies: - ansi-sequence-parser: 1.1.1 - jsonc-parser: 3.2.0 - vscode-oniguruma: 1.7.0 - vscode-textmate: 8.0.0 - dev: false - /shikiji-core@0.9.19: resolution: {integrity: sha512-AFJu/vcNT21t0e6YrfadZ+9q86gvPum6iywRyt1OtIPjPFe25RQnYJyxHQPMLKCCWA992TPxmEmbNcOZCAJclw==} @@ -5671,7 +5739,7 @@ packages: astro: '>=2.5.0' dependencies: '@astrojs/starlight': 0.19.0(astro@4.2.7) - astro: 4.2.7(@types/node@18.17.3)(typescript@5.1.6) + astro: 4.2.7 dev: false /stdin-discarder@0.1.0: @@ -5933,6 +6001,16 @@ packages: typescript: 5.1.6 dev: true + /tsconfck@3.0.2: + resolution: {integrity: sha512-6lWtFjwuhS3XI4HsX4Zg0izOI3FU/AI9EGVlPEUMDIhvLPMD4wkiof0WCoDgW7qY+Dy198g4d9miAqUHWHFH6Q==} + engines: {node: ^18 || >=20} + hasBin: true + peerDependencies: + typescript: ^5.0.0 + peerDependenciesMeta: + typescript: + optional: true + /tsconfck@3.0.2(typescript@5.1.6): resolution: {integrity: sha512-6lWtFjwuhS3XI4HsX4Zg0izOI3FU/AI9EGVlPEUMDIhvLPMD4wkiof0WCoDgW7qY+Dy198g4d9miAqUHWHFH6Q==} engines: {node: ^18 || >=20} @@ -5944,9 +6022,11 @@ packages: optional: true dependencies: typescript: 5.1.6 + dev: true /tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} + requiresBuild: true /tunnel-agent@0.6.0: resolution: {integrity: sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==} @@ -6046,6 +6126,7 @@ packages: resolution: {integrity: sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==} engines: {node: '>=14.17'} hasBin: true + dev: true /ufo@1.4.0: resolution: {integrity: sha512-Hhy+BhRBleFjpJ2vchUNN40qgkh0366FWJGqVLYBHev0vpHTrXSA0ryT+74UiW6KWsldNurQMKGqCm1M2zBciQ==} @@ -6239,6 +6320,40 @@ packages: unist-util-stringify-position: 4.0.0 vfile-message: 4.0.2 + /vite@5.1.3: + resolution: {integrity: sha512-UfmUD36DKkqhi/F75RrxvPpry+9+tTkrXfMNZD+SboZqBCMsxKtO52XeGzzuh7ioz+Eo/SYDBbdb0Z7vgcDJew==} + engines: {node: ^18.0.0 || >=20.0.0} + hasBin: true + peerDependencies: + '@types/node': ^18.0.0 || >=20.0.0 + less: '*' + lightningcss: ^1.21.0 + sass: '*' + stylus: '*' + sugarss: '*' + terser: ^5.4.0 + peerDependenciesMeta: + '@types/node': + optional: true + less: + optional: true + lightningcss: + optional: true + sass: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + dependencies: + esbuild: 0.19.12 + postcss: 8.4.35 + rollup: 4.12.0 + optionalDependencies: + fsevents: 2.3.3 + /vite@5.1.3(@types/node@18.17.3): resolution: {integrity: sha512-UfmUD36DKkqhi/F75RrxvPpry+9+tTkrXfMNZD+SboZqBCMsxKtO52XeGzzuh7ioz+Eo/SYDBbdb0Z7vgcDJew==} engines: {node: ^18.0.0 || >=20.0.0} @@ -6273,6 +6388,7 @@ packages: rollup: 4.12.0 optionalDependencies: fsevents: 2.3.3 + dev: true /vitefu@0.2.5(vite@5.1.3): resolution: {integrity: sha512-SgHtMLoqaeeGnd2evZ849ZbACbnwQCIwRH57t18FxcXoZop0uQu0uzlIhJBlF/eWVzuce0sHeqPcDo+evVcg8Q==} @@ -6282,15 +6398,7 @@ packages: vite: optional: true dependencies: - vite: 5.1.3(@types/node@18.17.3) - - /vscode-oniguruma@1.7.0: - resolution: {integrity: sha512-L9WMGRfrjOhgHSdOYgCt/yRMsXzLDJSL7BPrOZt73gU0iWO4mpqzqQzOz5srxqTvMBaR0XZTSrVWo4j55Rc6cA==} - dev: false - - /vscode-textmate@8.0.0: - resolution: {integrity: sha512-AFbieoL7a5LMqcnOF04ji+rpXadgOXnZsxQr//r83kLPr7biP7am3g9zbaZIaBGwBRWeSvoMD4mgPdX3e4NWBg==} - dev: false + vite: 5.1.3 /web-namespaces@2.0.1: resolution: {integrity: sha512-bKr1DkiNa2krS7qxNtdrtHAmzuYGFQLiQ13TsorsdT6ULTkPLKuu5+GsFpDlg6JFjUTwX2DyhMPG2be8uPrqsQ==}