-
Notifications
You must be signed in to change notification settings - Fork 57
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
Typespec python generator doesn’t consider namespaces #2435
Comments
@cdrlseg we are able to generate operations in different namespaces, but the design of the python SDK is to have all of the models defined in the I believe this would also be better typespec definition code so you don't generate duplicate models when not needed |
Hi @iscai-msft . I don't know if you opened the attached sample. In our case we would like to be able to define two models that have the same name but not the same signature, each model is in a separate namespace. Below the code extraction: namespace classA1{ using TypeSpec.Http; model operation1Request { model operation2Request { model operation1Response { model operation2Response { ======================= namespace classA2{ model operation1Request { model operation2Request { model operation1Response { model operation2Response { |
I see, so you had purposefully designed two models called I would still caution against this though, because code users can very easily run into model name conflicts when they're using your generated sdks. There are also a lot of languages that don't support this as well. Let me forward this issue to our Python code architect though @johanste |
Currently, our generators do not support generating things into separate modules/packages/namespaces. We have a feature on the backlog to override the namespace for a given model. The main reason that it has not been prioritized is that we/azure services avoid using the same model name for any given service due to the possibilities of confusion that @iscai-msft called out. In other words, it has not popped up as an urgent need. Can you elaborate a bit on the use case you have? Is there a specific scenario where having the same name is strongly preferred? |
I can send to you our typespec APi definition if you need. |
We would like to be able to generate python Api code that takes into account the namespaces. This is useful for parameters and function name simplification in a global API context.
We use TypeSpec compiler v0.53.1
Sample description:
--> Typespec-ts manage to generate the client.
--> Typespec-python generates the following error:
File "C:\Dev\zen-spec\node_modules@autorest\python\autorest\codegen_init_.py", line 467, in
).process()
^^^^^^^^^
File "C:\Dev\zen-spec\node_modules@autorest\python\autorest\codegen_init_.py", line 349, in process
code_model = CodeModel(yaml_data=yaml_data, options=options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Dev\zen-spec\node_modules@autorest\python\autorest\codegen\models\code_model.py", line 73, in init
self.sort_model_types()
File "C:\Dev\zen-spec\node_modules@autorest\python\autorest\codegen\models\code_model.py", line 255, in sort_model_types
self._sort_model_types_helper(
File "C:\Dev\zen-spec\node_modules@autorest\python\autorest\codegen\models\code_model.py", line 224, in _sort_model_types_helper
raise ValueError(
ValueError: We have already generated a schema with name Operation1Request
We would like to be able to have code generated for every operation – this can be done by creation a _models.py per namespace or by adding the namespace into the method name.
The text was updated successfully, but these errors were encountered: