Skip to content

feat: support for recursive and circular references #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

mtovts
Copy link
Contributor

@mtovts mtovts commented Aug 13, 2021

This PR aims to support references to schemas that have not been processed yet. Please see #466.

Strategy is to create models for indirect references without properties. And fill in the properties later.
It seems related with #419. There is also support for recursive references. See example below.

Example OpenAPI:

openapi: 3.0.3
info:
  title: 'Example'
  version: 0.1.0
servers:
  - url: 'http://example.com'
paths:
  '/foo':
    delete:
      responses:
        '200':
          description: OK
components:
  schemas:
    Matryoshka:
      type: object
      properties:
        inner_matryoshka:
          $ref: '#/components/schemas/Matryoshka'

From this OpenAPI generator produces following code:

T = TypeVar("T", bound="Matryoshka")


@attr.s(auto_attribs=True)
class Matryoshka:
    """ """

    inner_matryoshka: Union[Unset, T] = UNSET

I didn't write tests for this PR because I want to wait for feedback first. I will do so if this strategy is approved. All but one of the current tests passed. It was removed because the behavior changed.

@dbanty
Copy link
Collaborator

dbanty commented Aug 14, 2021

@mtovts there was already support for forward references, just not recursive or circular references. I haven't read through this yet but my guess is there is overlap with the current forward references support and should be some refactoring to reduce excess work.

See build_schemas in parser.properties, there is a top loop called while still_making_progess.

@mtovts mtovts changed the title feat: support references to unprocessed schemas feat: support for recursive and circular references Aug 15, 2021
@dbanty
Copy link
Collaborator

dbanty commented Oct 17, 2021

Closing per a comment that says this won't be completed: #466 (comment)

@dbanty dbanty closed this Oct 17, 2021
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