ReadOnly Attributes should not be included in parameter flattening
See original GitHub issueHello,
I’m not sure if other generated SDK’s use parameter flattening, but in Python we use it to a threshold of 2, and it’s caused some difficulties in the KeyVault client, where one of the Body Parameters includes a read-only attribute.
Read Only attributes should not be included in the count towards flattening threshold, nor should it be exposed as a parameter on the method which currently seems to be the case.
The issue seems to be here: https://github.com/Azure/autorest/blob/master/src/core/AutoRest.Extensions/SwaggerExtensions.cs#L403
My fix would be:
if (bodyParameterType != null && (bodyParameterType.ComposedProperties.Count(p => !p.IsConstant && !p.IsReadOnly) <= settings.PayloadFlatteningThreshold || bodyParameter.ShouldBeFlattened()))
{
var parameterTransformation = new ParameterTransformation
{
OutputParameter = bodyParameter
};
method.InputParameterTransformation.Add(parameterTransformation);
foreach (var property in bodyParameterType.ComposedProperties.Where(p => !p.IsConstant && p.Name != null && !p.IsReadOnly))
{
var newMethodParameter = new Parameter();
newMethodParameter.LoadFrom(property);
...
Let me know if you think this looks reasonable and I’ll submit a PR. Cheers, Anna
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Type error using _.flatten with items of different types
Type 'Item' is missing the following properties from type 'readonly string[]': length, concat, join, slice, and 18 more. */ const flattened = _....
Read more >Parameter flattening doesn't correctly handle "required" ...
A quick summary of the issue is that AutoRest treats flattened required: true parameters the same as it treats flattened required: false ...
Read more >flatten | Plugin API
An optional index argument that specifies where inside parent the new vector will be created. When this argument is not provided, it will...
Read more >Flattening
When you configure a source/destination type pair in AutoMapper, the configurator attempts to match properties and methods on the source type to properties...
Read more >Flattened field type | Elasticsearch Guide [8.5]
The flattened mapping type should not be used for indexing all document content, as it treats all values as keywords and does not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve put this change into the
RefactorCodeModel
branch already, and since it’ll bemaster
pretty quick, don’t worry about doing anything with the current master.Yup, that’s all it is - I think ReadOnly and Constant should be treated the same in this scenario - and no one has corrected me yet 😉