def test_missing_type_raises_exception(self): transformer = SchemaTransformer() with self.assertRaises(ParameterRequiredError): transformer.transform({ 'type': 'object', 'properties': { 'Foo': { 'description': 'foo', } } })
def assert_schema_transforms_to(self, schema, transforms_to): transformer = SchemaTransformer() actual = transformer.transform(schema) if actual != transforms_to: self.fail( "Transform failed.\n\nExpected:\n%s\n\nActual:\n%s\n" % (pprint.pformat(transforms_to), pprint.pformat(actual)) )
def create_argument_model_from_schema(schema): # Given a JSON schems (described in schema.py), convert it # to a shape object from `botocore.model.Shape` that can be # used as the argument_model for the Argument classes below. transformer = SchemaTransformer() shapes_map = transformer.transform(schema) shape_resolver = model.ShapeResolver(shapes_map) # The SchemaTransformer guarantees that the top level shape # will always be named 'InputShape'. arg_shape = shape_resolver.get_shape_by_name('InputShape') return arg_shape
def create_argument_object(self): """ Create an argument object based on the JSON schema if one is set. After calling this method, ``parameter.argument_object`` is available e.g. for generating docs. """ transformer = SchemaTransformer(self._schema) transformed = transformer.transform() # Set the parameter name from the parsed arg key name transformed.update({"name": self.name}) LOG.debug("Custom parameter schema for {0}: {1}".format(self.name, transformed)) # Select the correct top level type if transformed["type"] == "structure": self.argument_object = StructParameter(None, **transformed) elif transformed["type"] == "list": self.argument_object = ListParameter(None, **transformed) else: raise ValueError("Invalid top level type {0}!".format(transformed["type"]))
def create_argument_object(self): """ Create an argument object based on the JSON schema if one is set. After calling this method, ``parameter.argument_object`` is available e.g. for generating docs. """ transformer = SchemaTransformer(self._schema) transformed = transformer.transform() # Set the parameter name from the parsed arg key name transformed.update({'name': self.name}) LOG.debug('Custom parameter schema for {0}: {1}'.format( self.name, transformed)) # Select the correct top level type if transformed['type'] == 'structure': self.argument_object = StructParameter(None, **transformed) elif transformed['type'] == 'list': self.argument_object = ListParameter(None, **transformed) else: raise ValueError('Invalid top level type {0}!'.format( transformed['type']))
def test_missing_type(self): transformer = SchemaTransformer(MISSING_TYPE) with self.assertRaises(ParameterRequiredError): transformer.transform()
def test_schema(self): transformer = SchemaTransformer(INPUT_SCHEMA) output = transformer.transform() self.assertEqual(output, EXPECTED_OUTPUT)
def test_missing_type_raises_exception(self): transformer = SchemaTransformer() with self.assertRaises(ParameterRequiredError): transformer.transform({"type": "object", "properties": {"Foo": {"description": "foo"}}})
def test_missing_top_level_type_raises_exception(self): transformer = SchemaTransformer() with self.assertRaises(ParameterRequiredError): transformer.transform({})
def assert_schema_transforms_to(self, schema, transforms_to): transformer = SchemaTransformer() actual = transformer.transform(schema) if actual != transforms_to: self.fail("Transform failed.\n\nExpected:\n%s\n\nActual:\n%s\n" % (pprint.pformat(transforms_to), pprint.pformat(actual)))