Skip to content

Commit 4e0329a

Browse files
committed
DMP-5275 (Dev only) Spectral setup + initial warning reductions darts-api
Added spectral config
1 parent 22ea7f4 commit 4e0329a

File tree

2 files changed

+17
-101
lines changed

2 files changed

+17
-101
lines changed

.spectral.yaml

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -2,99 +2,3 @@ extends: [ "spectral:oas" ]
22
rules:
33
oas3-valid-media-example: off
44
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-
85-
# objects-should-forbid-unknown:
86-
# description:
87-
# Request objects should set additionalProperties: false
88-
# given:
89-
# - "$.paths.*.*.requestBody.content.*.schema"
90-
# then:
91-
# function: schema
92-
# functionOptions:
93-
# schema:
94-
# if:
95-
# properties: { type: { const: object } }
96-
# required: [ type ]
97-
# then:
98-
# required: [ additionalProperties ]
99-
# properties: { additionalProperties: { const: false } }
100-
# severity: warn

README.md

Lines changed: 17 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,18 @@ 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 spectral to validate OpenAPI specifications. To validate the OpenAPI specification:
399+
400+
```bash
401+
spectral lint "src/main/resources/openapi/**/*.{yml,yaml}"
402+
```
403+
404+
Documentation: https://stoplight.io/open-source/spectral
405+
406+
Validate the data payload JSON Schemas:
407+
396408
### Supported labels
397409
398410
| Label | Usages |

0 commit comments

Comments
 (0)