Ejemplo n.º 1
0
    def __init__(self, obj, exampilator=None, examples=None):
        self.exampilator = exampilator or Exampilator
        assert issubclass(self.exampilator, Exampilator)

        if examples:
            try:
                self.exampilator.schema_validate(examples,
                                                 examples_json_schema)
            except ValidationError as err:
                raise ConverterError(err.message)
            self.exampilator.fill_examples(examples)

        if obj.get('swagger') != '2.0':
            raise ConverterError('Invalid Swagger version')

        self._fill_root_parameters(obj)
        self._fill_schemas_from_definitions(obj)
        self._fill_parameter_definitions(obj)
        self._fill_response_definitions(obj)
        self._fill_security_definitions(obj)
        self._fill_securities(obj)
        self._fill_operations(obj)
Ejemplo n.º 2
0
    def __init__(self, obj, exampilator=None, examples=None):
        if obj['swagger'] != '2.0':
            raise ConverterError('Invalid Swagger version')

        self.raw = obj
        self.exampilator = exampilator or Exampilator
        assert issubclass(self.exampilator, Exampilator)
        if examples:
            try:
                self.exampilator.schema_validate(examples,
                                                 examples_json_schema)
            except ValidationError as err:
                raise ConverterError(err.message)

            self.exampilator.fill_examples(examples)

        if 'definitions' in obj:
            self._fill_schemas_from_definitions(obj['definitions'])

        if 'parameters' in obj:
            self._fill_parameter_definitions(obj['parameters'])

        if 'responses' in obj:
            self._fill_response_definitions(obj['responses'])

        if 'securityDefinitions' in obj:
            self._fill_security_definitions(obj['securityDefinitions'])

        if 'security' in obj:
            self._fill_securities(obj['security'])

        self.info = obj['info']
        self.host = obj.get('host', '')
        self.base_path = obj.get('basePath', '')
        self.consumes = obj.get('consumes', ['application/json'])
        self.produces = obj.get('produces', ['application/json'])
        self.schemes = obj.get('schemes', ['http'])
        self._fill_operations()
        self.external_docs = obj.get('externalDocs')
Ejemplo n.º 3
0
    def _set_type(self):
        self._type = self.raw['type']
        if self._type not in PRIMITIVE_TYPES and self._type != 'array':
            raise ConverterError('Invalid type of response header {}'.format(
                self.name))

        self.type_format = self.raw.get('format')
        if self.is_array:
            self.item = dict(
                zip(('type', 'type_format', 'type_properties'),
                    self.get_type_properties(self.raw['items'], self.name)))
        else:
            _, _, self.properties = self.get_type_properties(
                self.raw, self.name)
Ejemplo n.º 4
0
 def _fill_parameters(self, params, path_params):
     self.parameters = []
     for obj in params:
         if '$ref' in obj:
             self.parameters.append(
                 self.root.parameter_definitions[obj['$ref']])
         else:
             self.parameters.append(
                 Parameter(obj, name=obj['name'], root=self.root))
     if path_params:
         self.parameters += path_params
     if len(self.get_parameters_by_location(['body'])) > 1:
         raise ConverterError(
             'Invalid source file: More than one body parameters in %s' %
             self.path)
Ejemplo n.º 5
0
 def _set_type(self):
     if 'type' in self.raw:
         self._type = self.raw['type']
         self.type_format = self.raw.get('format')
         if self.is_array:
             self.item = dict(
                 zip(('type', 'type_format', 'type_properties'),
                     self.get_type_properties(self.raw['items'],
                                              self.name)))
         else:
             _, _, self.properties = self.get_type_properties(
                 self.raw, self.name)
     elif 'schema' in self.raw:
         self.set_type_by_schema(self.raw['schema'], SchemaTypes.INLINE)
     else:
         raise ConverterError('Invalid structure')