MLogdberg / APIManagementARMTemplateCreator

Azure API Management Template Extractor, extracts ARM templates for your API's to be used in the CI/CD process.
MIT License
45 stars 43 forks source link

Write-APIManagementTemplates: AlwaysAddPropertiesAndBackend + GenerateParameterFiles causes causes cast error #114

Closed jgarplind closed 1 year ago

jgarplind commented 2 years ago

When running this command: Write-APIManagementTemplates -OutputDirectory "C:\Users\me\someplaceonmymachine" -SeparatePolicyFile $true -SeparateSwaggerFile $true -GenerateParameterFiles $true -AlwaysAddPropertiesAndBackend $true

I get this error: Write-APIManagementTemplates : Cannot cast Newtonsoft.Json.Linq.JObject to Newtonsoft.Json.Linq.JToken

This only happens when I refer to a Backend by id. It doesn't seem to matter which Backend type or cert etc.

I tried creating a minimal repro, but of course it is not complete since then the extractor won't work. If you wish to use it, make sure to add <set-backend-service backend-id="Test" /> in the <inbound>-block: repro.zip.

Further, it seems that this issue only occurs when I combine AlwaysAddPropertiesAndBackend and GenerateParameterFiles. If either is missing, the script proceeds just fine. Admittedly, I haven't looked deeply into what these parameters actually do. Particularily AlwaysAddPropertiesAndBackend might be misused here, but since there is no validation rule stopping me, and I up until now have just been mindlessly using what a colleague offered me, it took a fair share of troubleshooting to reach this state.

Hope this issue is clear and actionable. If not, let me know if I can provide any further information.