Skip to content

GitHub Action to create x-code-sample snippets for a given OpenAPI specification

License

Notifications You must be signed in to change notification settings

grid-x/api-spec-snippets-generator-action

Repository files navigation

Generate Code Snippets from an OpenAPI specification

This GitHub Action takes an OpenAPI spec, generates code samples for each operation and adds them to the spec using the x-code-samples extension.

If you specified examples in your endpoint, it takes the first example as the payload when generating snippets. If there is no example, the payload will be empty/null.

The following languages are supported:

  • c
  • clojure
  • csharp
  • go
  • http
  • java
  • javascript
  • json
  • kotlin
  • node
  • cplusplus
  • objectivec
  • ocaml
  • php
  • powershell
  • python
  • r
  • ruby
  • shell
  • swift

The results look like this.

readme.com readme.com

rapidoc RapiDoc

redoc Redoc

Prerequisites / Inputs

  • spec_file - The OAS file to add code samples to
  • out_file - Where to store the augmented OAS JSON
  • languages- Comma-separated list of languages for which to generate code samples. Defaults to "go, python, shell, java, kotlin, swift"

Instructions

Add a GitHub Action in your workflow, passing the input spec file (json or YAML), the desired output file location (json) and, optionally, the list of languages to generate snippets for.

- name: Generate Code Samples
  uses: grid-x/api-spec-snippets-generator-action@v6
  with:
    spec_file: ./petstore.yaml
    out_file: ./petstore-with-samples.json
    languages: go,python,shell,java,kotlin,swift,csharp

Development

  • You can run the action locally using npm run test:run, providing the configuration parameters through the environment. See test.ts.
  • See package.json for linting, testing and formatting scripts.

About

GitHub Action to create x-code-sample snippets for a given OpenAPI specification

Resources

License

Stars

Watchers

Forks

Packages

No packages published