WIP: outil de test conformité API Swagger XP Z12-013 (#27) #34

Draft
bruno.d2b wants to merge 5 commits from 27_test_API_PA into main
Member
Q A
Branche? 27_test_API_PA
Correction? non
Nouvelle feature? oui
Ticket Fix #27
Licence GPL-3.0-or-later

Summary

cf Ticket #27

Ajout d'un outil de validation de conformité des API Swagger/OpenAPI
avec la norme AFNOR XP Z12-013.

L'outil compare le swagger exposé par une PA avec les fichiers de référence
AFNOR (Annexe A - Flow Service, Annexe B - Directory Service) et vérifie :

  • Présence des endpoints obligatoires
  • Route /healthcheck (XP Z12-013 §4.4)
  • Authentification Bearer (XP Z12-013 §5)
  • Version OpenAPI et section info

Disponible via CLI (pac test swagger) et via tests BDD (scénarios Gherkin).

Fichiers

Fichier Utilité
packages/pac0-cli/src/pac0/cli/command/test.py Commande CLI pac test swagger <URL>
packages/pac0-cli/src/pac0/cli/lib/swagger_validator.py Module de validation (compare swagger distant vs référence AFNOR)
packages/pac0-cli/src/pac0/cli/lib/__init__.py Package Python (nécessaire pour l'import du module lib)
docs/briques/01-api-gateway/openapi_conformite.feature Scénarios BDD Gherkin (Flow Service + Directory Service)
packages/pac-bdd/src/pac_bdd/openapi.py Step definitions BDD (validation directe contre les swaggers AFNOR)
packages/pac-bdd/test_openapi.py Tests directs (appel standalone du validateur)
docs/developpement/Test_API_Swagger.md Documentation d'utilisation

Utilisation

# Via pac-cli
uv run pac test swagger http://localhost:8000/openapi.json
uv run pac test swagger http://localhost:8000/openapi.json --service directory

# Mode standalone
uv run python -m pac0.cli.lib.swagger_validator http://localhost:8000/openapi.json

# Via BDD
cd packages/pac-bdd
uv run pytest test_scenario.py -k "conformit" -v

# Tests directs
cd packages/pac-bdd
uv run pytest test_openapi.py -v

Exemple de sortie

✅ Version OpenAPI: 3.1.0
✅ Info.title: FastAPI
❌ Sécurité Bearer: MANQUANT - authentification Bearer requise (XP Z12-013 §5)
✅ Healthcheck: présent (/healthcheck)
✅ POST /v1/flows: présent
❌ POST /v1/flows/search: MANQUANT
--------------------------------------------------
❌ 7/9 tests passés - NON CONFORME

Test plan

- Lancer pac test swagger http://localhost:8000/openapi.json avec l'API Gateway démarrée
- Lancer pac test swagger http://localhost:8000/openapi.json --service directory
- Vérifier le mode standalone
- Vérifier le --help
- Lancer uv run pytest test_scenario.py -k "conformit" -v (tests BDD)
- Lancer uv run pytest test_openapi.py -v (tests directs)
| Q | A | | --- | --- | | Branche? | 27_test_API_PA | | Correction? | non | | Nouvelle feature? | oui | | Ticket | Fix #27 | | Licence | GPL-3.0-or-later | ## Summary cf Ticket #27 Ajout d'un outil de validation de conformité des API Swagger/OpenAPI avec la norme AFNOR XP Z12-013. L'outil compare le swagger exposé par une PA avec les fichiers de référence AFNOR (Annexe A - Flow Service, Annexe B - Directory Service) et vérifie : - Présence des endpoints obligatoires - Route /healthcheck (XP Z12-013 §4.4) - Authentification Bearer (XP Z12-013 §5) - Version OpenAPI et section info Disponible via CLI (`pac test swagger`) et via tests BDD (scénarios Gherkin). ## Fichiers | Fichier | Utilité | | ------- | ------- | | `packages/pac0-cli/src/pac0/cli/command/test.py` | Commande CLI `pac test swagger <URL>` | | `packages/pac0-cli/src/pac0/cli/lib/swagger_validator.py` | Module de validation (compare swagger distant vs référence AFNOR) | | `packages/pac0-cli/src/pac0/cli/lib/__init__.py` | Package Python (nécessaire pour l'import du module lib) | | `docs/briques/01-api-gateway/openapi_conformite.feature` | Scénarios BDD Gherkin (Flow Service + Directory Service) | | `packages/pac-bdd/src/pac_bdd/openapi.py` | Step definitions BDD (validation directe contre les swaggers AFNOR) | | `packages/pac-bdd/test_openapi.py` | Tests directs (appel standalone du validateur) | | `docs/developpement/Test_API_Swagger.md` | Documentation d'utilisation | ## Utilisation ```bash # Via pac-cli uv run pac test swagger http://localhost:8000/openapi.json uv run pac test swagger http://localhost:8000/openapi.json --service directory # Mode standalone uv run python -m pac0.cli.lib.swagger_validator http://localhost:8000/openapi.json # Via BDD cd packages/pac-bdd uv run pytest test_scenario.py -k "conformit" -v # Tests directs cd packages/pac-bdd uv run pytest test_openapi.py -v Exemple de sortie ✅ Version OpenAPI: 3.1.0 ✅ Info.title: FastAPI ❌ Sécurité Bearer: MANQUANT - authentification Bearer requise (XP Z12-013 §5) ✅ Healthcheck: présent (/healthcheck) ✅ POST /v1/flows: présent ❌ POST /v1/flows/search: MANQUANT -------------------------------------------------- ❌ 7/9 tests passés - NON CONFORME Test plan - Lancer pac test swagger http://localhost:8000/openapi.json avec l'API Gateway démarrée - Lancer pac test swagger http://localhost:8000/openapi.json --service directory - Vérifier le mode standalone - Vérifier le --help - Lancer uv run pytest test_scenario.py -k "conformit" -v (tests BDD) - Lancer uv run pytest test_openapi.py -v (tests directs)
- Ajout commande `pac test swagger <URL>` (pac-cli)
- Mode standalone `python -m pac0.cli.lib.swagger_validator`
- Validation : endpoints, healthcheck, Bearer, version OpenAPI
- Documentation développeur
Author
Member

Intégrer le script dans la logique BDD
Tester avec des API externes - Teddy

Intégrer le script dans la logique BDD Tester avec des API externes - Teddy
bruno.d2b changed title from feat: outil de test conformité API Swagger XP Z12-013 (#27) to WIP: outil de test conformité API Swagger XP Z12-013 (#27) 2026-02-12 14:16:15 +01:00
Ajoute des scenarios Gherkin (Flow Service + Directory Service) qui
valident le swagger expose par l API Gateway contre les references
AFNOR. Remplace les stubs NotImplementedError de test_openapi.py par
des appels au validateur standalone de pac0-cli.
Author
Member

J'ai écrit un test BDD dans la brique 01-api-gateway avec mise à jour de packages/pac-bdd/test_openapi.py . Documentation mise à jour également.

J'ai réécrit la description de la PR pour inclure cela.

Après vérif avec une PA externe + verif que le test BDD fonctionne, on pourra merger.

J'ai écrit un test BDD dans la brique 01-api-gateway avec mise à jour de packages/pac-bdd/test_openapi.py . Documentation mise à jour également. J'ai réécrit la description de la PR pour inclure cela. Après vérif avec une PA externe + verif que le test BDD fonctionne, on pourra merger.
This pull request is marked as a work in progress.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 27_test_API_PA:27_test_API_PA
git switch 27_test_API_PA

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff 27_test_API_PA
git switch 27_test_API_PA
git rebase main
git switch main
git merge --ff-only 27_test_API_PA
git switch 27_test_API_PA
git rebase main
git switch main
git merge --no-ff 27_test_API_PA
git switch main
git merge --squash 27_test_API_PA
git switch main
git merge --ff-only 27_test_API_PA
git switch main
git merge 27_test_API_PA
git push origin main
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Construction_PA/PA_Communautaire!34
No description provided.