Skip to content

Wrong data type generated #362

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
Kludex opened this issue Mar 26, 2021 · 3 comments
Closed

Wrong data type generated #362

Kludex opened this issue Mar 26, 2021 · 3 comments
Labels
🐞bug Something isn't working

Comments

@Kludex
Copy link

Kludex commented Mar 26, 2021

Describe the bug
The wrong data type is generated on the client.

To Reproduce

I have this model:

{
   "SearchQuery":{
      "title":"SearchQuery",
      "type":"object",
      "properties":{
         "folder_ids":{
            "title":"Folder Ids",
            "type":"array",
            "items":{
               "type":"integer"
            }
         },
         "filters":{
            "title":"Filters",
            "type":"object",
            "additionalProperties":{
               "$ref":"#/components/schemas/SearchFilter"
            },
            "default":{
               
            }
         },
         "keywords":{
            "title":"Keywords",
            "type":"array",
            "items":{
               "type":"string"
            },
            "default":[
               
            ]
         },
         "keyword_op":{
            "allOf":[
               {
                  "$ref":"#/components/schemas/KeywordOperator"
               }
            ],
            "default":"and"
         },
         "file_ids":{
            "title":"File Ids",
            "type":"array",
            "items":{
               "type":"integer"
            }
         },
         "query":{
            "title":"Query",
            "type":"string"
         },
         "keywords_only_query":{
            "title":"Keywords Only Query",
            "type":"boolean",
            "default":false
         }
      },
      "description":"Schema for string query search queries."
   }

On the client, this is generated:

class SearchQuery:
    """ Schema for string query search queries. """

    folder_ids: Union[Unset, List[int]] = UNSET
    filters: Union[SearchQueryFilters, Unset] = UNSET
    keywords: Union[Unset, List[str]] = UNSET
    keyword_op: Union[Unset, None] = UNSET
    file_ids: Union[Unset, List[int]] = UNSET
    query: Union[Unset, str] = UNSET
    keywords_only_query: Union[Unset, bool] = False
    additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

On FastAPI that's an (str, Enum), fwiw 🤔

Expected behavior
Well, it should be this:

    keyword_op: Union[Unset, str] = UNSET

There are follow up problems, but I believe it starts here.

OpenAPI Spec File
openapi.json.txt

Desktop (please complete the following information):

  • OS: Ubuntu 20.04
  • Python Version: 3.8.5
  • openapi-python-client version: 0.8.0
@Kludex Kludex added the 🐞bug Something isn't working label Mar 26, 2021
@dbanty
Copy link
Collaborator

dbanty commented Mar 26, 2021

Hey @Kludex 👋. Trouble is actually that allOf support is on main but not released yet, so the generator doesn't know what type that property is. I'm not positive that the first round of allOf supported anything other than objects though, can you give it a try with what's currently on main and see what it does?

If my suspicions are correct, what we need to do is add support for non-object types in allOf.

@dbanty
Copy link
Collaborator

dbanty commented Mar 27, 2021

Actually I think #361 might solve this issue. It makes it so a single allOf will just pass through rather than attempting to generate a new type. I'll try this once that gets merged to confirm.

@dbanty
Copy link
Collaborator

dbanty commented Dec 16, 2021

Just doing a loop looking at older bugs, looks like this was fixed in 0.9.0. I tried generating with the spec and keyword_ops now correctly contains a Union[Unset, KeywordOperator] which I think is correct, so I'm gonna close this issue.

@dbanty dbanty closed this as completed Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants