Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any type for user defined types #13399

Open
slavizh opened this issue Feb 21, 2024 · 11 comments
Open

Any type for user defined types #13399

slavizh opened this issue Feb 21, 2024 · 11 comments
Labels
enhancement New feature or request intermediate language Related to the intermediate language Needs: Upvote This issue requires more votes to be considered

Comments

@slavizh
Copy link
Contributor

slavizh commented Feb 21, 2024

Is your feature request related to a problem? Please describe.
This API seems to have type of any. Should such type be available in user defined types?
image

Describe the solution you'd like
Should such type be available in user defined types?

@jeskew
Copy link
Contributor

jeskew commented Feb 21, 2024

Tagging as "intermediate language" because there's currently no way to represent any in ARM's parameter typing system, and that would need to be in place before any could be added to Bicep. The closest you can get right now is object (which corresponds to { *: any }) or array (which corresponds to any[]).

@jeskew jeskew added the intermediate language Related to the intermediate language label Feb 21, 2024
@slavizh
Copy link
Contributor Author

slavizh commented Feb 21, 2024

any is flagged as invalid type if you add it to parameter

@slavizh
Copy link
Contributor Author

slavizh commented Feb 22, 2024

Another example coming from the same resource:
image

It makes it hard to create schemas for these.
Cannot be overcome even with any() put in the Bicep parameters file for the value.

@slavizh
Copy link
Contributor Author

slavizh commented Feb 22, 2024

Additionally to the first example there is a Float type that also uses any

image

@jefedeltodos
Copy link

I could use this too. I am trying to setup some user defined types for a module I'm creating to setup parameter types that match the expected values for an apim operation templateParamteres, responses, etc:
image

but there is no way for met to define:

@export()
type ParameterExampleContract = {
  @description('Long description for the example')
  description: string?
  @description('A URL that points to the literal example')
  externalValue: string?
  @description('Short Description for the example')
  summary: string?
  @description('Examle value. May be a primative value, or an object')
  value: any
}

Although what would be cool is if I could just import ParameterContract[] from Microsoft.ApiManagement/service/apis/operations.

So I could do something like:

import {ParameterContract} from 'Microsoft.ApiManagement/service/apis/operations'

param operationTemplateParameters: ParameterContract[]

Then I don't have to try and recreate these contracts in my bicep files and can reuse the contracts already defined by the resource definitions. (Maybe I'll make a feature request for this)

@jeskew
Copy link
Contributor

jeskew commented Feb 23, 2024

@jefedeltodos You could try the experimental resource-derived types feature. This would require a bicepconfig.json file like the following:

{
  "experimentalFeaturesEnabled": {
    "resourceDerivedTypes": true
  }
}

With that in place, you could define your parameter as the following:

param operationTemplateParameters resource<'Microsoft.ApiManagement/service/apis/operations@2022-08-01'>.properties.templateParameters

image

@slavizh
Copy link
Contributor Author

slavizh commented Feb 27, 2024

Another example from policy assignments
image

This time I cannot make workaround by using discriminator type as I would have to make breaking change to existing template.

@stephaniezyen stephaniezyen added Needs: Upvote This issue requires more votes to be considered and removed Needs: Triage 🔍 labels Feb 28, 2024
@jan-delaet
Copy link

jan-delaet commented Mar 11, 2024

We are also running into this, not sure how to implement user-defined types for resources such as an Azure Policy assignment that has properties that can accept arbitrary types. Having the "any" type available would make this scenario a lot easier to deal with.

@Adunaphel
Copy link

Running into this issue as well, policy assignments are the most egregious ones.

@slavizh
Copy link
Contributor Author

slavizh commented Jun 19, 2024

another example of any:
image

@slavizh
Copy link
Contributor Author

slavizh commented Aug 5, 2024

Another big example of any() usage in API https://learn.microsoft.com/en-us/azure/templates/microsoft.datafactory/2018-06-01/factories/datasets?pivots=deployment-language-bicep
Becomes quite the big problem with these APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request intermediate language Related to the intermediate language Needs: Upvote This issue requires more votes to be considered
Projects
Status: Todo
Development

No branches or pull requests

6 participants