Skip to content

Commit 8247b3a

Browse files
authored
VED-494: OAS (#1056)
* init: YAML as master * prettier * deleted JSON * temp: --skip-rule=no-invalid-media-type-examples * make oas * make oas II * add generated immunisation-fhir-api.oas.json * read-only * read-only II * prettier * README re. hooks * README * review
1 parent 40df258 commit 8247b3a

File tree

6 files changed

+5757
-8589
lines changed

6 files changed

+5757
-8589
lines changed

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
# TODO - investigate
66
/infrastructure/proxies/live/apiproxy/resources/jsc/
77
/infrastructure/proxies/sandbox/apiproxy/resources/jsc/
8+
9+
# The oas.json file is deliberately minified
10+
immunisation-fhir-api.oas.json

Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SHELL=/usr/bin/env bash -euo pipefail
33
PYTHON_PROJECT_DIRS_WITH_UNIT_TESTS = lambdas/backend lambdas/ack_backend lambdas/batch_processor_filter lambdas/delta_backend lambdas/filenameprocessor lambdas/id_sync lambdas/mesh_processor lambdas/mns_subscription lambdas/recordforwarder lambdas/recordprocessor lambdas/redis_sync lambdas/shared
44
PYTHON_PROJECT_DIRS = tests/e2e tests/e2e_batch quality_checks $(PYTHON_PROJECT_DIRS_WITH_UNIT_TESTS)
55

6-
.PHONY: install lint format format-check clean publish build-proxy release initialise-all-python-venvs update-all-python-dependencies run-all-python-unit-tests build-all-docker-images
6+
.PHONY: install lint format format-check clean publish oas build-proxy release initialise-all-python-venvs update-all-python-dependencies run-all-python-unit-tests build-all-docker-images
77

88
#Installs dependencies using npm.
99
install:
@@ -19,18 +19,26 @@ format:
1919
format-check:
2020
npm run format-check
2121

22-
#Removes build/ + dist/ directories
22+
#Removes build/, dist/ and sandbox/specification/ directories
2323
clean:
2424
rm -rf build
2525
rm -rf dist
26+
rm -rf sandbox/specification
2627

27-
#Creates the fully expanded OAS spec in json
28+
#Creates the OAS spec in JSON for sandbox
2829
publish: clean
2930
mkdir -p build
3031
npm run publish 2> /dev/null
3132
cp build/immunisation-fhir-api.json sandbox/
3233
cp -r specification sandbox/specification
3334

35+
#Creates a minified OAS spec in JSON for sending to APIM
36+
oas: publish
37+
mkdir -p oas
38+
rm -f specification/immunisation-fhir-api.json
39+
jq -c . build/immunisation-fhir-api.json > oas/immunisation-fhir-api.json
40+
chmod -w oas/immunisation-fhir-api.json
41+
3442
#Runs build proxy script
3543
build-proxy:
3644
utilities/scripts/build_proxy.sh

README.specification.md

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ $ make install
4141
You can install some pre-commit hooks to ensure you can't commit invalid spec changes by accident. These are also run
4242
in CI, but it's useful to run them locally too.
4343

44-
```
45-
$ make install-hooks
46-
```
44+
Note that this step is now done automatically in `make install` above. `make install-hooks` is no longer run.
4745

4846
### Environment Variables
4947

@@ -56,8 +54,20 @@ Various scripts and commands rely on environment variables being set. These are
5654
There are `make` commands that alias some of this functionality:
5755

5856
- `lint` -- Lints the spec and code
59-
- `publish` -- Outputs the specification as a **single file** into the `build/` directory
60-
- `serve` -- Serves a preview of the specification in human-readable format
57+
- `publish` -- Outputs the specification as a **single** JSON file into the `build/` directory
58+
59+
### Modifying the OAS file
60+
61+
Note that the master OAS file is now the **YAML** version, as it is far easier to maintain than the JSON.
62+
63+
To review your modifications, use Swagger Editor (https://editor.swagger.io).
64+
65+
### Update the OAS file to the public website
66+
67+
Note that this is currently a **manual** process.
68+
69+
After modifying the OAS YAML file, run `make oas` on your local machine. This will output the specification into `oas/immunisation-fhir-api.json`. This is a **minified** JSON file suitable for sending to APIM
70+
for uploading to the pubic website.
6171

6272
### Testing
6373

@@ -72,26 +82,8 @@ Each API and team is unique. We encourage you to use a `test/` folder in the roo
7282

7383
- [**openapi-yaml-mode**](https://github.com/esc-emacs/openapi-yaml-mode) provides syntax highlighting, completion, and path help
7484

75-
### Speccy
76-
77-
> [Speccy](http://speccy.io/) _A handy toolkit for OpenAPI, with a linter to enforce quality rules, documentation rendering, and resolution._
78-
79-
Speccy does the lifting for the following npm scripts:
80-
81-
- `test` -- Lints the definition
82-
- `publish` -- Outputs the specification as a **single file** into the `build/` directory
83-
- `serve` -- Serves a preview of the specification in human-readable format
84-
85-
(Workflow detailed in a [post](https://developerjack.com/blog/2018/maintaining-large-design-first-api-specs/) on the _developerjack_ blog.)
86-
87-
:bulb: The `publish` command is useful when uploading to Apigee which requires the spec as a single file.
88-
8985
### Caveats
9086

91-
#### Swagger UI
92-
93-
Swagger UI unfortunately doesn't correctly render `$ref`s in examples, so use `speccy serve` instead.
94-
9587
#### Apigee Portal
9688

9789
The Apigee portal will not automatically pull examples from schemas, you must specify them manually.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.1",
44
"description": "OAS (Swagger v3) API Definition for Template API",
55
"scripts": {
6-
"lint": "redocly lint --skip-rule=security-defined specification/immunisation-fhir-api.yaml",
6+
"lint": "redocly lint --skip-rule=security-defined --skip-rule=no-invalid-media-type-examples specification/immunisation-fhir-api.yaml",
77
"format": "prettier --write .",
88
"format-check": "prettier --check .",
99
"publish": "redocly bundle specification/immunisation-fhir-api.yaml --remove-unused-components --ext json -o build/immunisation-fhir-api.json",
@@ -26,6 +26,6 @@
2626
"poetry -P quality_checks run ruff format"
2727
],
2828
"*.tf": "terraform fmt",
29-
"immunisation-fhir-api.{yaml,json}": "redocly lint --skip-rule=security-defined"
29+
"immunisation-fhir-api.{yaml,json}": "redocly lint --skip-rule=security-defined --skip-rule=no-invalid-media-type-examples"
3030
}
3131
}

0 commit comments

Comments
 (0)