Skip to content
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

Generated unsupport type bool in enum class #847

Closed
00Kai0 opened this issue Dec 11, 2020 · 8 comments
Closed

Generated unsupport type bool in enum class #847

00Kai0 opened this issue Dec 11, 2020 · 8 comments
Assignees

Comments

@00Kai0
Copy link

00Kai0 commented Dec 11, 2020

Hi @iscai-msft
Track2 codegen generated an unsupport type: bug

class Enum37(with_metaclass(_CaseInsensitiveEnumMeta, bool, Enum)):

    FALSE = False
    TRUE = True

I don't find this error in track1, so I think track2 codegen uses different logic here.

Another solution is that I add a directive in python.md to change the type in schema. Like this

I want to know should it be fixed in codegen ?

Import error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/vsts/work/1/s/sdk/security/azure-mgmt-security/.tox/depends/lib/python3.5/site-packages/azure/mgmt/security/__init__.py", line 9, in <module>
    from ._security_center import SecurityCenter
  File "/home/vsts/work/1/s/sdk/security/azure-mgmt-security/.tox/depends/lib/python3.5/site-packages/azure/mgmt/security/_security_center.py", line 21, in <module>
    from .operations import ComplianceResultsOperations
  File "/home/vsts/work/1/s/sdk/security/azure-mgmt-security/.tox/depends/lib/python3.5/site-packages/azure/mgmt/security/operations/__init__.py", line 9, in <module>
    from ._compliance_results_operations import ComplianceResultsOperations
  File "/home/vsts/work/1/s/sdk/security/azure-mgmt-security/.tox/depends/lib/python3.5/site-packages/azure/mgmt/security/operations/_compliance_results_operations.py", line 17, in <module>
    from .. import models
  File "/home/vsts/work/1/s/sdk/security/azure-mgmt-security/.tox/depends/lib/python3.5/site-packages/azure/mgmt/security/models/__init__.py", line 478, in <module>
    from ._security_center_enums import (
  File "/home/vsts/work/1/s/sdk/security/azure-mgmt-security/.tox/depends/lib/python3.5/site-packages/azure/mgmt/security/models/_security_center_enums.py", line 258, in <module>
    class Enum37(with_metaclass(_CaseInsensitiveEnumMeta, bool, Enum)):
  File "/home/vsts/work/1/s/sdk/security/azure-mgmt-security/.tox/depends/lib/python3.5/site-packages/six.py", line 856, in __new__
    return meta(name, resolved_bases, d)
  File "/opt/hostedtoolcache/Python/3.5.10/x64/lib/python3.5/enum.py", line 114, in __new__
    enum_class = super().__new__(metacls, cls, bases, classdict)
TypeError: type 'bool' is not an acceptable base typ
@iscai-msft
Copy link
Contributor

Hey @00Kai0 , looks like Python as a language can't handle bool enums. I'll do a better error message for this. However, looking at the swagger, I don't. think it makes sense to have this as an enum. Because it's a boolean, we already know its 2 possible values are true and false. What makes the most sense for the swagger, is to remove the object EnableHelmOperatorDefinition, then simply change this line from a ref to "type": "boolean"

I've checked, and the only references to EnableHelmOperationDefinition exist in kubernetes 2020-10-preview, so deleting this won't be an issue

@00Kai0
Copy link
Author

00Kai0 commented Dec 17, 2020

Hi @iscai-msft , do you know where this Enum37 comes from? I don't find this model in swagger :(

@iscai-msft
Copy link
Contributor

Since the enum is not defined with a name, m4 comes up with a name for it

@jsntcy
Copy link
Member

jsntcy commented Dec 21, 2020

@iscai-msft, which enum did you mean for "Since the enum is not defined with a name"? For EnableHelmOperatorDefinition, it has the name EnableHelmOperatorType

@iscai-msft
Copy link
Contributor

iscai-msft commented Dec 21, 2020

good point @jsntcy, I just tried to regenerate myself and it's generating as EnableHelmOperatorType, @00Kai0 , can you link the generated code for this? thanks!

Here's my generated code

image

Will also update this thread v soon with the swagger fixes. I have to get rid of bool enums

@iscai-msft
Copy link
Contributor

have a pr out. for the swagger fixes, going to close this issue

here's a discussion thread we have ongoing about bool enums

@00Kai0
Copy link
Author

00Kai0 commented Dec 22, 2020

Hi @iscai-msft , I am sorry for responsing so late. I found this issue in two sdks: kubernetesconfiguration and security.
In kubernetesconfiguration, I generated the same code you showed.
But in security, I generated an Enums37 which I didn't find in swagger: code link
You can have a try with this python.md

@iscai-msft
Copy link
Contributor

Still can't quite find it @00Kai0 , but autorest will assign a name to any unnamed model/ enum, so this enum must not be named. If you want to give it a name, you can add the name in the x-ms-enum section

Once again, want to strongly strongly discourage adding these types of bool enums into the swagger. As you can see from the PR I have to fix these, there's no point in having these enums. All you need to do is set the parameter / property's type to "boolean" and everything works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants