Skip to content

Commit a40a4c0

Browse files
committed
PI-2374 Migrate OpenAPI yaml to annotations
1 parent 55636fd commit a40a4c0

File tree

78 files changed

+1463
-3321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1463
-3321
lines changed
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Generate OpenAPI spec
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
generate-openapi-spec:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-java@v4
15+
with:
16+
java-version: '21'
17+
distribution: 'temurin'
18+
- uses: gradle/actions/setup-gradle@v4
19+
- name: Serve dependencies
20+
run: make serve-dependencies
21+
- name: Start service
22+
run: |
23+
./gradlew bootRun &
24+
timeout 300 sh -c 'until curl -s localhost:8080/v3/api-docs; do sleep 5; done'
25+
env:
26+
SPRING_PROFILES_ACTIVE: local
27+
- name: Fetch API docs
28+
run: mkdir -p openapi && curl -f localhost:8080/v3/api-docs -o openapi/api-docs.json
29+
- name: Publish API docs
30+
uses: JamesIves/github-pages-deploy-action@94f3c658273cf92fb48ef99e5fbc02bd2dc642b2 # v4.6.3
31+
with:
32+
folder: openapi
33+
target-folder: openapi

.github/workflows/generate-plantuml-diagrams.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
env:
1414
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1717
- name: Install Graphviz Dependency
1818
run: |
1919
sudo apt-get install graphviz

Makefile

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@ authenticate-docker:
22
./scripts/authenticate_docker.sh
33

44
build-dev:
5-
docker-compose pull hmpps-auth
6-
docker-compose build --no-cache
5+
docker compose pull hmpps-auth
6+
docker compose build
77

88
build:
99
docker build -t hmpps-integration-api .
1010

11+
serve-dependencies:
12+
docker compose up hmpps-auth prism local-stack-aws --build -d
13+
1114
serve: build-dev
12-
docker-compose up -d
15+
docker compose up -d
1316

1417
publish:
1518
./scripts/publish.sh
1619

1720
stop:
18-
docker-compose down
21+
docker compose down
1922

2023
unit-test:
2124
./gradlew unitTest

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,21 @@ minutes.
8888

8989
## Usage
9090

91-
### Running the application
91+
### Running the application locally
9292

9393
To run the application using IntelliJ:
9494

95-
1. Select the `HmppsIntegrationApi` run configuration file.
96-
2. Click the run button.
95+
1. Start dependencies using `make serve-dependencies`
96+
2. Select the `HmppsIntegrationApi` run configuration file.
97+
3. Click the run button.
9798

98-
To run the application using the command line:
99+
Or, to run the application using the command line:
99100

100101
```bash
101-
./gradlew bootRun
102+
SPRING_PROFILES_ACTIVE=local ./gradlew bootRun
102103
```
103104

104-
Then visit [http://localhost:8080](http://localhost:8080).
105+
Then visit [http://localhost:8080/swagger-ui/index.html](http://localhost:8080/swagger-ui/index.html).
105106

106107
#### With dependent services
107108

build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies {
2020
exclude("org.springframework.security", "spring-security-crypto")
2121
exclude("org.springframework.security", "spring-security-web")
2222
}
23+
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0")
2324
testImplementation("io.kotest:kotest-assertions-json-jvm:5.8.0")
2425
testImplementation("io.kotest:kotest-runner-junit5-jvm:5.8.0")
2526
testImplementation("io.kotest:kotest-assertions-core-jvm:5.8.0")

docs/adr/0011-openapi-revision.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 0011 - Revert decision 0003 and auto-generate OpenAPI specification
2+
3+
2024-08-16
4+
5+
## Status
6+
7+
Proposed
8+
9+
## Context
10+
11+
In [#0003](./0003-manually-manage-openapi-file.md), the team decided to manually manage the OpenAPI specification file, as opposed to generating them from code.
12+
This had the benefit of allowing the team to write documentation for endpoints before they have been built.
13+
However, in practice this has resulted in an out-of-date specification due to code changes not being reflected.
14+
15+
## Decision
16+
17+
Revert decision 0003 and auto-generate OpenAPI specification using the [Springdoc OpenAPI library](https://springdoc.org).
18+
When the code or annotations change, the OpenAPI specification will be generated and published automatically.
19+
Additional documentation can be added for endpoints that have not yet been implemented, by adding a separate "draft" OpenAPI specification file.
20+
21+
### Rationale
22+
* Auto-generating OpenAPI specifications from annotations in code is consistent with the wider HMPPS approach
23+
* Keeping documentation as close to the relevant code as possible ensures it is kept up-to-date
24+
* Pre-existing documentation is maintained
25+
* Additional documentation that doesn't correspond to code can be drafted separately
26+
27+
## Consequences
28+
* The existing OpenAPI yaml file will be converted into code annotations, and will be published automatically via GitHub pages.
29+
* The tech-docs pages will be updated to reference the new location.

0 commit comments

Comments
 (0)