Skip to content

additionalProperties issue in python code generation #2037

Closed
@mtngld

Description

@mtngld

Assume the following definition in a swagger.yaml file:

definitions:
  definition1:
    type: object
    properties:
      prop1:
        type: string
      prop2:
        type: integer
      prop3:
        type: object
        additionalProperties:
          $ref: '#/definitions/definition2'

  defintion2:
    type: object
    properties:
       foo:
          type: string
       bar:
          type: string

I had issues with the to_dict method of defenition1,

solved by adding another test in the to_dict as follows:

def to_dict(self):
        """
        Returns the model properties as a dict
        """
        result = {}
        for attr, _ in iteritems(self.swagger_types):
            value = getattr(self, attr)
            if isinstance(value, list):
                result[attr] = list(map(
                    lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
                    value
                ))
           # *fix start*
            if isinstance(value, dict):
                result[attr] = dict(map(
                    lambda (k,v): (k, v.to_dict()), value.iteritems()))
           # *fix end*
            elif hasattr(value, "to_dict"):
                result[attr] = value.to_dict()
            else:
                result[attr] = value

Not sure how to modify the code generator to create this, or if there is any other way to solve that

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions