trolie / spec

Transmission Ratings and Operating Limits Information Exchange
https://trolie.energy/
Other
3 stars 2 forks source link

OpenAPI spec and documentation transclusion #12

Closed catkins-miso closed 9 months ago

catkins-miso commented 9 months ago

We want to keep the prose used in the API specification and the external documentation DRY. We may eventually have need to include additional contributor information and/or server locations both for interactive testing and links to external documentation, while the source of truth for those values would be external.

Goals:

Some relevant constraints:

GH Pages can be built from a subfolder on a branch

The source branch can be any branch in your repository, and the source folder can either be the root of the repository (/) on the source branch or a /docs folder on the source branch. Whenever changes are pushed to the source branch, the changes in the source folder will be published to your GitHub Pages site.

GH Wiki doesn't support transclusion

Jekyll supports data files

This could be used, for example, to pull docs/_data/spec_description.yaml into the the gh-pages via standard Jekyll features, then using e.g. yq (.info.description)=$(yq .description docs/_data/spec_description.yaml) to include it in the openapi.yaml

There is a yq gh Action

This would be an effective way to ensure that every commit builds the OpenAPI spec as well as the gh-pages. One problem with using this is that we want to the same transclusion to happen locally. How might we reuse the yq commands?

The redoc visualization can be included via HTML tags and Jekyll supports raw HTML

VS Code supports .devcontainers and there is a run on save extensions

Proposal

caindy commented 9 months ago

Another option that I'm exploring is using redocly split and redocly bundle. The former would happen once as part of a check-in to decompose the openapi.yaml into smaller files. The latter would be used at build time to generate the single-file docs/openapi.yaml again.

I think the folder structure would be

docs/_data
    |___/components
    |   |_____/headers
    |   |_____/parameters
    |   |_____/responses
    |   |_____/schemas
    |___/paths
|___/openapi.yaml <-- build output, should be in .gitignore

This setup will likely require a custom workflow to generate the GH Pages