Skip to content

Support inline allOf enum #422

Closed
Closed

Description

@skpn

Describe the bug
In my openapi.json, a parameter for one of my schemas has a string enum as its type, and a member of that enum as its default value.
In the generated client it has type Union[Unset, None] and default value UNSET.

To Reproduce
Steps to reproduce the behavior:

  1. generate a client based on 'http://sandbox.platform.recital.ai:8000/api/v1/openapi.json'

Expected behavior
In the generated client, the schema's parameter should have type Union[Unset, MyEnum] and default value MyEnum.VALUE like in the openapi.json

OpenAPI Spec File
http://sandbox.platform.recital.ai:8000/api/v1/openapi.json

Desktop (please complete the following information):

  • OS: Ubuntu 20.04.2 LTS (Focal Fossa)
  • Python Version: 3.8.8
  • openapi-python-client version: 0.8.0

Activity

  1. illagrenan commented on Oct 13, 2021

    @illagrenan

    I have the same problem with the latest openapi-python-client==0.10.5. Here is the example of OpenAPI schema:

    {
      "openapi": "3.0.2",
      "info": {
        "title": "Example JSON API",
        "version": "0.2.1",
        "description": ""
      },
      "paths": {
        "/api/foo/bar": {
          "post": {
            "operationId": "foo_bar",
            "summary": " ",
            "parameters": [
              {
                "in": "query",
                "name": "item",
                "schema": {
                  "title": "Item",
                  "type": "string"
                },
                "required": true
              },
              {
                "in": "query",
                "name": "operation_type",
                "schema": {
                  "default": "aa",
                  "allOf": [
                    {
                      "title": "OperationType",
                      "description": "An enumeration.",
                      "enum": [
                        "aa",
                        "bb",
                        "cc"
                      ],
                      "type": "string"
                    }
                  ]
                },
                "required": false
              }
            ],
            "responses": {
              "200": {
                "description": "OK",
                "content": {
                  "application/json": {
                    "schema": {
                      "title": "Response",
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "components": {
        "schemas": {}
      }
    }

    And here is the generated code:

    from typing import Any, Dict, List, Type, TypeVar
    
    import attr
    
    T = TypeVar("T", bound="FooBarOperationType")
    
    
    @attr.s(auto_attribs=True)
    class FooBarOperationType:
        """ """
    
        additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
    
        def to_dict(self) -> Dict[str, Any]:
    
            field_dict: Dict[str, Any] = {}
            field_dict.update(self.additional_properties)
            field_dict.update({})
    
            return field_dict
    
        @classmethod
        def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
            d = src_dict.copy()
            foo_bar_operation_type = cls()
    
            foo_bar_operation_type.additional_properties = d
            return foo_bar_operation_type
    
        @property
        def additional_keys(self) -> List[str]:
            return list(self.additional_properties.keys())
    
        def __getitem__(self, key: str) -> Any:
            return self.additional_properties[key]
    
        def __setitem__(self, key: str, value: Any) -> None:
            self.additional_properties[key] = value
    
        def __delitem__(self, key: str) -> None:
            del self.additional_properties[key]
    
        def __contains__(self, key: str) -> bool:
            return key in self.additional_properties

    Note that the FooBarOperationType class is missing attributes for operation_type.

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

    @dbanty
    Collaborator

    Not sure if the first example was the same (URL doesn't go anywhere for me) but for the second one, it seems the problem is we don't support inline allOf an enum right now, only references. I'll adjust the issue title accordingly.

  5. changed the title [-]string enum present on openapi.json is not used in client[/-] [+]Support inline allOf enum[/+] on Dec 16, 2021
  6. added and removed
    🐞bugSomething isn't working
    on Dec 16, 2021
  7. removed this from the 0.10.8 milestone on Dec 16, 2021
  8. locked and limited conversation to collaborators on Aug 13, 2023
  9. converted this issue into a discussion #827 on Aug 13, 2023
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions