Skip to content

Wrong data type generated #362

Closed
Closed

Description

@Kludex

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

Activity

  1. dbanty commented on Mar 26, 2021

    @dbanty
    Collaborator

    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.

  2. dbanty commented on Mar 27, 2021

    @dbanty
    Collaborator

    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.

  3. added this to the 0.10.6 milestone on Oct 17, 2021
  4. modified the milestones: 0.10.6, 0.10.7, 0.10.8 on Oct 25, 2021
  5. removed this from the 0.10.8 milestone on Dec 16, 2021
  6. dbanty commented on Dec 16, 2021

    @dbanty
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions