-
Notifications
You must be signed in to change notification settings - Fork 210
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
Support trailing slash in URL paths #5651
base: main
Are you sure you want to change the base?
Changes from all commits
4a1c64c
1a6c287
49e8e19
4373e58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,6 +266,11 @@ private static string NormalizeSymbolsBeforeCleanup(string original) | |
result = result.Replace("+", "_plus_", StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
if (result.Contains('\\', StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
result = result.Replace(@"\", "Slash", StringComparison.OrdinalIgnoreCase); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from reading the unit tests this effectively inserts an additional suffix in the request builder's name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I completely agree and look forward to whatever alternative we come up with! |
||
} | ||
|
||
return result; | ||
} | ||
/// <summary> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
namespace Kiota.Builder.Tests.OpenApiSampleFiles; | ||
|
||
public static class TrailingSlashSampleYml | ||
{ | ||
/** | ||
* An OpenAPI 3.0.0 sample document with trailing slashes on some paths. | ||
*/ | ||
public static readonly string OpenApiYaml = @" | ||
openapi: 3.0.0 | ||
info: | ||
title: Sample API | ||
description: A sample API that uses trailing slashes. | ||
version: 1.0.0 | ||
servers: | ||
- url: https://api.example.com/v1 | ||
paths: | ||
/foo: | ||
get: | ||
summary: Get foo | ||
description: Returns foo. | ||
responses: | ||
'200': | ||
description: foo | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
/foo/: | ||
get: | ||
summary: Get foo slash | ||
description: Returns foo slash. | ||
responses: | ||
'200': | ||
description: foo slash | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
/message/{id}: | ||
get: | ||
summary: Get a Message | ||
description: Returns a single Message object. | ||
parameters: | ||
- name: id | ||
in: path | ||
required: true | ||
schema: | ||
type: string | ||
responses: | ||
'200': | ||
description: A Message object | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Message' | ||
/message/{id}/: | ||
get: | ||
summary: Get replies to a Message | ||
description: Returns a list of Message object replies for a Message. | ||
parameters: | ||
- name: id | ||
in: path | ||
required: true | ||
schema: | ||
type: string | ||
responses: | ||
'200': | ||
description: A list of Message objects | ||
content: | ||
application/json: | ||
schema: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/Message' | ||
/bucket/{name}/: | ||
get: | ||
summary: List items in a bucket | ||
description: Returns a list of BucketFiles in a bucket. | ||
parameters: | ||
- name: name | ||
in: path | ||
required: true | ||
schema: | ||
type: string | ||
responses: | ||
'200': | ||
description: A list of BucketFile objects | ||
content: | ||
application/json: | ||
schema: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/BucketFile' | ||
/bucket/{name}/{id}: | ||
get: | ||
summary: Get a bucket item | ||
description: Returns a single BucketFile object. | ||
parameters: | ||
- name: name | ||
in: path | ||
required: true | ||
schema: | ||
type: string | ||
- name: id | ||
in: path | ||
required: true | ||
schema: | ||
type: string | ||
responses: | ||
'200': | ||
description: A BucketFile object | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/BucketFile' | ||
components: | ||
schemas: | ||
Message: | ||
type: object | ||
properties: | ||
Guid: | ||
type: string | ||
required: | ||
- Guid | ||
BucketFile: | ||
type: object | ||
properties: | ||
Guid: | ||
type: string | ||
required: | ||
- Guid"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we using the class name as uri template here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mentioned it briefly in the PR description but part of the fix in the TypeScript refiner is merging multiple CodeFiles into one CodeFile.
The consequence is that a CodeFile now has multiple UriTemplates in it.
When the TypeScript writer finally gets to writing the request builder's RequestsMetadata constant, it previously only selects the first UriTemplate even if it is the wrong one.
This commit sets UriTemplate in the RequestMetadata CodeConstant so that the TypeScript writer can use it to look up the correct UriTemplate.