Skip to content

Commit e4514af

Browse files
committed
Revert "feat(models): add shared Content interface (#2695)"
This reverts commit 9e13b25.
1 parent 110b3b9 commit e4514af

File tree

10 files changed

+67
-84
lines changed

10 files changed

+67
-84
lines changed

src/Microsoft.OpenApi/Models/Interfaces/IOpenApiContentElement.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/Microsoft.OpenApi/Models/Interfaces/IOpenApiHeader.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.OpenApi;
88
/// Defines the base properties for the headers object.
99
/// This interface is provided for type assertions but should not be implemented by package consumers beyond automatic mocking.
1010
/// </summary>
11-
public interface IOpenApiHeader : IOpenApiDescribedElement, IOpenApiReadOnlyExtensible, IShallowCopyable<IOpenApiHeader>, IOpenApiReferenceable, IOpenApiReadOnlyContentElement
11+
public interface IOpenApiHeader : IOpenApiDescribedElement, IOpenApiReadOnlyExtensible, IShallowCopyable<IOpenApiHeader>, IOpenApiReferenceable
1212
{
1313
/// <summary>
1414
/// Determines whether this header is mandatory.
@@ -58,4 +58,9 @@ public interface IOpenApiHeader : IOpenApiDescribedElement, IOpenApiReadOnlyExte
5858
/// </summary>
5959
public IDictionary<string, IOpenApiExample>? Examples { get; }
6060

61+
/// <summary>
62+
/// A map containing the representations for the header.
63+
/// </summary>
64+
public IDictionary<string, IOpenApiMediaType>? Content { get; }
65+
6166
}

src/Microsoft.OpenApi/Models/Interfaces/IOpenApiParameter.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Microsoft.OpenApi;
77
/// Defines the base properties for the parameter object.
88
/// This interface is provided for type assertions but should not be implemented by package consumers beyond automatic mocking.
99
/// </summary>
10-
public interface IOpenApiParameter : IOpenApiDescribedElement, IOpenApiReadOnlyExtensible, IShallowCopyable<IOpenApiParameter>, IOpenApiReferenceable, IOpenApiReadOnlyContentElement
10+
public interface IOpenApiParameter : IOpenApiDescribedElement, IOpenApiReadOnlyExtensible, IShallowCopyable<IOpenApiParameter>, IOpenApiReferenceable
1111
{
1212
/// <summary>
1313
/// REQUIRED. The name of the parameter. Parameter names are case sensitive.
@@ -93,4 +93,15 @@ public interface IOpenApiParameter : IOpenApiDescribedElement, IOpenApiReadOnlyE
9393
/// Assign <see cref="JsonNullSentinel.JsonNull"/> to use get null as a serialized value.
9494
/// </summary>
9595
public JsonNode? Example { get; }
96+
97+
/// <summary>
98+
/// A map containing the representations for the parameter.
99+
/// The key is the media type and the value describes it.
100+
/// The map MUST only contain one entry.
101+
/// For more complex scenarios, the content property can define the media type and schema of the parameter.
102+
/// A parameter MUST contain either a schema property, or a content property, but not both.
103+
/// When example or examples are provided in conjunction with the schema object,
104+
/// the example MUST follow the prescribed serialization strategy for the parameter.
105+
/// </summary>
106+
public IDictionary<string, IOpenApiMediaType>? Content { get; }
96107
}

src/Microsoft.OpenApi/Models/Interfaces/IOpenApiRequestBody.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ namespace Microsoft.OpenApi;
66
/// Defines the base properties for the request body object.
77
/// This interface is provided for type assertions but should not be implemented by package consumers beyond automatic mocking.
88
/// </summary>
9-
public interface IOpenApiRequestBody : IOpenApiDescribedElement, IOpenApiReadOnlyExtensible, IShallowCopyable<IOpenApiRequestBody>, IOpenApiReferenceable, IOpenApiReadOnlyContentElement
9+
public interface IOpenApiRequestBody : IOpenApiDescribedElement, IOpenApiReadOnlyExtensible, IShallowCopyable<IOpenApiRequestBody>, IOpenApiReferenceable
1010
{
1111
/// <summary>
1212
/// Determines if the request body is required in the request. Defaults to false.
1313
/// </summary>
1414
public bool Required { get; }
1515

16+
/// <summary>
17+
/// REQUIRED. The content of the request body. The key is a media type or media type range and the value describes it.
18+
/// For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*
19+
/// </summary>
20+
public IDictionary<string, IOpenApiMediaType>? Content { get; }
1621
/// <summary>
1722
/// Converts the request body to a body parameter in preparation for a v2 serialization.
1823
/// </summary>

src/Microsoft.OpenApi/Models/Interfaces/IOpenApiResponse.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ namespace Microsoft.OpenApi;
66
/// Defines the base properties for the response object.
77
/// This interface is provided for type assertions but should not be implemented by package consumers beyond automatic mocking.
88
/// </summary>
9-
public interface IOpenApiResponse : IOpenApiDescribedElement, IOpenApiReadOnlyExtensible, IShallowCopyable<IOpenApiResponse>, IOpenApiReferenceable, IOpenApiSummarizedElement, IOpenApiReadOnlyContentElement
9+
public interface IOpenApiResponse : IOpenApiDescribedElement, IOpenApiReadOnlyExtensible, IShallowCopyable<IOpenApiResponse>, IOpenApiReferenceable, IOpenApiSummarizedElement
1010
{
1111
/// <summary>
1212
/// Maps a header name to its definition.
1313
/// </summary>
1414
public IDictionary<string, IOpenApiHeader>? Headers { get; }
1515

16+
/// <summary>
17+
/// A map containing descriptions of potential response payloads.
18+
/// The key is a media type or media type range and the value describes it.
19+
/// </summary>
20+
public IDictionary<string, IOpenApiMediaType>? Content { get; }
21+
1622
/// <summary>
1723
/// A map of operations links that can be followed from the response.
1824
/// The key of the map is a short name for the link,

src/Microsoft.OpenApi/Models/OpenApiHeader.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Microsoft.OpenApi
1111
/// Header Object.
1212
/// The Header Object follows the structure of the Parameter Object.
1313
/// </summary>
14-
public class OpenApiHeader : IOpenApiHeader, IOpenApiExtensible, IOpenApiContentElement
14+
public class OpenApiHeader : IOpenApiHeader, IOpenApiExtensible
1515
{
1616
/// <inheritdoc/>
1717
public string? Description { get; set; }
@@ -98,7 +98,7 @@ public virtual void SerializeAsV3(IOpenApiWriter writer)
9898
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0, (writer, element) => element.SerializeAsV3(writer));
9999
}
100100

101-
internal void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
101+
internal void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
102102
Action<IOpenApiWriter, IOpenApiSerializable> callback)
103103
{
104104
Utils.CheckArgumentNull(writer);
@@ -175,8 +175,7 @@ public virtual void SerializeAsV2(IOpenApiWriter writer)
175175
writer.WriteProperty(OpenApiConstants.AllowReserved, AllowReserved, false);
176176

177177
// schema
178-
var targetSchema = Schema switch
179-
{
178+
var targetSchema = Schema switch {
180179
OpenApiSchemaReference schemaReference => schemaReference.RecursiveTarget,
181180
OpenApiSchema schema => schema,
182181
_ => null,

src/Microsoft.OpenApi/Models/OpenApiParameter.cs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Microsoft.OpenApi
1111
/// <summary>
1212
/// Parameter Object.
1313
/// </summary>
14-
public class OpenApiParameter : IOpenApiExtensible, IOpenApiParameter, IOpenApiContentElement
14+
public class OpenApiParameter : IOpenApiExtensible, IOpenApiParameter
1515
{
1616
private bool? _explode;
1717
private ParameterStyle? _style;
@@ -60,15 +60,7 @@ public bool Explode
6060
/// <inheritdoc/>
6161
public JsonNode? Example { get; set; }
6262

63-
/// <summary>
64-
/// A map containing the representations for the parameter.
65-
/// The key is the media type and the value describes it.
66-
/// The map MUST only contain one entry.
67-
/// For more complex scenarios, the content property can define the media type and schema of the parameter.
68-
/// A parameter MUST contain either a schema property, or a content property, but not both.
69-
/// When example or examples are provided in conjunction with the schema object,
70-
/// the example MUST follow the prescribed serialization strategy for the parameter.
71-
/// </summary>
63+
/// <inheritdoc/>
7264
public IDictionary<string, IOpenApiMediaType>? Content { get; set; }
7365

7466
/// <inheritdoc/>
@@ -119,11 +111,11 @@ public virtual void SerializeAsV3(IOpenApiWriter writer)
119111
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0, (writer, element) => element.SerializeAsV3(writer));
120112
}
121113

122-
internal void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
114+
internal void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
123115
Action<IOpenApiWriter, IOpenApiSerializable> callback)
124116
{
125117
Utils.CheckArgumentNull(writer);
126-
118+
127119
// Validate that Cookie style is only used in OpenAPI 3.2 and later
128120
if (Style == ParameterStyle.Cookie && version < OpenApiSpecVersion.OpenApi3_2)
129121
{
@@ -234,8 +226,7 @@ internal virtual void WriteRequestBodySchemaForV2(IOpenApiWriter writer, Diction
234226
// uniqueItems
235227
// enum
236228
// multipleOf
237-
var targetSchema = Schema switch
238-
{
229+
var targetSchema = Schema switch {
239230
OpenApiSchemaReference schemaReference => schemaReference.RecursiveTarget,
240231
OpenApiSchema schema => schema,
241232
_ => null,
@@ -280,7 +271,7 @@ internal virtual void WriteRequestBodySchemaForV2(IOpenApiWriter writer, Diction
280271
public virtual void SerializeAsV2(IOpenApiWriter writer)
281272
{
282273
Utils.CheckArgumentNull(writer);
283-
274+
284275
// Validate that Cookie style is only used in OpenAPI 3.2 and later
285276
if (Style == ParameterStyle.Cookie)
286277
{

src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@ namespace Microsoft.OpenApi
1010
/// <summary>
1111
/// Request Body Object
1212
/// </summary>
13-
public class OpenApiRequestBody : IOpenApiExtensible, IOpenApiRequestBody, IOpenApiContentElement
13+
public class OpenApiRequestBody : IOpenApiExtensible, IOpenApiRequestBody
1414
{
1515
/// <inheritdoc />
1616
public string? Description { get; set; }
1717

1818
/// <inheritdoc />
1919
public bool Required { get; set; }
2020

21-
/// <summary>
22-
/// REQUIRED. The content of the request body. The key is a media type or media type range and the value describes it.
23-
/// For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*
24-
/// </summary>
21+
/// <inheritdoc />
2522
public IDictionary<string, IOpenApiMediaType>? Content { get; set; }
2623

2724
/// <inheritdoc />
@@ -67,7 +64,7 @@ public virtual void SerializeAsV3(IOpenApiWriter writer)
6764
{
6865
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0, (writer, element) => element.SerializeAsV3(writer));
6966
}
70-
67+
7168
internal void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
7269
Action<IOpenApiWriter, IOpenApiSerializable> callback)
7370
{
@@ -113,7 +110,7 @@ public IOpenApiParameter ConvertToBodyParameter(IOpenApiWriter writer)
113110
Extensions = Extensions?.ToDictionary(static k => k.Key, static v => v.Value)
114111
};
115112
// Clone extensions so we can remove the x-bodyName extensions from the output V2 model.
116-
if (bodyParameter.Extensions is not null &&
113+
if (bodyParameter.Extensions is not null &&
117114
bodyParameter.Extensions.TryGetValue(OpenApiConstants.BodyName, out var bodyNameExtension) &&
118115
bodyNameExtension is JsonNodeExtension bodyName)
119116
{
@@ -129,7 +126,7 @@ public IEnumerable<IOpenApiParameter> ConvertToFormDataParameters(IOpenApiWriter
129126
if (Content == null || !Content.Any())
130127
yield break;
131128
var properties = Content.First().Value.Schema?.Properties;
132-
if (properties != null)
129+
if(properties != null)
133130
{
134131
foreach (var property in properties)
135132
{
@@ -147,11 +144,11 @@ public IEnumerable<IOpenApiParameter> ConvertToFormDataParameters(IOpenApiWriter
147144
OpenApiSchemaReference => throw new InvalidOperationException("Unresolved reference target"),
148145
_ => throw new InvalidOperationException("Unexpected schema type")
149146
};
150-
147+
151148
updatedSchema.Type = "file".ToJsonSchemaType();
152149
updatedSchema.Format = null;
153150
paramSchema = updatedSchema;
154-
151+
155152
}
156153
yield return new OpenApiFormDataParameter()
157154
{
@@ -162,7 +159,7 @@ public IEnumerable<IOpenApiParameter> ConvertToFormDataParameters(IOpenApiWriter
162159
Required = Content.First().Value.Schema?.Required?.Contains(property.Key) ?? false
163160
};
164161
}
165-
}
162+
}
166163
}
167164

168165
/// <inheritdoc/>

src/Microsoft.OpenApi/Models/OpenApiResponse.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Microsoft.OpenApi
1010
/// <summary>
1111
/// Response object.
1212
/// </summary>
13-
public class OpenApiResponse : IOpenApiExtensible, IOpenApiResponse, IOpenApiContentElement
13+
public class OpenApiResponse : IOpenApiExtensible, IOpenApiResponse
1414
{
1515
/// <inheritdoc/>
1616
public string? Summary { get; set; }
@@ -73,7 +73,7 @@ public virtual void SerializeAsV3(IOpenApiWriter writer)
7373
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0, (writer, element) => element.SerializeAsV3(writer));
7474
}
7575

76-
private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
76+
private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
7777
Action<IOpenApiWriter, IOpenApiSerializable> callback)
7878
{
7979
Utils.CheckArgumentNull(writer);
@@ -177,7 +177,7 @@ public virtual void SerializeAsV2(IOpenApiWriter writer)
177177
// so remove it from the cloned collection so we don't write it again.
178178
extensionsClone?.Remove(key);
179179
}
180-
}
180+
}
181181
}
182182
}
183183

0 commit comments

Comments
 (0)