Exemple #1
0
 def get_object_response_schema(cls):
     return responses.json_content(
         schema.object(created_time=str,
                       id=str,
                       self_uri=str,
                       size=str,
                       version=str,
                       checksums=schema.object(sha1=str, **{'sha-256':
                                                            str}),
                       access_methods=schema.array(
                           schema.object(access_url=schema.optional(
                               schema.object(url=str)),
                                         type=schema.optional(str),
                                         access_id=schema.optional(str)))))
Exemple #2
0
 def list_catalogs(
     self
 ) -> schema.object(
         default_catalog=str,
         catalogs=schema.object(additional_properties=schema.object(
             atlas=str,
             internal=bool,
             plugins=schema.object(additional_properties=schema.object(
                 name=str,
                 sources=schema.optional(schema.array(str)),
             ), )))):
     return {
         'default_catalog': config.default_catalog,
         'catalogs': {
             catalog.name: {
                 'internal': catalog.internal,
                 'atlas': catalog.atlas,
                 'plugins': {
                     plugin_type: {
                         **attr.asdict(plugin),
                         **self._plugin_config(plugin_type, catalog.name)
                     }
                     for plugin_type, plugin in catalog.plugins.items()
                 }
             }
             for catalog in config.catalogs.values()
         }
     }
Exemple #3
0
 def test_complex_object(self):
     self.assertEqual(
         schema.object(git=schema.object(commit=str, dirty=bool),
                       changes=schema.array(
                           schema.object(title='string',
                                         issues=schema.array(str),
                                         upgrade=schema.array(str),
                                         notes=schema.optional(str)))),
         {
             'type': 'object',
             'properties': {
                 'git': {
                     'type': 'object',
                     'properties': {
                         'commit': {
                             'type': 'string'
                         },
                         'dirty': {
                             'type': 'boolean'
                         }
                     },
                     'required': ['commit', 'dirty'],
                     'additionalProperties': False
                 },
                 'changes': {
                     'type': 'array',
                     'items': {
                         'type': 'object',
                         'properties': {
                             'title': {
                                 'type': 'string'
                             },
                             'issues': {
                                 'type': 'array',
                                 'items': {
                                     'type': 'string'
                                 }
                             },
                             'upgrade': {
                                 'type': 'array',
                                 'items': {
                                     'type': 'string'
                                 }
                             },
                             'notes': {
                                 'type': 'string'
                             }
                         },
                         'required': ['title', 'issues', 'upgrade'],
                         'additionalProperties': False
                     }
                 }
             },
             'required': ['git', 'changes'],
             'additionalProperties': False
         })
Exemple #4
0
 def test_misuse(self):
     # Only `object_with` handles required fields via the optional()
     # wrapper.
     try:
         # noinspection PyTypeChecker
         schema.make_type(schema.optional(str))
     except AssertionError as e:
         self.assertIn(schema.optional, e.args)
     else:
         self.fail()
Exemple #5
0
    def test_shared_path_spec(self):
        """
        Assert that, when sharing the path_spec, routes don't overwrite each
        other's properties.
        """
        app = self.app({'foo': 'bar'})
        shared_path_spec = {
            'parameters': [
                params.query('foo', schema.optional({'type': 'string'})),
            ]
        }
        for i in range(2):

            @app.route(f'/swagger-test-{i}',
                       methods=['GET'],
                       cors=True,
                       path_spec=shared_path_spec,
                       method_spec={'summary': f'Swagger test {i}'})
            def swagger_test():
                pass

        method_specs = app.spec()['paths'].values()
        self.assertNotEqual(*method_specs)