Skip to content

Commit 1b214df

Browse files
Integrated swag-driven OpenAPI spec generation (#491)
1 parent 4759f2e commit 1b214df

13 files changed

Lines changed: 4944 additions & 26 deletions

File tree

Makefile

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
11
SHELL := /bin/bash
2-
.PHONY: help integration-test-amie integration-test-amie-down
2+
.PHONY: help gen-api build verify-no-drift test integration-test verify integration-test-amie integration-test-amie-down
33

44
help:
55
@echo "Targets:"
6+
@echo " gen-api regenerate every OpenAPI spec from swag annotations"
7+
@echo " build gen-api, then go build ./..."
8+
@echo " verify-no-drift gen-api, then fail if any *.openapi.yaml changed"
9+
@echo " test go test ./..."
10+
@echo " integration-test full integration suite (AMIE for now)"
11+
@echo " verify verify-no-drift + go vet + test"
612
@echo " integration-test-amie run the AMIE connector integration suite end-to-end"
713
@echo " integration-test-amie-down tear down the AMIE test stack only"
814

15+
gen-api:
16+
go generate ./...
17+
18+
build: gen-api
19+
go build ./...
20+
21+
verify-no-drift: gen-api
22+
@if [ -n "$$(git status --porcelain api/ connectors/*/api/ 2>/dev/null)" ]; then \
23+
echo "OpenAPI drift detected — run 'make gen-api' and commit the result."; \
24+
git status --porcelain api/ connectors/*/api/; \
25+
exit 1; \
26+
fi
27+
28+
test:
29+
go test ./...
30+
31+
verify: verify-no-drift
32+
go vet ./...
33+
$(MAKE) test
34+
35+
integration-test: integration-test-amie
36+
937
integration-test-amie:
1038
bash scripts/run-amie-integration-tests.sh
1139

api/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# API specs
21+
22+
Auto-generated OpenAPI specs for Apache Custos.
23+
24+
## Layout
25+
26+
One spec per code-ownership unit:
27+
28+
| Spec | Path | Scope |
29+
|---|---|---|
30+
| Core | `api/core.openapi.yaml` | Core REST endpoints. |
31+
| Connector | `connectors/<NAME>/api/<name>.openapi.yaml` | A connector's endpoints under `/connectors/<name>/`. |
32+
33+
Connector specs ship alongside the connector code; the core spec never
34+
declares connector endpoints. The reference connector today is AMIE at
35+
`connectors/ACCESS/AMIE-Processor/api/amie.openapi.yaml`.
36+
37+
## Generating
38+
39+
Specs are produced from [`swag`](https://github.com/swaggo/swag)
40+
annotations on each handler in the Go source. Regenerate after editing
41+
any annotation:
42+
43+
```
44+
make gen-api
45+
```
46+
47+
CI enforces freshness via `make verify-no-drift`: modifying a handler
48+
annotation without committing the regenerated spec fails the build. The
49+
`swag` version is pinned in `go.sum`; `go generate` invokes it through
50+
`go run`, so contributors do not need to install the binary separately.
51+
52+
## Consuming
53+
54+
Both files are standard OpenAPI documents and load into any
55+
OpenAPI-aware client, viewer, or codegen tool.

0 commit comments

Comments
 (0)