Browse Source

add many support for input/output body

Guénaël Muller 6 years ago
parent
commit
6113b2c5de
1 changed files with 26 additions and 20 deletions
  1. 26 20
      hapic/doc.py

+ 26 - 20
hapic/doc.py View File

@@ -14,42 +14,48 @@ from hapic.decorator import DecoratedController
14 14
 from hapic.description import ControllerDescription
15 15
 
16 16
 
17
+def generate_schema_ref(spec, schema):
18
+    schema_class = spec.schema_class_resolver(
19
+        spec,
20
+        schema
21
+    )
22
+    ref = {
23
+        '$ref': '#/definitions/{}'.format(
24
+            spec.schema_name_resolver(schema_class)
25
+        )
26
+    }
27
+    if schema.many:
28
+        ref = {
29
+            'type': 'array',
30
+            'items': ref
31
+        }
32
+    return ref
33
+
34
+
17 35
 def bottle_generate_operations(
18 36
     spec,
19 37
     route: RouteRepresentation,
20 38
     description: ControllerDescription,
21 39
 ):
22 40
     method_operations = dict()
23
-    # TODO : Convert many=True in list of elems
24
-    # schema based
25 41
     if description.input_body:
26
-        schema_class = spec.schema_class_resolver(
27
-            spec,
28
-            description.input_body.wrapper.processor.schema
29
-        )
30 42
         method_operations.setdefault('parameters', []).append({
31 43
             'in': 'body',
32 44
             'name': 'body',
33
-            'schema': {
34
-                '$ref': '#/definitions/{}'.format(
35
-                    spec.schema_name_resolver(schema_class)
36
-                )
37
-            }
45
+            'schema': generate_schema_ref(
46
+                spec,
47
+                description.input_body.wrapper.processor.schema,
48
+            )
38 49
         })
39 50
 
40 51
     if description.output_body:
41
-        schema_class = spec.schema_class_resolver(
42
-            spec,
43
-            description.output_body.wrapper.processor.schema
44
-        )
45 52
         method_operations.setdefault('responses', {})\
46 53
             [int(description.output_body.wrapper.default_http_code)] = {
47 54
                 'description': str(int(description.output_body.wrapper.default_http_code)),  # nopep8
48
-                'schema': {
49
-                    '$ref': '#/definitions/{}'.format(
50
-                        spec.schema_name_resolver(schema_class)
51
-                    )
52
-                }
55
+                'schema': generate_schema_ref(
56
+                    spec,
57
+                    description.output_body.wrapper.processor.schema,
58
+                )
53 59
             }
54 60
 
55 61
     if description.output_file: