From b96c617adba9b36e1904f64ed51be56ad95322bf Mon Sep 17 00:00:00 2001 From: Julien Maupetit Date: Tue, 16 Jul 2024 15:41:25 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9(api)=20improve=20Swagger=20data=20?= =?UTF-8?q?examples?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Swagger auto-generated example fields given a regex are often confusing. We've added some real life example to ease our users' life. --- src/api/CHANGELOG.md | 4 + src/api/qualicharge/models/dynamic.py | 10 +- src/api/qualicharge/models/static.py | 445 +++++++++++++++++++++++++- 3 files changed, 455 insertions(+), 4 deletions(-) diff --git a/src/api/CHANGELOG.md b/src/api/CHANGELOG.md index 6af4dc0f..9051a634 100644 --- a/src/api/CHANGELOG.md +++ b/src/api/CHANGELOG.md @@ -14,6 +14,10 @@ and this project adheres to - Upgrade geoalchemy2 to `0.15.2` - Upgrade sentry-sdk to `2.10.0` +### Fixed + +- Add relevant data examples for Swagger + ## [0.10.0] - 2024-07-01 ### Changed diff --git a/src/api/qualicharge/models/dynamic.py b/src/api/qualicharge/models/dynamic.py index d755edd8..ad86ac22 100644 --- a/src/api/qualicharge/models/dynamic.py +++ b/src/api/qualicharge/models/dynamic.py @@ -49,7 +49,10 @@ class StatusCreate(StatusBase): """Point of charge status create.""" id_pdc_itinerance: str = Field( - regex="(?:(?:^|,)(^[A-Z]{2}[A-Z0-9]{4,33}$|Non concerné))+$" + regex="(?:(?:^|,)(^[A-Z]{2}[A-Z0-9]{4,33}$|Non concerné))+$", + schema_extra={ + "examples": ["FR0NXEVSEXB9YG", "FRFASE3300405", "FR073012308585"] + }, ) @@ -69,5 +72,8 @@ class SessionCreate(SessionBase): """Point of charge sessions create.""" id_pdc_itinerance: str = Field( - regex="(?:(?:^|,)(^[A-Z]{2}[A-Z0-9]{4,33}$|Non concerné))+$" + regex="(?:(?:^|,)(^[A-Z]{2}[A-Z0-9]{4,33}$|Non concerné))+$", + schema_extra={ + "examples": ["FR0NXEVSEXB9YG", "FRFASE3300405", "FR073012308585"] + }, ) diff --git a/src/api/qualicharge/models/static.py b/src/api/qualicharge/models/static.py index 97fb77f2..a625af82 100644 --- a/src/api/qualicharge/models/static.py +++ b/src/api/qualicharge/models/static.py @@ -111,7 +111,17 @@ class Statique(ModelSchemaMixin, BaseModel): """IRVE static model.""" nom_amenageur: Optional[str] - siren_amenageur: Optional[Annotated[str, Field(pattern=r"^\d{9}$")]] + siren_amenageur: Optional[ + Annotated[ + str, + Field( + pattern=r"^\d{9}$", + examples=[ + "853300010", + ], + ), + ] + ] contact_amenageur: Optional[EmailStr] nom_operateur: Optional[str] contact_operateur: EmailStr @@ -130,7 +140,11 @@ class Statique(ModelSchemaMixin, BaseModel): coordonneesXY: DataGouvCoordinate nbre_pdc: PositiveInt id_pdc_itinerance: Annotated[ - str, Field(pattern="(?:(?:^|,)(^[A-Z]{2}[A-Z0-9]{4,33}$|Non concerné))+$") + str, + Field( + pattern="(?:(?:^|,)(^[A-Z]{2}[A-Z0-9]{4,33}$|Non concerné))+$", + examples=["FR0NXEVSEXB9YG", "FRFASE3300405", "FR073012308585"], + ), ] id_pdc_local: Optional[str] puissance_nominale: PositiveFloat @@ -170,3 +184,430 @@ def check_afirev_prefix(self) -> Self: ) ) return self + + model_config = { + "json_schema_extra": { + "examples": [ + { + "nom_amenageur": "Fastned France", + "siren_amenageur": "853300010", + "contact_amenageur": "support@fastned.nl", + "nom_operateur": "Fastned France", + "contact_operateur": "support@fastned.nl", + "telephone_operateur": "tel:+33-1-84-71-00-62", + "nom_enseigne": "Fastned Aire de la Plaine du Forez Est", + "id_station_itinerance": "FRFASE33004", + "id_station_local": "FRFASE33004", + "nom_station": "Fastned Aire de la Plaine du Forez Est", + "implantation_station": "Station dédiée à la recharge rapide", + "adresse_station": "Aire de la Plaine du Forez A72, 42600 Magneux", + "code_insee_commune": "42130", + "coordonneesXY": "[4.156034, 45.679959]", + "nbre_pdc": 8, + "id_pdc_itinerance": "FRFASE3300401", + "id_pdc_local": "FRFASE3300401", + "puissance_nominale": 20.0, + "prise_type_ef": False, + "prise_type_2": True, + "prise_type_combo_ccs": True, + "prise_type_chademo": True, + "prise_type_autre": True, + "gratuit": False, + "paiement_acte": True, + "paiement_cb": True, + "paiement_autre": True, + "tarification": "0,40€ par KWh pour les non abonnés", + "condition_acces": "Accès libre", + "reservation": False, + "horaires": "24/7", + "accessibilite_pmr": "Accessible mais non réservé PMR", + "restriction_gabarit": "Hauteur maximale 3m", + "station_deux_roues": False, + "raccordement": "Direct", + "num_pdl": "00001234567890", + "date_mise_en_service": "2022-12-02", + "observations": "Néant", + "date_maj": "2024-06-04", + "cable_t2_attache": True, + }, + { + "nom_amenageur": "Fastned France", + "siren_amenageur": "853300010", + "contact_amenageur": "support@fastned.nl", + "nom_operateur": "Fastned France", + "contact_operateur": "support@fastned.nl", + "telephone_operateur": "tel:+33-1-84-71-00-62", + "nom_enseigne": "Fastned Aire de la Plaine du Forez Est", + "id_station_itinerance": "FRFASE33004", + "id_station_local": "FRFASE33004", + "nom_station": "Fastned Aire de la Plaine du Forez Est", + "implantation_station": "Station dédiée à la recharge rapide", + "adresse_station": "Aire de la Plaine du Forez A72, 42600 Magneux", + "code_insee_commune": "42130", + "coordonneesXY": "[4.156034, 45.679959]", + "nbre_pdc": 8, + "id_pdc_itinerance": "FRFASE3300402", + "id_pdc_local": "FRFASE3300402", + "puissance_nominale": 20.0, + "prise_type_ef": False, + "prise_type_2": True, + "prise_type_combo_ccs": True, + "prise_type_chademo": True, + "prise_type_autre": True, + "gratuit": False, + "paiement_acte": True, + "paiement_cb": True, + "paiement_autre": True, + "tarification": "0,40€ par KWh pour les non abonnés", + "condition_acces": "Accès libre", + "reservation": False, + "horaires": "24/7", + "accessibilite_pmr": "Accessible mais non réservé PMR", + "restriction_gabarit": "Hauteur maximale 3m", + "station_deux_roues": False, + "raccordement": "Direct", + "num_pdl": "00001234567890", + "date_mise_en_service": "2022-12-02", + "observations": "Néant", + "date_maj": "2024-06-04", + "cable_t2_attache": True, + }, + { + "nom_amenageur": "Fastned France", + "siren_amenageur": "853300010", + "contact_amenageur": "support@fastned.nl", + "nom_operateur": "Fastned France", + "contact_operateur": "support@fastned.nl", + "telephone_operateur": "tel:+33-1-84-71-00-62", + "nom_enseigne": "Fastned Aire de la Plaine du Forez Est", + "id_station_itinerance": "FRFASE33004", + "id_station_local": "FRFASE33004", + "nom_station": "Fastned Aire de la Plaine du Forez Est", + "implantation_station": "Station dédiée à la recharge rapide", + "adresse_station": "Aire de la Plaine du Forez A72, 42600 Magneux", + "code_insee_commune": "42130", + "coordonneesXY": "[4.156034, 45.679959]", + "nbre_pdc": 8, + "id_pdc_itinerance": "FRFASE3300403", + "id_pdc_local": "FRFASE3300403", + "puissance_nominale": 20.0, + "prise_type_ef": False, + "prise_type_2": False, + "prise_type_combo_ccs": True, + "prise_type_chademo": True, + "prise_type_autre": False, + "gratuit": False, + "paiement_acte": True, + "paiement_cb": True, + "paiement_autre": True, + "tarification": "0,40€ par KWh pour les non abonnés", + "condition_acces": "Accès libre", + "reservation": False, + "horaires": "24/7", + "accessibilite_pmr": "Accessible mais non réservé PMR", + "restriction_gabarit": "Hauteur maximale 3m", + "station_deux_roues": False, + "raccordement": "Direct", + "num_pdl": "00001234567890", + "date_mise_en_service": "2022-12-02", + "observations": "Néant", + "date_maj": "2024-06-04", + "cable_t2_attache": False, + }, + { + "nom_amenageur": "Fastned France", + "siren_amenageur": "853300010", + "contact_amenageur": "support@fastned.nl", + "nom_operateur": "Fastned France", + "contact_operateur": "support@fastned.nl", + "telephone_operateur": "tel:+33-1-84-71-00-62", + "nom_enseigne": "Fastned Aire de la Plaine du Forez Est", + "id_station_itinerance": "FRFASE33004", + "id_station_local": "FRFASE33004", + "nom_station": "Fastned Aire de la Plaine du Forez Est", + "implantation_station": "Station dédiée à la recharge rapide", + "adresse_station": "Aire de la Plaine du Forez A72, 42600 Magneux", + "code_insee_commune": "42130", + "coordonneesXY": "[4.156034, 45.679959]", + "nbre_pdc": 8, + "id_pdc_itinerance": "FRFASE3300404", + "id_pdc_local": "FRFASE3300404", + "puissance_nominale": 20.0, + "prise_type_ef": False, + "prise_type_2": False, + "prise_type_combo_ccs": True, + "prise_type_chademo": True, + "prise_type_autre": False, + "gratuit": False, + "paiement_acte": True, + "paiement_cb": True, + "paiement_autre": True, + "tarification": "0,40€ par KWh pour les non abonnés", + "condition_acces": "Accès libre", + "reservation": False, + "horaires": "24/7", + "accessibilite_pmr": "Accessible mais non réservé PMR", + "restriction_gabarit": "Hauteur maximale 3m", + "station_deux_roues": False, + "raccordement": "Direct", + "num_pdl": "00001234567890", + "date_mise_en_service": "2022-12-02", + "observations": "Néant", + "date_maj": "2024-06-04", + "cable_t2_attache": False, + }, + { + "nom_amenageur": "Fastned France", + "siren_amenageur": "853300010", + "contact_amenageur": "support@fastned.nl", + "nom_operateur": "Fastned France", + "contact_operateur": "support@fastned.nl", + "telephone_operateur": "tel:+33-1-84-71-00-62", + "nom_enseigne": "Fastned Aire de la Plaine du Forez Est", + "id_station_itinerance": "FRFASE33004", + "id_station_local": "FRFASE33004", + "nom_station": "Fastned Aire de la Plaine du Forez Est", + "implantation_station": "Station dédiée à la recharge rapide", + "adresse_station": "Aire de la Plaine du Forez A72, 42600 Magneux", + "code_insee_commune": "42130", + "coordonneesXY": "[4.156034, 45.679959]", + "nbre_pdc": 8, + "id_pdc_itinerance": "FRFASE3300405", + "id_pdc_local": "FRFASE3300405", + "puissance_nominale": 20.0, + "prise_type_ef": False, + "prise_type_2": False, + "prise_type_combo_ccs": True, + "prise_type_chademo": True, + "prise_type_autre": False, + "gratuit": False, + "paiement_acte": True, + "paiement_cb": True, + "paiement_autre": True, + "tarification": "0,40€ par KWh pour les non abonnés", + "condition_acces": "Accès libre", + "reservation": False, + "horaires": "24/7", + "accessibilite_pmr": "Accessible mais non réservé PMR", + "restriction_gabarit": "Hauteur maximale 3m", + "station_deux_roues": False, + "raccordement": "Direct", + "num_pdl": "00001234567890", + "date_mise_en_service": "2022-12-02", + "observations": "Néant", + "date_maj": "2024-06-04", + "cable_t2_attache": False, + }, + { + "nom_amenageur": "Fastned France", + "siren_amenageur": "853300010", + "contact_amenageur": "support@fastned.nl", + "nom_operateur": "Fastned France", + "contact_operateur": "support@fastned.nl", + "telephone_operateur": "tel:+33-1-84-71-00-62", + "nom_enseigne": "Fastned Aire de la Plaine du Forez Est", + "id_station_itinerance": "FRFASE33004", + "id_station_local": "FRFASE33004", + "nom_station": "Fastned Aire de la Plaine du Forez Est", + "implantation_station": "Station dédiée à la recharge rapide", + "adresse_station": "Aire de la Plaine du Forez A72, 42600 Magneux", + "code_insee_commune": "42130", + "coordonneesXY": "[4.156034, 45.679959]", + "nbre_pdc": 8, + "id_pdc_itinerance": "FRFASE3300406", + "id_pdc_local": "FRFASE3300406", + "puissance_nominale": 20.0, + "prise_type_ef": False, + "prise_type_2": False, + "prise_type_combo_ccs": True, + "prise_type_chademo": True, + "prise_type_autre": False, + "gratuit": False, + "paiement_acte": True, + "paiement_cb": True, + "paiement_autre": True, + "tarification": "0,40€ par KWh pour les non abonnés", + "condition_acces": "Accès libre", + "reservation": False, + "horaires": "24/7", + "accessibilite_pmr": "Accessible mais non réservé PMR", + "restriction_gabarit": "Hauteur maximale 3m", + "station_deux_roues": False, + "raccordement": "Direct", + "num_pdl": "00001234567890", + "date_mise_en_service": "2022-12-02", + "observations": "Néant", + "date_maj": "2024-06-04", + "cable_t2_attache": False, + }, + { + "nom_amenageur": "Fastned France", + "siren_amenageur": "853300010", + "contact_amenageur": "support@fastned.nl", + "nom_operateur": "Fastned France", + "contact_operateur": "support@fastned.nl", + "telephone_operateur": "tel:+33-1-84-71-00-62", + "nom_enseigne": "Fastned Aire de la Plaine du Forez Est", + "id_station_itinerance": "FRFASE33004", + "id_station_local": "FRFASE33004", + "nom_station": "Fastned Aire de la Plaine du Forez Est", + "implantation_station": "Station dédiée à la recharge rapide", + "adresse_station": "Aire de la Plaine du Forez A72, 42600 Magneux", + "code_insee_commune": "42130", + "coordonneesXY": "[4.156034, 45.679959]", + "nbre_pdc": 8, + "id_pdc_itinerance": "FRFASE3300407", + "id_pdc_local": "FRFASE3300407", + "puissance_nominale": 20.0, + "prise_type_ef": False, + "prise_type_2": False, + "prise_type_combo_ccs": True, + "prise_type_chademo": True, + "prise_type_autre": False, + "gratuit": False, + "paiement_acte": True, + "paiement_cb": True, + "paiement_autre": True, + "tarification": "0,40€ par KWh pour les non abonnés", + "condition_acces": "Accès libre", + "reservation": False, + "horaires": "24/7", + "accessibilite_pmr": "Accessible mais non réservé PMR", + "restriction_gabarit": "Hauteur maximale 3m", + "station_deux_roues": False, + "raccordement": "Direct", + "num_pdl": "00001234567890", + "date_mise_en_service": "2022-12-02", + "observations": "Néant", + "date_maj": "2024-06-04", + "cable_t2_attache": False, + }, + { + "nom_amenageur": "Fastned France", + "siren_amenageur": "853300010", + "contact_amenageur": "support@fastned.nl", + "nom_operateur": "Fastned France", + "contact_operateur": "support@fastned.nl", + "telephone_operateur": "tel:+33-1-84-71-00-62", + "nom_enseigne": "Fastned Aire de la Plaine du Forez Est", + "id_station_itinerance": "FRFASE33004", + "id_station_local": "FRFASE33004", + "nom_station": "Fastned Aire de la Plaine du Forez Est", + "implantation_station": "Station dédiée à la recharge rapide", + "adresse_station": "Aire de la Plaine du Forez A72, 42600 Magneux", + "code_insee_commune": "42130", + "coordonneesXY": "[4.156034, 45.679959]", + "nbre_pdc": 8, + "id_pdc_itinerance": "FRFASE3300408", + "id_pdc_local": "FRFASE3300408", + "puissance_nominale": 20.0, + "prise_type_ef": False, + "prise_type_2": False, + "prise_type_combo_ccs": True, + "prise_type_chademo": True, + "prise_type_autre": False, + "gratuit": False, + "paiement_acte": True, + "paiement_cb": True, + "paiement_autre": True, + "tarification": "0,40€ par KWh pour les non abonnés", + "condition_acces": "Accès libre", + "reservation": False, + "horaires": "24/7", + "accessibilite_pmr": "Accessible mais non réservé PMR", + "restriction_gabarit": "Hauteur maximale 3m", + "station_deux_roues": False, + "raccordement": "Direct", + "num_pdl": "00001234567890", + "date_mise_en_service": "2022-12-02", + "observations": "Néant", + "date_maj": "2024-06-04", + "cable_t2_attache": False, + }, + { + "nom_amenageur": "Fastned France", + "siren_amenageur": "853300010", + "contact_amenageur": "support@fastned.nl", + "nom_operateur": "Fastned France", + "contact_operateur": "support@fastned.nl", + "telephone_operateur": "tel:+33-1-84-71-00-62", + "nom_enseigne": "Fastned Aire d’Ambrussum Nord", + "id_station_itinerance": "FRFASE33007", + "id_station_local": "FRFASE33007", + "nom_station": "Fastned Aire d’Ambrussum Nord", + "implantation_station": "Station dédiée à la recharge rapide", + "adresse_station": "Aire d’Ambrussum Nord A9, 34400 Villetelle", + "code_insee_commune": "42130", + "coordonneesXY": "[4.13341, 43.715255]", + "nbre_pdc": 8, + "id_pdc_itinerance": "FRFASE3300701", + "id_pdc_local": "FRFASE3300701", + "puissance_nominale": 20.0, + "prise_type_ef": False, + "prise_type_2": True, + "prise_type_combo_ccs": True, + "prise_type_chademo": True, + "prise_type_autre": True, + "gratuit": False, + "paiement_acte": True, + "paiement_cb": True, + "paiement_autre": True, + "tarification": "0,40€ par KWh pour les non abonnés", + "condition_acces": "Accès libre", + "reservation": False, + "horaires": "24/7", + "accessibilite_pmr": "Accessible mais non réservé PMR", + "restriction_gabarit": "Hauteur maximale 3m", + "station_deux_roues": False, + "raccordement": "Direct", + "num_pdl": "00001234567890", + "date_mise_en_service": "2022-11-22", + "observations": "Néant", + "date_maj": "2024-06-04", + "cable_t2_attache": True, + }, + { + "nom_amenageur": "Fastned France", + "siren_amenageur": "853300010", + "contact_amenageur": "support@fastned.nl", + "nom_operateur": "Fastned France", + "contact_operateur": "support@fastned.nl", + "telephone_operateur": "tel:+33-1-84-71-00-62", + "nom_enseigne": "Fastned Aire d’Ambrussum Nord", + "id_station_itinerance": "FRFASE33007", + "id_station_local": "FRFASE33007", + "nom_station": "Fastned Aire d’Ambrussum Nord", + "implantation_station": "Station dédiée à la recharge rapide", + "adresse_station": "Aire d’Ambrussum Nord A9, 34400 Villetelle", + "code_insee_commune": "42130", + "coordonneesXY": "[4.13341, 43.715255]", + "nbre_pdc": 8, + "id_pdc_itinerance": "FRFASE3300702", + "id_pdc_local": "FRFASE3300702", + "puissance_nominale": 20.0, + "prise_type_ef": False, + "prise_type_2": True, + "prise_type_combo_ccs": True, + "prise_type_chademo": True, + "prise_type_autre": True, + "gratuit": False, + "paiement_acte": True, + "paiement_cb": True, + "paiement_autre": True, + "tarification": "0,40€ par KWh pour les non abonnés", + "condition_acces": "Accès libre", + "reservation": False, + "horaires": "24/7", + "accessibilite_pmr": "Accessible mais non réservé PMR", + "restriction_gabarit": "Hauteur maximale 3m", + "station_deux_roues": False, + "raccordement": "Direct", + "num_pdl": "00001234567890", + "date_mise_en_service": "2022-11-22", + "observations": "Néant", + "date_maj": "2024-06-04", + "cable_t2_attache": True, + }, + ] + } + }