Skip to content

Commit 2e18d09

Browse files
committed
Add small readme for reference-gen
1 parent 3b023b3 commit 2e18d09

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

reference-gen/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TESTCOVER ?= -coverprofile c.out
1212
endif
1313

1414
.PHONY: lint
15-
lint: validate-go-version
15+
lint: validate-go-version check-golangci-lint
1616
GO111MODULE=on $(GOLANGCILINT) run
1717

1818
.PHONY: test
@@ -30,3 +30,10 @@ validate-go-version:
3030
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
3131
exit 1; \
3232
fi
33+
34+
.PHONY: check-golangci-lint
35+
check-golangci-lint:
36+
@ if [ ! $$(which golangci-lint) ]; then \
37+
echo "Missing golangci-lint, please install from https://golangci-lint.run/usage/install/ before linting"; \
38+
exit 1; \
39+
fi

reference-gen/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Reference Gen
2+
3+
This is a utility for generating markdown references from Go structs.
4+
It is used to generate part of the documentation of the [OAuth2 Proxy](https://github.com/oauth2-proxy/oauth2-proxy) project.
5+
6+
For example, a struct as below:
7+
8+
```golang
9+
// MyStruct contains a collection of fields.
10+
type MyStruct struct {
11+
// Name is the name of the MyStruct.
12+
Name string `json:"name"`
13+
14+
// Data is a slice of raw byte data.
15+
Data []byte `json:"bytes"`
16+
}
17+
```
18+
19+
Would be turned into markdown such as:
20+
21+
```markdown
22+
### MyStruct
23+
24+
MyStruct contains a collection of fields.
25+
26+
| Field | Type | Description |
27+
| ----- | ---- | ----------- |
28+
| `name` | _string_ | Name is the name of the MyStruct. |
29+
| `data` | _[]byte_ | Data is a slice of raw byte data. |
30+
```
31+
32+
Where a struct contains another struct, the other structs will also be included
33+
in the api references. Check out the [test data](https://github.com/oauth2-proxy/tools/tree/master/reference-gen/pkg/generator/testdata)
34+
for full examples of more complex struct documentation generation.
35+
36+
## Running tests
37+
38+
Tests can be executed using the `test` target from the Makefile.
39+
40+
```bash
41+
make test
42+
```
43+
44+
The tests will also run the `lint` target which requires [golangci-lint](https://golangci-lint.run/usage/install/).
45+
You will be prompted to install it should it not already be installed.

0 commit comments

Comments
 (0)