Creating API management policy fragment with c# snippet containing double quotes #10888
Closed
christian-jendeberg-sj
started this conversation in
Authoring Help
Replies: 1 comment 6 replies
-
are you able to share the fragment? <fragment>
<set-header name="x-request-context-data" exists-action="override">
<value>@(context.User.Id)</value>
<value>@(context.Deployment.Region)</value>
</set-header>
</fragment> The above works fine and I also tested a few others without any issues. resource APIM 'Microsoft.ApiManagement/service@2022-09-01-preview' existing = {
name: 'AEU1-PE-AKS-D2-apim01'
}
resource myFragment 'Microsoft.ApiManagement/service/policyFragments@2022-08-01' = {
name: 'myFragment'
parent: APIM
properties: {
description: 'x-request-context-data'
format: 'xml'
value: loadTextContent('loadtextcontent/fragment-request-context-data.xml')
}
} right click "Build ARM Template" to get the json version {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.17.104.16619",
"templateHash": "6228299398059222876"
}
},
"variables": {
"$fxv#0": "<fragment>\r\n <set-header name=\"x-request-context-data\" exists-action=\"override\">\r\n <value>@(context.User.Id)</value>\r\n <value>@(context.Deployment.Region)</value>\r\n </set-header>\r\n</fragment>"
},
"resources": [
{
"type": "Microsoft.ApiManagement/service/policyFragments",
"apiVersion": "2022-08-01",
"name": "[format('{0}/{1}', 'AEU1-PE-AKS-D2-apim01', 'myFragment')]",
"properties": {
"description": "x-request-context-data",
"format": "xml",
"value": "[variables('$fxv#0')]"
}
}
]
} Please also ensure you are using a later version of Bicep. code --list-extensions --show-versions --category Azure
> ms-azuretools.vscode-bicep@0.17.1
bicep --version
> Bicep CLI version 0.17.104 (40eb1127ff) Then also please share if you have enabled any preview features. e.g. if you have modified the |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to automate the creation of a fragment with Bicep. I am using the resource something similar to this
resource symbolicname 'Microsoft.ApiManagement/service/policyFragments@2022-08-01' = {
name: 'myFragment'
parent: apimResource
properties: {
description: 'my fragment description'
format: 'xml'
value: loadTextContent('myPolicyFragment.xml')
}
}
and the myPolicyFragment.xml file starts with these lines
...The problem seems to be that the xml syntax is invalid, containing C# snippets with double quotes.
Any ideas on how to achieve this, without changing the logic in the fragment?
Beta Was this translation helpful? Give feedback.
All reactions