Skip to content

Commit 648404e

Browse files
authored
Add OpenAPI schema validation to CI and local dev (#1817)
1 parent 177daf6 commit 648404e

File tree

6 files changed

+139
-4
lines changed

6 files changed

+139
-4
lines changed

.github/workflows/code_coverage.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,13 @@ jobs:
136136
make update-openapi-schema
137137
git diff --exit-code -- tools/openapi-schema/ansible-ai-connect-service.yaml
138138
git diff --exit-code -- tools/openapi-schema/ansible-ai-connect-service.json
139+
140+
- name: Validate OpenAPI schema
141+
continue-on-error: true
142+
run: |
143+
python3 -c "
144+
from openapi_spec_validator import validate_url
145+
from openapi_spec_validator.validation.validators import OpenAPIV30SpecValidator
146+
147+
validate_url('http://localhost:8000/api/schema/', cls=OpenAPIV30SpecValidator)
148+
"

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ update-openapi-schema:
9393
curl -X GET http://localhost:8000/api/schema/ -o tools/openapi-schema/ansible-ai-connect-service.yaml
9494
curl -w "\n" -X GET "http://localhost:8000/api/schema/?format=json" > tools/openapi-schema/ansible-ai-connect-service.json
9595

96+
.PHONY: validate-openapi-schema
97+
# Validate OpenAPI schema against OpenAPI 3.0 specification (requires server to be running)
98+
validate-openapi-schema:
99+
@echo "Validating OpenAPI schema at http://localhost:8000/api/schema/ ..."
100+
@python3 -c "from openapi_spec_validator import validate_url; from openapi_spec_validator.validation.validators import OpenAPIV30SpecValidator; validate_url('http://localhost:8000/api/schema/', cls=OpenAPIV30SpecValidator); print('✓ OpenAPI schema is valid!')"
101+
96102
.PHONY: docker-compose-clean
97103
docker-compose-clean:
98104
${COMPOSE_RUNTIME} -f ${PWD}/tools/docker-compose/compose.yaml down

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,25 @@ with the following steps:
386386
3. Run `make update-openapi-schema` in the project root.
387387
4. Commit the updated OpenAPI Schema YAML file with your API changes.
388388

389+
#### OpenAPI Schema Validation
390+
391+
The OpenAPI schema is automatically validated against the OpenAPI 3.0 specification in CI/CD on every PR and push to main. This ensures the schema remains compliant and catches issues early.
392+
393+
To validate the schema locally before pushing:
394+
395+
```bash
396+
# Install the validator (included in dev dependencies)
397+
pip install .[dev]
398+
399+
# Start the development server (in one terminal)
400+
make run-server
401+
402+
# In another terminal, run the validation
403+
make validate-openapi-schema
404+
```
405+
406+
**Note:** Schema validation is currently non-blocking in CI/CD, meaning PRs will not be blocked by validation failures. However, validation errors will be visible in the CI logs and should be addressed.
407+
389408
Also a dynamically generated OpenAPI 3.0 Schema YAML file can be downloaded either:
390409

391410
- Click the /api/schema/ link on Swagger UI, or

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ dev = [
7070
'flake8~=6.0.0',
7171
'grpcio-tools~=1.68.1',
7272
'isort~=5.10.1',
73+
'openapi-spec-validator',
7374
'pre-commit',
7475
'responses~=0.24.1',
7576
'torch-model-archiver',

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ pyyaml==6.0.3
425425
# pydrive2
426426
# tablib
427427
# yamllint
428-
referencing==0.37.0
428+
referencing==0.36.2
429429
# via
430430
# ansible-lint
431431
# jsonschema

uv.lock

Lines changed: 102 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)