Skip to content

Conversation

straz
Copy link

@straz straz commented Oct 11, 2022

The codegen algorithm has a bug when it descends into UnionProperties with an anonymous object as an inner type. Example:

    FieldValueWithResolution:
      oneOf:
        - type: string
        - type: boolean
        - type: number
        - type: array
        - type: object

The codegen used to be forgiving because it would always return an instance of FieldValueWithResolution(additional_properties=...) without any attempt to get the nested structure correct.
Now that we are generating typevars, the broken recursion is generating children with the same name
as the parent, which results in this output:

FieldValueWithResolution = Union[str, bool, float, List[str], FieldValueWithResolution, UnknownType]

A correct fix would overhaul the recursive parser, much more than we can afford to do for now.
A reasonable quick fix is to add a filter on the get_type_strings() method to filter out children with the same name as the parent:

FieldValueWithResolution = Union[str, bool, float, List[str], UnknownType]

Copy link

@alexrejto alexrejto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@straz straz merged commit c380c1e into main Oct 11, 2022
@straz straz deleted the bugfix-dedupe-union-typestrings branch October 11, 2022 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants