Skip to content

Commit 678e2cf

Browse files
committed
Revert "feat(models): add shared Content interface (#2695)"
This reverts commit 80e4bbf.
1 parent 7a4ee7f commit 678e2cf

File tree

10 files changed

+66
-82
lines changed

10 files changed

+66
-82
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: 7 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.
@@ -57,4 +57,10 @@ public interface IOpenApiHeader : IOpenApiDescribedElement, IOpenApiReadOnlyExte
5757
/// Examples of the media type.
5858
/// </summary>
5959
public IDictionary<string, IOpenApiExample>? Examples { get; }
60+
61+
/// <summary>
62+
/// A map containing the representations for the header.
63+
/// </summary>
64+
public IDictionary<string, OpenApiMediaType>? Content { get; }
65+
6066
}

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, OpenApiMediaType>? 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, OpenApiMediaType>? 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, IOpenApiReadOnlyContentElement
9+
public interface IOpenApiResponse : IOpenApiDescribedElement, IOpenApiReadOnlyExtensible, IShallowCopyable<IOpenApiResponse>, IOpenApiReferenceable
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, OpenApiMediaType>? 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; }
@@ -90,7 +90,7 @@ public virtual void SerializeAsV3(IOpenApiWriter writer)
9090
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0, (writer, element) => element.SerializeAsV3(writer));
9191
}
9292

93-
internal void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
93+
internal void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
9494
Action<IOpenApiWriter, IOpenApiSerializable> callback)
9595
{
9696
Utils.CheckArgumentNull(writer);
@@ -167,8 +167,7 @@ public virtual void SerializeAsV2(IOpenApiWriter writer)
167167
writer.WriteProperty(OpenApiConstants.AllowReserved, AllowReserved, false);
168168

169169
// schema
170-
var targetSchema = Schema switch
171-
{
170+
var targetSchema = Schema switch {
172171
OpenApiSchemaReference schemaReference => schemaReference.RecursiveTarget,
173172
OpenApiSchema schema => schema,
174173
_ => null,

src/Microsoft.OpenApi/Models/OpenApiParameter.cs

Lines changed: 4 additions & 13 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, OpenApiMediaType>? Content { get; set; }
7365

7466
/// <inheritdoc/>
@@ -113,7 +105,7 @@ public virtual void SerializeAsV3(IOpenApiWriter writer)
113105
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0, (writer, element) => element.SerializeAsV3(writer));
114106
}
115107

116-
internal void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
108+
internal void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
117109
Action<IOpenApiWriter, IOpenApiSerializable> callback)
118110
{
119111
Utils.CheckArgumentNull(writer);
@@ -208,8 +200,7 @@ internal virtual void WriteRequestBodySchemaForV2(IOpenApiWriter writer, Diction
208200
// uniqueItems
209201
// enum
210202
// multipleOf
211-
var targetSchema = Schema switch
212-
{
203+
var targetSchema = Schema switch {
213204
OpenApiSchemaReference schemaReference => schemaReference.RecursiveTarget,
214205
OpenApiSchema schema => schema,
215206
_ => null,

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, OpenApiMediaType>? Content { get; set; }
2623

2724
/// <inheritdoc />
@@ -59,7 +56,7 @@ public virtual void SerializeAsV3(IOpenApiWriter writer)
5956
{
6057
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0, (writer, element) => element.SerializeAsV3(writer));
6158
}
62-
59+
6360
internal void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
6461
Action<IOpenApiWriter, IOpenApiSerializable> callback)
6562
{
@@ -105,7 +102,7 @@ public IOpenApiParameter ConvertToBodyParameter(IOpenApiWriter writer)
105102
Extensions = Extensions?.ToDictionary(static k => k.Key, static v => v.Value)
106103
};
107104
// Clone extensions so we can remove the x-bodyName extensions from the output V2 model.
108-
if (bodyParameter.Extensions is not null &&
105+
if (bodyParameter.Extensions is not null &&
109106
bodyParameter.Extensions.TryGetValue(OpenApiConstants.BodyName, out var bodyNameExtension) &&
110107
bodyNameExtension is JsonNodeExtension bodyName)
111108
{
@@ -121,7 +118,7 @@ public IEnumerable<IOpenApiParameter> ConvertToFormDataParameters(IOpenApiWriter
121118
if (Content == null || !Content.Any())
122119
yield break;
123120
var properties = Content.First().Value.Schema?.Properties;
124-
if (properties != null)
121+
if(properties != null)
125122
{
126123
foreach (var property in properties)
127124
{
@@ -139,11 +136,11 @@ public IEnumerable<IOpenApiParameter> ConvertToFormDataParameters(IOpenApiWriter
139136
OpenApiSchemaReference => throw new InvalidOperationException("Unresolved reference target"),
140137
_ => throw new InvalidOperationException("Unexpected schema type")
141138
};
142-
139+
143140
updatedSchema.Type = "file".ToJsonSchemaType();
144141
updatedSchema.Format = null;
145142
paramSchema = updatedSchema;
146-
143+
147144
}
148145
yield return new OpenApiFormDataParameter()
149146
{
@@ -154,7 +151,7 @@ public IEnumerable<IOpenApiParameter> ConvertToFormDataParameters(IOpenApiWriter
154151
Required = Content.First().Value.Schema?.Required?.Contains(property.Key) ?? false
155152
};
156153
}
157-
}
154+
}
158155
}
159156

160157
/// <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? Description { get; set; }
@@ -61,7 +61,7 @@ public virtual void SerializeAsV3(IOpenApiWriter writer)
6161
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0, (writer, element) => element.SerializeAsV3(writer));
6262
}
6363

64-
private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
64+
private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
6565
Action<IOpenApiWriter, IOpenApiSerializable> callback)
6666
{
6767
Utils.CheckArgumentNull(writer);
@@ -153,7 +153,7 @@ public virtual void SerializeAsV2(IOpenApiWriter writer)
153153
// so remove it from the cloned collection so we don't write it again.
154154
extensionsClone?.Remove(key);
155155
}
156-
}
156+
}
157157
}
158158
}
159159

0 commit comments

Comments
 (0)