Projet

Général

Profil

0001-utils-add-helper-argument-post_json_schema-48308.patch

Benjamin Dauvergne, 06 mai 2021 16:58

Télécharger (13,1 ko)

Voir les différences:

Subject: [PATCH] utils: add helper argument post_json_schema (#48308)

 passerelle/contrib/rsa13/models.py | 254 ++++++++++++-----------------
 passerelle/utils/api.py            |   7 +
 2 files changed, 110 insertions(+), 151 deletions(-)
passerelle/contrib/rsa13/models.py
297 297
        ),
298 298
        display_category=_('Platform'),
299 299
        display_order=3,
300
        post={
301
            'request_body': {
302
                'schema': {
303
                    'application/json': {
304
                        'type': 'object',
305
                        'required': ['nom', 'prenom'],
306
                        'properties': {
307
                            'email': {
308
                                'type': 'string',
309
                                'maxLength': 78,
310
                                'pattern': '^(.*@.*)?$',
311
                            },
312
                            'nom': {
313
                                'type': 'string',
314
                                'maxLength': 28,
315
                            },
316
                            'prenom': {
317
                                'type': 'string',
318
                                'maxLength': 32,
319
                            },
320
                            'tel': {
321
                                'type': 'string',
322
                                'maxLength': 10,
323
                                'pattern': '^[0-9]{0,10}$',
324
                            },
325
                        },
326
                    },
300
        post_json_schema={
301
            'type': 'object',
302
            'required': ['nom', 'prenom'],
303
            'properties': {
304
                'email': {
305
                    'type': 'string',
306
                    'maxLength': 78,
307
                    'pattern': '^(.*@.*)?$',
327 308
                },
328
            }
309
                'nom': {
310
                    'type': 'string',
311
                    'maxLength': 28,
312
                },
313
                'prenom': {
314
                    'type': 'string',
315
                    'maxLength': 32,
316
                },
317
                'tel': {
318
                    'type': 'string',
319
                    'maxLength': 10,
320
                    'pattern': '^[0-9]{0,10}$',
321
                },
322
            },
329 323
        },
330 324
        json_schema_response=response_schema(
331 325
            {
......
406 400
        ),
407 401
        display_category=_('Platform'),
408 402
        display_order=3.5,
409
        post={
410
            'request_body': {
411
                'schema': {
412
                    'application/json': {
413
                        'type': 'object',
414
                        'required': ['nom', 'prenom', 'statut'],
415
                        'properties': {
416
                            'email': {
417
                                'type': 'string',
418
                                'maxLength': 78,
419
                                'pattern': '^(.*@.*)?$',
420
                            },
421
                            'nom': {
422
                                'type': 'string',
423
                                'maxLength': 28,
424
                            },
425
                            'prenom': {
426
                                'type': 'string',
427
                                'maxLength': 32,
428
                            },
429
                            'tel': {
430
                                'type': 'string',
431
                                'maxLength': 10,
432
                                'pattern': '^[0-9]{0,10}$',
433
                            },
434
                            'statut': {'enum': ['C', 'A']},
435
                        },
436
                    },
403
        post_json_schema={
404
            'type': 'object',
405
            'required': ['nom', 'prenom', 'statut'],
406
            'properties': {
407
                'email': {
408
                    'type': 'string',
409
                    'maxLength': 78,
410
                    'pattern': '^(.*@.*)?$',
437 411
                },
438
            }
412
                'nom': {
413
                    'type': 'string',
414
                    'maxLength': 28,
415
                },
416
                'prenom': {
417
                    'type': 'string',
418
                    'maxLength': 32,
419
                },
420
                'tel': {
421
                    'type': 'string',
422
                    'maxLength': 10,
423
                    'pattern': '^[0-9]{0,10}$',
424
                },
425
                'statut': {'enum': ['C', 'A']},
426
            },
439 427
        },
440 428
        json_schema_response=response_schema(),
441 429
    )
......
789 777
        ),
790 778
        display_category=_('Platform'),
791 779
        display_order=5.1,
792
        post={
793
            'request_body': {
794
                'schema': {
795
                    'application/json': {
796
                        'type': 'object',
797
                        'required': ['tel'],
798
                        'properties': {
799
                            'tel': {
800
                                'type': 'string',
801
                                'maxLength': 10,
802
                                'pattern': '^[0-9]{0,10}$',
803
                            },
804
                            'commentaire': {
805
                                'type': 'string',
806
                            },
807
                        },
808
                    },
780
        post_json_schema={
781
            'type': 'object',
782
            'required': ['tel'],
783
            'properties': {
784
                'tel': {
785
                    'type': 'string',
786
                    'maxLength': 10,
787
                    'pattern': '^[0-9]{0,10}$',
809 788
                },
810
            }
789
                'commentaire': {
790
                    'type': 'string',
791
                },
792
            },
811 793
        },
812 794
        json_schema_response=response_schema(),
813 795
    )
......
848 830
        ),
849 831
        display_category=_('Platform'),
850 832
        display_order=5.2,
851
        post={
852
            'request_body': {
853
                'schema': {
854
                    'application/json': {
855
                        'type': 'object',
856
                        'required': ['commentaire'],
857
                        'properties': {
858
                            'commentaire': {
859
                                'type': 'string',
860
                            },
861
                        },
862
                    },
833
        post_json_schema={
834
            'type': 'object',
835
            'required': ['commentaire'],
836
            'properties': {
837
                'commentaire': {
838
                    'type': 'string',
863 839
                },
864
            }
840
            },
865 841
        },
866 842
        json_schema_response=response_schema(),
867 843
    )
......
906 882
        ),
907 883
        display_category=_('Platform'),
908 884
        display_order=5.1,
909
        post={
885
        post_json_schema={
910 886
            'request_body': {
911 887
                'schema': {
912 888
                    'application/json': {
......
962 938
        ),
963 939
        display_category=_('Platform'),
964 940
        display_order=5.2,
965
        post={
966
            'request_body': {
967
                'schema': {
968
                    'application/json': {
969
                        'type': 'object',
970
                        'required': ['commentaire'],
971
                        'properties': {
972
                            'commentaire': {
973
                                'type': 'string',
974
                            },
975
                        },
976
                    },
941
        post_json_schema={
942
            'type': 'object',
943
            'required': ['commentaire'],
944
            'properties': {
945
                'commentaire': {
946
                    'type': 'string',
977 947
                },
978
            }
948
            },
979 949
        },
980 950
        json_schema_response=response_schema(),
981 951
    )
......
1266 1236
        ),
1267 1237
        display_category=_('Platform'),
1268 1238
        display_order=10,
1269
        post={
1270
            'request_body': {
1271
                'schema': {
1272
                    'application/json': {
1273
                        'type': 'object',
1274
                        'properties': {
1275
                            'date_debut': DATE_SCHEMA,
1276
                            'date_fin': DATE_SCHEMA,
1277
                            'moticlodac': {'type': 'string'},
1278
                            'commentaire_ref': {'type': 'string', 'maxLength': 1000},
1279
                        },
1280
                    },
1281
                },
1282
            }
1239
        post_json_schema={
1240
            'type': 'object',
1241
            'properties': {
1242
                'date_debut': DATE_SCHEMA,
1243
                'date_fin': DATE_SCHEMA,
1244
                'moticlodac': {'type': 'string'},
1245
                'commentaire_ref': {'type': 'string', 'maxLength': 1000},
1246
            },
1283 1247
        },
1284 1248
        json_schema_response=response_schema(
1285 1249
            {
......
1575 1539
        ),
1576 1540
        display_category=_('Platform'),
1577 1541
        display_order=13.5,
1578
        post={
1579
            'request_body': {
1580
                'schema': {
1581
                    'application/json': {
1582
                        'type': 'object',
1583
                        'properties': {
1584
                            'motif': {'type': 'string'},
1585
                            'commentaire_ref': {'type': 'string'},
1586
                        },
1587
                    },
1588
                },
1589
            }
1542
        post_json_schema={
1543
            'type': 'object',
1544
            'properties': {
1545
                'motif': {'type': 'string'},
1546
                'commentaire_ref': {'type': 'string'},
1547
            },
1590 1548
        },
1591 1549
        json_schema_response=response_schema(),
1592 1550
    )
......
1628 1586
        ),
1629 1587
        display_category=_('Platform'),
1630 1588
        display_order=14,
1631
        post={
1632
            'request_body': {
1633
                'schema': {
1634
                    'application/json': {
1635
                        'type': 'object',
1636
                        'properties': {
1637
                            'rendezvous': {
1638
                                'type': 'object',
1639
                                'properties': {
1640
                                    'date_prise': DATE_SCHEMA,
1641
                                    'relance': {
1642
                                        'type': 'object',
1643
                                        'properties': {
1644
                                            'date': DATE_SCHEMA,
1645
                                            'motif': {'type': 'string'},
1646
                                        },
1647
                                    },
1648
                                    'date_reelle': DATE_SCHEMA,
1649
                                    'resultat': {'type': 'string'},
1650
                                },
1589
        post_json_schema={
1590
            'type': 'object',
1591
            'properties': {
1592
                'rendezvous': {
1593
                    'type': 'object',
1594
                    'properties': {
1595
                        'date_prise': DATE_SCHEMA,
1596
                        'relance': {
1597
                            'type': 'object',
1598
                            'properties': {
1599
                                'date': DATE_SCHEMA,
1600
                                'motif': {'type': 'string'},
1651 1601
                            },
1652
                            'commentaire_ref': {'type': 'string'},
1653 1602
                        },
1654
                        'unflatten': True,
1603
                        'date_reelle': DATE_SCHEMA,
1604
                        'resultat': {'type': 'string'},
1655 1605
                    },
1656 1606
                },
1657
            }
1607
                'commentaire_ref': {'type': 'string'},
1608
            },
1609
            'unflatten': True,
1658 1610
        },
1659 1611
        json_schema_response=response_schema(
1660 1612
            {
passerelle/utils/api.py
59 59
        display_category='',
60 60
        json_schema_response=None,
61 61
        datasource=False,
62
        post_json_schema=None,
62 63
    ):
63 64
        self.perm = perm
64 65
        self.methods = methods
......
83 84
        self.example_pattern = example_pattern
84 85
        self.parameters = parameters or {}
85 86
        self.cache_duration = cache_duration
87
        if post_json_schema:
88
            # helper to define the POST json schema
89
            post = post or {}
90
            schema = post.setdefault('request_body', {}).setdefault('schema', {})
91
            assert not schema.get('application/json'), 'a json schema was already set in the post argument'
92
            schema['application/json'] = post_json_schema
86 93
        self.post = post
87 94
        if post:
88 95
            self.methods = ['post']
89
-