You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can install some pre-commit hooks to ensure you can't commit invalid spec changes by accident. These are also run
37
-
in CI, but it's useful to run them locally too.
38
-
39
-
```
40
-
$ make install-hooks
41
-
```
42
-
43
-
### Environment Variables
44
-
Various scripts and commands rely on environment variables being set. These are documented with the commands.
45
-
46
-
:bulb: Consider using [direnv](https://direnv.net/) to manage your environment variables during development and maintaining your own `.envrc` file - the values of these variables will be specific to you and/or sensitive.
47
-
48
-
### Make commands
49
-
There are `make` commands that alias some of this functionality:
50
-
*`lint` -- Lints the spec and code
51
-
*`publish` -- Outputs the specification as a **single file** into the `build/` directory
52
-
*`serve` -- Serves a preview of the specification in human-readable format
53
-
54
-
### Testing
55
-
Each API and team is unique. We encourage you to use a `test/` folder in the root of the project, and use whatever testing frameworks or apps your team feels comfortable with. It is important that the URL your test points to be configurable. We have included some stubs in the Makefile for running tests.
56
-
57
-
### VS Code Plugins
58
-
59
-
*[openapi-lint](https://marketplace.visualstudio.com/items?itemName=mermade.openapi-lint) resolves links and validates entire spec with the 'OpenAPI Resolve and Validate' command
*[**openapi-yaml-mode**](https://github.com/esc-emacs/openapi-yaml-mode) provides syntax highlighting, completion, and path help
66
-
67
-
### Speccy
68
-
69
-
> [Speccy](http://speccy.io/)*A handy toolkit for OpenAPI, with a linter to enforce quality rules, documentation rendering, and resolution.*
70
-
71
-
Speccy does the lifting for the following npm scripts:
72
-
73
-
*`test` -- Lints the definition
74
-
*`publish` -- Outputs the specification as a **single file** into the `build/` directory
75
-
*`serve` -- Serves a preview of the specification in human-readable format
76
-
77
-
(Workflow detailed in a [post](https://developerjack.com/blog/2018/maintaining-large-design-first-api-specs/) on the *developerjack* blog.)
78
-
79
-
:bulb: The `publish` command is useful when uploading to Apigee which requires the spec as a single file.
80
-
81
-
### Caveats
82
-
83
-
#### Swagger UI
84
-
Swagger UI unfortunately doesn't correctly render `$ref`s in examples, so use `speccy serve` instead.
85
-
86
-
#### Apigee Portal
87
-
The Apigee portal will not automatically pull examples from schemas, you must specify them manually.
88
-
89
-
### Platform setup
90
-
91
-
As currently defined in your `proxies` folder, your proxies do pretty much nothing.
92
-
Telling Apigee how to connect to your backend requires a *Target Server*, which you should call named `nhs-website-content-api-target`.
93
-
Our *Target Servers* defined in the [api-management-infrastructure](https://github.com/NHSDigital/api-management-infrastructure) repository.
94
-
95
-
:bulb: For Sandbox-running environments (`test`) these need to be present for successful deployment but can be set to empty/dummy values.
96
-
97
-
### Detailed folder walk through
98
-
To get started developing your API use this template repo alongside guidance provided by the [API Producer Zone confluence](https://nhsd-confluence.digital.nhs.uk/display/APM/Deliver+your+API)
99
-
100
-
#### `/.github`:
101
-
102
-
This folder contains templates that can be customised for items such as opening pull requests or issues within the repo
103
-
104
-
`/.github/workflows`: This folder contains templates for github action workflows such as:
105
-
-`pr-lint.yaml`: This workflow template shows how to link Pull Request's to Jira tickets and runs when a pull request is opened.
106
-
-`continuous-integration.yml`: This workflow template shows how to publish a Github release when pushing to master.
107
-
108
-
#### `/azure`:
109
-
110
-
Contains templates defining Azure Devops pipelines. By default the following pipelines are available:
111
-
-`azure-build-pipeline.yml`: Assembles the contents of your repository into a single file ("artifact") on Azure Devops and pushes any containers to our Docker registry. By default this pipeline is enabled for all branches.
112
-
-`azure-pr-pipeline.yml`: Deploys ephemeral versions of your proxy/spec to Apigee (and docker containers on AWS) to internal environments. You can run automated and manual tests against these while you develop. By default this pipeline will deploy to internal-dev, but the template can be amended to add other environments as required.
113
-
-`azure-release-pipeline.yml`: Deploys the long-lived version of your pipeline to internal and external environments, typically when you merge to master.
114
-
115
-
The `project.yml` file needs to be populated with your service names to make them available to the pipelines
116
-
117
-
`/azure/templates`: Here you can define reusable actions, such as running tests, and call these actions during Azure Devops pipelines.
118
-
119
-
#### `/proxies`:
120
-
121
-
This folder contains files relating to your Apigee API proxy.
122
-
123
-
There are 2 folders `/live` and `/sandbox` allowing you to define a different proxy for sandbox use. By default, this sandbox proxy is implemented to route to the sandbox target server (code for this sandbox is found under /sandbox of this template repo)
124
-
125
-
Within the `live/apiproxy` and `sandbox/apiproxy` folders are:
126
-
127
-
`/proxies/default.xml`: Defines the proxy's Flows. Flows define how the proxy should handle different requests. By default, _ping and _status endpoint flows are defined.
128
-
See the APM confluence for more information on how the [_ping](https://nhsd-confluence.digital.nhs.uk/display/APM/_ping+endpoint) and [_status](https://nhsd-confluence.digital.nhs.uk/display/APM/_status+endpoint) endpoints work.
129
-
130
-
`/policies`: Populated with a set of standard XML Apigee policies that can be used in flows.
131
-
132
-
`/resources/jsc`: Snippets of javascript code that are used in Apigee Javascript policies. For more info about Javascript policies see [here](https://docs.apigee.com/api-platform/reference/policies/javascript-policy)
133
-
134
-
`/targets`: The XMLs within these folders set up target definitions which allow connections to external target servers. The sandbox target definition is implemented to route to the sandbox target server (code for this sandbox is found under /sandbox of this template repo). For more info on setting up a target server see the [API Producer Zone confluence](https://nhsd-confluence.digital.nhs.uk/display/APM/Setting+up+a+target+server)
135
-
136
-
#### `/sandbox`:
137
-
138
-
This folder contains a template for a sandbox API. This example is a NodeJs application running in Docker. The application handles a few simple endpoints such as: /_ping, /health, /_status, /hello and some logging logic.
139
-
For more information about building sandbox APIs see the [API Producer Zone confluence](https://nhsd-confluence.digital.nhs.uk/display/APM/Setting+up+your+API+sandbox ).
140
-
141
-
#### `/scripts`:
142
-
143
-
Contains useful scripts that are used throughout the project, for example in Makefile and Github workflows
144
-
145
-
#### `/specification`:
146
-
147
-
Create an OpenAPI Specification to document your API. For more information about developing specifications see the [API Producer Zone confluence](https://nhsd-confluence.digital.nhs.uk/display/APM/Documenting+your+API).
148
-
149
-
#### `/tests`:
150
-
151
-
End-to-end tests. These tests are written in Python and use the PyTest test runner. Before running these tests you will need to set environment variables. The `test_endpoint.py` file provides a template of how to set up tests which test your api endpoints. For more information about testing your API see the [API Producer Zone confluence](https://nhsd-confluence.digital.nhs.uk/display/APM/Testing+your+API ).
152
-
153
-
#### `Makefile`:
154
-
Useful `make` targets to get started including: installing dependencies and running smoke tests.
155
-
156
-
#### `ecs-proxies-containers.yml ` and `ecs-proxies-deploy.yml`:
157
-
158
-
These files are required to deploy containers alongside your Apigee proxy during the Azure Devops `azure-build-pipeline`. In this template repo we are deploying our sandbox container which is used as the target server for the sandbox proxy.
159
-
160
-
`ecs-proxies-containers.yml`: The path to a container's Dockerfile is defined here. This path needs to be defined to allow containers to be pushed to our repository during the `azure-build-pipeline`.
161
-
162
-
`ecs-proxies-deploy.yml` : Here you can define config for your container deployment.
163
-
164
-
For more information about deploying ECS containers see the [API Producer Zone confluence](https://nhsd-confluence.digital.nhs.uk/display/APM/Developing+ECS+proxies#DevelopingECSproxies-Buildingandpushingdockercontainers ).
31
+
Consider using a **dev container**. While this is in no way a requirement, you may find it more convenient.
165
32
166
-
#### `manifest_template.yml`:
33
+
###Get Environmental Variables
167
34
168
-
This file defines 2 dictionaries of fields that are required for the Apigee deployment. For more info see the [API Producer Zone confluence](https://nhsd-confluence.digital.nhs.uk/display/APM/Manifest.yml+reference ).
35
+
1. Make a new `.env` file in this directory, using `example.env` as a base.
36
+
1. Fill in the missing environmental variables:
37
+
- At the time of writing, `PROXY_NAME` should be set to `nhs-website-content-api-internal-dev`.
38
+
- You can get an `APIGEE_ACCESS_TOKEN` via the `get_token` command. If you don't already have access to the `get_token` command, you can install it using [these instructions](https://docs.apigee.com/api-platform/system-administration/auth-tools#install).
39
+
- You can get the latest `SOURCE_COMMIT_ID` via the `/_ping` endpoint of the proxy you're using. For example, with `PROXY_NAME` set to `nhs-website-content-api-internal-dev`, we would want to access the URL https://internal-dev.api.service.nhs.uk/nhs-website-content/_ping - this should return some JSON, and the value we want has key `commitId`.
169
40
170
-
#### Package management:
41
+
:bulb: The `make token` command provides a useful shorthand for calling `get_token` with all the right environmental variables.
171
42
172
-
This template uses poetry for python dependency management, and uses these files: poetry.lock, poetry.toml, pyproject.toml.
43
+
### Let's Roll
173
44
174
-
Node dependencies of this template project and some npm scripts are listed in: package.json, package-lock.json.
45
+
1. Install by running `make install` from this directory.
46
+
1. Test this installation by running `make test`, also from this directory.
47
+
1. Try out the preview server by running `make publish` and then `make serve`; then visit the local URL printed in the console.
0 commit comments