Skip to content

Support references to non-object types #371

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

Closed
p1-alexandrevaney opened this issue Mar 31, 2021 · 4 comments · Fixed by #425
Closed

Support references to non-object types #371

p1-alexandrevaney opened this issue Mar 31, 2021 · 4 comments · Fixed by #425
Labels
✨ enhancement New feature or improvement

Comments

@p1-alexandrevaney
Copy link

Describe the bug
root component schemas do not get parsed correctly, resolved to None

To Reproduce
Steps to reproduce the behavior:
openapi-python-client generate --path path_to_test.yaml

Expected behavior
The generated model Link should have href: Union[Unset, str] = UNSET as attribute
instead we have href: Union[Unset, None] = UNSET

OpenAPI Spec File

openapi: 3.0.0

info:
  version: '1'
  title: 'test file'
  description: 'description'

paths: {}

components:
  schemas:
    Link:
      type: object
      properties:
        href:
          Uri:
            type: string

Desktop (please complete the following information):

  • OS: Ubuntu 20.04
  • Python Version: 3.8.5
  • openapi-python-client version: up to date with main

Additional context

I am trying to build a 5g stack with the open source 5g api. This file in particular contains a lot of components schemas that get resolved to None

https://github.com/jdegre/5GC_APIs/blob/master/TS29571_CommonData.yaml

For example the Uri components is translated to

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

    additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

which does not seem right as it is only a type:string component

@p1-alexandrevaney p1-alexandrevaney added the 🐞bug Something isn't working label Mar 31, 2021
@dbanty
Copy link
Collaborator

dbanty commented Mar 31, 2021

@p1-alexandrevaney I don't think I understand the example spec.

components:
  schemas:
    Link:
      type: object
      properties:
        href:
          Uri:
            type: string

Shouldn't type: string be directly part of the href property? What is Uri supposed to do?

@p1-alexandrevaney
Copy link
Author

p1-alexandrevaney commented Mar 31, 2021

The real world example is this:

https://github.com/jdegre/5GC_APIs/blob/master/TS29571_CommonData.yaml#L296

    Link:
      type: object
      properties:
        href:
          $ref: '#/components/schemas/Uri'

It has a ref to https://github.com/jdegre/5GC_APIs/blob/master/TS29571_CommonData.yaml#L182

    Uri:
      type: string

So i figured it should be resolved to

    Link:
      type: object
      properties:
        href:
          Uri:
            type: string

A simpler example would be to just have

    Link:
      type: string

During the generation, the type=string will be ignored and the model will be

ModelProperty(name='Link', required=True, nullable=False, default=None, python_name='link', reference=Reference(class_name='Link', module_name='link'), required_properties=[], optional_properties=[], description='', relative_imports=set(), additional_properties=True)

@dbanty
Copy link
Collaborator

dbanty commented Mar 31, 2021

Ah, our reference resolution is pretty barebones right now and I think only supports references to objects (not basic types), so that's probably the issue.

@dbanty dbanty changed the title api components schema get parsed to empty schemas Support references to non-object types Mar 31, 2021
@dbanty dbanty added ✨ enhancement New feature or improvement and removed 🐞bug Something isn't working labels Mar 31, 2021
@dbanty
Copy link
Collaborator

dbanty commented Mar 31, 2021

No one should try to do this until #366 is done though, since that big rework of reference resolution will conflict with anything else related.

dbanty added a commit that referenced this issue May 13, 2021
][#425]. Thanks @p1-ra!

* parser / properties / do not restrict reference pointer type to `enum` or `object`

* e2e / update `openapi.json` and golden-record

* tpl / model / add missing typing import: `Tuple,Optional,BinaryIO,TextIO`

* test: Make big ref test model properties required to lessen generated code

Co-authored-by: Nementon <[email protected]>
p1-ra pushed a commit to P1sec/openapi-python-client that referenced this issue May 14, 2021
…-generators#371][openapi-generators#418][openapi-generators#425]. Thanks @p1-ra!

* parser / properties / do not restrict reference pointer type to `enum` or `object`

* e2e / update `openapi.json` and golden-record

* tpl / model / add missing typing import: `Tuple,Optional,BinaryIO,TextIO`

* test: Make big ref test model properties required to lessen generated code

Co-authored-by: Nementon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or improvement
Projects
None yet
2 participants