Git Product home page Git Product logo

openapi-github-pages-action's Introduction

openapi-github-pages-action

GitHub Action to generate and deploy API documentation to GitHub Pages, using OpenAPI specification files as input.

By default, API docs are generated at username.github.io/repository-name/provided-api-doc-filepath.

If you've set up a GitHub Pages custom domain for your account, that will be used instead of username.github.io.

See example API docs generated by this GitHub Action:

Prerequisites

  1. GitHub Pages requires that source repositories either be public or in supported paid accounts.
  2. The repository must have GitHub Pages enabled with GitHub Actions, by going to "Settings" > "Pages" > "Build and deployment", and under "Source", selecting "GitHub Actions".
  3. The repository must provide a pre-built OpenAPI JSON spec file.

Usage

See action.yml

Add the following permissions to your GitHub workflow, prior to the lines defining workflow jobs.

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

Add the following steps to your GitHub workflow, replacing the input values:

- name: Generate API docs and deploy to GitHub Pages
  uses: msayson/[email protected]
  with:
    # JSON string configs for each OpenAPI spec to document
    # - branch: (Optional) Git branch to fetch spec file from, eg. origin/main
    #           If not provided, assumes file is available from current branch
    # - generate-api-spec-command: (Optional) Command to run to generate spec file
    # - openapi-json-filepath: Filepath of OpenAPI JSON spec
    # - api-doc-filepath: Filepath for generated API doc, within the common directory defined by api-docs-dir
    api-configs: |-
      [
        {
          "branch": "YOUR_BRANCH",
          "openapi-json-filepath": "YOUR_OPENAPI_SPEC_FILEPATH",
          "api-doc-filepath": "YOUR_API_DOC_FILEPATH"
        }
      ]
    # Parent directory to use for generated API docs HTML
    api-docs-dir: 'YOUR_API_DOCS_FILEPATH'

Scenarios

Generate API docs for main branch

name: Generate API docs and deploy to GitHub Pages

on:
  # Automatically trigger when push to main branch
  push:
    branches: ["main"]
  # Enable running workflow manually from GitHub Actions
  workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

jobs:
  generate-api-docs:
    name: Generate API Documentation
    runs-on: ubuntu-latest
    steps:
      - name: Generate API docs and deploy to GitHub Pages
        uses: msayson/[email protected]
        with:
          api-configs: |-
            [
              {
                "openapi-json-filepath": "openapi/ConsentManagementApi.openapi.json",
                "api-doc-filepath": "latest/docs.html"
              }
            ]
          api-docs-dir: docs

Generate API docs for multiple releases

name: Generate API docs and deploy to GitHub Pages

on:
  # Automatically trigger when push to any branch
  push:
  # Enable running workflow manually from GitHub Actions
  workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

jobs:
  generate-api-docs:
    name: Generate API Documentation
    runs-on: ubuntu-latest
    steps:
      - name: Generate API docs and deploy to GitHub Pages
        uses: msayson/[email protected]
        with:
          api-configs: |-
            [
              {
                "branch": "main",
                "openapi-json-filepath": "openapi/ConsentManagementApi.openapi.json",
                "api-doc-filepath": "latest/docs.html"
              },
              {
                "branch": "v1",
                "openapi-json-filepath": "openapi/ConsentManagementApi.openapi.json",
                "api-doc-filepath": "v1/docs.html"
              },
              {
                "branch": "v2",
                "openapi-json-filepath": "openapi/ConsentManagementApi.openapi.json",
                "api-doc-filepath": "v2/docs.html"
              }
            ]
          api-docs-dir: docs

Technologies

jq is a lightweight and flexible command-line JSON processor.

yq is used to convert JSON to YAML, since YAML is the required format for ReDoc, while many tools such as Smithy generate OpenAPI specs with the JSON format.

ReDoc is used to automatically generate API documentation from the OpenAPI YAML specification.

GitHub Actions are used to automatically generate and deploy HTML API documentation to GitHub Pages.

GitHub CLI is used to retrieve OpenAPI spec files from other Git branches.

openapi-github-pages-action's People

Contributors

msayson avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.