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.

Add support for override of property names

See original GitHub issue

Hi! Thank you for the great library!

Could you add support of overrided property names by attributes? For example, we have following model:

public class BestShot
    {
        [JsonProperty("photo")]
        public string Link { get; set; }

        [JsonProperty("zone")]
        public string Area { get; set; }
    }

Json properties are received from external system and can not be changed, but in our code we wish to work with more clear property names, so we use [JsonProperty] attribute

In such case validation rules are not applied because they does not know about OpenAPI properties generated by attributes. The only place it could be done is inside FluentValidationRules, but where istoo many internal stuff to override it

May be it could be done introducing some sort of map between .Net Property name and OpenAPI name like

new Dictionary<string, string>{{nameof(BestShot.Link), "photo"}}

attached to the type somewhere in AddFluentValidationRules options

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
Sergey-Terekhincommented, Apr 1, 2021
  1. We use Newtonsoft
  2. In Swagger I see photo as expected, but validator works for the Link property (as expected too) and does not know anything about property names in OpenAPI

The only place where mapping is possible is documentation filter - it knows about type and about open api schema. But we need to define mapping somehow - in dictionary or in other way (read from attribute for example).

Some interface which I could implement would be great

0reactions
Sergey-Terekhincommented, May 22, 2021

I’ll try a bit later. Next week possible

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Overriding fields or properties in subclasses
Option 1: Use an abstract Property and override it on the inherited classes. This benefits from being enforced (you have to override it)...
Read more >
override modifier - C# Reference
An overriding property declaration must specify exactly the same access modifier, type, and name as the inherited property.
Read more >
Override a property
When you override a property on an event or property group, any changes to ... Navigate to the Events table and click on...
Read more >
Using and Overriding Property Methods
To override the getter method for a property, modify the class that contains the property and add a method as follows: It must...
Read more >
Property override configuration reference | Consul
This topic describes how to configure the property-override extension so that you can set and remove individual properties on the Envoy resources Consul ......
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