Skip to content

Commit

Permalink
Merge pull request #3652 from iozcelik/main
Browse files Browse the repository at this point in the history
Fixed #3536 and also converting float to string
  • Loading branch information
baywet authored Nov 6, 2023
2 parents f67a35f + a83dfa2 commit bedffa8
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Fixed generating any-type schemas [#3536](https://github.com/microsoft/kiota/issues/3536)
- Fixed float to string convertation with invariant culture.

## [1.8.1] - 2023-11-02

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static string NormalizeMimeType(KeyValuePair<string, float> mimeType)
}
private static string NormalizeMimeType(string key, float value)
{
return $"{key};q={value}";
return FormattableString.Invariant($"{key};q={value}");
}
///<inheritdoc/>
public bool Remove(string item)
Expand Down
11 changes: 11 additions & 0 deletions src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,17 @@ codeType.TypeDefinition is CodeClass codeClass &&
return (modelType, obsoleteComposedType);
}
}
else if (modelType is null)
{
string returnType;
if (operation.Responses.Any(static x => noContentStatusCodes.Contains(x.Key)))
returnType = VoidType;
else if (operation.Responses.Any(static x => x.Value.Content.ContainsKey(RequestBodyPlainTextContentType)))
returnType = "string";
else
returnType = "binary";
return (new CodeType { Name = returnType, IsExternal = true, }, null);
}
return (modelType, null);
}
else
Expand Down
138 changes: 138 additions & 0 deletions tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7155,4 +7155,142 @@ public async Task InheritanceWithAllOfWith3Parts()
Assert.Single(resultClass.Properties.Where(x => x.Name.Equals("groupprop1", StringComparison.OrdinalIgnoreCase)));
Assert.Single(resultClass.Properties.Where(x => x.Name.Equals("groupprop2", StringComparison.OrdinalIgnoreCase)));
}
[Fact]
public async Task AnyTypeResponse()
{
var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
await using var fs = await GetDocumentStream(@"openapi: 3.0.1
info:
title: The Jira Cloud platform REST API
externalDocs:
description: Find out more about Atlassian products and services.
url: http://www.atlassian.com
paths:
/issueLink:
post:
tags:
- Issue links
summary: Create issue link
operationId: linkIssues
parameters: []
requestBody:
description: The issue link request.
content:
application/json:
schema:
$ref: '#/components/schemas/LinkIssueRequestJsonBean'
required: true
responses:
'201':
description: Returned if the request is successful.
content:
application/json:
schema: {}
'400':
description: no desc.
'401':
description: no desc.
'404':
description: no desc.
deprecated: false
components:
schemas:
Comment:
type: object
properties:
body:
description: >-
The comment text in [Atlassian Document
Format](https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/).
created:
type: string
format: date-time
readOnly: true
id:
type: string
readOnly: true
jsdAuthorCanSeeRequest:
type: boolean
readOnly: true
jsdPublic:
type: boolean
readOnly: true
renderedBody:
type: string
readOnly: true
self:
type: string
description: The URL of the comment.
readOnly: true
updated:
type: string
description: The date and time at which the comment was updated last.
format: date-time
readOnly: true
additionalProperties: true
description: A comment.
IssueLinkType:
type: object
properties:
id:
type: string
inward:
type: string
name:
type: string
outward:
type: string
self:
type: string
format: uri
readOnly: true
additionalProperties: false
LinkIssueRequestJsonBean:
required:
- inwardIssue
- outwardIssue
- type
type: object
properties:
comment:
$ref: '#/components/schemas/Comment'
inwardIssue:
$ref: '#/components/schemas/LinkedIssue'
outwardIssue:
$ref: '#/components/schemas/LinkedIssue'
type:
$ref: '#/components/schemas/IssueLinkType'
additionalProperties: false
LinkedIssue:
type: object
properties:
fields:
description: The fields associated with the issue.
readOnly: true
id:
type: string
description: The ID of an issue. Required if `key` isn't provided.
key:
type: string
description: The key of an issue. Required if `id` isn't provided.
self:
type: string
description: The URL of the issue.
format: uri
readOnly: true
additionalProperties: false
description: The ID or key of a linked issue.");
var mockLogger = new Mock<ILogger<KiotaBuilder>>();
var builder = new KiotaBuilder(mockLogger.Object, new GenerationConfiguration { ClientClassName = "Graph", OpenAPIFilePath = tempFilePath, IncludeAdditionalData = false }, _httpClient);
var document = await builder.CreateOpenApiDocumentAsync(fs);
var node = builder.CreateUriSpace(document);
var codeModel = builder.CreateSourceModel(node);
Assert.NotNull(codeModel);
var rbClass = codeModel.FindChildByName<CodeClass>("issueLinkRequestBuilder");
Assert.NotNull(rbClass);
var postMethod = rbClass.FindChildByName<CodeMethod>("Post", false);
Assert.NotNull(postMethod);
var linkIssueRequestJsonBeanClass = codeModel.FindChildByName<CodeClass>("LinkIssueRequestJsonBean");
Assert.NotNull(linkIssueRequestJsonBeanClass);
}
}

0 comments on commit bedffa8

Please sign in to comment.