-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from BigDaddy1337/feature/CSHARP-204-support-…
…json-attr feature(autodoc): OpenRpcDoc: support JsonPropertyName, JsonConverter, JsonIgnore attributes
- Loading branch information
Showing
4 changed files
with
165 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Tochka.JsonRpc.OpenRpc.Models; | ||
|
||
internal record XmlDocValuesWrapper(string? Summary, string? Remarks); |
34 changes: 30 additions & 4 deletions
34
src/Tochka.JsonRpc.OpenRpc/Services/JsonSchemaBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,42 @@ | ||
using Json.Schema; | ||
using Tochka.JsonRpc.OpenRpc.Models; | ||
|
||
namespace Tochka.JsonRpc.OpenRpc.Services; | ||
|
||
internal static class JsonSchemaBuilderExtensions | ||
{ | ||
public static JsonSchemaBuilder TryAppendTitle(this JsonSchemaBuilder builder, string? propertySummary) | ||
private const string OpenRpcUiNewLine = "\n\r"; | ||
|
||
public static JsonSchemaBuilder AppendXmlDocs(this JsonSchemaBuilder builder, XmlDocValuesWrapper xmlDocs) | ||
{ | ||
if (propertySummary is { Length: > 0 }) | ||
var documentation = xmlDocs.Summary; | ||
|
||
if (!string.IsNullOrEmpty(xmlDocs.Remarks)) | ||
{ | ||
builder.Title(propertySummary); | ||
if (!string.IsNullOrEmpty(documentation)) | ||
{ | ||
documentation += OpenRpcUiNewLine; | ||
} | ||
|
||
documentation += xmlDocs.Remarks; | ||
} | ||
|
||
if (!string.IsNullOrEmpty(documentation)) | ||
{ | ||
// OpenRPC UI does not accept line breaks without carriage return | ||
documentation = documentation.Replace(Environment.NewLine, OpenRpcUiNewLine); | ||
|
||
var newLineIndex = documentation.IndexOf(OpenRpcUiNewLine, StringComparison.Ordinal); | ||
if (newLineIndex >= 0) | ||
{ | ||
builder.Title(documentation[..newLineIndex] + "...") | ||
.Description(documentation); | ||
} | ||
else | ||
{ | ||
builder.Title(documentation); | ||
} | ||
} | ||
|
||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters