blackchoey / azure-cli-extensions

Public Repository for Extensions of Azure CLI.
https://docs.microsoft.com/en-us/cli/azure
MIT License
0 stars 0 forks source link

az apic metadata create ... --schema throws a validation error even if JSON is correctly formatted #61

Closed juliamuiruri4 closed 1 month ago

juliamuiruri4 commented 2 months ago

Describe the bug

I'm trying to create metadata, and even after correctly formatting the JSON for my --schema, I keep getting the same validation error.

Steps

I have a resource group called - contoso I created a new apic instance called contoso-apis-new image

I try using the command below to create metadata, but I'm stuck on this error.

az apic metadata create -g contoso -n contoso-apis-new --metadata-name apiApprover --schema '{"type":"string","title":"APIApprover"}' --assignments '[{entity:api,required:true,deprecated:false},{entity:environment,required:true,deprecated:false}]'

Related command

az apic metadata create -g contoso -n contoso-apis-new --metadata-name apiApprover --schema '{"type":"string","title":"APIApprover"}' --assignments '[{entity:api,required:true,deprecated:false},{entity:environment,required:true,deprecated:false}]'

Errors

image

(ValidationError) Invalid metadata schema: invalid JSON detected. Please check for any syntax errors or missing brackets, commas, or quotes. Code: ValidationError Message: Invalid metadata schema: invalid JSON detected. Please check for any syntax errors or missing brackets, commas, or quotes.

Issue script & Debug output

cli.azure.cli.core.azclierror: (ValidationError) Invalid metadata schema: invalid JSON detected. Please check for any syntax errors or missing brackets, commas, or quotes.
Code: ValidationError
Message: Invalid metadata schema: invalid JSON detected. Please check for any syntax errors or missing brackets, commas, or quotes.
az_command_data_logger: (ValidationError) Invalid metadata schema: invalid JSON detected. Please check for any syntax errors or missing brackets, commas, or quotes.
Code: ValidationError
Message: Invalid metadata schema: invalid JSON detected. Please check for any syntax errors or missing brackets, commas, or quotes.

Expected behavior

No error

Environment Summary

azure-cli 2.62.0

core 2.62.0 telemetry 1.1.0

Extensions: apic-extension 1.0.0+d26e680

Dependencies: msal 1.28.1 azure-mgmt-resource 23.1.1

Additional context

No response

juliamuiruri4 commented 2 months ago

@pierceboggan - Just to bring this to your attention.

blackchoey commented 1 month ago

@juliamuiruri4 When using Azure CLI, you need to be aware of how your scripting language uses quotation marks and escapes characters. You can refer Quoting differences between scripting languages for more details.

Here're some suggestions for your scenario:

  1. Try to use Azure CLI's @<file> convention to read JSON content from a file and bypass the shell's interpretation mechanisms.
  2. Append --debug parameter to your command to inspect the actual parameter value received by Azure CLI. Then update the JSON parameter value to ensure Azure CLI gets the correct value. The document shared above provides some tips for you to fix the parameter value.
juliamuiruri4 commented 1 month ago

Thanks @blackchoey - I got it to work on bash. image

blackchoey commented 1 month ago

Cool! I will close this issue as you can run the command successfully. Feel free to contact me if you have further questions.