Skip to content

Commit 101c73e

Browse files
authored
DMP-5275 (Dev only) Spectral setup + initial warning reductions darts-api (#3087)
1 parent 14f43ad commit 101c73e

File tree

2 files changed

+105
-5
lines changed

2 files changed

+105
-5
lines changed

.spectral.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
extends: [ "spectral:oas" ]
2+
rules:
3+
oas3-valid-media-example: off
4+
oas3-valid-schema-example: off
5+
strings-need-bounds:
6+
description: Strings must be bounded unless they already use format/enum/pattern
7+
given:
8+
- "$.components.schemas.*"
9+
- "$.paths.*.*.parameters[*].schema"
10+
- "$.paths.*.*.requestBody.content.*.schema"
11+
- "$.paths.*.*.responses.*.content.*.schema"
12+
then:
13+
function: schema
14+
functionOptions:
15+
schema:
16+
if:
17+
properties: { type: { const: string } }
18+
required: [ type ]
19+
then:
20+
anyOf:
21+
- required: [ maxLength ]
22+
- required: [ enum ]
23+
- required: [ pattern ]
24+
- required: [ format ]
25+
severity: warn
26+
27+
arrays-need-maxitems:
28+
given:
29+
- "$.components.schemas.*"
30+
- "$.paths.*.*.parameters[*].schema"
31+
- "$.paths.*.*.requestBody.content.*.schema"
32+
- "$.paths.*.*.responses.*.content.*.schema"
33+
then:
34+
function: schema
35+
functionOptions:
36+
schema:
37+
if:
38+
properties: { type: { const: array } }
39+
required: [ type ]
40+
then:
41+
required: [ maxItems ]
42+
severity: warn
43+
44+
path-string-params-need-format-or-pattern:
45+
given:
46+
- "$.paths.*.*.parameters[?(@.in=='path')].schema"
47+
then:
48+
function: schema
49+
functionOptions:
50+
schema:
51+
if:
52+
properties: { type: { const: string } }
53+
required: [ type ]
54+
then:
55+
anyOf:
56+
- required: [ format ]
57+
- required: [ pattern ]
58+
severity: warn
59+
60+
param-id-needs-format-or-pattern:
61+
given:
62+
- "$.paths.*.*.parameters[?(@.name=='id')].schema"
63+
then:
64+
function: schema
65+
functionOptions:
66+
schema:
67+
anyOf:
68+
- required: [ format ]
69+
- required: [ pattern ]
70+
severity: warn
71+
72+
schema-id-prop-needs-format-or-pattern:
73+
given:
74+
- "$.components.schemas.*.properties.id"
75+
- "$.paths.*.*.requestBody.content.*.schema.properties.id"
76+
then:
77+
function: schema
78+
functionOptions:
79+
schema:
80+
anyOf:
81+
- required: [ format ]
82+
- required: [ pattern ]
83+
severity: warn
84+

README.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,12 @@ There is no need to remove postgres and java or similar core images.
328328
The following Spring Profiles are defined. "External Components" are defined as any service upon which the application
329329
is dependent, such as database servers, web services etc.
330330
331-
| Profile | Config Location | Purpose | External Components |
332-
|------------------|----------------------------------------------------------------|------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
333-
| `local` | `src/main/resources/application-local.yaml` | For running the application locally as a docker compose stack with `docker-compose-local.yml`. | Provided as needed by `docker-compose-local.yml`. No external connectivity permitted outside the network boundary of the stack. |
331+
| Profile | Config Location | Purpose | External Components |
332+
|------------------|----------------------------------------------------------------|------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
333+
| `local` | `src/main/resources/application-local.yaml` | For running the application locally as a docker compose stack with `docker-compose-local.yml`. | Provided as needed by `docker-compose-local.yml`. No external connectivity permitted outside the network boundary of the stack. |
334334
| `intTest` | `src/integrationTest/resources/application-intTest.yaml` | For running integration tests under `src/integrationTest`. | No interaction required or permitted, all external calls are mocked via embedded wiremock (for HTTP requests), an embedded database (for db queries) or `@MockitoBean` for anything else. Spring Security is explicitly disabled. |
335-
| `functionalTest` | `src/functionalTest/resources/application-functionalTest.yaml` | For running functional tests under `src/functionalTest`. | Functional tests execute API calls against the application deployed in the PR environment. That application is deployed with the `dev` profile (see below). |
336-
| `dev` | `src/main/resources/application-dev.yaml` | For running the application in the Pull Request (dev) environment. | Interaction permitted with "real" components, which may be services deployed to a test environment. |
335+
| `functionalTest` | `src/functionalTest/resources/application-functionalTest.yaml` | For running functional tests under `src/functionalTest`. | Functional tests execute API calls against the application deployed in the PR environment. That application is deployed with the `dev` profile (see below). |
336+
| `dev` | `src/main/resources/application-dev.yaml` | For running the application in the Pull Request (dev) environment. | Interaction permitted with "real" components, which may be services deployed to a test environment. |
337337
338338
## Automated Tasks
339339
@@ -393,6 +393,22 @@ Please see the separate [Dev environment](https://tools.hmcts.net/confluence/dis
393393
394394
This repo contains overrides for the default dev environment configuration, controlled by PR labels.
395395
396+
## OpenAPI Specification and Data Schema Validation
397+
398+
This repository uses spectral to validate OpenAPI specifications. To install spectral, you can use npm or yarn:
399+
400+
https://docs.stoplight.io/docs/spectral/b8391e051b7d8-installation
401+
402+
To validate the OpenAPI specification:
403+
404+
```bash
405+
spectral lint --verbose "src/main/resources/openapi/**/*.{yml,yaml}"
406+
```
407+
408+
Documentation: https://stoplight.io/open-source/spectral
409+
410+
Validate the data payload JSON Schemas:
411+
396412
### Supported labels
397413
398414
| Label | Usages |

0 commit comments

Comments
 (0)