azure-sdk-for-python
azure-sdk-for-python copied to clipboard
[ApiManagement] Subscription scope is not optional
Package Name: azure-mgmt-apimanagement Package Version: 3.0.0 Operating System: Windows 10 Python Version: 3.10
Describe the bug
When I create an api subscription programmatically without specifying a scope explicitly, then I get a ValidationError
.
To Reproduce Steps to reproduce the behavior:
- create an api management client like this:
api_mgmt_client = ApiManagementClient(
credential=my_credential, subscription_id=my_subscription_id
)
- create an api like so:
api_mgmt_client.api.begin_create_or_update(
resource_group_name=my_resource_group_name,
service_name="the-api-mgmt-name",
api_id="the-api-name",
parameters=ApiCreateOrUpdateParameter(
authentication_settings=auth_settings,
display_name="The API Name",
service_url=f"{my_service_url}/some-endpoint",
path="some-suffix",
protocols=["https"],
format=ContentFormat.OPENAPI,
value="some open api content",
subscription_required=True,
subscription_key_parameter_names=SubscriptionKeyParameterNamesContract(
header="api-subscription-key"
),
),
)
- create an api subscription like this:
api_mgmt_client.subscription.create_or_update(
resource_group_name=self._resource_group_name,
service_name=self._api_mgmt_name,
sid="api-subscription",
parameters=SubscriptionCreateParameters(
display_name="All APIs Subscription",
state=SubscriptionState.ACTIVE,
),
)
Then I get the following error:
api_mgmt_client.subscription.create_or_update(
File "/usr/local/lib/python3.8/dist-packages/azure/core/tracing/decorator.py", line 78, in wrapper_use_tracer
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/azure/mgmt/apimanagement/operations/_subscription_operations.py", line 720, in create_or_update
raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)
azure.core.exceptions.HttpResponseError: (ValidationError) One or more fields contain incorrect values:
Code: ValidationError
Message: One or more fields contain incorrect values:
Exception Details: (ValidationError) 'scope' should not be empty.
Code: ValidationError
Message: 'scope' should not be empty.
Target: scope
Expected behavior I expect no error because the scope is defined as optional here.
Am I misunderstanding something in the way that library is working?
Label prediction was below confidence level 0.6
for Model:ServiceLabels
: 'API Management:0.40698162,ARM:0.11255618,Subscription:0.09508873'
Thank you for your feedback. This has been routed to the support team for assistance.
Hi @zadigus thanks for the feedback, we'll get back to you asap.
Label prediction was below confidence level 0.6
for Model:ServiceLabels
: 'API Management:0.40698162,ARM:0.11255618,Subscription:0.09508873'
I will make an investigation soon
Hi @zadigus SDK is generated automatically with swagger. As for this model, it has additional definition "x-ms-client-flatten": true, so the inner properties of the model is flatten and their required
attribute is also overridden by outer optional
.(for more info about x-ms-client-flatten
, see doc). If you think it is misleading, please open issue in https://github.com/Azure/azure-rest-api-specs/issues to ask for change of swagger. Thanks!
Hi @zadigus. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve
” to remove the “issue-addressed” label and continue the conversation.
Hi @zadigus, since you haven’t asked that we “/unresolve
” the issue, we’ll close this out. If you believe further discussion is needed, please add a comment “/unresolve
” to reopen the issue.