Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress CS1591 when generating CSharp code and documentation is not available #4511

Merged
merged 2 commits into from
Apr 18, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Suppress CS1591 when generating CSharp code and documentation is not available

### Changed

- Changed URI template generation to reuse templates when required templates are absent across operations.
Expand Down
15 changes: 9 additions & 6 deletions src/Kiota.Builder/Writers/CSharp/CSharpConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,29 @@ public static void WriteNullableClosing(LanguageWriter writer)
private const string ReferenceTypePrefix = "<see cref=\"";
private const string ReferenceTypeSuffix = "\"/>";
#pragma warning disable S1006 // Method overrides should not change parameter defaults
public override void WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "<summary>", string suffix = "</summary>")
public override bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "<summary>", string suffix = "</summary>")
#pragma warning restore S1006 // Method overrides should not change parameter defaults
{
ArgumentNullException.ThrowIfNull(writer);
ArgumentNullException.ThrowIfNull(element);
if (element is not CodeElement codeElement) return;
if (!element.Documentation.DescriptionAvailable) return;
if (element is not CodeElement codeElement) return false;
if (!element.Documentation.DescriptionAvailable) return false;
var description = element.Documentation.GetDescription(type => GetTypeStringForDocumentation(type, codeElement), normalizationFunc: static x => x.CleanupXMLString());
writer.WriteLine($"{DocCommentPrefix}{prefix}{description}{suffix}");
return true;
}
public void WriteAdditionalDescriptionItem(string description, LanguageWriter writer)
{
ArgumentNullException.ThrowIfNull(writer);
ArgumentNullException.ThrowIfNull(description);
writer.WriteLine($"{DocCommentPrefix}{description}");
}
public void WriteLongDescription(IDocumentedElement element, LanguageWriter writer)
public bool WriteLongDescription(IDocumentedElement element, LanguageWriter writer)
{
ArgumentNullException.ThrowIfNull(writer);
ArgumentNullException.ThrowIfNull(element);
if (element.Documentation is not { } documentation) return;
if (element is not CodeElement codeElement) return;
if (element.Documentation is not { } documentation) return false;
if (element is not CodeElement codeElement) return false;
if (documentation.DescriptionAvailable || documentation.ExternalDocumentationAvailable)
{
writer.WriteLine($"{DocCommentPrefix}<summary>");
Expand All @@ -72,7 +73,9 @@ public void WriteLongDescription(IDocumentedElement element, LanguageWriter writ
if (documentation.ExternalDocumentationAvailable)
writer.WriteLine($"{DocCommentPrefix}{documentation.DocumentationLabel} <see href=\"{documentation.DocumentationLink}\" />");
writer.WriteLine($"{DocCommentPrefix}</summary>");
return true;
}
return false;
}
public override string GetAccessModifier(AccessModifier access)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ public override void WriteCodeElement(ClassDeclaration codeElement, LanguageWrit
.Select(static x => x.ToFirstCharacterUpperCase())
.ToArray();
var derivation = derivedTypes.Length != 0 ? ": " + derivedTypes.Aggregate(static (x, y) => $"{x}, {y}") + " " : string.Empty;
conventions.WriteLongDescription(parentClass, writer);
bool hasDescription = conventions.WriteLongDescription(parentClass, writer);
conventions.WriteDeprecationAttribute(parentClass, writer);
if (!hasDescription) writer.WriteLine("#pragma warning disable CS1591");
writer.WriteLine($"public class {codeElement.Name.ToFirstCharacterUpperCase()} {derivation}");
if (!hasDescription) writer.WriteLine("#pragma warning restore CS1591");
writer.StartBlock();
}
}
8 changes: 6 additions & 2 deletions src/Kiota.Builder/Writers/CSharp/CodeEnumWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,26 @@ public override void WriteCodeElement(CodeEnum codeElement, LanguageWriter write
writer.WriteLine(x);
writer.StartBlock($"namespace {codeNamespace.Name} {{");
}
conventions.WriteShortDescription(codeElement, writer);
bool hasDescription = conventions.WriteShortDescription(codeElement, writer);
if (codeElement.Flags)
writer.WriteLine("[Flags]");
conventions.WriteDeprecationAttribute(codeElement, writer);
if (!hasDescription) writer.WriteLine("#pragma warning disable CS1591");
writer.WriteLine($"public enum {codeElement.Name.ToFirstCharacterUpperCase()}");
if (!hasDescription) writer.WriteLine("#pragma warning restore CS1591");
writer.StartBlock();
var idx = 0;
foreach (var option in codeElement.Options)
{
conventions.WriteShortDescription(option, writer);
hasDescription = conventions.WriteShortDescription(option, writer);

if (option.IsNameEscaped)
{
writer.WriteLine($"[EnumMember(Value = \"{option.SerializationName}\")]");
}
if (!hasDescription) writer.WriteLine("#pragma warning disable CS1591");
writer.WriteLine($"{option.Name.ToFirstCharacterUpperCase()}{(codeElement.Flags ? " = " + GetEnumFlag(idx) : string.Empty)},");
if (!hasDescription) writer.WriteLine("#pragma warning restore CS1591");
idx++;
}
if (codeNamespace != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ public string TranslateType(CodeTypeBase type)
}

public abstract string TranslateType(CodeType type);
public abstract void WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "");
public abstract bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "");
}
7 changes: 4 additions & 3 deletions src/Kiota.Builder/Writers/Go/GoConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,20 @@ currentEnumDefinition.Parent is CodeNamespace enumNS &&
return string.Empty;
}

public override void WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "")
public override bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "")
{
ArgumentNullException.ThrowIfNull(writer);
ArgumentNullException.ThrowIfNull(element);
if (!element.Documentation.DescriptionAvailable) return;
if (element is not CodeElement codeElement) return;
if (!element.Documentation.DescriptionAvailable) return false;
if (element is not CodeElement codeElement) return false;

var description = element.Documentation.GetDescription(x => GetTypeString(x, codeElement, true, false));
if (!string.IsNullOrEmpty(prefix))
{
description = description.ToFirstCharacterLowerCase();
}
WriteDescriptionItem($"{prefix}{description}{suffix}", writer);
return true;
}
public void WriteDescriptionItem(string description, LanguageWriter writer)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/ILanguageConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ string TempDictionaryVarName
string GetTypeString(CodeTypeBase code, CodeElement targetElement, bool includeCollectionInformation = true, LanguageWriter? writer = null);
string TranslateType(CodeType type);
string GetParameterSignature(CodeParameter parameter, CodeElement targetElement, LanguageWriter? writer = null);
void WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "");
bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "");
}
8 changes: 5 additions & 3 deletions src/Kiota.Builder/Writers/Java/JavaConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,18 @@ internal string GetReturnDocComment(string returnType)
}
private const string ReferenceTypePrefix = "{@link ";
private const string ReferenceTypeSuffix = "}";
public override void WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "")
public override bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "")
{
ArgumentNullException.ThrowIfNull(writer);
ArgumentNullException.ThrowIfNull(element);
if (!element.Documentation.DescriptionAvailable) return;
if (element is not CodeElement codeElement) return;
if (!element.Documentation.DescriptionAvailable) return false;
if (element is not CodeElement codeElement) return false;

var description = element.Documentation.GetDescription(x => GetTypeReferenceForDocComment(x, codeElement), ReferenceTypePrefix, ReferenceTypeSuffix, RemoveInvalidDescriptionCharacters);

writer.WriteLine($"{DocCommentStart} {description}{DocCommentEnd}");

return true;
}
internal string GetTypeReferenceForDocComment(CodeTypeBase code, CodeElement targetElement)
{
Expand Down
8 changes: 5 additions & 3 deletions src/Kiota.Builder/Writers/Php/PhpConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,20 @@ private string GetCollectionDocString(CodeParameter codeParameter)
}

internal static string RemoveInvalidDescriptionCharacters(string originalDescription) => originalDescription.Replace("\\", "/", StringComparison.OrdinalIgnoreCase);
public override void WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "")
public override bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "")
{
ArgumentNullException.ThrowIfNull(writer);
ArgumentNullException.ThrowIfNull(element);
if (!element.Documentation.DescriptionAvailable) return;
if (element is not CodeElement codeElement) return;
if (!element.Documentation.DescriptionAvailable) return false;
if (element is not CodeElement codeElement) return false;

var description = element.Documentation.GetDescription(type => GetTypeString(type, codeElement), normalizationFunc: RemoveInvalidDescriptionCharacters);

writer.WriteLine(DocCommentStart);
writer.WriteLine($"{DocCommentPrefix}{description}");
writer.WriteLine(DocCommentEnd);

return true;
}

public void WriteLongDescription(IDocumentedElement element, LanguageWriter writer, IEnumerable<string>? additionalRemarks = default)
Expand Down
8 changes: 5 additions & 3 deletions src/Kiota.Builder/Writers/Python/PythonConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,19 @@ private string WriteInlineDeclaration(CodeType currentType, CodeElement targetEl
return "object";
return $"{{{innerDeclaration}}}";
}
public override void WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "")
public override bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "")
{
ArgumentNullException.ThrowIfNull(writer);
ArgumentNullException.ThrowIfNull(element);
if (!element.Documentation.DescriptionAvailable) return;
if (element is not CodeElement codeElement) return;
if (!element.Documentation.DescriptionAvailable) return false;
if (element is not CodeElement codeElement) return false;

var description = element.Documentation.GetDescription(type => GetTypeString(type, codeElement), normalizationFunc: RemoveInvalidDescriptionCharacters);
writer.WriteLine(DocCommentStart);
writer.WriteLine(description);
writer.WriteLine(DocCommentEnd);

return true;
}
public void WriteLongDescription(IDocumentedElement element, LanguageWriter writer, IEnumerable<string>? additionalRemarks = default)
{
Expand Down
8 changes: 5 additions & 3 deletions src/Kiota.Builder/Writers/Ruby/RubyConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,18 @@ public override string TranslateType(CodeType type)
_ => type.Name.ToFirstCharacterUpperCase() is string typeName && !string.IsNullOrEmpty(typeName) ? typeName : "object",
};
}
public override void WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "")
public override bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "")
{
ArgumentNullException.ThrowIfNull(writer);
ArgumentNullException.ThrowIfNull(element);
if (!element.Documentation.DescriptionAvailable) return;
if (element is not CodeElement codeElement) return;
if (!element.Documentation.DescriptionAvailable) return false;
if (element is not CodeElement codeElement) return false;

var description = element.Documentation.GetDescription(type => GetTypeString(type, codeElement));
writer.WriteLine($"{DocCommentPrefix}");
writer.WriteLine($"# {description}");

return true;
}
#pragma warning disable CA1822 // Method should be static
public string GetNormalizedNamespacePrefixForType(CodeTypeBase type)
Expand Down
8 changes: 5 additions & 3 deletions src/Kiota.Builder/Writers/Swift/SwiftConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ public SwiftConventionService(string clientNamespaceName)
public static readonly char NullableMarker = '?';
public static string NullableMarkerAsString => "?";
public override string ParseNodeInterfaceName => "ParseNode";
public override void WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "<summary>", string suffix = "</summary>")
public override bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "<summary>", string suffix = "</summary>")
{
ArgumentNullException.ThrowIfNull(writer);
ArgumentNullException.ThrowIfNull(element);
if (!element.Documentation.DescriptionAvailable) return;
if (element is not CodeElement codeElement) return;
if (!element.Documentation.DescriptionAvailable) return false;
if (element is not CodeElement codeElement) return false;

var description = element.Documentation.GetDescription(type => GetTypeString(type, codeElement));
writer.WriteLine($"{DocCommentPrefix}{prefix}{description}{prefix}");

return true;
}
public override string GetAccessModifier(AccessModifier access)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,17 @@ public bool IsPrimitiveType(string typeName)
}
#pragma warning restore CA1822 // Method should be static
internal static string RemoveInvalidDescriptionCharacters(string originalDescription) => originalDescription?.Replace("\\", "/", StringComparison.OrdinalIgnoreCase) ?? string.Empty;
public override void WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "")
public override bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "")
{
ArgumentNullException.ThrowIfNull(writer);
ArgumentNullException.ThrowIfNull(element);
if (!element.Documentation.DescriptionAvailable) return;
if (element is not CodeElement codeElement) return;
if (!element.Documentation.DescriptionAvailable) return false;
if (element is not CodeElement codeElement) return false;

var description = element.Documentation.GetDescription(type => GetTypeString(type, codeElement), ReferenceTypePrefix, ReferenceTypeSuffix, RemoveInvalidDescriptionCharacters);
writer.WriteLine($"{DocCommentStart} {description}{DocCommentEnd}");

return true;
}
internal const string ReferenceTypePrefix = "{@link ";
internal const string ReferenceTypeSuffix = "}";
Expand Down
Loading