Bladeren bron

merge autoref-compat code

Guénaël Muller 6 jaren geleden
bovenliggende
commit
0544ab69c0
1 gewijzigde bestanden met toevoegingen van 22 en 13 verwijderingen
  1. 22 13
      hapic/doc.py

+ 22 - 13
hapic/doc.py Bestand weergeven

20
     description: ControllerDescription,
20
     description: ControllerDescription,
21
 ):
21
 ):
22
     method_operations = dict()
22
     method_operations = dict()
23
-
23
+    # TODO : Convert many=True in list of elems
24
     # schema based
24
     # schema based
25
     if description.input_body:
25
     if description.input_body:
26
-        schema_class = type(description.input_body.wrapper.processor.schema)
26
+        schema_class = spec.schema_class_resolver(
27
+            description.input_body.wrapper.processor.schema)
27
         method_operations.setdefault('parameters', []).append({
28
         method_operations.setdefault('parameters', []).append({
28
             'in': 'body',
29
             'in': 'body',
29
             'name': 'body',
30
             'name': 'body',
30
             'schema': {
31
             'schema': {
31
-                '$ref': '#/definitions/{}'.format(schema_class.__name__)
32
+                '$ref': '#/definitions/{}'.format(
33
+                    spec.schema_name_resolver(schema_class))
32
             }
34
             }
33
         })
35
         })
34
 
36
 
35
     if description.output_body:
37
     if description.output_body:
36
-        schema_class = type(description.output_body.wrapper.processor.schema)
38
+        schema_class = spec.schema_class_resolver(
39
+            description.output_body.wrapper.processor.schema)
37
         method_operations.setdefault('responses', {})\
40
         method_operations.setdefault('responses', {})\
38
             [int(description.output_body.wrapper.default_http_code)] = {
41
             [int(description.output_body.wrapper.default_http_code)] = {
39
                 'description': str(int(description.output_body.wrapper.default_http_code)),  # nopep8
42
                 'description': str(int(description.output_body.wrapper.default_http_code)),  # nopep8
40
                 'schema': {
43
                 'schema': {
41
-                    '$ref': '#/definitions/{}'.format(schema_class.__name__)
44
+                    '$ref': '#/definitions/{}'.format(
45
+                        spec.schema_name_resolver(schema_class)
46
+                    )
42
                 }
47
                 }
43
             }
48
             }
44
 
49
 
58
                 [int(error.wrapper.http_code)] = {
63
                 [int(error.wrapper.http_code)] = {
59
                     'description': str(int(error.wrapper.http_code)),
64
                     'description': str(int(error.wrapper.http_code)),
60
                     'schema': {
65
                     'schema': {
61
-                        '$ref': '#/definitions/{}'.format(schema_class.__name__)  # nopep8
66
+                        '$ref': '#/definitions/{}'.format(
67
+                            spec.schema_name_resolver(schema_class)
68
+                        )
62
                     }
69
                     }
63
                 }
70
                 }
64
 
71
 
65
     # jsonschema based
72
     # jsonschema based
66
     if description.input_path:
73
     if description.input_path:
67
-        schema_class = type(description.input_path.wrapper.processor.schema)
74
+        schema_class = spec.schema_class_resolver(
75
+            description.input_path.wrapper.processor.schema)
68
         # TODO: look schema2parameters ?
76
         # TODO: look schema2parameters ?
69
         jsonschema = schema2jsonschema(schema_class, spec=spec)
77
         jsonschema = schema2jsonschema(schema_class, spec=spec)
70
         for name, schema in jsonschema.get('properties', {}).items():
78
         for name, schema in jsonschema.get('properties', {}).items():
76
             })
84
             })
77
 
85
 
78
     if description.input_query:
86
     if description.input_query:
79
-        schema_class = type(description.input_query.wrapper.processor.schema)
87
+        schema_class = spec.schema_class_resolver(
88
+            description.input_query.wrapper.processor.schema)
80
         jsonschema = schema2jsonschema(schema_class, spec=spec)
89
         jsonschema = schema2jsonschema(schema_class, spec=spec)
81
         for name, schema in jsonschema.get('properties', {}).items():
90
         for name, schema in jsonschema.get('properties', {}).items():
82
             method_operations.setdefault('parameters', []).append({
91
             method_operations.setdefault('parameters', []).append({
131
             plugins=(
140
             plugins=(
132
                 'apispec.ext.marshmallow',
141
                 'apispec.ext.marshmallow',
133
             ),
142
             ),
134
-            schema_name_resolver=generate_schema_name,
143
+            auto_referencing=True,
135
         )
144
         )
136
 
145
 
137
         schemas = []
146
         schemas = []
140
             description = controller.description
149
             description = controller.description
141
 
150
 
142
             if description.input_body:
151
             if description.input_body:
143
-                schemas.append(type(
152
+                schemas.append(spec.schema_class_resolver(
144
                     description.input_body.wrapper.processor.schema
153
                     description.input_body.wrapper.processor.schema
145
                 ))
154
                 ))
146
 
155
 
147
             if description.input_forms:
156
             if description.input_forms:
148
-                schemas.append(type(
157
+                schemas.append(spec.schema_class_resolver(
149
                     description.input_forms.wrapper.processor.schema
158
                     description.input_forms.wrapper.processor.schema
150
                 ))
159
                 ))
151
 
160
 
152
             if description.output_body:
161
             if description.output_body:
153
-                schemas.append(type(
162
+                schemas.append(spec.schema_class_resolver(
154
                     description.output_body.wrapper.processor.schema
163
                     description.output_body.wrapper.processor.schema
155
                 ))
164
                 ))
156
 
165
 
159
                     schemas.append(type(error.wrapper.error_builder))
168
                     schemas.append(type(error.wrapper.error_builder))
160
 
169
 
161
         for schema in set(schemas):
170
         for schema in set(schemas):
162
-            spec.definition(schema.__name__, schema=schema)
171
+            spec.definition(spec.schema_name_resolver(schema), schema=schema)
163
 
172
 
164
         # add views
173
         # add views
165
         # with app.test_request_context():
174
         # with app.test_request_context():