Skip to content

Commit b759821

Browse files
committed
Revert "Set readOnly status for properties"
This reverts commit dbe3bae.
1 parent 04799a4 commit b759821

File tree

5 files changed

+0
-64
lines changed

5 files changed

+0
-64
lines changed

src/OpenApi/src/Extensions/JsonNodeSchemaExtensions.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -394,22 +394,4 @@ internal static void ApplyNullabilityContextInfo(this JsonNode schema, JsonPrope
394394
schema[OpenApiSchemaKeywords.NullableKeyword] = true;
395395
}
396396
}
397-
398-
/// <summary>
399-
/// Apply `readOnly` to the schema based on the presence of the <see cref="ReadOnlyAttribute"/> or whether the
400-
/// property exposes a setter.
401-
/// </summary>
402-
/// <param name="schema"></param>
403-
/// <param name="attributeProvider"></param>
404-
internal static void ApplyReadOnly(this JsonNode schema, ICustomAttributeProvider attributeProvider)
405-
{
406-
if (attributeProvider is PropertyInfo jsonPropertyInfo)
407-
{
408-
schema[OpenApiSchemaKeywords.ReadOnlyKeyword] = !jsonPropertyInfo.CanWrite;
409-
}
410-
if (attributeProvider.GetCustomAttributes(inherit: false).OfType<ReadOnlyAttribute>().SingleOrDefault() is { } readOnlyAttribute)
411-
{
412-
schema[OpenApiSchemaKeywords.ReadOnlyKeyword] = readOnlyAttribute.IsReadOnly;
413-
}
414-
}
415397
}

src/OpenApi/src/Schemas/OpenApiJsonSchema.Helpers.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,6 @@ public static void ReadProperty(ref Utf8JsonReader reader, string propertyName,
313313
schema.Enum = [ReadOpenApiAny(ref reader, out var constType)];
314314
schema.Type = constType;
315315
break;
316-
case OpenApiSchemaKeywords.ReadOnlyKeyword:
317-
reader.Read();
318-
schema.ReadOnly = reader.GetBoolean();
319-
break;
320316
default:
321317
reader.Skip();
322318
break;

src/OpenApi/src/Schemas/OpenApiSchemaKeywords.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,4 @@ internal class OpenApiSchemaKeywords
2626
public const string RefKeyword = "$ref";
2727
public const string SchemaIdKeyword = "x-schema-id";
2828
public const string ConstKeyword = "const";
29-
public const string ReadOnlyKeyword = "readOnly";
3029
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ internal sealed class OpenApiSchemaService(
9494
if (context.PropertyInfo is { AttributeProvider: { } attributeProvider } jsonPropertyInfo)
9595
{
9696
schema.ApplyNullabilityContextInfo(jsonPropertyInfo);
97-
schema.ApplyReadOnly(attributeProvider);
9897
if (attributeProvider.GetCustomAttributes(inherit: false).OfType<ValidationAttribute>() is { } validationAttributes)
9998
{
10099
schema.ApplyValidationAttributes(validationAttributes);

src/OpenApi/test/Services/OpenApiDocumentService/OpenApiDocumentServiceTests.RequestBody.cs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.ComponentModel;
54
using System.IO.Pipelines;
65
using Microsoft.AspNetCore.Builder;
76
using Microsoft.AspNetCore.Http;
@@ -1040,43 +1039,4 @@ static void VerifyDocument(OpenApiDocument document)
10401039
private void ActionWithStream(Stream stream) { }
10411040
[Route("/pipereader")]
10421041
private void ActionWithPipeReader(PipeReader pipeReader) { }
1043-
1044-
[Fact]
1045-
public async Task GetOpenApiRequestBody_AppliesReadOnlyOnProperties()
1046-
{
1047-
// Arrange
1048-
var builder = CreateBuilder();
1049-
1050-
// Act
1051-
builder.MapPost("/", (TypeWithReadOnlyProperties model) => { });
1052-
1053-
// Assert
1054-
await VerifyOpenApiDocument(builder, document =>
1055-
{
1056-
var paths = Assert.Single(document.Paths.Values);
1057-
var operation = paths.Operations[OperationType.Post];
1058-
var content = Assert.Single(operation.RequestBody.Content);
1059-
var schema = content.Value.Schema;
1060-
Assert.NotNull(schema.Properties);
1061-
Assert.Collection(schema.Properties,
1062-
property =>
1063-
{
1064-
Assert.Equal("computedProperty", property.Key);
1065-
Assert.True(property.Value.ReadOnly);
1066-
},
1067-
property =>
1068-
{
1069-
Assert.Equal("readOnlyProperty", property.Key);
1070-
Assert.True(property.Value.ReadOnly);
1071-
});
1072-
});
1073-
}
1074-
1075-
private class TypeWithReadOnlyProperties
1076-
{
1077-
public int ComputedProperty { get; } = 42;
1078-
1079-
[ReadOnly(true)]
1080-
public int ReadOnlyProperty { get; set; }
1081-
}
10821042
}

0 commit comments

Comments
 (0)