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:
cclojurecsharpgohttpjavajavascriptjsonkotlinnodecplusplusobjectivecocamlphppowershellpythonrrubyshellswift
The results look like this.
spec_file- The OAS file to add code samples toout_file- Where to store the augmented OAS JSONlanguages- Comma-separated list of languages for which to generate code samples. Defaults to "go, python, shell, java, kotlin, swift"
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- 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.


