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

Add shell language support #738

Merged
merged 88 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
ad5cf7d
Add shell writer based on C# writer
calebkiage Oct 18, 2021
7ec5869
Fix method writer reference
calebkiage Oct 18, 2021
5ee05a0
Add shell writer based on C# writer
calebkiage Oct 18, 2021
e0061ea
Fix method writer reference
calebkiage Oct 18, 2021
f3bf3f6
Fix generation error
calebkiage Oct 19, 2021
b36cf92
Add code class kind for shell language
calebkiage Oct 21, 2021
5d370c7
Remove unused code
calebkiage Oct 21, 2021
e7ce85f
Rename AddCodeElementWriter function to reflect updated behavior whic…
calebkiage Oct 21, 2021
0802de4
- adds path and query parameters for non fluent languages
baywet Oct 21, 2021
0c668ec
Update shell refiner to add command builders
calebkiage Oct 25, 2021
d23f2a7
Merge branch 'feat/cli_generator' of https://github.com/microsoft/kio…
calebkiage Oct 25, 2021
87d12e6
Remove parameters from build command
calebkiage Oct 25, 2021
cdd23bb
Update command handler
calebkiage Oct 25, 2021
4a78a55
Apply suggested Linq optimization
calebkiage Oct 26, 2021
c43d8fa
Add code to set up command tree
calebkiage Oct 26, 2021
14995f9
Update import declarations in generated code
calebkiage Oct 27, 2021
1c613e5
Merge remote-tracking branch 'origin/main' into feat/cli_generator
calebkiage Oct 27, 2021
7162adb
Generate code to output command results
calebkiage Nov 1, 2021
2bb0dad
Read request body input as json string
calebkiage Nov 2, 2021
d65d247
Add file IO support for stream data upload & download
calebkiage Nov 3, 2021
fe9b1e8
Merge branch main into feat/cli_generator
calebkiage Nov 10, 2021
84b2fc5
Fix NullReferenceException when there are no parameters
calebkiage Dec 2, 2021
9b418e7
Apply suggested code changes
calebkiage Dec 2, 2021
e567be5
Handle edge cases that broke the generated code build
calebkiage Dec 3, 2021
4597b62
Merge branch 'main' into feat/cli_generator
calebkiage Dec 6, 2021
8772b4a
Order methods for deterministic output
calebkiage Dec 6, 2021
0ba0e09
Add missing import
calebkiage Dec 6, 2021
b23dc85
Throw exception for attempts to use CommandBuilders in CSharp
calebkiage Dec 6, 2021
1d0f3c3
Fix bug with command builder writer
calebkiage Dec 7, 2021
a3ea49b
Fix stack overflow exception in builder methods
calebkiage Dec 7, 2021
7d6745f
- fixes a bug where path and query parameters of type collection woul…
baywet Dec 8, 2021
db176be
Update src/Kiota.Builder/Writers/Shell/ShellCodeMethodWriter.cs
calebkiage Dec 9, 2021
8e7236f
Add required flag to options
calebkiage Dec 9, 2021
0c81ef4
Merge branch 'feat/cli_generator' of https://github.com/microsoft/kio…
calebkiage Dec 9, 2021
af989d1
Use generator method to add query parameters to request
calebkiage Dec 9, 2021
d593305
Merge remote-tracking branch 'origin/main' into feat/cli_generator
calebkiage Jan 19, 2022
a0b4c3a
Update shell writer to accomodate breaking changes in System.Commandl…
calebkiage Jan 19, 2022
9ecf819
Merge pull request #1038 from microsoft/chore/update_system_commandline
baywet Jan 19, 2022
7f19244
Update method writer to use output formatter
calebkiage Jan 25, 2022
0610a1f
Fix duplicated output in generated code for streams
calebkiage Jan 26, 2022
6ee2632
Merge branch 'main' into feat/cli_generator
calebkiage Jan 26, 2022
839c8c0
Fix issue with some commands being skipped.
calebkiage Jan 27, 2022
fad1be8
Merge branch 'feat/cli_generator' into feat/output_formatter
calebkiage Jan 27, 2022
f835f83
Print server response if an error occurs in the request
calebkiage Jan 27, 2022
1a23e25
Refactor for generation performance
calebkiage Jan 28, 2022
e2f825f
Move from using response handler and use SendPrimitiveAsync<Stream>
calebkiage Feb 4, 2022
cfba6ef
Add CLI commons package
calebkiage Feb 9, 2022
9a2fdf7
Add missing types
calebkiage Feb 9, 2022
fa2bec3
Update dependabot config
calebkiage Feb 10, 2022
20169c1
Merge remote-tracking branch 'origin/main' into chore/commons_package
calebkiage Feb 10, 2022
eee1036
Merge remote-tracking branch 'origin/main' into feat/output_formatter
calebkiage Feb 10, 2022
e285e77
Merge branch 'feat/output_formatter' into chore/commons_package
calebkiage Feb 10, 2022
00471e9
Add shell language to main readme
calebkiage Feb 10, 2022
5bb480e
Merge pull request #1180 from microsoft/chore/commons_package
calebkiage Feb 10, 2022
9bc455d
Merge remote-tracking branch 'origin/main' into feat/cli_generator
calebkiage Feb 10, 2022
0188007
Merge branch 'feat/cli_generator' into feat/output_formatter
calebkiage Feb 10, 2022
8e6f55f
Merge pull request #1071 from microsoft/feat/output_formatter
calebkiage Feb 10, 2022
ef8c275
Fix possible null pointer exception
calebkiage Feb 10, 2022
d562acc
Fix code smells
calebkiage Feb 10, 2022
d2e6be9
Simplify WriteCommandBuilderBody function
calebkiage Feb 10, 2022
bf6614c
Correct core types in shell refiner
calebkiage Feb 11, 2022
1f61f7e
Remove raw url constructor overload
calebkiage Feb 11, 2022
9aed749
Simplify CreateCommandType method
calebkiage Feb 11, 2022
8cc0438
Remove unused request methods
calebkiage Feb 11, 2022
61d6311
Check for whitespace as well as null on string values
calebkiage Feb 11, 2022
a6f9d7d
Refactor duplicated code
calebkiage Feb 11, 2022
3eaa361
Get serialization contect type from generator method
calebkiage Feb 11, 2022
5cfb3a1
Add IsOfKind extension method for CodeParameter
calebkiage Feb 11, 2022
3bd2e32
Merge branch 'main' into feat/cli_generator
calebkiage Feb 11, 2022
e06f262
Fix build error
calebkiage Feb 11, 2022
0ac97f3
Remove unnecessary extension method
calebkiage Feb 11, 2022
1fe18c4
Fix unintended revert in CodeMethodWriter after conflict resolution
calebkiage Feb 11, 2022
c9352e7
Refactor code
calebkiage Feb 14, 2022
81670b1
Add shell code method writer tests
calebkiage Feb 14, 2022
b166e23
Replace if...else with switch expression
calebkiage Feb 14, 2022
791578d
Use string.Equals function
calebkiage Feb 14, 2022
bf6d4b9
Add additional unit tests
calebkiage Feb 15, 2022
e27e15a
Add unit tests
calebkiage Feb 16, 2022
11d6e82
Refactor code
calebkiage Feb 16, 2022
65e245c
Update default value to handle string option types
calebkiage Feb 16, 2022
f4aaa20
Add assertion for optional parameters
calebkiage Feb 16, 2022
bfff3a1
Rename root build command
calebkiage Feb 16, 2022
ebb18a1
Merge remote-tracking branch 'origin/main' into feat/cli_generator
calebkiage Feb 16, 2022
f5597b8
Fix failing tests
calebkiage Feb 16, 2022
97671bd
Simplify code complexity
calebkiage Feb 16, 2022
5c0347c
Use OfKind extension method
calebkiage Feb 16, 2022
a7cf475
Add error handling support to shell generation
calebkiage Feb 16, 2022
d5d3c02
Fix failing tests
calebkiage Feb 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,10 @@ updates:
open-pull-requests-limit: 10
labels:
- TypeScript
- package-ecosystem: nuget
directory: "/cli/commons"
schedule:
interval: daily
open-pull-requests-limit: 10
labels:
- CLI
64 changes: 64 additions & 0 deletions .github/workflows/cli-commons.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CLI commons

on:
workflow_dispatch:
push:
branches: [ main ]
paths: ['cli/commons/**', '.github/workflows/**']
pull_request:
paths: ['cli/commons/**', '.github/workflows/**']

jobs:
build:
runs-on: ubuntu-latest
env:
relativePath: ./cli/commons
solutionName: Microsoft.Kiota.Cli.Commons.sln
steps:
- uses: actions/checkout@v2.4.0
- name: Setup .NET
uses: actions/setup-dotnet@v1.9.0
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore ${{ env.solutionName }}
working-directory: ${{ env.relativePath }}
- name: Build
run: dotnet build ${{ env.solutionName }} --no-restore -c Release
working-directory: ${{ env.relativePath }}
- name: Test
run: dotnet test ${{ env.solutionName }} --no-build --verbosity normal -c Release /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=opencover
working-directory: ${{ env.relativePath }}
- name: Publish
run: dotnet publish ${{ env.solutionName }} --no-restore --no-build --verbosity normal -c Release
working-directory: ${{ env.relativePath }}
- name: Pack
run: dotnet pack ${{ env.solutionName }} --no-restore --no-build --verbosity normal -c Release
working-directory: ${{ env.relativePath }}
- name: Upload Coverage Results
uses: actions/upload-artifact@v2
with:
name: codeCoverage
path: |
${{ env.relativePath }}src/Microsoft.Kiota.Cli.Commons.Tests/TestResults
- name: Upload Nuget Package
uses: actions/upload-artifact@v2
with:
name: drop
path: |
${{ env.relativePath }}/src/bin/Release/*.nupkg
deploy:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
environment:
name: staging_feeds
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v1.9.0
with:
dotnet-version: 6.0.x
- uses: actions/download-artifact@v2
with:
name: drop
- run: dotnet nuget push "*.nupkg" --skip-duplicate -s https://nuget.pkg.github.com/microsoft/index.json -k ${{ secrets.PUBLISH_GH_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ on:
workflow_dispatch:
push:
branches: [ main ]
path-ignore: ['abstractions/**', 'authentication/**', 'serialization/**', 'http/**', '**.md', '.vscode/**', '**.svg']
path-ignore: ['abstractions/**', 'authentication/**', 'serialization/**', 'http/**', 'cli/**', '**.md', '.vscode/**', '**.svg']
pull_request:
# The branches below must be a subset of the branches above
path-ignore: ['abstractions/**', 'authentication/**', 'serialization/**', 'http/**', '**.md', '.vscode/**', '**.svg']
path-ignore: ['abstractions/**', 'authentication/**', 'serialization/**', 'http/**', 'cli/**', '**.md', '.vscode/**', '**.svg']
schedule:
- cron: '20 9 * * 5'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ on:
push:
branches:
- main
path-ignore: ['abstractions/**', 'authentication/**', 'serialization/**', 'http/**', '**.md', '.vscode/**', '**.svg']
path-ignore: ['abstractions/**', 'authentication/**', 'serialization/**', 'http/**', 'cli/**', '**.md', '.vscode/**', '**.svg']
pull_request:
types: [opened, synchronize, reopened]
path-ignore: ['abstractions/**', 'authentication/**', 'serialization/**', 'http/**', '**.md', '.vscode/**', '**.svg']
path-ignore: ['abstractions/**', 'authentication/**', 'serialization/**', 'http/**', 'cli/**', '**.md', '.vscode/**', '**.svg']

env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The following table provides an overview of the languages supported by Kiota and
| Python | [▶](https://github.com/microsoft/kiota/projects/3) | [✔](./abstractions/python) | ❌ | [Anonymous](./abstractions/python/kiota/abstractions/authentication/anonymous_authentication_provider.py), [Azure](./authentication/python/azure) | ❌ | |
| Ruby | [✔](https://github.com/microsoft/kiota/projects/6) | [✔](./abstractions/ruby) | [JSON](./serialization/ruby/json/microsoft_kiota_serialization) | [Anonymous](./abstractions/ruby/microsoft_kiota_abstractions/lib/microsoft_kiota_abstractions/authentication/anonymous_authentication_provider.rb), [❌ Azure](https://github.com/microsoft/kiota/issues/421) | [✔](./http/ruby/nethttp/microsoft_kiota_nethttplibrary)| [link](https://microsoft.github.io/kiota/get-started/ruby) |
| TypeScript/JavaScript | [✔](https://github.com/microsoft/kiota/projects/2) | [✔](./abstractions/typescript) | [JSON](./serialization/typescript/json) | [Anonymous](./abstractions/typescript/src/authentication/anonymousAuthenticationProvider.ts), [Azure](./authentication/typescript/azure) | [✔](./http/typescript/fetch) | [link](https://microsoft.github.io/kiota/get-started/typescript) |
| Shell | [✔](https://github.com/microsoft/kiota/projects/10) | [✔](./abstractions/dotnet), [✔](./cli/commonc) | [JSON](./serialization/dotnet/json) | [Anonymous](./abstractions/dotnet/src/authentication/AnonymousAuthenticationProvider.cs), [Azure](./authentication/dotnet/azure) | [✔](./http/dotnet/httpclient) | [link](https://microsoft.github.io/kiota/get-started/dotnet) |

> Legend: ✔ -> in preview, ❌ -> not started, ▶ -> in progress.

Expand Down
34 changes: 34 additions & 0 deletions cli/commons/Microsoft.Kiota.Cli.Commons.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8DEB9AF3-BEA6-4E73-BB5E-EBC1DFE6AF22}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Kiota.Cli.Commons", "src\Microsoft.Kiota.Cli.Commons\Microsoft.Kiota.Cli.Commons.csproj", "{23DD14C5-3060-4498-B2F9-85B68770AE0B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Kiota.Cli.Commons.Tests", "src\Microsoft.Kiota.Cli.Commons.Tests\Microsoft.Kiota.Cli.Commons.Tests.csproj", "{D1228DD9-C98F-46C1-911A-65AE2D34DBE5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{23DD14C5-3060-4498-B2F9-85B68770AE0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23DD14C5-3060-4498-B2F9-85B68770AE0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23DD14C5-3060-4498-B2F9-85B68770AE0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23DD14C5-3060-4498-B2F9-85B68770AE0B}.Release|Any CPU.Build.0 = Release|Any CPU
{D1228DD9-C98F-46C1-911A-65AE2D34DBE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1228DD9-C98F-46C1-911A-65AE2D34DBE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1228DD9-C98F-46C1-911A-65AE2D34DBE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1228DD9-C98F-46C1-911A-65AE2D34DBE5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{23DD14C5-3060-4498-B2F9-85B68770AE0B} = {8DEB9AF3-BEA6-4E73-BB5E-EBC1DFE6AF22}
{D1228DD9-C98F-46C1-911A-65AE2D34DBE5} = {8DEB9AF3-BEA6-4E73-BB5E-EBC1DFE6AF22}
EndGlobalSection
EndGlobal
3 changes: 3 additions & 0 deletions cli/commons/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Kiota CLI Commons Package

Contains CLI specific types that are referenced in code generated by the shell language.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Microsoft.Kiota.Cli.Commons.IO;

public enum FormatterType
{
JSON,
TABLE,
NONE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.CommandLine;

namespace Microsoft.Kiota.Cli.Commons.IO;

public interface IOutputFormatter
{
void WriteOutput(string content, IConsole console);

void WriteOutput(Stream content, IConsole console);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Microsoft.Kiota.Cli.Commons.IO;

public interface IOutputFormatterFactory
{
IOutputFormatter GetFormatter(FormatterType formatterType);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.1.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta2.21617.1" />
</ItemGroup>

</Project>
39 changes: 37 additions & 2 deletions src/Kiota.Builder/CodeDOM/CodeMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum CodeMethodKind
RequestBuilderWithParameters,
RawUrlConstructor,
NullCheck,
CommandBuilder,
}
public enum HttpMethod {
Get,
Expand Down Expand Up @@ -48,14 +49,40 @@ public class CodeMethod : CodeTerminal, ICloneable, IDocumentedElement
public void RemoveParametersByKind(params CodeParameterKind[] kinds) {
parameters.RemoveAll(p => p.IsOfKind(kinds));
}

public void ClearParameters()
{
parameters.Clear();
}
public IEnumerable<CodeParameter> Parameters { get => parameters; }
public bool IsStatic {get;set;} = false;
public bool IsAsync {get;set;} = true;
public string Description {get; set;}
/// <summary>
/// The property this method accesses to when it's a getter or setter.
/// </summary>
public CodeProperty AccessedProperty { get; set; }
public CodeProperty AccessedProperty { get; set;
}
/// <summary>
/// The combination of the path and query parameters for the current URL.
/// Only use this property if the language you are generating for doesn't support fluent API style (e.g. Shell/CLI)
/// </summary>
public IEnumerable<CodeParameter> PathAndQueryParameters
{
get; private set;
}
public void AddPathOrQueryParameter(params CodeParameter[] parameters)
{
if (parameters == null || !parameters.Any()) return;
foreach (var parameter in parameters)
{
EnsureElementsAreChildren(parameter);
}
if (PathAndQueryParameters == null)
PathAndQueryParameters = new List<CodeParameter>(parameters);
else if (PathAndQueryParameters is List<CodeParameter> cast)
cast.AddRange(parameters);
}
public bool IsOfKind(params CodeMethodKind[] kinds) {
return kinds?.Contains(MethodKind) ?? false;
}
Expand Down Expand Up @@ -83,7 +110,15 @@ public class CodeMethod : CodeTerminal, ICloneable, IDocumentedElement
/// The base url for every request read from the servers property on the description.
/// Only provided for constructor on Api client
/// </summary>
public string BaseUrl { get; set; }
public string BaseUrl { get; set;
}

/// <summary>
/// This is currently used for CommandBuilder methods to get the original name without the Build prefix & Command suffix.
/// Avoids regex operations
/// </summary>
public string SimpleName { get; set; } = String.Empty;

/// <summary>
/// Mapping of the error code and response types for this method.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using System.Collections.Generic;

namespace Kiota.Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@ public static bool IsComplexPathWithAnyNumberOfParameters(this OpenApiUrlTreeNod
if(string.IsNullOrEmpty(original) || !original.Contains('{')) return original;
var parameters = pathParamMatcher.Matches(original);
foreach(var value in parameters.Select(x => x.Value))
original = original.Replace(value, value.Replace('-', '_'));
original = original.SanitizePathParameterName();
return original;
}
public static string SanitizePathParameterName(this string original) {
if(string.IsNullOrEmpty(original)) return original;
return original.Replace('-', '_');
}
}
}
6 changes: 3 additions & 3 deletions src/Kiota.Builder/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
Expand Down Expand Up @@ -26,7 +26,7 @@ public static string ToPascalCase(this string name)
public static string TrimQuotes(this string original) =>
original?.Trim('\'', '"');

public static string ToSnakeCase(this string name)
public static string ToSnakeCase(this string name, char separator = '_')
{
if(string.IsNullOrEmpty(name)) return name;
var chunks = name.Split('-', StringSplitOptions.RemoveEmptyEntries);
Expand All @@ -40,7 +40,7 @@ public static string ToSnakeCase(this string name)
foreach (var item in identifier[1..])
{
if(char.IsUpper(item)) {
sb.Append('_');
sb.Append(separator);
sb.Append(char.ToLowerInvariant(item));
} else {
sb.Append(item);
Expand Down
3 changes: 2 additions & 1 deletion src/Kiota.Builder/GenerationLanguage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Kiota.Builder {
namespace Kiota.Builder {
public enum GenerationLanguage {
CSharp,
Java,
Expand All @@ -7,5 +7,6 @@ public enum GenerationLanguage {
Python,
Go,
Ruby,
Shell
}
}
37 changes: 37 additions & 0 deletions src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,40 @@ private void CreateOperationMethods(OpenApiUrlTreeNode currentNode, OperationTyp
Description = operation.Description ?? operation.Summary,
ReturnType = new CodeType { Name = "RequestInformation", IsNullable = false, IsExternal = true},
};
if (config.Language == GenerationLanguage.Shell)
SetPathAndQueryParameters(generatorMethod, currentNode, operation);
parentClass.AddMethod(generatorMethod);
AddRequestBuilderMethodParameters(currentNode, operation, parameterClass, generatorMethod);
logger.LogTrace("Creating method {name} of {type}", generatorMethod.Name, generatorMethod.ReturnType);
}
private static void SetPathAndQueryParameters(CodeMethod target, OpenApiUrlTreeNode currentNode, OpenApiOperation operation)
{
var pathAndQueryParameters = currentNode
.PathItems[Constants.DefaultOpenApiLabel]
.Parameters
.Where(x => x.In == ParameterLocation.Path || x.In == ParameterLocation.Query)
.Select(x => new CodeParameter
{
Name = x.Name.TrimStart('$').SanitizePathParameterName(),
Type = GetQueryParameterType(x.Schema),
Description = x.Description,
ParameterKind = x.In == ParameterLocation.Path ? CodeParameterKind.Path : CodeParameterKind.QueryParameter,
Optional = !x.Required
})
.Union(operation
.Parameters
.Where(x => x.In == ParameterLocation.Path || x.In == ParameterLocation.Query)
.Select(x => new CodeParameter
{
Name = x.Name.TrimStart('$').SanitizePathParameterName(),
Type = GetQueryParameterType(x.Schema),
Description = x.Description,
ParameterKind = x.In == ParameterLocation.Path ? CodeParameterKind.Path : CodeParameterKind.QueryParameter,
Optional = !x.Required
}))
.ToArray();
target.AddPathOrQueryParameter(pathAndQueryParameters);
}
private void AddRequestBuilderMethodParameters(OpenApiUrlTreeNode currentNode, OpenApiOperation operation, CodeClass parameterClass, CodeMethod method) {
var nonBinaryRequestBody = operation.RequestBody?.Content?.FirstOrDefault(x => !RequestBodyBinaryContentType.Equals(x.Key, StringComparison.OrdinalIgnoreCase));
if (nonBinaryRequestBody.HasValue && nonBinaryRequestBody.Value.Value != null)
Expand Down Expand Up @@ -979,6 +1009,13 @@ private CodeClass CreateOperationParameter(OpenApiUrlTreeNode node, OperationTyp
return parameterClass;
} else return null;
}
private static CodeType GetQueryParameterType(OpenApiSchema schema) =>
new()
{
IsExternal = true,
Name = schema.Items?.Type ?? schema.Type,
CollectionKind = schema.IsArray() ? CodeType.CodeTypeCollectionKind.Array : default,
};

private static string FixQueryParameterIdentifier(OpenApiParameter parameter)
{
Expand Down