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

feature/x ms primary error message #3273

Merged
merged 20 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
6 changes: 1 addition & 5 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
"recommendations": [
"formulahendry.dotnet-test-explorer",
"ms-dotnettools.csharp",
"editorconfig.editorconfig"
]
"recommendations": ["ms-dotnettools.csharp", "editorconfig.editorconfig"]
}
53 changes: 15 additions & 38 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
{
"label": "clean:target",
"type": "shell",
"command": "rm -r C:/sources/github/msgraph-sdk-typescript/src/*",
"command": "rm -r C:/sources/github/msgraph-sdk-typescript/src/*"
},
{
"label": "cleantargetandbuild",
"dependsOrder": "sequence",
"dependsOn": [
"clean:target",
"build"
]
"dependsOn": ["clean:target", "build"]
},
{
"label": "build",
Expand All @@ -21,7 +18,7 @@
"group": "build",
"args": [
"build",
"${workspaceFolder}/src/kiota/kiota.csproj",
"${workspaceFolder}/kiota.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
Expand Down Expand Up @@ -70,7 +67,7 @@
"args": [
"-reports:${workspaceFolder}/tests/**/coverage.cobertura.xml",
"-targetdir:${workspaceFolder}/reports/coverage"
],
]
},
"windows": {
"command": "reportgenerator",
Expand All @@ -79,10 +76,7 @@
"-targetdir:${workspaceFolder}\\reports\\coverage"
]
},
"dependsOn": [
"coverage:clean",
"test"
],
"dependsOn": ["coverage:clean", "test"],
"dependsOrder": "sequence"
},
{
Expand All @@ -94,7 +88,7 @@
"args": [
"-reports:${workspaceFolder}/tests/Kiota.Builder.Tests/**/coverage.cobertura.xml",
"-targetdir:${workspaceFolder}/reports/coverage"
],
]
},
"windows": {
"command": "reportgenerator",
Expand All @@ -103,61 +97,44 @@
"-targetdir:${workspaceFolder}\\reports\\coverage"
]
},
"dependsOn": [
"coverage:clean",
"test"
],
"dependsOn": ["coverage:clean", "test"],
"dependsOrder": "sequence"
},
{
"label": "coverage:launch",
"type": "shell",
"linux": {
"command": "xdg-open",
"args": [
"${workspaceFolder}/reports/coverage/index.html"
]
"args": ["${workspaceFolder}/reports/coverage/index.html"]
},
"osx": {
"command": "open",
"args": [
"${workspaceFolder}/reports/coverage/index.html"
]
"args": ["${workspaceFolder}/reports/coverage/index.html"]
},
"windows": {
"command": "start",
"args": [
"${workspaceFolder}/reports/coverage/index.html"
]
"args": ["${workspaceFolder}/reports/coverage/index.html"]
},
"group": "test",
"group": "test"
},
{
"label": "coverage:launch:global",
"group": "test",
"dependsOrder": "sequence",
"dependsOn": [
"coverage:global",
"coverage:launch"
]
"dependsOn": ["coverage:global", "coverage:launch"]
},
{
"label": "coverage:launch:unit",
"group": "test",
"dependsOrder": "sequence",
"dependsOn": [
"coverage:unit",
"coverage:launch"
]
"dependsOn": ["coverage:unit", "coverage:launch"]
},
{
"label": "clean",
"command": "dotnet",
"type": "process",
"group": "build",
"args": [
"clean"
],
"args": ["clean"],
"problemMatcher": "$msCompile"
},
{
Expand All @@ -181,7 +158,7 @@
"args": [
"watch",
"run",
"${workspaceFolder}/src/kiota/kiota.csproj",
"${workspaceFolder}/kiota.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added support for reserved path parameters. [#2320](https://github.com/microsoft/kiota/issues/2320)
- Added support for csv enum values in enums using a mask in Go.
- Added support for `x-ms-enum-flags` extension in Generator to enable generation of bitwise(flagged) enum values[#3237](https://github.com/microsoft/kiota/issues/3237).
- Added support for mapping primary error messages in CSharp, Go, Java, and TypeScript. [#3066](https://github.com/microsoft/kiota/issues/3066)

### Changed

Expand Down
7 changes: 7 additions & 0 deletions src/Kiota.Builder/CodeDOM/CodeClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ public IEnumerable<CodeInterface> AddInnerInterface(params CodeInterface[] codeI
return AddRange(codeInterfaces);
}
public CodeClass? BaseClass => StartBlock.Inherits?.TypeDefinition as CodeClass;
/// <summary>
/// The interface associated with this class, if any.
/// </summary>
public CodeInterface? AssociatedInterface
{
get; set;
}
public bool DerivesFrom(CodeClass codeClass)
{
ArgumentNullException.ThrowIfNull(codeClass);
Expand Down
4 changes: 4 additions & 0 deletions src/Kiota.Builder/CodeDOM/CodeMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public enum CodeMethodKind
/// Fluent API method returning a request builder with a set raw URL. depends on the RawUrlConstructor.
/// </summary>
RawUrlBuilder,
/// <summary>
/// The override for the error message for the error/exception type.
/// </summary>
ErrorMessageOverride
}
public enum HttpMethod
{
Expand Down
12 changes: 12 additions & 0 deletions src/Kiota.Builder/CodeDOM/CodeProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public enum CodePropertyKind
/// The request middleware options. Used when request parameters are wrapped in a class.
/// </summary>
Options,
/// <summary>
/// The override for the error message for the error/exception type.
/// </summary>
ErrorMessageOverride
}

public class CodeProperty : CodeTerminalWithKind<CodePropertyKind>, IDocumentedElement, IAlternativeName, ICloneable, IDeprecableElement
Expand Down Expand Up @@ -110,6 +114,13 @@ public DeprecationInformation? Deprecation
{
get; set;
}
/// <summary>
/// Indicates if the property is the primary error message for the error/exception type.
/// </summary>
public bool IsPrimaryErrorMessage
{
get; set;
}

public object Clone()
{
Expand All @@ -130,6 +141,7 @@ public object Clone()
NamePrefix = NamePrefix,
OriginalPropertyFromBaseType = OriginalPropertyFromBaseType?.Clone() as CodeProperty,
Deprecation = Deprecation,
IsPrimaryErrorMessage = IsPrimaryErrorMessage,
};
return property;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Linq;
using Kiota.Builder.CodeDOM;
using Kiota.Builder.OpenApiExtensions;
using Microsoft.OpenApi.MicrosoftExtensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Services;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text.RegularExpressions;
using Kiota.Builder.OpenApiExtensions;
using Microsoft.OpenApi.MicrosoftExtensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Services;

Expand Down
40 changes: 11 additions & 29 deletions src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text.RegularExpressions;
using System.Threading;
Expand All @@ -24,15 +25,16 @@
using Kiota.Builder.Refiners;
using Kiota.Builder.Validation;
using Kiota.Builder.Writers;

using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.ApiManifest;
using Microsoft.OpenApi.MicrosoftExtensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers;
using Microsoft.OpenApi.Services;
using Microsoft.OpenApi.Validations;
using HttpMethod = Kiota.Builder.CodeDOM.HttpMethod;
[assembly: InternalsVisibleTo("Kiota.Builder.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100957cb48387b2a5f54f5ce39255f18f26d32a39990db27cf48737afc6bc62759ba996b8a2bfb675d4e39f3d06ecb55a178b1b4031dcb2a767e29977d88cce864a0d16bfc1b3bebb0edf9fe285f10fffc0a85f93d664fa05af07faa3aad2e545182dbf787e3fd32b56aca95df1a3c4e75dec164a3f1a4c653d971b01ffc39eb3c4")]

namespace Kiota.Builder;

Expand Down Expand Up @@ -450,35 +452,10 @@
ruleSet.AddKiotaValidationRules(config);
var settings = new OpenApiReaderSettings
{
ExtensionParsers = new()
{
{
OpenApiPagingExtension.Name,
static (i, _) => OpenApiPagingExtension.Parse(i)
},
{
OpenApiEnumValuesDescriptionExtension.Name,
static (i, _ ) => OpenApiEnumValuesDescriptionExtension.Parse(i)
},
{
OpenApiKiotaExtension.Name,
static (i, _ ) => OpenApiKiotaExtension.Parse(i)
},
{
OpenApiDeprecationExtension.Name,
static (i, _ ) => OpenApiDeprecationExtension.Parse(i)
},
{
OpenApiReservedParameterExtension.Name,
static (i, _ ) => OpenApiReservedParameterExtension.Parse(i)
},
{
OpenApiEnumFlagsExtension.Name,
static (i, _ ) => OpenApiEnumFlagsExtension.Parse(i)
}
},
RuleSet = ruleSet,
};
settings.AddMicrosoftExtensionParsers();
settings.ExtensionParsers.TryAdd(OpenApiKiotaExtension.Name, static (i, _) => OpenApiKiotaExtension.Parse(i));
try
{
var rawUri = config.OpenAPIFilePath.TrimEnd(ForwardSlash);
Expand Down Expand Up @@ -530,7 +507,7 @@
.ToArray();
if (distinctKeys.FirstOrDefault() is not string longestKey) return string.Empty;
var candidate = string.Empty;
var longestKeySegments = longestKey?.Split(NsNameSeparator, StringSplitOptions.RemoveEmptyEntries) ?? Enumerable.Empty<string>();
var longestKeySegments = longestKey.Split(NsNameSeparator, StringSplitOptions.RemoveEmptyEntries);
foreach (var segment in longestKeySegments)
{
var testValue = (candidate + NsNameSeparator + segment).Trim(NsNameSeparator);
Expand Down Expand Up @@ -1137,7 +1114,7 @@

if (!"string".Equals(parameter.Type.Name, StringComparison.OrdinalIgnoreCase))
{ // adding a second indexer for the string version of the parameter so we keep backward compatibility
//TODO remove for v2

Check warning on line 1117 in src/Kiota.Builder/KiotaBuilder.cs

View workflow job for this annotation

GitHub Actions / Build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
var backCompatibleValue = (CodeIndexer)result[0].Clone();
backCompatibleValue.Name += "-string";
backCompatibleValue.IndexParameter.Type = DefaultIndexerParameterType;
Expand Down Expand Up @@ -1170,6 +1147,11 @@
ReadOnly = propertySchema?.ReadOnly ?? false,
Type = resultType,
Deprecation = propertySchema?.GetDeprecationInformation(),
IsPrimaryErrorMessage = kind == CodePropertyKind.Custom &&
propertySchema is not null &&
propertySchema.Extensions.TryGetValue(OpenApiPrimaryErrorMessageExtension.Name, out var openApiExtension) &&
openApiExtension is OpenApiPrimaryErrorMessageExtension primaryErrorMessageExtension &&
primaryErrorMessageExtension.IsPrimaryErrorMessage
};
if (prop.IsOfKind(CodePropertyKind.Custom, CodePropertyKind.QueryParameter) &&
!propertyName.Equals(childIdentifier, StringComparison.Ordinal))
Expand Down
Loading
Loading