toulouse-maelis: invert oneOf schema order to get explicit error messages (#70851)

This commit is contained in:
Nicolas Roche 2022-10-23 15:25:46 +02:00
parent c25007919b
commit 2a60072e53
2 changed files with 75 additions and 61 deletions

View File

@ -75,11 +75,11 @@ ADDRESS_SCHEMA = {
'properties': {
'num': {
'description': 'numéro',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'numComp': {
'description': 'Complément du numéro (depuis référentiel)',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'street1': {
'description': 'Libellé de la voie',
@ -87,7 +87,7 @@ ADDRESS_SCHEMA = {
},
'street2': {
'description': 'Complément de la voie',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'town': {
'description': 'Ville',
@ -111,15 +111,15 @@ CONTACT_SCHEMA = {
'properties': {
'phone': {
'description': 'Téléphone',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'mobile': {
'description': 'Portable',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'mail': {
'description': 'Mail',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'isContactMail': {
'description': 'Accepte de recevoir des mails',
@ -149,19 +149,19 @@ ADDRESSPROF_SCHEMA = {
'properties': {
'num': {
'description': "Numéro de l'adresse",
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'street': {
'description': 'Nom de la voie',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'town': {
'description': 'Ville',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'zipcode': {
'description': 'Code postal',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
},
@ -179,19 +179,19 @@ PROFESSION_SCHEMA = {
'properties': {
'codeCSP': {
'description': 'Catégorie socio-professionnelle (depuis référentiel)',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'profession': {
'description': 'Profession',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'employerName': {
'description': "Nom de l'employeur",
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'phone': {
'description': 'Téléphone',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'addressPro': ADDRESSPROF_SCHEMA,
},
@ -210,11 +210,11 @@ CAFINFO_SCHEMA = {
'properties': {
'number': {
'description': "Numéro d'allocataire",
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'organ': {
'description': "Nom de l'organisme (depuis référentiel)",
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
},
@ -261,7 +261,7 @@ CHILDBIRTH_SCHEMA = {
},
'place': {
'description': 'Lieu de naissance',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
}
@ -287,31 +287,31 @@ FSL_SCHEMA = {
},
'allergieAlimentaire': {
'description': 'Allergie alimentaire',
'oneOf': [{'type': 'null'}] + BOOLEAN_TYPES,
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'allergieRespiratoire': {
'description': 'Allergie respiratoire',
'oneOf': [{'type': 'null'}] + BOOLEAN_TYPES,
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'allergieAutre': {
'description': 'Allergie autre',
'oneOf': [{'type': 'null'}] + BOOLEAN_TYPES,
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'allergieMedicament': {
'description': 'Allergie médicament',
'oneOf': [{'type': 'null'}] + BOOLEAN_TYPES,
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'asthme': {
'description': 'Asthmatique',
'oneOf': [{'type': 'null'}] + BOOLEAN_TYPES,
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'flPAI': {
'description': 'PAI',
'oneOf': [{'type': 'null'}] + BOOLEAN_TYPES,
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'flImage': {
'description': 'Autorisation photo',
'oneOf': [{'type': 'null'}] + BOOLEAN_TYPES,
'oneOf': BOOLEAN_TYPES + [{'type': 'null'}],
},
'dtcPrap1': {
'description': 'Date du dernier rappel DT Polio',
@ -320,47 +320,47 @@ FSL_SCHEMA = {
},
'obsMed1': {
'description': 'Observation médecin 1',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsMed2': {
'description': 'Observation médecin 2',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsMed3': {
'description': 'Observation médecin 3',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsDir1': {
'description': 'Observation directeur 1',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsDir2': {
'description': 'Observation directeur 2',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsDir3': {
'description': 'Observation directeur 3',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsAssist1': {
'description': 'Observation assistant sanitaire 1',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsAssist2': {
'description': 'Observation assistant sanitaire 2',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'obsAssist3': {
'description': 'Observation assistant sanitaire 3',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'cons1Med': {
'description': 'Conseil médecin 1',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'cons2Med': {
'description': 'Conseil médecin 2',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
'additionalProperties': False,
@ -376,15 +376,15 @@ DOCTORADDRESS_SCHEMA = {
'properties': {
'street1': {
'description': 'Libellé de la voie',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'town': {
'description': 'Ville',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'zipcode': {
'description': 'Code postal',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
}
@ -397,11 +397,11 @@ FAMILYDOCTOR_SCHEMA = {
'properties': {
'name': {
'description': 'Nom',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'phone': {
'description': 'Téléphone',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'address': DOCTORADDRESS_SCHEMA,
},
@ -415,11 +415,11 @@ VACCIN_SCHEMA = {
'properties': {
'code': {
'description': 'Code du vaccin (depuis référentiel)',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'label': {
'description': 'Nom du vaccin',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'vaccinationDate': {
'description': 'Date du vaccin',
@ -434,23 +434,23 @@ MEDICALRECORD_SCHEMA = {
'title': 'Medical record',
'description': "Informations médicales",
'oneOf': [
{'type': 'null'},
{
'type': 'object',
'properties': {
'familyDoctor': FAMILYDOCTOR_SCHEMA,
'vaccinList': {
'oneOf': [
{'type': 'null'},
{
'type': 'array',
'items': VACCIN_SCHEMA,
},
{'type': 'null'},
],
},
},
'additionalProperties': False,
},
{'type': 'null'},
],
'unflatten': True,
}
@ -460,7 +460,6 @@ PAIINFO_SCHEMA = {
'title': 'PAI',
'description': "Informations médicales",
'oneOf': [
{'type': 'null'},
{
'type': 'object',
'required': ['code'],
@ -482,11 +481,12 @@ PAIINFO_SCHEMA = {
},
'description': {
'description': 'Texte libre de description (max 500 caractères)',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
'additionalProperties': False,
},
{'type': 'null'},
],
}
@ -509,7 +509,7 @@ CHILD_SCHEMA = {
'birth': CHILDBIRTH_SCHEMA,
'dietcode': {
'description': 'Code de régime alimentaire (depuis référentiel)',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'bPhoto': {
'description': 'Autorisation photo',
@ -532,24 +532,24 @@ CONTACTLIGHT_SCHEMA = {
'title': 'Contact light',
'description': "Informations de contact pour les personnes autorisées à récupérer les enfants ou à prévenir en cas d'urgence",
'oneOf': [
{'type': 'null'},
{
'type': 'object',
'properties': {
'phone': {
'description': 'Téléphone',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'mobile': {
'description': 'Portable',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'mail': {
'description': 'Mail',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
},
},
{'type': 'null'},
],
}
@ -562,7 +562,7 @@ FAMILYPERSON_SCHEMA = {
'properties': {
'civility': {
'description': 'civilité (depuis référentiel)',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'quality': {
'description': 'Qualité',
@ -571,7 +571,7 @@ FAMILYPERSON_SCHEMA = {
},
'sexe': {
'description': 'Sexe (depuis référentiel)',
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'contact': CONTACTLIGHT_SCHEMA,
},
@ -588,11 +588,11 @@ AUTHORIZEDPERSON_SCHEMA = {
'properties': {
'personList': {
'oneOf': [
{'type': 'null'},
{
'type': 'array',
'items': FAMILYPERSON_SCHEMA,
},
{'type': 'null'},
],
},
},
@ -621,43 +621,43 @@ UPDATE_FAMILY_SCHEMA = {
},
'nbChild': {
'description': "Nombre d'enfants à charge",
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'nbTotalChild': {
'description': "Nombre total d'enfants",
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'nbAES': {
'description': "Nombre d'AES",
'oneOf': [{'type': 'null'}, {'type': 'string'}],
'oneOf': [{'type': 'string'}, {'type': 'null'}],
},
'rl1': RLINFO_SCHEMA,
'rl2': RLINFO_SCHEMA,
'authorizedPersonList': {
'oneOf': [
{'type': 'null'},
{
'type': 'array',
'items': AUTHORIZEDPERSON_SCHEMA,
},
{'type': 'null'},
],
},
'emergencyPersonList': {
'oneOf': [
{'type': 'null'},
{
'type': 'array',
'items': AUTHORIZEDPERSON_SCHEMA,
},
{'type': 'null'},
],
},
'childList': {
'oneOf': [
{'type': 'null'},
{
'type': 'array',
'items': CHILD_SCHEMA,
},
{'type': 'null'},
],
},
},
@ -667,7 +667,7 @@ UPDATE_FAMILY_SCHEMA = {
CREATE_FAMILY_SCHEMA = copy.deepcopy(UPDATE_FAMILY_SCHEMA)
CREATE_FAMILY_SCHEMA['required'] = ['rl1', 'categorie', 'situation']
create_family_child_schema = CREATE_FAMILY_SCHEMA['properties']['childList']['oneOf'][1]['items']
create_family_child_schema = CREATE_FAMILY_SCHEMA['properties']['childList']['oneOf'][0]['items']
del create_family_child_schema['properties']['fsl']
del create_family_child_schema['properties']['bPhoto']
del create_family_child_schema['properties']['bLeaveAlone']

View File

@ -2586,6 +2586,20 @@ def test_update_child_pai(mocked_post, mocked_get, con, app):
assert resp.json['data'] == 'ok'
def test_update_child_pai_wrong_payload_type_error(con, app):
url = get_endpoint('update-child-pai')
params = {
'code': 'PAIALI',
'dateDeb': '2022-01-01',
'dateFin': '',
'description': 42,
}
resp = app.post_json(url + '?NameID=local&child_id=613878', params=params, status=400)
assert resp.json['err'] == 1
assert resp.json['err_desc'] == "42 is not of type 'string'"
def test_update_child_pai_empty_referential_key_error(con, app):
url = get_endpoint('update-child-pai')
params = {