Exemple #1
0
    def register_views_in_doc(self, app, spec):
        for endpoint, endpoint_auto_doc in self._auto_docs.items():
            doc = OrderedDict()
            for key, auto_doc in endpoint_auto_doc.items():
                # Deepcopy to avoid mutating the source
                # Allows calling this function twice
                endpoint_doc = deepcopy(auto_doc)
                # Format operations documentation in OpenAPI structure
                self._prepare_doc(endpoint_doc, spec.openapi_version)

                # Merge auto_doc and manual_doc into doc
                manual_doc = self._manual_docs[endpoint][key]
                # Tag all operations with Blueprint name
                if 'tags' not in manual_doc:
                    manual_doc['tags'] = []
                manual_doc['tags'].append(self.name)
                doc[key] = deepupdate(endpoint_doc, manual_doc)

            # Thanks to self.route, there can only be one rule per endpoint
            full_endpoint = '.'.join((self.name, endpoint))
            rule = next(app.url_map.iter_rules(full_endpoint))
            # if APISPEC_VERSION_MAJOR < 1:
            #     spec.add_path(rule=rule, operations=doc)
            # else:
            spec.path(rule=rule, operations=doc)
Exemple #2
0
    def test_deepupdate(self):
        """Test deepupdate function

        Taken from http://stackoverflow.com/questions/38987#8310229
        """
        pluto_original = {
            'name': 'Pluto',
            'details': {
                'tail': True,
                'color': 'orange'
            }
        }

        pluto_update = {
            'name': 'Pluutoo',
            'details': {
                'color': 'blue'
            }
        }

        assert deepupdate(pluto_original, pluto_update) == {
            'name': 'Pluutoo',
            'details': {
                'color': 'blue',
                'tail': True
            }
        }
Exemple #3
0
    def path_helper(self, rule, operations=None, **kwargs):
        """Get path from flask Rule and set path parameters in operations"""
        path = self.flaskpath2openapi(rule.rule)

        if operations:
            # Get path parameters
            path_parameters = self.rule_to_params(rule)
            if path_parameters:
                for operation in operations.values():
                    parameters = operation.setdefault('parameters', [])
                    # Add path parameters to documentation, updating if the name already exists
                    for path_p in path_parameters:
                        updated = False
                        for existing in parameters:
                            if getattr(existing, "name",
                                       None) == path_p["name"]:
                                existing = deepupdate(path_p, existing)
                                updated = True
                        if not updated:
                            parameters.append(path_p)

        if APISPEC_VERSION_MAJOR == 0:
            return Path(path=path, operations=operations)
        return path