danielgtaylor / danielgtaylor/huma

Inline the OpenAPI spec into the docs HTML page

Open
#1,112 4 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
4.4k
Forks
285
Avg merge
40m
Merged PRs (30d)
1

Description

Hello I have a feature proposal for the project 👋

Today registerDocsRoute emits a docs HTML page that points the renderer at a URL:
* data-url="/openapi.json" (Scalar)
* apiDescriptionUrl="/openapi.yaml" (Stoplight Elements)
* SwaggerUIBundle({url}) (SwaggerUI).

This means that the browser then makes a second round-trip to fetch the spec at runtime. This was proven to be an issue for me when the browser cannot reach the /openapi.json. In my case it is because of my API gateway rewriting path but it could be for various reasons.

From what I saw in the code, the spec is already fully in memory in the Go process so I was wondering if we could directly pass it when we render the page.

Looking at the code I think the 3 implementation support direct passing of the content (with the drawback of the HTML page being larger).
We could add a configuration flag (something like `DocsInlineSpec bool`) to do this when set to `true` (and thus still allow user to refer to external url / do a browser fetch).

WDYT ?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading registerDocsRoute and the three renderer integrations described in the issue: Scalar, Stoplight Elements, and SwaggerUI. Compare how each accepts an in-memory specification, then define the configuration behavior so the existing URL mode remains available and the inline mode embeds the spec; done means all three renderers support the selected mode.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, openapi
Domain
api, documentation
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.