Open dornfeder opened 3 weeks ago
Thank you for opening this issue, we will look into it.
@yonzhan Do you have any idea when this patch will be released? Indeed, I have exactly the same issue and it is quite critical, I would really appreciate to keep our use of azure cli and not have to switch to REST API implementation
In the meantime, as a workaround, I ended up using https://github.com/mikefarah/yq to switch all query parameters inside the openapi spec from required: true
to required: false
in our pipeline before uploading the spec to api management.
That way the spec in the repo remains correct but we avoid the issues with api management:
# We are setting all required query parameters to false to avoid any issues with the import
# see https://learn.microsoft.com/en-us/answers/questions/829259/apim-returning-404-when-mandatory-query-parameter
echo "Preparing Api Schema for import..."
yq "(
.paths.*.*
|= select(has(\"parameters\"))
|= .parameters[]
|= select(.in == \"query\")
|= .required = false
) | (
.components
|= select(has(\"parameters\"))
|= .parameters.*
|= select(.in == \"query\")
|= .required = false
)" -i ${file}
echo "done"
Related command
az apim api import
Is your feature request related to a problem? Please describe. In Azure Api Management, during the import of an OpenApi spec, by default, required query parameters get translated to template parameters. (see https://learn.microsoft.com/en-us/azure/api-management/api-management-api-import-restrictions#api-management-during-openapi-import)
Which leads an API imported that way to return unexpected status codes when the required parameters are missing (the issue is documented here: https://learn.microsoft.com/en-us/answers/questions/829259/apim-returning-404-when-mandatory-query-parameter)
To prevent this behaviour and import the query parameters as query parameters, the Rest API provides the property
translateRequiredQueryParameters
, which can be set toquery
. (see https://learn.microsoft.com/en-us/rest/api/apimanagement/apis/create-or-update?view=rest-apimanagement-2022-08-01&tabs=HTTP#translaterequiredqueryparametersconduct).Unfortunately, the corresponding azure cli command
az apim api import
does not seem to provide any way to set the above mentioned property, so you are currently stuck with the default behaviour, when using azure cli.Describe the solution you'd like I would like an additional parameter
translateRequiredQueryParameters
for theaz apim api import
command to be able to control the behaviour during the import. The parameter should map to the already existing property in the Rest Api (see above).examples:
Describe alternatives you've considered
required
in the OpenApi spec, even if they actually are, but that would create a delta between the API description and the actual implementationAdditional context Since this is a behaviour very specific to Azure API Management which is not really to be expected, I think its vital to provide a way to change the default behaviour, regardless if the API was imported through UI, REST Api or Azure cli.