Skip to content

Commit

Permalink
Merge branch 'main' into feature/plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
andrueastman authored Apr 19, 2024
2 parents bbf9f45 + 5e4716b commit fbb3fd8
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 49 deletions.
30 changes: 17 additions & 13 deletions .azure-pipelines/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,6 @@ extends:
baselineFile: $(Build.SourcesDirectory)/guardian/SDL/common/.gdnbaselines
suppression:
suppressionFile: $(Build.SourcesDirectory)/guardian/SDL/common/.gdnsuppress
variables:
- group: kiota-vscode-extension-publish
dependsOn:
- github_release
steps:
Expand All @@ -586,18 +584,24 @@ extends:
- pwsh: npm i -g @vscode/vsce
- pwsh: $(Build.SourcesDirectory)/scripts/get-prerelease-version.ps1 -currentBranch $(Build.SourceBranch) -previewBranch ${{ parameters.previewBranch }}
displayName: "Set version suffix"
- pwsh: |
Get-ChildItem -Path $(Pipeline.Workspace) -Filter *.vsix -Recurse | ForEach-Object {
Write-Host "Publishing $_.FullName"
if ($Env:isPrerelease -eq "true") {
Write-Host "Publishing $_.FullName as a pre-release"
vsce publish --pat "$(vs-marketplace-token)" --packagePath $_.FullName --pre-release
}
else {
Write-Host "Publishing $_.FullName as a release"
vsce publish --pat "$(vs-marketplace-token)" --packagePath $_.FullName
- task: AzureCLI@2
inputs:
azureSubscription: "kiota-vscode-marketplace-publish"
scriptType: "pscore"
scriptLocation: 'inlineScript'
inlineScript: |
$aadToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
Get-ChildItem -Path $(Pipeline.Workspace) -Filter *.vsix -Recurse | ForEach-Object {
Write-Host "Publishing $_.FullName"
if ($Env:isPrerelease -eq "true") {
Write-Host "Publishing $_.FullName as a pre-release"
vsce publish --pat "$aadToken" --packagePath $_.FullName --pre-release
}
else {
Write-Host "Publishing $_.FullName as a release"
vsce publish --pat "$aadToken" --packagePath $_.FullName
}
}
}
env:
isPrerelease: $(isPrerelease)
- deployment: github_release
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ 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.
- Updated reserved name providers for Java and Php so that "object" can be escaped.
- Do not generate CS8603 warnings when enabling backing store in CSharp generation.

## [1.13.0] - 2024-04-04

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
6 changes: 4 additions & 2 deletions src/Kiota.Builder/Writers/CSharp/CodePropertyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ private void WritePropertyInternal(CodeProperty codeElement, LanguageWriter writ
case CodePropertyKind.AdditionalData when backingStoreProperty != null:
case CodePropertyKind.Custom when backingStoreProperty != null:
var backingStoreKey = codeElement.WireName;
var nullableOp = !codeElement.IsOfKind(CodePropertyKind.AdditionalData) ? "?" : string.Empty;
var nullableEx = codeElement.IsOfKind(CodePropertyKind.AdditionalData) ? " ?? throw new InvalidOperationException(\"AdditionalData can not be null\")" : string.Empty;
writer.WriteLine($"{conventions.GetAccessModifier(codeElement.Access)} {propertyType} {codeElement.Name.ToFirstCharacterUpperCase()} {{");
writer.IncreaseIndent();
writer.WriteLine($"get {{ return {backingStoreProperty.Name.ToFirstCharacterUpperCase()}?.Get<{propertyType}>(\"{backingStoreKey}\"); }}");
writer.WriteLine($"set {{ {backingStoreProperty.Name.ToFirstCharacterUpperCase()}?.Set(\"{backingStoreKey}\", value); }}");
writer.WriteLine($"get {{ return {backingStoreProperty.Name.ToFirstCharacterUpperCase()}{nullableOp}.Get<{propertyType}>(\"{backingStoreKey}\"){nullableEx}; }}");
writer.WriteLine($"set {{ {backingStoreProperty.Name.ToFirstCharacterUpperCase()}{nullableOp}.Set(\"{backingStoreKey}\", value); }}");
writer.DecreaseIndent();
writer.WriteLine("}");
break;
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

0 comments on commit fbb3fd8

Please sign in to comment.