HiDeoo / starlight-openapi

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

Disable Pre-render #51

Open brunoalano opened 3 weeks ago

brunoalano commented 3 weeks ago

Describe the bug

There is some way to disable the pre-render when using this plugin? I am using an authentication middleware on my documentation, and would like to block some requests.

To Reproduce

Using an authentication middleware won't work because of the following snippet:

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]`,
          prerender: true,
        })

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

  return starlightOpenAPI
}

Expected behavior

An option to disable the pre-render

How often does this bug happen?

Every time

System Info

No response

Additional Context

No response

HiDeoo commented 3 weeks ago

Thanks for the feedback :raised_hands:

This is not something currently supported. This brings up some interesting questions as how this would work as I assume we would not want to parse the schemas for every requests. Some parser utilities are also still used during the rendering process (e.g. to resolve references) and we may not want to bundle them in the final build.

Considering how heavy some schemas can be and how it can increase the build time, if the goal is just to protect the schema pages behind an authentication wall, I also wonder if some other approach could be used, e.g. edge middlewares or something else, so that these pages which don't change very often can still be pre-rendered.

There are definitely more research and investigation to be done here, not something I'll have the bandwidth to do in the near future, but I'll be happy to discuss more if someone wants to take a stab at it.