-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Cannot read the ReadOnly Property from SwaggerSchemaAttribute #1702
Comments
The current access restrictions are by design because the attribute is only supposed to be used in conjunction with the Can you elaborate a little more on what you're using it for - code samples would help? Thanks |
Thanks for your response. We have some logic in our controller where we want clients to send updates on the schema objects without specifying changes to read-only properties (since they are not supposed to change from the schema specs point of view). On the service, we check for the readonly attribute and assume that this field was not changed. If it is changed, we return a bad request. This is why we need to read this attribute. |
Still not enough info to understand what you're doing - please provide code samples that explain what you're doing in more detail. As I said, you're looking to piggy back on some implementation detail that's internal to Swashbuckle and I don't want to open that up for use-case I don't fully understand. |
Sorry for the delayed response. Here is what we do:
PropertyInfo[] oldPropertyInfo = oldObject.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.CanRead));
SwaggerSchemaAttribute resourceModelSchemaAttribute = propertyInfo.GetCustomAttribute(); PropertyInfo internalReadOnlyProperty = resourceModelSchemaAttribute.GetType().GetProperty("ReadOnlyFlag", BindingFlags.NonPublic | BindingFlags.Instance); object readOnlyValue = internalReadOnlyProperty.GetValue(resourceModelSchemaAttribute); We hope we can use the ReadOnly property directly to know whether the changed property is a swagger readonly attribute or not. |
Gentle reminder about this. |
Gentle reminder. Thank you! |
As mentioned previously, the |
smh... I will need to double attribute my models to add my own checks during reflection mapping so future me doesn't cause a vulnerability. |
The getter of the
ReadOnly
property onSwaggerSchemaAttribute
throws an exception and doesn't allow external code to use it. There is an internal only property (ReadOnlyFlag
) that is used by the library. We need to read the ReadOnly property to do some verification on the input objects. Such as allow readonly properties to be null in an update request. Thanks!The text was updated successfully, but these errors were encountered: