HiDeoo / starlight-openapi

Starlight plugin to generate documentation from OpenAPI/Swagger specifications
https://starlight-openapi.vercel.app
MIT License
112 stars 14 forks source link

Circular route matching pattern causing infinite loop #22

Closed fl0wo closed 8 months ago

fl0wo commented 8 months ago

Is your feature request related to a problem?

When deploying using SST I get an Trace: RangeError: Maximum call stack size exceeded

This is due the fact that the OpenAPI plugin is injecting a very greedy route at the root of the site which conflicts with the root level matching route.

Ref: sst.buildMeta.json

    {
      "route": "/[...openapislug]",
      "type": "page",
      "pattern": "/^(?:\\/(.*?))?\\/?$/",
      "prerender": true
    },
    {
      "route": "/[...slug]",
      "type": "page",
      "pattern": "/^(?:\\/(.*?))?\\/?$/",
      "prerender": true
    }

More details at this Issue: https://github.com/sst/sst/issues/3707

Describe the solution you'd like

Have a customizable "pattern" field in the Astro Integration:

export function starlightOpenAPIIntegration(schemas: Schema[]): AstroIntegration {
  const starlightOpenAPI: AstroIntegration = {
    name: 'starlight-openapi',
    hooks: {
      'astro:config:setup': ({ injectRoute, updateConfig }) => {
        injectRoute({
          entrypoint: 'starlight-openapi/route',
    pattern: `[...openAPISlug]`,                     // <- i would like to place this in a sub-folder /abc/[...openAPISlug]
          prerender: true,
        })

        updateConfig({
          vite: {
            plugins: [vitePluginStarlightOpenAPISchemas(schemas)],
          },
        })
      },
    },
  }

Describe alternatives you've considered

No response

Additional Context

https://discord.com/channels/983865673656705025/1068236979659092038/1217354520086974515

HiDeoo commented 8 months ago

Thanks for the report, very interesting. Is this something that is fixed by this PR as it's tagged as closing your issue or is it still an issue?