Skip to content

Commit

Permalink
Use string type for parameters with no schemas. (#3392)
Browse files Browse the repository at this point in the history
* Use string type for parameters with no schemas.

* Add test for schema-less parameter.
Add changelog entry.
  • Loading branch information
calebkiage authored Oct 2, 2023
1 parent b0fdf42 commit 3363577
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed redundant undefined qualifier in TypeScript for properties. [#3244](https://github.com/microsoft/kiota/issues/3244)
- The default status code response is now used as 4XX and 5XX when those class responses are not provided in the description. [#3245](https://github.com/microsoft/kiota/issues/3245)
- Adds codes files in typescript to reduce number of generated files. [#2116](https://github.com/microsoft/kiota/issues/2116)
- Fix null reference exception when a parameter is defined without a schema. (CLI).

## [1.6.1] - 2023-09-11

Expand Down
11 changes: 10 additions & 1 deletion src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ private void CreateOperationMethods(OpenApiUrlTreeNode currentNode, OperationTyp
{
Name = codeName,
SerializationName = codeName.Equals(x.Name, StringComparison.Ordinal) ? string.Empty : x.Name,
Type = GetQueryParameterType(x.Schema),
Type = x.Schema is null ? GetDefaultQueryParameterType() : GetQueryParameterType(x.Schema),
Documentation = new()
{
Description = x.Description.CleanupDescription(),
Expand Down Expand Up @@ -2321,6 +2321,15 @@ private void AddPropertyForQueryParameter(OpenApiParameter parameter, CodeClass
logger.LogWarning("Ignoring duplicate parameter {Name}", parameter.Name);
}
}

private static CodeType GetDefaultQueryParameterType()
{
return new()
{
IsExternal = true,
Name = "string",
};
}
private static CodeType GetQueryParameterType(OpenApiSchema schema) =>
new()
{
Expand Down
24 changes: 24 additions & 0 deletions tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,30 @@ public async Task DoesntFailOnEmptyKiotaExtension()
Assert.Null(extensionResult);
}
[Fact]
public async Task DoesntFailOnParameterWithoutSchemaKiotaExtension()
{
var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
await using var fs = await GetDocumentStream(@"openapi: 3.0.1
info:
title: OData Service for namespace microsoft.graph
description: This OData service is located at https://graph.microsoft.com/v1.0
version: 1.0.1
servers:
- url: https://graph.microsoft.com/v1.0
paths:
'/users/{user-id}':
get:
parameters:
- name: user-id
in: path");
var mockLogger = new Mock<ILogger<KiotaBuilder>>();
var builder = new KiotaBuilder(mockLogger.Object, new GenerationConfiguration { ClientClassName = "Graph", OpenAPIFilePath = tempFilePath, Language = GenerationLanguage.CLI }, _httpClient);
var document = await builder.CreateOpenApiDocumentAsync(fs);
var node = builder.CreateUriSpace(document);
var model = builder.CreateSourceModel(node);
Assert.NotNull(model);
}
[Fact]
public async Task GetsUrlTreeNode()
{
var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
Expand Down

0 comments on commit 3363577

Please sign in to comment.