Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)

case PrimitiveType.String:
var stringValue = (OpenApiString)(IOpenApiPrimitive)this;
writer.WriteValue(stringValue.Value);
if (stringValue.IsRawString())
writer.WriteRaw(stringValue.Value);
else
writer.WriteValue(stringValue.Value);
break;

case PrimitiveType.Byte:
Expand Down
22 changes: 22 additions & 0 deletions src/Microsoft.OpenApi/Any/OpenApiString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Microsoft.OpenApi.Any
public class OpenApiString : OpenApiPrimitive<string>
{
private bool isExplicit;
private bool isRawString;

/// <summary>
/// Initializes the <see cref="OpenApiString"/> class.
Expand All @@ -30,6 +31,19 @@ public OpenApiString(string value, bool isExplicit)
this.isExplicit = isExplicit;
}

/// <summary>
/// Initializes the <see cref="OpenApiString"/> class.
/// </summary>
/// <param name="value"></param>
/// <param name="isExplicit">Used to indicate if a string is quoted.</param>
/// <param name="isRawString">Used to indicate to the writer that the value should be written without encoding.</param>
public OpenApiString(string value, bool isExplicit, bool isRawString)
: base(value)
{
this.isExplicit = isExplicit;
this.isRawString = isRawString;
}

/// <summary>
/// The primitive class this object represents.
/// </summary>
Expand All @@ -42,5 +56,13 @@ public bool IsExplicit()
{
return this.isExplicit;
}

/// <summary>
/// True if the writer should process the value as supplied without encoding.
/// </summary>
public bool IsRawString()
{
return this.isRawString;
}
}
}
2 changes: 2 additions & 0 deletions test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ namespace Microsoft.OpenApi.Any
{
public OpenApiString(string value) { }
public OpenApiString(string value, bool isExplicit) { }
public OpenApiString(string value, bool isExplicit, bool isRawString) { }
public override Microsoft.OpenApi.Any.PrimitiveType PrimitiveType { get; }
public bool IsExplicit() { }
public bool IsRawString() { }
}
public enum PrimitiveType
{
Expand Down