Exemplo n.º 1
0
    def process_result(self, result, method_name, obj, **kwargs):
        if isinstance(result, openapi.Schema.OR_REF) and is_json_api(
                self.view):
            schema = openapi.resolve_ref(result, self.components)
            self.format_schema(schema)

        return result
 def process_result(self, result, method_name, obj, **kwargs):
     has_examples = hasattr(obj, 'Meta') and hasattr(obj.Meta, 'examples')
     if isinstance(result, openapi.Schema.OR_REF) and has_examples:
         schema = openapi.resolve_ref(result, self.components)
         if 'properties' in schema:
             properties = schema['properties']
             for name in properties.keys():
                 if name in obj.Meta.examples:
                     properties[name]['example'] = obj.Meta.examples[name]
     return result
    def process_result(self, result, method_name, obj, **kwargs):
        has_examples = hasattr(obj, "Meta") and hasattr(obj.Meta, "examples")
        if isinstance(result, openapi.Schema.OR_REF) and has_examples:
            schema = openapi.resolve_ref(result, self.components)
            if "properties" in schema:
                properties = schema["properties"]
                for name in properties.keys():
                    if name in obj.Meta.examples:
                        properties[name]["example"] = obj.Meta.examples[name]

        return result
Exemplo n.º 4
0
    def process_result(self, result, method_name, obj, **kwargs):
        # remove the `title` attribute of all Schema objects
        if isinstance(result, openapi.Schema.OR_REF):
            # traverse any references and alter the Schema object in place
            schema = openapi.resolve_ref(result, self.components)
            schema.pop('title', None)

            # no ``return schema`` here, because it would mean we always generate
            # an inline `object` instead of a definition reference

        # return back the same object that we got - i.e. a reference if we got a reference
        return result
 def process_result(self, result, method_name, obj, **kwargs):
     result = super(ChoiceDescriptionInspector,
                    self).process_result(result, method_name, obj, **kwargs)
     if isinstance(result, openapi.Schema.OR_REF) and hasattr(
             obj, "choices"):
         schema = openapi.resolve_ref(result, self.components)
         desc = schema.get("description", "")
         if desc:
             desc += "\n\n"
         desc += "\n".join("* `{}` - {}".format(k, v)
                           for k, v in obj.choices.items())
         schema["description"] = desc
     return result
Exemplo n.º 6
0
    def format_schema(self, schema):
        """Recursively format property names for the given schema according to``JSON_API_FORMAT_KEYS`` setting.
        The target schema object must be modified in-place.

        :param openapi.Schema schema: the :class:`.Schema` object
        """
        if getattr(schema, 'properties', {}):
            schema.properties = OrderedDict(
                (self.format_string(key),
                 self.format_schema(openapi.resolve_ref(val, self.components))
                 or val) for key, val in schema.properties.items())

            if getattr(schema, 'required', []):
                schema.required = [
                    self.format_string(p) for p in schema.required
                ]
Exemplo n.º 7
0
    def process_result(self, result, method_name, obj, **kwargs):
        # obj.Meta.examples 에 접근할 수 없다면 예시를 넣을 수 없습니다.
        has_examples = hasattr(obj, 'Meta') and hasattr(obj.Meta, 'examples')
        if isinstance(result, openapi.Schema.OR_REF) and has_examples:
            schema = openapi.resolve_ref(result, self.components)
            # properties가 정의되지 않은 경우엔 할 수 있는게 없습니다.
            if 'properties' in schema:
                properties = schema['properties']
                for name in properties.keys():
                    # 예시를 정해둔 필드만 손댑니다.
                    if name in obj.Meta.examples:
                        properties[name]['example'] = obj.Meta.examples[name]

        # schema를 return하면 안 됩니다.
        # 위에서 schema를 수정해도 reference되어서 result에 반영됩니다.
        return result
Exemplo n.º 8
0
    def process_result(self, result, method_name, obj, **kwargs):
        if not isinstance(result, openapi.Schema.OR_REF):
            return result

        if not isinstance(obj, GegevensGroepSerializer):
            return result

        if method_name != "field_to_swagger_object":
            return result

        if not obj.allow_null:
            return result

        schema = openapi.resolve_ref(result, self.components)
        schema.x_nullable = True

        return result
Exemplo n.º 9
0
    def transform_operation(self, operation, resolver):
        operation_id = operation["operationId"]
        if not operation_id.endswith(self._operation_name):
            return operation

        responses = operation["responses"]
        for code, params in self._extra_fields.items():
            if code in responses:
                original_schema = responses[code]["schema"]
                schema = original_schema if type(
                    original_schema) is Schema else resolve_ref(
                        original_schema, resolver)
                schema = copy.deepcopy(schema)

                for name, param in params.items():
                    schema["properties"][name] = resolve_lazy_ref(
                        param, resolver)
                responses[code]["schema"] = schema
        return operation
Exemplo n.º 10
0
 def _get_schema(self, serializer, schema_ref=None):
     if schema_ref is None:
         schema_ref = self._get_schema_ref(serializer)
     schema = openapi.resolve_ref(schema_ref, self.components)
     return schema