Skip to content

Commit feb7e9b

Browse files
authored
Merge pull request #8 from grid-x/feat/improve-docs
feat: Improve documentation
2 parents 29bfbe4 + 800849a commit feb7e9b

File tree

10 files changed

+66
-5
lines changed

10 files changed

+66
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ jobs:
3131
- name: Verify Output
3232
run: |
3333
stat ./petstore-with-samples.json
34-
cat ./petstore-with-samples.json | grep 'x-code-samples'
34+
grep 'x-code-samples' < petstore-with-samples.json
3535
shell: bash

.github/workflows/linter.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ jobs:
4747
VALIDATE_JAVASCRIPT_STANDARD: false
4848
VALIDATE_JSCPD: false
4949
VALIDATE_TYPESCRIPT_STANDARD: false
50+
VALIDATE_OPENAPI: false
51+
VALIDATE_CHECKOV: false
52+
VALIDATE_MARKDOWN: false
53+
VALIDATE_MARKDOWN_PRETTIER: false

README.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,44 @@
11
# Generate Code Snippets from an OpenAPI specification
22

3-
TODO: Synopsis
3+
This GitHub Action takes an OpenAPI spec, generates code samples for each
4+
operation and adds them to the spec using
5+
[the `x-code-samples` extension](https://redocly.com/docs/api-reference-docs/specification-extensions/x-code-samples).
6+
7+
If you
8+
[specified `examples` in your endpoint](https://swagger.io/docs/specification/adding-examples/),
9+
it takes the first example as the payload when generating snippets. If there is
10+
no example, the payload will be empty/`null`.
11+
12+
The following languages are supported:
13+
14+
- `c`
15+
- `clojure`
16+
- `csharp`
17+
- `go`
18+
- `http`
19+
- `java`
20+
- `javascript`
21+
- `json`
22+
- `kotlin`
23+
- `node`
24+
- `cplusplus`
25+
- `objectivec`
26+
- `ocaml`
27+
- `php`
28+
- `powershell`
29+
- `python`
30+
- `r`
31+
- `ruby`
32+
- `shell`
33+
- `swift`
34+
35+
The results look like this.
36+
37+
![readme.com](./docs/readme.png) _readme.com_
38+
39+
![rapidoc](./docs/rapidoc.png) _RapiDoc_
40+
41+
![redoc](./docs/redoc.png) _Redoc_
442

543
## Prerequisites / Inputs
644

@@ -11,7 +49,18 @@ TODO: Synopsis
1149

1250
## Instructions
1351

14-
1. ...
52+
Add a GitHub Action in your workflow, passing the input spec file (json or
53+
YAML), the desired output file location (json) and, optionally, the list of
54+
languages to generate snippets for.
55+
56+
```yaml
57+
- name: Generate Code Samples
58+
uses: grid-x/api-spec-snippets-generator-action@v6
59+
with:
60+
spec_file: ./petstore.yaml
61+
out_file: ./petstore-with-samples.json
62+
languages: go,python,shell,java,kotlin,swift,csharp
63+
```
1564
1665
## Development
1766

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/rapidoc.png

387 KB
Loading

docs/readme.png

246 KB
Loading

docs/redoc.png

347 KB
Loading

src/main.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ const label = (lang: SupportedTargets): string => {
7777
switch (lang) {
7878
case 'csharp':
7979
return 'C#'
80+
case 'cplusplus':
81+
return 'C++'
82+
case 'objectivec':
83+
return 'Objective-C'
8084
default:
8185
return lang.charAt(0).toUpperCase() + lang.slice(1)
8286
}

0 commit comments

Comments
 (0)