def test_accepts_custom_schema_generator(self): call_command('generateschema', '--generator_class={}.{}'.format( __name__, CustomSchemaGenerator.__name__), stdout=self.out) out_json = yaml.safe_load(self.out.getvalue()) assert out_json == CustomSchemaGenerator.SCHEMA
def test_renders_default_schema_with_custom_title_url_and_description(self): call_command('generateschema', '--title=SampleAPI', '--url=http://api.sample.com', '--description=Sample description', stdout=self.out) # Check valid YAML was output. schema = yaml.safe_load(self.out.getvalue()) assert schema['openapi'] == '3.0.2'
def parse(self, stream, media_type=None, parser_context=None): """ Returns a 2-tuple of `(data, files)`. `data` will be an object which is the parsed content of the response. `files` will always be `None`. """ try: return yaml.safe_load(stream) except (ValueError, yaml.parser.ParserError), exc: raise ParseError('YAML parse error - %s' % unicode(exc))
def parse(self, stream, media_type=None, parser_context=None): """ Parses the incoming bytestream as YAML and returns the resulting data. """ assert yaml, 'YAMLParser requires pyyaml to be installed' parser_context = parser_context or {} encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET) try: data = stream.read().decode(encoding) return yaml.safe_load(data) except (ValueError, yaml.parser.ParserError) as exc: raise ParseError('YAML parse error - %s' % six.text_type(exc))
def parse(self, stream, media_type=None, parser_context=None): """ Returns a 2-tuple of `(data, files)`. `data` will be an object which is the parsed content of the response. `files` will always be `None`. """ parser_context = parser_context or {} encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET) try: data = stream.read().decode(encoding) return yaml.safe_load(data) except (ValueError, yaml.parser.ParserError) as exc: raise ParseError('YAML parse error - %s' % six.u(exc))
def parse(self, stream, media_type=None, parser_context=None): """ Returns a 2-tuple of `(data, files)`. `data` will be an object which is the parsed content of the response. `files` will always be `None`. """ assert yaml, 'YAMLParser requires pyyaml to be installed' parser_context = parser_context or {} encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET) try: data = stream.read().decode(encoding) return yaml.safe_load(data) except (ValueError, yaml.parser.ParserError) as exc: raise ParseError('YAML parse error - %s' % six.u(exc))