Skip to content

Commit d78e47e

Browse files
committed
Retrieve the property attributes once when transforming schema nodes
1 parent 91e890a commit d78e47e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,26 @@ internal sealed class OpenApiSchemaService(
107107
}
108108
if (context.PropertyInfo is { AttributeProvider: { } attributeProvider })
109109
{
110+
var propertyAttributes = attributeProvider.GetCustomAttributes(inherit: false);
110111
var isInlinedSchema = schema[OpenApiConstants.SchemaId] is null;
111112
if (isInlinedSchema)
112113
{
113-
if (attributeProvider.GetCustomAttributes(inherit: false).OfType<ValidationAttribute>() is { } validationAttributes)
114+
if (propertyAttributes.OfType<ValidationAttribute>() is { } validationAttributes)
114115
{
115116
schema.ApplyValidationAttributes(validationAttributes);
116117
}
117-
if (attributeProvider.GetCustomAttributes(inherit: false).OfType<DefaultValueAttribute>().LastOrDefault() is { } defaultValueAttribute)
118+
if (propertyAttributes.OfType<DefaultValueAttribute>().LastOrDefault() is { } defaultValueAttribute)
118119
{
119120
schema.ApplyDefaultValue(defaultValueAttribute.Value, context.TypeInfo);
120121
}
121-
if (attributeProvider.GetCustomAttributes(inherit: false).OfType<DescriptionAttribute>().LastOrDefault() is { } descriptionAttribute)
122+
if (propertyAttributes.OfType<DescriptionAttribute>().LastOrDefault() is { } descriptionAttribute)
122123
{
123124
schema[OpenApiSchemaKeywords.DescriptionKeyword] = descriptionAttribute.Description;
124125
}
125126
}
126127
else
127128
{
128-
if (attributeProvider.GetCustomAttributes(inherit: false).OfType<DescriptionAttribute>().LastOrDefault() is { } descriptionAttribute)
129+
if (propertyAttributes.OfType<DescriptionAttribute>().LastOrDefault() is { } descriptionAttribute)
129130
{
130131
schema[OpenApiConstants.RefDescriptionAnnotation] = descriptionAttribute.Description;
131132
}

0 commit comments

Comments
 (0)