skip to Main Content

I have got a requirement in which my client would like to supply an OpenAPI specification to create the API with the operations and need developers to create operation policies. I understand this can be done on all operations for the API, however each operation policy is different. Is this possible through Bicep to use OpenAPI then use use bicep to assign the different xml policy?

param apiName string = 'reallycool-api-dev'
param apimName  string = 'apim-coolness-01'
resource apimServiceResource 'Microsoft.ApiManagement/service@2022-04-01-preview' existing  = {
  name: apimName
}

resource apiService  'Microsoft.ApiManagement/service/apis@2023-05-01-preview' = {
  name: apiName
  parent: apimServiceResource
  properties: {
    displayName                                     : 'ReallyCool-API-dev'
    isCurrent                                       : true
    description                                     : 'ReallyCool API-dev'
    protocols                                       : ['https']    
    subscriptionRequired                            : true
    format: 'openapi+json'
    value                                           : loadTextContent('OpenAPI ReallyCoolAPI.json')
    path                                            : 'reallycool/dev'
    subscriptionKeyParameterNames: {
        header : 'Ocp-Apim-Subscription-Key'
        query   : 'subscription-key'
    }
    }    
}         



resource firstOperationPolicy 'Microsoft.ApiManagement/service/apis/operations/policies@2022-09-01-preview'    = {   
    name: '${apimName}/api/operations/operationNamefromOpenAPIspec/policy'   
    parent: apiService   properties: {
                  format: 'rawxml'
                  value: loadTextContent('TestPolicy.xml')   
        } 
        }

I get the following error:

Error BCP170: Expected resource name to not contain any "/" characters. Child resources with a parent resource reference (via the parent property or via nesting) must not contain a fully-qualified name.

2

Answers


  1. Chosen as BEST ANSWER

    Need to know the operation Id in the openAPI.json specification on what policy you need to apply the policy.xml to. format: '${apimName}/${apiName}/operationIdfromOpenAPIspec/policy'

    Need to supply the full name of the policy resource ie:

    param apiName string = 'reallycool-api-dev'
    param apimName  string = 'apim-coolness-01'
    
    resource firstOperationPolicy 'Microsoft.ApiManagement/service/apis/operations/policies@2022-09-01-preview'    = {   
        name: '${apimName}/${apiName}/operationIdfromOpenAPIspec/policy'             
        properties: {
                      format: 'rawxml'
                      value: loadTextContent('TestPolicy.xml')   
            } 
    }
    

  2. Error BCP170: Expected resource name to not contain any "/" characters. Child resources with a parent resource reference (via the parent property or via nesting) must not contain a fully-qualified name.

    I tried to execute the code in my environment and received the same error message as you.

    The error is with the format of the name argument passing in Api operation policy resource. You can simply pass name: 'policy' as it has already defined parent resources with the relevant resource providers of specific API management service operations (API’s).

    Modified code:

    resource firstOperationPolicy 'Microsoft.ApiManagement/service/apis/operations/policies@2022-09-01-preview'    = {   
        name: 'policy'   
        parent: apiOperationExample  
        properties: {
           format: 'rawxml'
           value: loadTextContent('vcs.xml')
        } 
    }
    

    Deployment succeeded:

    enter image description here

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search