-
-
Notifications
You must be signed in to change notification settings - Fork 228
feat: Support for recursive and circular references #582
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
This commit adds support for recursive and circular references in object properties and additionalProperties, but not in allOf. The changes include: -Delayed processing of schema model properties -Cascading removal of invalid schema reference dependencies -Prevention of self import in ModelProperty relative imports -Prevention of forward recursive type reference errors in generated modules -Logging for detection of recursive references in allOf
Previous changes prevented models defined in array schemas from being built properly. This commit fixes that issue and adds support for recursive and circular references in array schema item objects, a behavior that was previously expected but not functioning correctly. This does not add support for recursive and circular references directly in an array schema's 'items' section. However, this feature would be functionally useless, so a warning is logged on detection.
Codecov Report
@@ Coverage Diff @@
## main #582 +/- ##
===========================================
- Coverage 100.00% 99.94% -0.06%
===========================================
Files 49 49
Lines 1713 1816 +103
===========================================
+ Hits 1713 1815 +102
- Misses 0 1 +1
Continue to review full report at Codecov.
|
@maz808 Hello! Thanks for your work and PR! Seems like the generated client doesn’t work due to circular import exceptions. For example: 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:
Brother:
type: object
properties:
sister:
$ref: '#/components/schemas/Sister'
Sister:
type: object
properties:
brother:
$ref: '#/components/schemas/Brother' When I trying to use from example_client.models.sister import Sister
if __name__ == '__main__':
Sister()
Seems like the first problem should be solved in the way that supports circular references. It has several workarounds. But I like the approach to use just one module for storing all models, like module from __future__ import annotations
@attr.s(auto_attribs=True)
class Brother:
…
sister: Union[Unset, Sister] = UNSET
…
@classmethod
def from_dict(cls: Brother, src_dict: Dict[str, Any]) -> Brother:
…
@attr.s(auto_attribs=True)
class Sister:
… @dbanty What do you think about it? |
@dbanty I noticed the release page doesn't acknowledge my contribution to the recursive and nested schema issue. Could I be added to the list of thanks? |
Weird... I remember explicitly adding you. Sorry about that, I'll fix it!! |
@dbanty I thought you had too 🤔 I appreciate it though! Thank you! |
This PR adds support for recursive and circular references in
properties
andadditionalProperties
.Related To/May Close
Known Issues