question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReadOnly Attributes should not be included in parameter flattening

See original GitHub issue

Hello,

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

FYI @lmazuel, @tbombach

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fearthecowboycommented, Oct 28, 2016

I’ve put this change into the RefactorCodeModel branch already, and since it’ll be master pretty quick, don’t worry about doing anything with the current master.

1reaction
annatischcommented, Oct 26, 2016

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 😉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found