├── it ├── php │ ├── .gitignore │ ├── phpstan.neon │ ├── src │ │ └── main.php │ └── composer.json ├── csharp │ ├── basic │ │ ├── Usings.cs │ │ └── KiotaMockServerTests.cs │ ├── Program.cs │ └── dotnet.csproj ├── typescript │ ├── .gitignore │ ├── .eslintignore │ ├── tsconfig.eslint.json │ ├── src │ │ ├── typings │ │ │ └── typings.d.ts │ │ ├── config │ │ │ ├── config.interface.ts │ │ │ ├── config.global.ts │ │ │ ├── config.ts │ │ │ └── config.dev.ts │ │ └── main.ts │ ├── .editorconfig │ ├── build │ │ └── file-replacer.js │ ├── tsconfig.json │ └── .prettierrc.json ├── python │ ├── mypy.ini │ └── integration_test │ │ └── __init__.py ├── ruby │ ├── .rspec │ ├── client.rb │ ├── lib │ │ ├── integration_test │ │ │ ├── version.rb │ │ │ └── client │ │ │ │ └── client.rb │ │ └── integration_test.rb │ ├── sig │ │ └── integration_test.rbs │ ├── .gitignore │ ├── Rakefile │ ├── Gemfile │ └── spec │ │ ├── spec_helper.rb │ │ └── integration_test_spec.rb ├── java │ └── .gitignore ├── Readme.md ├── mockserver │ └── pom.xml ├── go │ └── basic │ │ ├── go.mod │ │ └── client_test.go └── do-clean.ps1 ├── .github ├── CODEOWNERS └── workflows │ ├── abstractions-swift.yml │ ├── dotnet-required-workaround.yml │ ├── codeql-required-workaround.yml │ ├── auto-merge-dependabot.yml │ └── deploy-kiota-dev.yml ├── tests ├── Kiota.Web.Tests │ ├── Usings.cs │ └── KiotaWebGeneralTests.cs ├── Kiota.Builder.Tests │ ├── Exceptions │ │ └── InvalidSchemaExceptionTests.cs │ ├── Writers │ │ ├── Go │ │ │ ├── GoConventionServiceTests.cs │ │ │ ├── GoWriterTests.cs │ │ │ └── NamespaceExtensionsTests.cs │ │ ├── StringExtensionsTests.cs │ │ ├── Java │ │ │ └── JavaWriterTests.cs │ │ ├── Ruby │ │ │ └── RubyWriterTests.cs │ │ ├── CSharp │ │ │ └── CSharpWriterTests.cs │ │ ├── Python │ │ │ └── PythonWriterTests.cs │ │ ├── TypeScript │ │ │ └── TypeScriptWriterTests.cs │ │ └── CommonLanguageConventionServiceTests.cs │ ├── CodeDOM │ │ ├── CodeIndexerTests.cs │ │ ├── CodeEnumTests.cs │ │ ├── CodeUnionTypeTests.cs │ │ ├── CodeUsingComparerTests.cs │ │ └── CodeFunctionTests.cs │ ├── UriExtensionsTests.cs │ ├── Lock │ │ └── KiotaLockTests.cs │ ├── Extensions │ │ └── OpenApiReferenceExtensionsTests.cs │ ├── CountLogger.cs │ ├── KiotaGeneratedTests.cs │ ├── Configuration │ │ └── GenerationConfigurationTests.cs │ ├── CodeDomExtensions.cs │ ├── OpenApiExtensions │ │ └── OpenApiEnumValuesDescriptionExtensionTests.cs │ └── SearchProviders │ │ └── GitHub │ │ └── Authentication │ │ └── PatAuthenticationProviderTests.cs └── Kiota.Builder.IntegrationTests │ ├── GeneratesQueryMappers.yaml │ ├── ModelWithDictionary.yaml │ ├── InheritingErrors.yaml │ └── ResponseWithMultipleReturnFormats.yaml ├── vscode └── microsoft-kiota │ ├── .gitignore │ ├── images │ └── logo.png │ ├── .vscode │ ├── extensions.json │ ├── settings.json │ ├── tasks.json │ └── launch.json │ ├── .vscodeignore │ ├── media │ ├── views │ │ └── deps │ │ │ └── reset.css │ └── logo.svg │ ├── debugging.md │ ├── src │ ├── test │ │ ├── suite │ │ │ ├── extension.test.ts │ │ │ └── index.ts │ │ └── runTest.ts │ ├── updateClients.ts │ ├── searchDescription.ts │ ├── getKiotaVersion.ts │ ├── generateClient.ts │ └── getLanguageInformation.ts │ ├── tsconfig.json │ └── .eslintrc.json ├── abstractions ├── swift │ ├── Tests │ │ └── MicrosoftKiotaAbstractionsTests │ │ │ └── RequestInformationTests.swift │ ├── Source │ │ └── MicrosoftKiotaAbstractions │ │ │ ├── RequestOption.swift │ │ │ ├── ApiError.swift │ │ │ ├── Serialization │ │ │ ├── AdditionalDataHolder.swift │ │ │ ├── SerializationWriterFactory.swift │ │ │ ├── ParseNodeFactory.swift │ │ │ ├── Parsable.swift │ │ │ ├── SerializationWriterFactoryRegistry.swift │ │ │ └── ParseNodeFactoryRegistry.swift │ │ │ ├── Authentication │ │ │ ├── AuthenticationProvider.swift │ │ │ ├── AccessTokenProvider.swift │ │ │ ├── AnonymousAuthenticationProvider.swift │ │ │ ├── AllowedHostsValidator.swift │ │ │ └── BaseBearerAuthenticationProvider.swift │ │ │ ├── HttpMethod.swift │ │ │ └── RequestAdapter.swift │ ├── .gitignore │ ├── MicrosoftKiotaAbstractions.xcworkspace │ │ └── contents.xcworkspacedata │ ├── Package.swift │ ├── Podfile │ ├── Package.resolved │ └── MicrosoftKiotaAbstractions.podspec └── README.md ├── src ├── Microsoft.OpenApi.snk ├── Kiota.Web │ ├── wwwroot │ │ ├── favicon.ico │ │ ├── icon-192.png │ │ ├── service-worker.js │ │ └── kiota.webmanifest │ ├── Shared │ │ ├── GitHubSignIn.razor.css │ │ ├── MainLayout.razor │ │ └── NavMenu.razor.css │ ├── Pages │ │ ├── Generate.razor.css │ │ └── Index.razor.css │ ├── README.md │ ├── _Imports.razor │ ├── App.razor │ ├── ComponentWithCancellationToken.cs │ ├── StringBuilderLogger.cs │ └── Properties │ │ └── launchSettings.json ├── kiota │ ├── Rpc │ │ ├── RpcMode.cs │ │ ├── LogEntry.cs │ │ ├── SearchResult.cs │ │ ├── ShowResult.cs │ │ ├── ForwardedLogger.cs │ │ └── IServer.cs │ ├── KiotaConfigurationJsonContext.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Program.cs │ └── Authentication │ │ └── GitHub │ │ └── DeviceCode │ │ ├── DeviceCodeResponse.cs │ │ └── DeviceCodeAuthenticationProvider.cs ├── Kiota.Builder │ ├── CodeDOM │ │ ├── CodeTerminal.cs │ │ ├── ITypeDefinition.cs │ │ ├── AccessModifier.cs │ │ ├── IDocumentedElement.cs │ │ ├── DeprecationInformation.cs │ │ ├── ICodeElement.cs │ │ ├── IDeprecableElement.cs │ │ ├── IDiscriminatorInformationHolder.cs │ │ ├── CodeTerminalWithKind.cs │ │ ├── CodeUnionType.cs │ │ ├── CodeIntersectionType.cs │ │ ├── IBlock.cs │ │ ├── CodeEnumOption.cs │ │ ├── CodeUsing.cs │ │ ├── CodeFile.cs │ │ ├── NamespaceDifferentialTracker.cs │ │ └── IAlternativeName.cs │ ├── Configuration │ │ ├── SearchConfigurationBase.cs │ │ ├── UpdateConfiguration.cs │ │ ├── DownloadConfiguration.cs │ │ └── KiotaConfiguration.cs │ ├── GenerationLanguage.cs │ ├── Writers │ │ ├── ICodeElementWriter.cs │ │ ├── StringExtensions.cs │ │ ├── Go │ │ │ ├── CodeFileBlockEndWriter.cs │ │ │ ├── StringExtensions.cs │ │ │ ├── CodeBlockEndWriter.cs │ │ │ ├── GoWriter.cs │ │ │ └── GoCodeParameterOrderComparer.cs │ │ ├── Php │ │ │ ├── CodeBlockEndWriter.cs │ │ │ └── PhpWriter.cs │ │ ├── Python │ │ │ ├── CodeBlockEndWriter.cs │ │ │ ├── CodeNameSpaceWriter.cs │ │ │ ├── PythonWriter.cs │ │ │ └── PythonCodeParameterOrderComparer.cs │ │ ├── Swift │ │ │ ├── CodeMethodWriter.cs │ │ │ ├── CodeBlockEndWriter.cs │ │ │ ├── SwiftWriter.cs │ │ │ └── CodeNamespaceWriter.cs │ │ ├── RequestParams.cs │ │ ├── TypeScript │ │ │ ├── CodeBlockEndWriter.cs │ │ │ └── CodeEnumWriter.cs │ │ ├── Java │ │ │ ├── CodeBlockEndWriter.cs │ │ │ └── JavaWriter.cs │ │ ├── CodeTypeWriter.cs │ │ ├── CSharp │ │ │ ├── CodeBlockEndWriter.cs │ │ │ └── CSharpWriter.cs │ │ ├── BaseElementWriter.cs │ │ ├── CodePropertyTypeComparer.cs │ │ ├── Ruby │ │ │ ├── CodeBlockEndWriter.cs │ │ │ └── RubyWriter.cs │ │ ├── Shell │ │ │ └── ShellWriter.cs │ │ └── ILanguageConventionService.cs │ ├── Lock │ │ ├── KiotaLockGenerationContext.cs │ │ └── StringIEnumerableDeepComparer.cs │ ├── Refiners │ │ ├── IReservedNamesProvider.cs │ │ ├── AdditionalUsingEvaluator.cs │ │ ├── SwiftReservedNamesProvider.cs │ │ ├── GoExceptionsReservedNamesProvider.cs │ │ ├── CSharpReservedClassNamesProvider.cs │ │ ├── PythonExceptionsReservedNamesProvider.cs │ │ ├── TypeScriptExceptionsReservedNamesProvider.cs │ │ ├── CSharpExceptionsReservedNamesProvider.cs │ │ ├── PhpExceptionsReservedNamesProvider.cs │ │ ├── CodeUsingDeclarationNameComparer.cs │ │ ├── JavaExceptionsReservedNamesProvider.cs │ │ ├── CodeUsingComparer.cs │ │ ├── GoReservedNamesProvider.cs │ │ └── RubyReservedNamesProvider.cs │ ├── PathSegmenters │ │ ├── IPathSegmenter.cs │ │ ├── CSharpPathSegmenter.cs │ │ ├── JavaPathSegementer.cs │ │ ├── PHPPathSegmenter.cs │ │ ├── PythonPathSegmenter.cs │ │ └── SwiftPathSegmenter.cs │ ├── CodeRenderers │ │ ├── PythonCodeRenderer.cs │ │ └── TypeScriptCodeRenderer.cs │ ├── SearchProviders │ │ ├── GitHub │ │ │ ├── GitHubClient │ │ │ │ ├── Models │ │ │ │ │ ├── ContentFile_type.cs │ │ │ │ │ ├── ContentSymlink_type.cs │ │ │ │ │ ├── ContentSubmodule_type.cs │ │ │ │ │ ├── ReleaseAsset_state.cs │ │ │ │ │ ├── AppPermissions_workflows.cs │ │ │ │ │ ├── AppPermissions_organization_plan.cs │ │ │ │ │ ├── AppPermissions_checks.cs │ │ │ │ │ ├── AppPermissions_statuses.cs │ │ │ │ │ ├── AppPermissions_secrets.cs │ │ │ │ │ ├── AppPermissions_members.cs │ │ │ │ │ ├── AppPermissions_single_file.cs │ │ │ │ │ ├── AppPermissions_environments.cs │ │ │ │ │ ├── AppPermissions_packages.cs │ │ │ │ │ ├── AppPermissions_deployments.cs │ │ │ │ │ ├── AppPermissions_organization_secrets.cs │ │ │ │ │ ├── AppPermissions_vulnerability_alerts.cs │ │ │ │ │ ├── AppPermissions_actions.cs │ │ │ │ │ ├── AppPermissions_issues.cs │ │ │ │ │ ├── AppPermissions_team_discussions.cs │ │ │ │ │ ├── Installation_repository_selection.cs │ │ │ │ │ ├── AppPermissions_repository_hooks.cs │ │ │ │ │ ├── AppPermissions_secret_scanning_alerts.cs │ │ │ │ │ ├── AppPermissions_metadata.cs │ │ │ │ │ ├── AppPermissions_organization_administration.cs │ │ │ │ │ ├── AppPermissions_organization_hooks.cs │ │ │ │ │ ├── AppPermissions_security_events.cs │ │ │ │ │ ├── AppPermissions_contents.cs │ │ │ │ │ ├── AppPermissions_pages.cs │ │ │ │ │ ├── AppPermissions_organization_packages.cs │ │ │ │ │ ├── AppPermissions_organization_user_blocking.cs │ │ │ │ │ ├── AppPermissions_administration.cs │ │ │ │ │ ├── AppPermissions_pull_requests.cs │ │ │ │ │ ├── AppPermissions_organization_announcement_banners.cs │ │ │ │ │ ├── AppPermissions_organization_custom_roles.cs │ │ │ │ │ ├── AppPermissions_organization_self_hosted_runners.cs │ │ │ │ │ ├── AppPermissions_repository_projects.cs │ │ │ │ │ ├── AppPermissions_organization_personal_access_tokens.cs │ │ │ │ │ ├── AppPermissions_organization_projects.cs │ │ │ │ │ └── AppPermissions_organization_personal_access_token_requests.cs │ │ │ │ └── Repos │ │ │ │ │ └── Item │ │ │ │ │ └── Item │ │ │ │ │ └── Releases │ │ │ │ │ └── ReleasesPostRequestBody_make_latest.cs │ │ │ ├── Index │ │ │ │ ├── YamlNamingConvention.cs │ │ │ │ ├── BlockList.cs │ │ │ │ └── IndexRoot.cs │ │ │ └── Authentication │ │ │ │ ├── ITokenStorageService.cs │ │ │ │ ├── PatAuthenticationProvider.cs │ │ │ │ ├── AccessCodeResponse.cs │ │ │ │ ├── AnonymousAuthenticationProvider.cs │ │ │ │ └── PatAccessTokenProvider.cs │ │ ├── SearchResult.cs │ │ ├── ISearchProvider.cs │ │ └── APIsGuru │ │ │ └── APIEntry.cs │ ├── Extensions │ │ ├── UriExtensions.cs │ │ ├── OpenApiReferenceExtensions.cs │ │ ├── CodeParametersEnumerableExtensions.cs │ │ ├── IEnumerableExtensions.cs │ │ └── CodePropertiesEnumerableExtensions.cs │ ├── Constants.cs │ ├── Exceptions │ │ └── InvalidSchemaException.cs │ ├── Logging │ │ ├── AggregateScope.cs │ │ ├── AggregateLogger.cs │ │ └── FileLogLoggerProvider.cs │ ├── GlobComparer.cs │ ├── Validation │ │ ├── GetWithBody.cs │ │ ├── NoContentWithBody.cs │ │ ├── NoServerEntry.cs │ │ └── MultipleServerEntries.cs │ ├── CodeElementOrderComparerWithExternalMethods.cs │ ├── BaseStringComparisonComparer.cs │ ├── OpenApiServerComparer.cs │ └── CodeElementOrderComparerPython.cs └── Kiota.Generated │ ├── PathHelper.cs │ └── KiotaGenerated.csproj ├── resources └── index-block-list.yml ├── global.json ├── docs ├── _sass │ └── custom │ │ └── custom.scss ├── 404.md ├── _config.yml └── _includes │ └── js │ └── custom.js ├── .vscode ├── extensions.json └── settings.json ├── CODE_OF_CONDUCT.md ├── SUPPORT.md ├── scripts ├── entitlements.plist └── get-release-notes.ps1 ├── Dockerfile └── .devcontainer └── Dockerfile /it/php/.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | composer.lock -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @microsoft/kiota-write 2 | -------------------------------------------------------------------------------- /it/csharp/basic/Usings.cs: -------------------------------------------------------------------------------- 1 | global using Xunit; -------------------------------------------------------------------------------- /it/typescript/.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | -------------------------------------------------------------------------------- /tests/Kiota.Web.Tests/Usings.cs: -------------------------------------------------------------------------------- 1 | global using Xunit; 2 | -------------------------------------------------------------------------------- /it/python/mypy.ini: -------------------------------------------------------------------------------- 1 | [mypy] 2 | ignore_missing_imports = True 3 | -------------------------------------------------------------------------------- /it/typescript/.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | .vscode 4 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | .kiotabin/ 3 | *.vsix -------------------------------------------------------------------------------- /it/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | --require spec_helper 4 | -------------------------------------------------------------------------------- /abstractions/swift/Tests/MicrosoftKiotaAbstractionsTests/RequestInformationTests.swift: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /it/java/.gitignore: -------------------------------------------------------------------------------- 1 | /src 2 | target 3 | /basic/src/main 4 | /basic/src/kiota-lock.json 5 | -------------------------------------------------------------------------------- /it/typescript/tsconfig.eslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": ["build/*.js", ".eslintrc.js"] 3 | } 4 | -------------------------------------------------------------------------------- /src/Microsoft.OpenApi.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slmnsh/kiota/main/src/Microsoft.OpenApi.snk -------------------------------------------------------------------------------- /it/typescript/src/typings/typings.d.ts: -------------------------------------------------------------------------------- 1 | declare const VERSION: string; 2 | declare const DEVELOP: boolean; 3 | -------------------------------------------------------------------------------- /resources/index-block-list.yml: -------------------------------------------------------------------------------- 1 | repositories: 2 | - exampleOwner/exampleRepo 3 | organizations: 4 | - exampleOwner -------------------------------------------------------------------------------- /src/Kiota.Web/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slmnsh/kiota/main/src/Kiota.Web/wwwroot/favicon.ico -------------------------------------------------------------------------------- /src/Kiota.Web/wwwroot/icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slmnsh/kiota/main/src/Kiota.Web/wwwroot/icon-192.png -------------------------------------------------------------------------------- /it/ruby/client.rb: -------------------------------------------------------------------------------- 1 | require_relative "api_client" 2 | 3 | module Integration_test 4 | module Client 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /src/kiota/Rpc/RpcMode.cs: -------------------------------------------------------------------------------- 1 | namespace kiota.Rpc; 2 | 3 | public enum RpcMode 4 | { 5 | Stdio, 6 | NamedPipe 7 | } 8 | -------------------------------------------------------------------------------- /it/csharp/Program.cs: -------------------------------------------------------------------------------- 1 | // See https://aka.ms/new-console-template for more information 2 | Console.WriteLine("Hello, World!"); 3 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slmnsh/kiota/main/vscode/microsoft-kiota/images/logo.png -------------------------------------------------------------------------------- /it/ruby/lib/integration_test/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Integration_test 4 | VERSION = "0.1.0" 5 | end 6 | -------------------------------------------------------------------------------- /abstractions/swift/Source/MicrosoftKiotaAbstractions/RequestOption.swift: -------------------------------------------------------------------------------- 1 | public protocol RequestOption { 2 | var key: String { get } 3 | } -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "7.0.0", 4 | "rollForward": "latestMajor", 5 | "allowPrerelease": false 6 | } 7 | } -------------------------------------------------------------------------------- /abstractions/swift/Source/MicrosoftKiotaAbstractions/ApiError.swift: -------------------------------------------------------------------------------- 1 | public enum ApiError: Error { 2 | case unknownError(String, Any? = nil) 3 | } -------------------------------------------------------------------------------- /it/ruby/lib/integration_test/client/client.rb: -------------------------------------------------------------------------------- 1 | require_relative "api_client" 2 | 3 | module Integration_test 4 | module Client 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/CodeTerminal.cs: -------------------------------------------------------------------------------- 1 | namespace Kiota.Builder.CodeDOM; 2 | 3 | public abstract class CodeTerminal : CodeElement 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/ITypeDefinition.cs: -------------------------------------------------------------------------------- 1 | namespace Kiota.Builder.CodeDOM; 2 | public interface ITypeDefinition : ICodeElement 3 | { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /it/ruby/sig/integration_test.rbs: -------------------------------------------------------------------------------- 1 | module Integration_test 2 | VERSION: String 3 | # See the writing guide of rbs: https://github.com/ruby/rbs#guides 4 | end 5 | -------------------------------------------------------------------------------- /src/Kiota.Web/Shared/GitHubSignIn.razor.css: -------------------------------------------------------------------------------- 1 | .gh-dialog-content { 2 | margin: 10px; 3 | 4 | } 5 | .gh-dialog-content-form { 6 | margin-top:10px; 7 | } -------------------------------------------------------------------------------- /src/Kiota.Web/Pages/Generate.razor.css: -------------------------------------------------------------------------------- 1 | .log-box { 2 | white-space: pre-wrap; 3 | overflow: auto; 4 | } 5 | .log-container { 6 | max-width: fit-content; 7 | } -------------------------------------------------------------------------------- /src/kiota/Rpc/LogEntry.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | namespace kiota.Rpc; 3 | public record LogEntry( 4 | LogLevel level, 5 | string message 6 | ); 7 | -------------------------------------------------------------------------------- /it/typescript/src/config/config.interface.ts: -------------------------------------------------------------------------------- 1 | import { IGlobalConfig } from './config.global'; 2 | 3 | export interface IConfig extends IGlobalConfig { 4 | apiUrl: string; 5 | } 6 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/AccessModifier.cs: -------------------------------------------------------------------------------- 1 | namespace Kiota.Builder.CodeDOM; 2 | public enum AccessModifier 3 | { 4 | Public = 2, 5 | Protected = 1, 6 | Private = 0 7 | } 8 | -------------------------------------------------------------------------------- /abstractions/swift/Source/MicrosoftKiotaAbstractions/Serialization/AdditionalDataHolder.swift: -------------------------------------------------------------------------------- 1 | public protocol AdditionalDataHolder { 2 | var additionalData : [String:Any] { get set } 3 | } -------------------------------------------------------------------------------- /docs/_sass/custom/custom.scss: -------------------------------------------------------------------------------- 1 | .main-content { 2 | blockquote { 3 | border-left: .25em solid; 4 | padding: 0 1em; 5 | color: #8b949e; 6 | margin-inline-start: 0; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /it/ruby/.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /_yardoc/ 4 | /coverage/ 5 | /doc/ 6 | /pkg/ 7 | /spec/reports/ 8 | /tmp/ 9 | 10 | # rspec failure tracking 11 | .rspec_status 12 | 13 | Gemfile.lock -------------------------------------------------------------------------------- /src/Kiota.Web/Pages/Index.razor.css: -------------------------------------------------------------------------------- 1 | .dialog-content { 2 | margin-left: 10px; 3 | margin-right: 10px; 4 | } 5 | .additional-information { 6 | margin-top: 10px; 7 | margin-bottom: 10px; 8 | } -------------------------------------------------------------------------------- /abstractions/swift/Source/MicrosoftKiotaAbstractions/Authentication/AuthenticationProvider.swift: -------------------------------------------------------------------------------- 1 | public protocol AuthenticationProvider { 2 | func authenticateRequest(request: RequestInformation) async throws 3 | } -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/IDocumentedElement.cs: -------------------------------------------------------------------------------- 1 | namespace Kiota.Builder.CodeDOM; 2 | public interface IDocumentedElement 3 | { 4 | CodeDocumentation Documentation 5 | { 6 | get; set; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /it/typescript/src/main.ts: -------------------------------------------------------------------------------- 1 | import { App } from './app/app'; 2 | import { Logger } from './app/common/logger'; 3 | 4 | Logger.logTask('SYSTEM', 'STARTING'); 5 | 6 | App.run(); 7 | 8 | Logger.logTask('SYSTEM', 'FINISHED'); 9 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "formulahendry.dotnet-test-explorer", 4 | "ms-dotnettools.csharp", 5 | "editorconfig.editorconfig", 6 | "ms-dotnettools.blazorwasm-companion" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /it/typescript/src/config/config.global.ts: -------------------------------------------------------------------------------- 1 | export interface IGlobalConfig { 2 | sharedConfigSetting: string; 3 | } 4 | 5 | export const globalConfig: IGlobalConfig = { 6 | sharedConfigSetting: 'this is a shared setting', 7 | }; 8 | -------------------------------------------------------------------------------- /abstractions/swift/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | /*.xcodeproj 5 | xcuserdata/ 6 | DerivedData/ 7 | .swiftpm/config/registries.json 8 | .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata 9 | .netrc 10 | -------------------------------------------------------------------------------- /src/kiota/Rpc/SearchResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Kiota.Builder.SearchProviders; 3 | 4 | namespace kiota.Rpc; 5 | 6 | public record SearchOperationResult(List logs, IDictionary results); 7 | -------------------------------------------------------------------------------- /docs/404.md: -------------------------------------------------------------------------------- 1 | --- 2 | permalink: /404.html 3 | nav_exclude: true 4 | --- 5 | 6 | # Kiota documentation has moved 7 | 8 | Our documentation has been moved to [Microsoft Learn](https://learn.microsoft.com/openapi/kiota/). Please update your bookmarks. 9 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Configuration/SearchConfigurationBase.cs: -------------------------------------------------------------------------------- 1 | namespace Kiota.Builder.Configuration; 2 | 3 | public abstract class SearchConfigurationBase 4 | { 5 | public bool ClearCache 6 | { 7 | get; set; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | remote_theme: pmarsceill/just-the-docs 2 | aux_links: 3 | "Kiota on GitHub": 4 | - "//github.com/microsoft/kiota" 5 | '': 6 | - '#"onclick="switchTheme()"' 7 | -------------------------------------------------------------------------------- /it/typescript/src/config/config.ts: -------------------------------------------------------------------------------- 1 | import { IConfig } from './config.interface'; 2 | import { globalConfig } from './config.global'; 3 | 4 | export const config: IConfig = { 5 | ...globalConfig, 6 | 7 | apiUrl: 'http://a-production-url', 8 | }; 9 | -------------------------------------------------------------------------------- /it/typescript/src/config/config.dev.ts: -------------------------------------------------------------------------------- 1 | import { globalConfig } from './config.global'; 2 | import { IConfig } from './config.interface'; 3 | 4 | export const config: IConfig = { 5 | ...globalConfig, 6 | 7 | apiUrl: 'http://a-development-url', 8 | }; 9 | -------------------------------------------------------------------------------- /src/Kiota.Builder/GenerationLanguage.cs: -------------------------------------------------------------------------------- 1 | namespace Kiota.Builder; 2 | public enum GenerationLanguage 3 | { 4 | CSharp, 5 | Java, 6 | TypeScript, 7 | PHP, 8 | Python, 9 | Go, 10 | Swift, 11 | Ruby, 12 | Shell 13 | } 14 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": ["dbaeumer.vscode-eslint", "amodio.tsl-problem-matcher"] 5 | } 6 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/ICodeElementWriter.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | 3 | namespace Kiota.Builder.Writers; 4 | public interface ICodeElementWriter where T : CodeElement 5 | { 6 | void WriteCodeElement(T codeElement, LanguageWriter writer); 7 | } 8 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/DeprecationInformation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kiota.Builder.CodeDOM; 4 | 5 | public record DeprecationInformation(string? Description, DateTimeOffset? Date, DateTimeOffset? RemovalDate, string? Version, bool IsDeprecated = true); 6 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/ICodeElement.cs: -------------------------------------------------------------------------------- 1 | namespace Kiota.Builder.CodeDOM; 2 | public interface ICodeElement 3 | { 4 | string Name 5 | { 6 | get; set; 7 | } 8 | CodeElement? Parent 9 | { 10 | get; set; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Lock/KiotaLockGenerationContext.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Kiota.Builder.Lock; 4 | 5 | [JsonSerializable(typeof(KiotaLock))] 6 | internal partial class KiotaLockGenerationContext : JsonSerializerContext 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Refiners/IReservedNamesProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Kiota.Builder.Refiners; 4 | public interface IReservedNamesProvider 5 | { 6 | HashSet ReservedNames 7 | { 8 | get; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /abstractions/swift/Source/MicrosoftKiotaAbstractions/HttpMethod.swift: -------------------------------------------------------------------------------- 1 | public enum HttpMethod { 2 | case get 3 | case post 4 | case patch 5 | case delete 6 | case options 7 | case connect 8 | case put 9 | case trace 10 | case head 11 | } -------------------------------------------------------------------------------- /abstractions/swift/Source/MicrosoftKiotaAbstractions/Serialization/SerializationWriterFactory.swift: -------------------------------------------------------------------------------- 1 | public protocol SerializationWriterFactory { 2 | func getValidContentType() throws -> String 3 | func getSerializationWriter(contentType: String) throws -> SerializationWriter 4 | } -------------------------------------------------------------------------------- /it/ruby/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "bundler/gem_tasks" 4 | require "rspec/core/rake_task" 5 | 6 | RSpec::Core::RakeTask.new(:spec) 7 | 8 | require "rubocop/rake_task" 9 | 10 | RuboCop::RakeTask.new 11 | 12 | task default: %i[spec rubocop] 13 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Kiota.Builder.Writers; 2 | public static class StringExtensions 3 | { 4 | public static string StripArraySuffix(this string original) => string.IsNullOrEmpty(original) ? original : original.TrimEnd(']').TrimEnd('['); 5 | } 6 | -------------------------------------------------------------------------------- /src/Kiota.Web/README.md: -------------------------------------------------------------------------------- 1 | # Kiota Web 2 | 3 | ## Debug tips 4 | 5 | ```powershell 6 | dotnet watch run 7 | chrome --remote-debugging-port=9222 --user-data-dir="$Env:TEMP\blazor-chrome-debug" https://localhost:7230/ 8 | ``` 9 | 10 | Once on the page: 11 | alt + shift + D 12 | -------------------------------------------------------------------------------- /abstractions/swift/Source/MicrosoftKiotaAbstractions/Serialization/ParseNodeFactory.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | public protocol ParseNodeFactory { 3 | func getValidContentType() throws -> String 4 | func getRootParseNode(contentType: String, content: Data?) throws -> ParseNode 5 | } -------------------------------------------------------------------------------- /it/ruby/lib/integration_test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative "integration_test/version" 4 | require_relative "integration_test/client/client" 5 | 6 | module Integration_test 7 | class Error < StandardError; end 8 | # Your code goes here... 9 | end 10 | -------------------------------------------------------------------------------- /abstractions/swift/Source/MicrosoftKiotaAbstractions/Authentication/AccessTokenProvider.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public protocol AccessTokenProvider { 4 | func getAuthenticationToken(url: URL) async throws -> String? 5 | var allowedHostsValidator: AllowedHostsValidator { get } 6 | } -------------------------------------------------------------------------------- /src/Kiota.Builder/PathSegmenters/IPathSegmenter.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | 3 | namespace Kiota.Builder.PathSegmenters; 4 | public interface IPathSegmenter 5 | { 6 | string GetPath(CodeNamespace currentNamespace, CodeElement currentElement, bool shouldNormalizePath = true); 7 | } 8 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | out/** 4 | node_modules/** 5 | src/** 6 | .gitignore 7 | .yarnrc 8 | webpack.config.js 9 | vsc-extension-quickstart.md 10 | **/tsconfig.json 11 | **/.eslintrc.json 12 | **/*.map 13 | **/*.ts 14 | .kiotabin/ 15 | .vsix -------------------------------------------------------------------------------- /abstractions/swift/Source/MicrosoftKiotaAbstractions/Authentication/AnonymousAuthenticationProvider.swift: -------------------------------------------------------------------------------- 1 | public class AnonymousAuthenticationProvider : AuthenticationProvider { 2 | public func authenticateRequest(request: RequestInformation) async throws { 3 | // Do nothing 4 | } 5 | } -------------------------------------------------------------------------------- /src/kiota/KiotaConfigurationJsonContext.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Text.Json.Serialization; 3 | using Kiota.Builder.Configuration; 4 | 5 | namespace kiota; 6 | [JsonSerializable(typeof(KiotaConfiguration))] 7 | internal partial class KiotaConfigurationJsonContext : JsonSerializerContext 8 | { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/Kiota.Web/wwwroot/service-worker.js: -------------------------------------------------------------------------------- 1 | // In development, always fetch from the network and do not enable offline support. 2 | // This is because caching would make development more difficult (changes would not 3 | // be reflected on the first load after each change). 4 | self.addEventListener('fetch', () => { }); 5 | -------------------------------------------------------------------------------- /it/typescript/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeRenderers/PythonCodeRenderer.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.Configuration; 2 | 3 | namespace Kiota.Builder.CodeRenderers; 4 | public class PythonCodeRenderer : CodeRenderer 5 | { 6 | public PythonCodeRenderer(GenerationConfiguration configuration) : base(configuration, new CodeElementOrderComparerPython()) { } 7 | } 8 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/ContentFile_type.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | public enum ContentFile_type 6 | { 7 | [EnumMember(Value = "file")] 8 | File, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/kiota/Rpc/ShowResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace kiota.Rpc; 5 | 6 | public record PathItem(string path, string segment, PathItem[] children, bool isOperation = false, Uri? documentationUrl = null); 7 | 8 | public record ShowResult(List logs, PathItem? rootNode, string? apiTitle); 9 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Go/CodeFileBlockEndWriter.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | 3 | namespace Kiota.Builder.Writers.Go; 4 | 5 | public class CodeFileBlockEndWriter : ICodeElementWriter 6 | { 7 | public void WriteCodeElement(CodeFileBlockEnd codeElement, LanguageWriter writer) 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/IDeprecableElement.cs: -------------------------------------------------------------------------------- 1 | namespace Kiota.Builder.CodeDOM; 2 | public interface IDeprecableElement 3 | { 4 | /// 5 | /// Provides detailed information about the deprecation of the element. 6 | /// 7 | DeprecationInformation? Deprecation 8 | { 9 | get; set; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/ContentSymlink_type.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | public enum ContentSymlink_type 6 | { 7 | [EnumMember(Value = "symlink")] 8 | Symlink, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/kiota/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "kiota": { 4 | "commandName": "Project", 5 | "commandLineArgs": "--openapi C:\\src\\msgraph-sdk-powershell\\openApiDocs\\v1.0\\mail.yml -o C:\\Users\\darrmi\\source\\github\\darrelmiller\\OpenApiClient\\Generated -c GraphClient --loglevel Information" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/ContentSubmodule_type.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | public enum ContentSubmodule_type 6 | { 7 | [EnumMember(Value = "submodule")] 8 | Submodule, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /abstractions/swift/MicrosoftKiotaAbstractions.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Refiners/AdditionalUsingEvaluator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Kiota.Builder.CodeDOM; 4 | 5 | namespace Kiota.Builder.Refiners; 6 | 7 | #pragma warning disable CA1819 8 | public record AdditionalUsingEvaluator(Func CodeElementEvaluator, string NamespaceName, params string[] ImportSymbols); 9 | #pragma warning restore CA1819 10 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/Exceptions/InvalidSchemaExceptionTests.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.Exceptions; 2 | 3 | using Xunit; 4 | 5 | namespace Kiota.Builder.Tests.Exceptions; 6 | 7 | public class InvalidSchemaExceptionTests 8 | { 9 | [Fact] 10 | public void Instantiates() 11 | { 12 | Assert.NotNull(new InvalidSchemaException()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /abstractions/swift/Source/MicrosoftKiotaAbstractions/Serialization/Parsable.swift: -------------------------------------------------------------------------------- 1 | public typealias FieldDeserializer = (T, ParseNode) throws -> Void 2 | public typealias ParsableFactory = (ParseNode) throws -> Parsable 3 | public protocol Parsable { 4 | func serialize(writer: SerializationWriter) throws 5 | func getFieldDeserializers() -> [String:FieldDeserializer] 6 | } -------------------------------------------------------------------------------- /src/Kiota.Web/Shared/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | 3 |
4 |
5 | 6 |
7 | 8 |
9 |
10 | 11 |
12 |
13 | @Body 14 |
15 |
16 |
17 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Extensions/UriExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace Kiota.Builder.Extensions; 5 | 6 | public static class UriExtensions 7 | { 8 | public static string GetFileName(this Uri uri) 9 | { 10 | if (uri is null) return string.Empty; 11 | return Path.GetFileName($"{uri.Scheme}://{uri.Host}{uri.AbsolutePath}"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/Index/YamlNamingConvention.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.Extensions; 2 | using YamlDotNet.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.Index; 4 | 5 | internal class YamlNamingConvention : INamingConvention 6 | { 7 | public string Apply(string value) 8 | { 9 | return value.ToFirstCharacterLowerCase(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kiota.Builder; 4 | public static class Constants 5 | { 6 | public const string DefaultOpenApiLabel = "default"; 7 | public const string RawUrlParameterName = "request-raw-url"; 8 | public static readonly TimeSpan DefaultRegexTimeout = TimeSpan.FromMilliseconds(100); 9 | public const string TempDirectoryName = "kiota"; 10 | } 11 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/media/views/deps/reset.css: -------------------------------------------------------------------------------- 1 | html { 2 | box-sizing: border-box; 3 | font-size: 13px; 4 | } 5 | 6 | *, 7 | *:before, 8 | *:after { 9 | box-sizing: inherit; 10 | } 11 | 12 | body, 13 | h1, 14 | h2, 15 | h3, 16 | h4, 17 | h5, 18 | h6, 19 | p, 20 | ol, 21 | ul { 22 | margin: 0; 23 | padding: 0; 24 | font-weight: normal; 25 | } 26 | 27 | img { 28 | max-width: 100%; 29 | height: auto; 30 | } -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/IDiscriminatorInformationHolder.cs: -------------------------------------------------------------------------------- 1 | namespace Kiota.Builder.CodeDOM; 2 | 3 | public interface IDiscriminatorInformationHolder 4 | { 5 | /// 6 | /// Provides information to discriminate the payload response into the correct member type. 7 | /// 8 | public DiscriminatorInformation DiscriminatorInformation 9 | { 10 | get; set; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Php/CodeBlockEndWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Kiota.Builder.CodeDOM; 3 | 4 | namespace Kiota.Builder.Writers.Php; 5 | public class CodeBlockEndWriter : ICodeElementWriter 6 | { 7 | public void WriteCodeElement(BlockEnd codeElement, LanguageWriter writer) 8 | { 9 | ArgumentNullException.ThrowIfNull(writer); 10 | writer.CloseBlock(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/debugging.md: -------------------------------------------------------------------------------- 1 | # Debugging the extension 2 | 3 | 1. run `dotnet publish ./src/kiota/kiota.csproj -p:PublishSingleFile=true -p:PublishReadyToRun=true --self-contained -c Release -r -o ./vscode/microsoft-kiota/.kiotabin///` 4 | 1. in `vscode/microsoft-kiota` run `code . && npm i` 5 | 1. in the code instance that was opened at step 2, just press f5 6 | -------------------------------------------------------------------------------- /it/typescript/build/file-replacer.js: -------------------------------------------------------------------------------- 1 | const { readFile } = require('fs').promises; 2 | 3 | const fileReplacer = (pattern, transformer) => ({ 4 | name: 'fileReplacer', 5 | setup(build) { 6 | build.onLoad({ filter: pattern }, async (args) => ({ 7 | contents: await readFile(transformer(args.path), 'utf8'), 8 | loader: 'default', 9 | })); 10 | }, 11 | }); 12 | 13 | module.exports = fileReplacer; 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/SearchResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Kiota.Builder.SearchProviders; 5 | 6 | #pragma warning disable CA2227 7 | #pragma warning disable CA1002 8 | public record SearchResult(string Title, string Description, Uri? ServiceUrl, Uri? DescriptionUrl, List VersionLabels); 9 | #pragma warning restore CA1002 10 | #pragma warning restore CA2227 11 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Python/CodeBlockEndWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Kiota.Builder.CodeDOM; 3 | 4 | namespace Kiota.Builder.Writers.Python; 5 | public class CodeBlockEndWriter : ICodeElementWriter 6 | { 7 | public void WriteCodeElement(BlockEnd codeElement, LanguageWriter writer) 8 | { 9 | ArgumentNullException.ThrowIfNull(writer); 10 | writer.CloseBlock(string.Empty); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Kiota.Web/wwwroot/kiota.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Kiota.dev", 3 | "short_name": "kiota-dev", 4 | "description": "Generate OpenAPI clients.", 5 | "icons": [ 6 | { 7 | "src": "icon-192.png", 8 | "sizes": "192x192", 9 | "type": "image/png" 10 | } 11 | ], 12 | "start_url": "/", 13 | "lang": "en-us", 14 | "display": "fullscreen", 15 | "theme_color": "#94C73D", 16 | "background_color": "#4C5B31" 17 | } -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/CodeTerminalWithKind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace Kiota.Builder.CodeDOM; 5 | 6 | public abstract class CodeTerminalWithKind : CodeTerminal where T : Enum 7 | { 8 | #nullable disable 9 | public T Kind 10 | { 11 | get; set; 12 | } 13 | #nullable enable 14 | public bool IsOfKind(params T[] kinds) 15 | { 16 | return kinds?.Contains(Kind) ?? false; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/ReleaseAsset_state.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// State of the release asset. 6 | public enum ReleaseAsset_state 7 | { 8 | [EnumMember(Value = "uploaded")] 9 | Uploaded, 10 | [EnumMember(Value = "open")] 11 | Open, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/Index/BlockList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Kiota.Builder.SearchProviders.GitHub.Index; 4 | #pragma warning disable CA2227 5 | #pragma warning disable CA1002 6 | public class BlockList 7 | { 8 | public List Repositories { get; set; } = new(); 9 | public List Organizations { get; set; } = new(); 10 | } 11 | #pragma warning restore CA1002 12 | #pragma warning restore CA2227 13 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_workflows.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to update GitHub Actions workflow files. 6 | public enum AppPermissions_workflows 7 | { 8 | [EnumMember(Value = "write")] 9 | Write, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Swift/CodeMethodWriter.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | 3 | namespace Kiota.Builder.Writers.Swift; 4 | public class CodeMethodWriter : BaseElementWriter 5 | { 6 | public CodeMethodWriter(SwiftConventionService conventionService) : base(conventionService) { } 7 | public override void WriteCodeElement(CodeMethod codeElement, LanguageWriter writer) 8 | { 9 | // TODO (Swift) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/RequestParams.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | 3 | namespace Kiota.Builder.Writers; 4 | public record RequestParams(CodeParameter? requestBody, CodeParameter? requestConfiguration) 5 | { 6 | public CodeProperty? Headers => requestConfiguration?.GetHeadersProperty(); 7 | public CodeProperty? QueryParameters => requestConfiguration?.GetQueryProperty(); 8 | public CodeProperty? Options => requestConfiguration?.GetOptionsProperty(); 9 | } 10 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.IntegrationTests/GeneratesQueryMappers.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.0 2 | info: 3 | title: Test 4 | version: 1.0.0 5 | description: something 6 | paths: 7 | /api/something/v1: 8 | get: 9 | parameters: 10 | - name: "ifExists" 11 | schema: 12 | type: boolean 13 | in: "query" 14 | responses: 15 | "200": 16 | description: "something" 17 | content: 18 | application/json: {} 19 | -------------------------------------------------------------------------------- /it/typescript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2022", 4 | "module": "es2022", 5 | "moduleResolution": "node", 6 | "lib": ["dom", "es2022"], 7 | "experimentalDecorators": true, 8 | "noUnusedLocals": true, 9 | "removeComments": true, 10 | "strict": true, 11 | "typeRoots": ["node_modules/@types"], 12 | "useDefineForClassFields": false 13 | }, 14 | "include": ["src/**/*.ts"], 15 | "exclude": ["node_modules"] 16 | } 17 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_organization_plan.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for viewing an organization's plan. 6 | public enum AppPermissions_organization_plan 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Extensions/OpenApiReferenceExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Models; 2 | 3 | namespace Kiota.Builder.Extensions; 4 | public static class OpenApiReferenceExtensions 5 | { 6 | public static string GetClassName(this OpenApiReference? reference) 7 | { 8 | if (reference?.Id is string referenceId && !string.IsNullOrEmpty(referenceId)) 9 | return referenceId[(referenceId.LastIndexOf('.') + 1)..]; 10 | return string.Empty; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Exceptions/InvalidSchemaException.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | 4 | namespace Kiota.Builder.Exceptions; 5 | 6 | internal class InvalidSchemaException : InvalidOperationException 7 | { 8 | public InvalidSchemaException(string message) : base(message) 9 | { 10 | } 11 | 12 | public InvalidSchemaException(string message, Exception innerException) : base(message, innerException) 13 | { 14 | } 15 | public InvalidSchemaException() 16 | { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Logging/AggregateScope.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kiota.Builder.Logging; 4 | 5 | internal sealed class AggregateScope : IDisposable 6 | { 7 | private readonly IDisposable[] _scopes; 8 | public AggregateScope(params IDisposable[] scopes) 9 | { 10 | _scopes = scopes; 11 | } 12 | public void Dispose() 13 | { 14 | foreach (var scope in _scopes) 15 | scope.Dispose(); 16 | GC.SuppressFinalize(this); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /it/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | # Specify your gem's dependencies in integration_test.gemspec 6 | gemspec 7 | 8 | gem "rake", "~> 13.0" 9 | 10 | gem "rspec", "~> 3.0" 11 | 12 | gem "rubocop", "~> 1.21" 13 | 14 | gem "microsoft_kiota_abstractions", "~> 0.13.0" 15 | 16 | gem "microsoft_kiota_faraday", "~> 0.11.0" 17 | 18 | gem "microsoft_kiota_serialization_json", "~> 0.8.0" 19 | 20 | gem "microsoft_kiota_authentication_oauth", "~> 0.7.0" 21 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Refiners/SwiftReservedNamesProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Kiota.Builder.Refiners; 5 | public class SwiftReservedNamesProvider : IReservedNamesProvider 6 | { 7 | private readonly Lazy> _reservedNames = new(() => new HashSet(StringComparer.OrdinalIgnoreCase) { 8 | "any" 9 | // TODO (Swift) add full list 10 | }); 11 | public HashSet ReservedNames => _reservedNames.Value; 12 | } 13 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_checks.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for checks on code. 6 | public enum AppPermissions_checks 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_statuses.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for commit statuses. 6 | public enum AppPermissions_statuses 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /it/python/integration_test/__init__.py: -------------------------------------------------------------------------------- 1 | from azure.identity.aio import DefaultAzureCredential 2 | from kiota_authentication_azure.azure_identity_authentication_provider import AzureIdentityAuthenticationProvider 3 | from kiota_http.httpx_request_adapter import HttpxRequestAdapter 4 | from .client.api_client import ApiClient 5 | 6 | credential=DefaultAzureCredential() 7 | auth_provider = AzureIdentityAuthenticationProvider(credential) 8 | adapter = HttpxRequestAdapter(auth_provider) 9 | client = ApiClient(adapter) 10 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Refiners/GoExceptionsReservedNamesProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Kiota.Builder.Refiners; 5 | public class GoExceptionsReservedNamesProvider : IReservedNamesProvider 6 | { 7 | private readonly Lazy> _reservedNames = new(static () => new(StringComparer.OrdinalIgnoreCase) 8 | { 9 | "error", 10 | "ResponseStatusCode", 11 | }); 12 | public HashSet ReservedNames => _reservedNames.Value; 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Web/_Imports.razor: -------------------------------------------------------------------------------- 1 | @inherits ComponentWithCancellationToken 2 | @using System.Net.Http 3 | @using System.Net.Http.Json 4 | @using Microsoft.AspNetCore.Components.Forms 5 | @using Microsoft.AspNetCore.Components.Routing 6 | @using Microsoft.AspNetCore.Components.Web 7 | @using Microsoft.AspNetCore.Components.Web.Virtualization 8 | @using Microsoft.AspNetCore.Components.WebAssembly.Http 9 | @using Microsoft.JSInterop 10 | @using Kiota.Web 11 | @using Kiota.Web.Shared 12 | @using BlazorApplicationInsights; 13 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_secrets.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to manage repository secrets. 6 | public enum AppPermissions_secrets 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /SUPPORT.md: -------------------------------------------------------------------------------- 1 | # Support 2 | 3 | ## How to file issues and get help 4 | 5 | This project uses GitHub Issues to track bugs and feature requests. Please search the existing 6 | issues before filing new issues to avoid duplicates. For new issues, file your bug or 7 | feature request as a new Issue. 8 | 9 | For help and questions about using this project, please uses the GitHub discussions. 10 | 11 | ## Microsoft Support Policy 12 | 13 | Support for this **PROJECT** is limited to the resources listed above. 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_members.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for organization teams and members. 6 | public enum AppPermissions_members 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_single_file.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to manage just a single file. 6 | public enum AppPermissions_single_file 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/ISearchProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | namespace Kiota.Builder.SearchProviders; 6 | 7 | public interface ISearchProvider 8 | { 9 | Task> SearchAsync(string term, string? version, CancellationToken cancellationToken); 10 | string ProviderKey 11 | { 12 | get; 13 | } 14 | HashSet KeysToExclude 15 | { 16 | get; init; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Refiners/CSharpReservedClassNamesProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Kiota.Builder.Refiners; 5 | 6 | public class CSharpReservedClassNamesProvider : IReservedNamesProvider 7 | { 8 | private readonly Lazy> _reservedNames = new(static () => new(StringComparer.OrdinalIgnoreCase) 9 | { 10 | "BaseRequestBuilder", 11 | "BaseCliRequestBuilder" 12 | }); 13 | public HashSet ReservedNames => _reservedNames.Value; 14 | } 15 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_environments.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for managing repository environments. 6 | public enum AppPermissions_environments 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_packages.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for packages published to GitHub Packages. 6 | public enum AppPermissions_packages 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Go/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kiota.Builder.Writers.Go; 4 | public static class StringExtensions 5 | { 6 | public static string TrimCollectionAndPointerSymbols(this string s) => 7 | string.IsNullOrEmpty(s) ? s : s.TrimStart('[').TrimStart(']').TrimStart('*'); 8 | 9 | public static string TrimSuffix(this string s, string suffix) => 10 | !string.IsNullOrEmpty(s) && suffix != null && s.EndsWith(suffix, StringComparison.Ordinal) ? s[..^suffix.Length] : s; 11 | } 12 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_deployments.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for deployments and deployment statuses. 6 | public enum AppPermissions_deployments 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_organization_secrets.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to manage organization secrets. 6 | public enum AppPermissions_organization_secrets 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_vulnerability_alerts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to manage Dependabot alerts. 6 | public enum AppPermissions_vulnerability_alerts 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_actions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for GitHub Actions workflows, workflow runs, and artifacts. 6 | public enum AppPermissions_actions 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/TypeScript/CodeBlockEndWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Kiota.Builder.CodeDOM; 3 | 4 | namespace Kiota.Builder.Writers.TypeScript; 5 | public class CodeBlockEndWriter : ICodeElementWriter 6 | { 7 | public void WriteCodeElement(BlockEnd codeElement, LanguageWriter writer) 8 | { 9 | ArgumentNullException.ThrowIfNull(codeElement); 10 | ArgumentNullException.ThrowIfNull(writer); 11 | if (codeElement.Parent is CodeNamespace) return; 12 | writer.CloseBlock(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /it/Readme.md: -------------------------------------------------------------------------------- 1 | # Running the Integration Tests 2 | 3 | Run the following steps to locally run the integration tests. 4 | 5 | Publish locally a development version of `kiota`: 6 | 7 | ```bash 8 | dotnet publish ./src/kiota/kiota.csproj -c Release -p:PublishSingleFile=true -p:PublishReadyToRun=true -o ./publish 9 | ``` 10 | 11 | Generate the code: 12 | 13 | ```bash 14 | ./it/generate-code.ps1 -descriptionUrl ${FILE/URL} -language ${LANG} 15 | ``` 16 | 17 | And finally run the test: 18 | 19 | ```bash 20 | ./it/exec-cmd.ps1 -language ${LANG} 21 | ``` 22 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Refiners/PythonExceptionsReservedNamesProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Kiota.Builder.Refiners; 5 | public class PythonExceptionsReservedNamesProvider : IReservedNamesProvider 6 | { 7 | private readonly Lazy> _reservedNames = new(static () => new(StringComparer.OrdinalIgnoreCase) 8 | { 9 | "mro", 10 | "with_traceback", 11 | "response_status_code", 12 | }); 13 | public HashSet ReservedNames => _reservedNames.Value; 14 | } 15 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_issues.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for issues and related comments, assignees, labels, and milestones. 6 | public enum AppPermissions_issues 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_team_discussions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to manage team discussions and related comments. 6 | public enum AppPermissions_team_discussions 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/Installation_repository_selection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// Describe whether all repositories have been selected or there's a selection involved 6 | public enum Installation_repository_selection 7 | { 8 | [EnumMember(Value = "all")] 9 | All, 10 | [EnumMember(Value = "selected")] 11 | Selected, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /it/typescript/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "tabWidth": 2, 4 | "useTabs": false, 5 | "singleQuote": true, 6 | "quoteProps": "consistent", 7 | "trailingComma": "all", 8 | "bracketSpacing": true, 9 | "bracketSameLine": false, 10 | "arrowParens": "always", 11 | "rangeStart": 0, 12 | "requirePragma": false, 13 | "insertPragma": false, 14 | "proseWrap": "always", 15 | "htmlWhitespaceSensitivity": "css", 16 | "endOfLine": "lf", 17 | "embeddedLanguageFormatting": "auto", 18 | "singleAttributePerLine": true 19 | } 20 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_repository_hooks.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to manage the post-receive hooks for a repository. 6 | public enum AppPermissions_repository_hooks 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_secret_scanning_alerts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to view and manage secret scanning alerts. 6 | public enum AppPermissions_secret_scanning_alerts 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/kiota/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CommandLine; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace kiota; 7 | static class Program 8 | { 9 | static async Task Main(string[] args) 10 | { 11 | var rootCommand = KiotaHost.GetRootCommand(); 12 | var result = await rootCommand.InvokeAsync(args); 13 | foreach (var subCommand in rootCommand.Subcommands.Select(static x => x.Handler).OfType()) 14 | subCommand.Dispose(); 15 | return result; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_metadata.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to search repositories, list collaborators, and access repository metadata. 6 | public enum AppPermissions_metadata 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_organization_administration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to manage access to an organization. 6 | public enum AppPermissions_organization_administration 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_organization_hooks.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to manage the post-receive hooks for an organization. 6 | public enum AppPermissions_organization_hooks 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_security_events.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to view and manage security events like code scanning alerts. 6 | public enum AppPermissions_security_events 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Extensions/CodeParametersEnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | using Kiota.Builder.CodeDOM; 6 | 7 | namespace Kiota.Builder.Extensions; 8 | public static class CodeParametersEnumerableExtensions 9 | { 10 | public static CodeParameter? OfKind(this IEnumerable parameters, CodeParameterKind kind) 11 | { 12 | ArgumentNullException.ThrowIfNull(parameters); 13 | return parameters.FirstOrDefault(x => x != null && x.IsOfKind(kind)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_contents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for repository contents, commits, branches, downloads, releases, and merges. 6 | public enum AppPermissions_contents 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_pages.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to retrieve Pages statuses, configuration, and builds, as well as create new builds. 6 | public enum AppPermissions_pages 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Go/CodeBlockEndWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Kiota.Builder.CodeDOM; 3 | 4 | namespace Kiota.Builder.Writers.Go; 5 | public class CodeBlockEndWriter : ICodeElementWriter 6 | { 7 | public void WriteCodeElement(BlockEnd codeElement, LanguageWriter writer) 8 | { 9 | ArgumentNullException.ThrowIfNull(writer); 10 | ArgumentNullException.ThrowIfNull(codeElement); 11 | if (codeElement.Parent is CodeNamespace || codeElement.Parent is CodeEnum) return; 12 | writer.CloseBlock(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /scripts/entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.cs.allow-jit 6 | 7 | com.apple.security.cs.allow-unsigned-executable-memory 8 | 9 | com.apple.security.cs.allow-dyld-environment-variables 10 | 11 | com.apple.security.cs.disable-library-validation 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeRenderers/TypeScriptCodeRenderer.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Kiota.Builder.CodeDOM; 3 | using Kiota.Builder.Configuration; 4 | 5 | namespace Kiota.Builder.CodeRenderers; 6 | public class TypeScriptCodeRenderer : CodeRenderer 7 | { 8 | public TypeScriptCodeRenderer(GenerationConfiguration configuration) : base(configuration) { } 9 | public override bool ShouldRenderNamespaceFile(CodeNamespace codeNamespace) 10 | { 11 | if (codeNamespace is null) return false; 12 | return codeNamespace.Interfaces.Any(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/Authentication/ITokenStorageService.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | namespace Kiota.Builder.SearchProviders.GitHub.Authentication; 5 | 6 | public interface ITokenStorageService 7 | { 8 | Task GetTokenAsync(CancellationToken cancellationToken); 9 | Task SetTokenAsync(string value, CancellationToken cancellationToken); 10 | Task IsTokenPresentAsync(CancellationToken cancellationToken); 11 | Task DeleteTokenAsync(CancellationToken cancellationToken); 12 | } 13 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_organization_packages.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for organization packages published to GitHub Packages. 6 | public enum AppPermissions_organization_packages 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Java/CodeBlockEndWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Kiota.Builder.CodeDOM; 3 | 4 | namespace Kiota.Builder.Writers.Java; 5 | public class CodeBlockEndWriter : ICodeElementWriter 6 | { 7 | public void WriteCodeElement(BlockEnd codeElement, LanguageWriter writer) 8 | { 9 | ArgumentNullException.ThrowIfNull(writer); 10 | ArgumentNullException.ThrowIfNull(codeElement); 11 | if (codeElement.Parent is CodeNamespace || codeElement.Parent is CodeEnum) return; 12 | writer.CloseBlock(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Kiota.Web/App.razor: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Not found 8 | 9 |

Sorry, there's nothing at this address.

10 |
11 |
12 |
13 | 14 | 15 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_organization_user_blocking.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to view and manage users blocked by the organization. 6 | public enum AppPermissions_organization_user_blocking 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/src/test/suite/extension.test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from 'assert'; 2 | 3 | // You can import and use all API from the 'vscode' module 4 | // as well as import your extension to test it 5 | import * as vscode from 'vscode'; 6 | // import * as myExtension from '../../extension'; 7 | 8 | suite('Extension Test Suite', () => { 9 | void vscode.window.showInformationMessage('Start all tests.'); 10 | 11 | test('Sample test', () => { 12 | assert.strictEqual(-1, [1, 2, 3].indexOf(5)); 13 | assert.strictEqual(-1, [1, 2, 3].indexOf(0)); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_administration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for repository creation, deletion, settings, teams, and collaborators creation. 6 | public enum AppPermissions_administration 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_pull_requests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for pull requests and related comments, assignees, labels, milestones, and merges. 6 | public enum AppPermissions_pull_requests 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_organization_announcement_banners.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to view and manage announcement banners for an organization. 6 | public enum AppPermissions_organization_announcement_banners 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/Writers/Go/GoConventionServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Kiota.Builder.CodeDOM; 4 | using Kiota.Builder.Writers.Go; 5 | 6 | using Xunit; 7 | 8 | namespace Kiota.Builder.Tests.Writers.Go; 9 | public class GoConventionServiceTests 10 | { 11 | private readonly GoConventionService instance = new(); 12 | [Fact] 13 | public void ThrowsOnInvalidOverloads() 14 | { 15 | var root = CodeNamespace.InitRootNamespace(); 16 | Assert.Throws(() => instance.GetAccessModifier(AccessModifier.Private)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Kiota.Builder/GlobComparer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using DotNet.Globbing; 5 | 6 | namespace Kiota.Builder; 7 | 8 | internal class GlobComparer : IEqualityComparer 9 | { 10 | public bool Equals(Glob? x, Glob? y) 11 | { 12 | return x == null && y == null || x != null && y != null && GetHashCode(x) == GetHashCode(y); 13 | } 14 | 15 | public int GetHashCode([DisallowNull] Glob obj) 16 | { 17 | return obj.ToString().GetHashCode(StringComparison.OrdinalIgnoreCase); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/Writers/StringExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.Writers; 2 | 3 | using Xunit; 4 | 5 | namespace Kiota.Builder.Tests.Writers; 6 | public class StringExtensionsTests 7 | { 8 | [Fact] 9 | public void Defensive() 10 | { 11 | Assert.Null(StringExtensions.StripArraySuffix(null)); 12 | Assert.Empty(string.Empty.StripArraySuffix()); 13 | } 14 | [Fact] 15 | public void StripsSuffix() 16 | { 17 | Assert.Equal("foo", "foo[]".StripArraySuffix()); 18 | Assert.Equal("[]foo", "[]foo".StripArraySuffix()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /it/php/phpstan.neon: -------------------------------------------------------------------------------- 1 | parameters: 2 | level: 9 3 | polluteScopeWithAlwaysIterableForeach: false 4 | polluteScopeWithLoopInitialAssignments: false 5 | reportUnmatchedIgnoredErrors: false 6 | paths: 7 | - src 8 | ignoreErrors: 9 | - '#Parameter [\w\W]+ \$errorMappings of method [\w\\]+RequestAdapter::send[\w]+\(\) expects [\w\W\s]+ given\.#' 10 | - '#getFieldDeserializers\(\) should return array\ but returns array\{[\d]\: Closure\(Microsoft\\Kiota\\Abstractions\\Serialization\\ParseNode\)\: void.+#' 11 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Configuration/UpdateConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kiota.Builder.Configuration; 4 | 5 | public class UpdateConfiguration : ICloneable 6 | { 7 | public string OrgName { get; set; } = "microsoft"; 8 | public string RepoName { get; set; } = "kiota"; 9 | public bool Disabled 10 | { 11 | get; set; 12 | } 13 | public object Clone() 14 | { 15 | return new UpdateConfiguration 16 | { 17 | OrgName = OrgName, 18 | RepoName = RepoName, 19 | Disabled = Disabled 20 | }; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/CodeTypeWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Kiota.Builder.CodeDOM; 3 | 4 | namespace Kiota.Builder.Writers; 5 | public class CodeTypeWriter : BaseElementWriter 6 | { 7 | public CodeTypeWriter(ILanguageConventionService conventionService) : base(conventionService) { } 8 | public override void WriteCodeElement(CodeType codeElement, LanguageWriter writer) 9 | { 10 | ArgumentNullException.ThrowIfNull(writer); 11 | writer.Write(conventions.GetTypeString(codeElement, codeElement), includeIndent: false); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Python/CodeNameSpaceWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Kiota.Builder.CodeDOM; 3 | 4 | namespace Kiota.Builder.Writers.Python; 5 | public class CodeNameSpaceWriter : BaseElementWriter 6 | { 7 | public CodeNameSpaceWriter(PythonConventionService conventionService) : base(conventionService) { } 8 | public override void WriteCodeElement(CodeNamespace codeElement, LanguageWriter writer) 9 | { 10 | ArgumentNullException.ThrowIfNull(writer); 11 | writer.WriteLine(); //Add single blank line in init files 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/Writers/Go/GoWriterTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Kiota.Builder.Writers.Go; 4 | 5 | using Xunit; 6 | 7 | namespace Kiota.Builder.Tests.Writers.Go; 8 | public class GoWriterTests 9 | { 10 | [Fact] 11 | public void Instanciates() 12 | { 13 | var writer = new GoWriter("./", "graph"); 14 | Assert.NotNull(writer); 15 | Assert.NotNull(writer.PathSegmenter); 16 | Assert.Throws(() => new GoWriter(null, "graph")); 17 | Assert.Throws(() => new GoWriter("./", null)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_organization_custom_roles.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for custom repository roles management. This property is in beta and is subject to change. 6 | public enum AppPermissions_organization_custom_roles 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Validation/GetWithBody.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Models; 2 | using Microsoft.OpenApi.Validations; 3 | 4 | namespace Kiota.Builder.Validation; 5 | 6 | public class GetWithBody : ValidationRule 7 | { 8 | public GetWithBody() : base(static (context, pathItem) => 9 | { 10 | if (pathItem.Operations.TryGetValue(OperationType.Get, out var getOperation) && getOperation.RequestBody != null) 11 | context.CreateWarning(nameof(GetWithBody), "A GET operation with a body was found. The request body will be ignored."); 12 | }) 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "ES2020", 5 | "lib": [ 6 | "ES2020" 7 | ], 8 | "sourceMap": true, 9 | "rootDir": "src", 10 | "strict": true /* enable all strict type-checking options */ 11 | /* Additional Checks */ 12 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 13 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 14 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/CodeUnionType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kiota.Builder.CodeDOM; 4 | 5 | /// 6 | /// The base class for union types. (anyOf multiple properties at a time) 7 | /// 8 | public class CodeUnionType : CodeComposedTypeBase, ICloneable, IDeprecableElement 9 | { 10 | public DeprecationInformation? Deprecation 11 | { 12 | get; set; 13 | } 14 | public override object Clone() 15 | { 16 | var value = new CodeUnionType().BaseClone(this); 17 | value.Deprecation = Deprecation; 18 | return value; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Configuration/DownloadConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kiota.Builder.Configuration; 4 | 5 | public class DownloadConfiguration : SearchConfigurationBase, ICloneable 6 | { 7 | public string OutputPath { get; set; } = "./output/result.json"; 8 | public bool CleanOutput 9 | { 10 | get; set; 11 | } 12 | 13 | public object Clone() 14 | { 15 | return new DownloadConfiguration 16 | { 17 | OutputPath = OutputPath, 18 | CleanOutput = CleanOutput, 19 | ClearCache = ClearCache 20 | }; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_organization_self_hosted_runners.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to view and manage GitHub Actions self-hosted runners available to an organization. 6 | public enum AppPermissions_organization_self_hosted_runners 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_repository_projects.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to manage repository projects, columns, and cards. 6 | public enum AppPermissions_repository_projects 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | [EnumMember(Value = "admin")] 13 | Admin, 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/Writers/Java/JavaWriterTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Kiota.Builder.Writers.Java; 4 | 5 | using Xunit; 6 | 7 | namespace Kiota.Builder.Tests.Writers.Java; 8 | public class JavaWriterTests 9 | { 10 | [Fact] 11 | public void Instanciates() 12 | { 13 | var writer = new JavaWriter("./", "graph"); 14 | Assert.NotNull(writer); 15 | Assert.NotNull(writer.PathSegmenter); 16 | Assert.Throws(() => new JavaWriter(null, "graph")); 17 | Assert.Throws(() => new JavaWriter("./", null)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/Writers/Ruby/RubyWriterTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Kiota.Builder.Writers.Ruby; 4 | 5 | using Xunit; 6 | 7 | namespace Kiota.Builder.Tests.Writers.Ruby; 8 | public class RubyWriterTests 9 | { 10 | [Fact] 11 | public void Instanciates() 12 | { 13 | var writer = new RubyWriter("./", "graph"); 14 | Assert.NotNull(writer); 15 | Assert.NotNull(writer.PathSegmenter); 16 | Assert.Throws(() => new RubyWriter(null, "graph")); 17 | Assert.Throws(() => new RubyWriter("./", null)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /docs/_includes/js/custom.js: -------------------------------------------------------------------------------- 1 | jtd.onReady(function() { 2 | const theme = localStorage.getItem('theme'); 3 | setTheme(theme); 4 | }); 5 | 6 | function switchTheme() { 7 | const theme = localStorage.getItem('theme'); 8 | const newTheme = theme === 'dark' ? 'light' : 'dark'; 9 | setTheme(newTheme); 10 | } 11 | 12 | function setTheme(theme) { 13 | theme = theme === 'dark' ? 'dark' : 'light'; 14 | jtd.setTheme(theme); 15 | localStorage.setItem('theme', theme); 16 | 17 | const buttonText = theme === 'dark' ? 'Light mode' : 'Dark mode'; 18 | document.getElementById('theme-switch').innerHTML = buttonText; 19 | } 20 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/CodeDOM/CodeIndexerTests.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | using Xunit; 3 | 4 | namespace Kiota.Builder.Tests.CodeDOM; 5 | public class CodeIndexerTests 6 | { 7 | [Fact] 8 | public void IndexerInits() 9 | { 10 | _ = new CodeIndexer 11 | { 12 | Name = "idx", 13 | Documentation = new() 14 | { 15 | Description = "some description", 16 | }, 17 | IndexType = new CodeType(), 18 | ReturnType = new CodeType(), 19 | IndexParameterName = "param", 20 | }; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_organization_personal_access_tokens.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for viewing and managing fine-grained personal access token requests to an organization. 6 | public enum AppPermissions_organization_personal_access_tokens 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/Writers/CSharp/CSharpWriterTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Kiota.Builder.Writers.CSharp; 4 | 5 | using Xunit; 6 | 7 | namespace Kiota.Builder.Tests.Writers.CSharp; 8 | public class CSharpWriterTests 9 | { 10 | [Fact] 11 | public void Instanciates() 12 | { 13 | var writer = new CSharpWriter("./", "graph"); 14 | Assert.NotNull(writer); 15 | Assert.NotNull(writer.PathSegmenter); 16 | Assert.Throws(() => new CSharpWriter(null, "graph")); 17 | Assert.Throws(() => new CSharpWriter("./", null)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/Writers/Python/PythonWriterTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Kiota.Builder.Writers.Python; 4 | 5 | using Xunit; 6 | 7 | namespace Kiota.Builder.Tests.Writers.Python; 8 | public class PythonWriterTests 9 | { 10 | [Fact] 11 | public void Instantiates() 12 | { 13 | var writer = new PythonWriter("./", "graph"); 14 | Assert.NotNull(writer); 15 | Assert.NotNull(writer.PathSegmenter); 16 | Assert.Throws(() => new PythonWriter(null, "graph")); 17 | Assert.Throws(() => new PythonWriter("./", null)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /it/ruby/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "integration_test" 4 | require "microsoft_kiota_abstractions" 5 | require "microsoft_kiota_faraday" 6 | require "microsoft_kiota_serialization_json" 7 | require "microsoft_kiota_authentication_oauth" 8 | 9 | RSpec.configure do |config| 10 | # Enable flags like --only-failures and --next-failure 11 | config.example_status_persistence_file_path = ".rspec_status" 12 | 13 | # Disable RSpec exposing methods globally on `Module` and `main` 14 | config.disable_monkey_patching! 15 | 16 | config.expect_with :rspec do |c| 17 | c.syntax = :expect 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_organization_projects.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token to manage organization projects and projects beta (where available). 6 | public enum AppPermissions_organization_projects 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | [EnumMember(Value = "admin")] 13 | Admin, 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/src/updateClients.ts: -------------------------------------------------------------------------------- 1 | import { connectToKiota, KiotaLogEntry } from "./kiotaInterop"; 2 | import * as rpc from "vscode-jsonrpc/node"; 3 | import * as vscode from "vscode"; 4 | 5 | export function updateClients(context: vscode.ExtensionContext): Promise { 6 | return connectToKiota(context, async (connection) => { 7 | const request = new rpc.RequestType( 8 | "Update" 9 | ); 10 | const result = await connection.sendRequest( 11 | request, 12 | vscode.workspace.workspaceFolders![0].uri.fsPath 13 | ); 14 | return result; 15 | }); 16 | }; -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/CodeIntersectionType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kiota.Builder.CodeDOM; 4 | 5 | /// 6 | /// The base class for exclusion types. (one of the properties at a time) 7 | /// 8 | public class CodeIntersectionType : CodeComposedTypeBase, ICloneable, IDeprecableElement 9 | { 10 | public DeprecationInformation? Deprecation 11 | { 12 | get; set; 13 | } 14 | 15 | public override object Clone() 16 | { 17 | var value = new CodeIntersectionType().BaseClone(this); 18 | value.Deprecation = Deprecation; 19 | return value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Validation/NoContentWithBody.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Microsoft.OpenApi.Models; 3 | using Microsoft.OpenApi.Validations; 4 | 5 | namespace Kiota.Builder.Validation; 6 | 7 | public class NoContentWithBody : ValidationRule 8 | { 9 | public NoContentWithBody() : base(static (context, operation) => 10 | { 11 | if (operation.Responses.TryGetValue("204", out var response) && (response?.Content?.Any() ?? false)) 12 | context.CreateWarning(nameof(NoContentWithBody), "A 204 response with a body media type was found. The response body will be ignored."); 13 | }) 14 | { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Kiota.Web/Shared/NavMenu.razor.css: -------------------------------------------------------------------------------- 1 | .navbar-toggler { 2 | background-color: rgba(255, 255, 255, 0.1); 3 | } 4 | 5 | .top-row { 6 | height: 3.5rem; 7 | background-color: rgba(0,0,0,0.4); 8 | } 9 | 10 | .navbar-brand { 11 | font-size: 1.1rem; 12 | } 13 | 14 | .collapse { 15 | display: none; 16 | } 17 | 18 | @media (min-width: 641px) { 19 | .navbar-toggler { 20 | display: none; 21 | } 22 | .main-nav-menu { 23 | margin-top: 40px; 24 | min-width: 100px; 25 | } 26 | 27 | .collapse { 28 | /* Never collapse the sidebar for wide screens */ 29 | display: block; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Models/AppPermissions_organization_personal_access_token_requests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Models 4 | { 5 | /// The level of permission to grant the access token for viewing and managing fine-grained personal access tokens that have been approved by an organization. 6 | public enum AppPermissions_organization_personal_access_token_requests 7 | { 8 | [EnumMember(Value = "read")] 9 | Read, 10 | [EnumMember(Value = "write")] 11 | Write, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /it/php/src/main.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Kiota.Generated/PathHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | internal class PathHelper 5 | { 6 | internal static string Join(string first, string second) 7 | { 8 | if (string.IsNullOrEmpty(second)) return first; 9 | if (string.IsNullOrEmpty(first)) return second; 10 | return first + 11 | (first.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase) || first.EndsWith(Path.AltDirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase) ? 12 | string.Empty : 13 | Path.DirectorySeparatorChar) + 14 | second; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/Writers/TypeScript/TypeScriptWriterTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Kiota.Builder.Writers.TypeScript; 4 | 5 | using Xunit; 6 | 7 | namespace Kiota.Builder.Tests.Writers.TypeScript; 8 | public class TypeScriptWriterTests 9 | { 10 | [Fact] 11 | public void Instantiates() 12 | { 13 | var writer = new TypeScriptWriter("./", "graph"); 14 | Assert.NotNull(writer); 15 | Assert.NotNull(writer.PathSegmenter); 16 | Assert.Throws(() => new TypeScriptWriter(null, "graph")); 17 | Assert.Throws(() => new TypeScriptWriter("./", null)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Kiota.Builder/PathSegmenters/CSharpPathSegmenter.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | using Kiota.Builder.Extensions; 3 | 4 | namespace Kiota.Builder.PathSegmenters; 5 | public class CSharpPathSegmenter : CommonPathSegmenter 6 | { 7 | public CSharpPathSegmenter(string rootPath, string clientNamespaceName) : base(rootPath, clientNamespaceName) { } 8 | public override string FileSuffix => ".cs"; 9 | public override string NormalizeNamespaceSegment(string segmentName) => segmentName.ToFirstCharacterUpperCase(); 10 | public override string NormalizeFileName(CodeElement currentElement) => GetLastFileNameSegment(currentElement).ToFirstCharacterUpperCase(); 11 | } 12 | -------------------------------------------------------------------------------- /abstractions/swift/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.0 2 | import PackageDescription 3 | 4 | let package = Package( 5 | name: "MicrosoftKiotaAbstractions", 6 | products: [ 7 | .library(name: "MicrosoftKiotaAbstractions", targets: ["MicrosoftKiotaAbstractions"]) 8 | ], 9 | dependencies: [ 10 | .package(url: "https://github.com/kylef/URITemplate.swift.git", from: "3.0.0") 11 | ], 12 | targets: [ 13 | .target(name: "MicrosoftKiotaAbstractions", dependencies: ["URITemplate"]), 14 | .testTarget(name: "MicrosoftKiotaAbstractionsTests", dependencies: ["MicrosoftKiotaAbstractions"]) 15 | ], 16 | swiftLanguageVersions: [.v5] 17 | ) -------------------------------------------------------------------------------- /src/Kiota.Builder/PathSegmenters/JavaPathSegementer.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | using Kiota.Builder.Extensions; 3 | 4 | namespace Kiota.Builder.PathSegmenters; 5 | public class JavaPathSegmenter : CommonPathSegmenter 6 | { 7 | public JavaPathSegmenter(string rootPath, string clientNamespaceName) : base(rootPath, clientNamespaceName) { } 8 | public override string FileSuffix => ".java"; 9 | public override string NormalizeFileName(CodeElement currentElement) => GetLastFileNameSegment(currentElement).ToFirstCharacterUpperCase(); 10 | public override string NormalizeNamespaceSegment(string segmentName) => segmentName?.ToLowerInvariant() ?? string.Empty; 11 | } 12 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/UriExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Kiota.Builder.Extensions; 3 | using Xunit; 4 | 5 | namespace Kiota.Builder.Tests.Writers; 6 | public class UriExtensionsTests 7 | { 8 | [Fact] 9 | public void Defensive() 10 | { 11 | Assert.Empty(UriExtensions.GetFileName(null)); 12 | } 13 | [Fact] 14 | public void GetsFileName() 15 | { 16 | Assert.Equal("todo.yml", new Uri("https://contoso.com/todo.yml").GetFileName()); 17 | } 18 | [Fact] 19 | public void StripsQueryParameters() 20 | { 21 | Assert.Equal("todo.yml", new Uri("https://contoso.com/todo.yml?foo=bar").GetFileName()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/Lock/KiotaLockTests.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.Configuration; 2 | using Kiota.Builder.Lock; 3 | using Xunit; 4 | 5 | namespace Kiota.Builder.Tests.Lock; 6 | 7 | public class KiotaLockTests 8 | { 9 | [Fact] 10 | public void UpdatesAConfiguration() 11 | { 12 | var kiotaLock = new KiotaLock 13 | { 14 | DescriptionLocation = "description", 15 | }; 16 | var generationConfiguration = new GenerationConfiguration(); 17 | kiotaLock.UpdateGenerationConfigurationFromLock(generationConfiguration); 18 | Assert.Equal(kiotaLock.DescriptionLocation, generationConfiguration.OpenAPIFilePath); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /abstractions/swift/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment the next line to define a global platform for your project 2 | platform :ios, '9.0' 3 | 4 | target 'MicrosoftKiotaAbstractions' do 5 | # Comment the next line if you don't want to use dynamic frameworks 6 | use_frameworks! 7 | 8 | # Pods for MicrosoftKiotaAbstractions 9 | pod 'URITemplate' 10 | 11 | target 'MicrosoftKiotaAbstractionsTests' do 12 | # Pods for testing 13 | end 14 | 15 | end 16 | 17 | target 'MicrosoftKiotaAbstractionsPackageDescription' do 18 | # Comment the next line if you don't want to use dynamic frameworks 19 | use_frameworks! 20 | 21 | # Pods for MicrosoftKiotaAbstractionsPackageDescription 22 | 23 | end 24 | -------------------------------------------------------------------------------- /it/ruby/spec/integration_test_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe Integration_test do 4 | it "has a version number" do 5 | expect(Integration_test::VERSION).not_to be nil 6 | end 7 | 8 | it "does something useful" do 9 | context = MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new("9A2BF795-AB23-46CF-BA7D-08F48912CEE0", "E4650AC0-9E59-4997-8215-31D3A42B9A8B", "foo") 10 | auth_provider = MicrosoftKiotaAuthenticationOAuth::OAuthAuthenticationProvider.new(context, nil, nil) 11 | api = Integration_test::Client::ApiClient.new(MicrosoftKiotaFaraday::FaradayRequestAdapter.new(auth_provider)) 12 | expect(api).to_not be nil 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Refiners/TypeScriptExceptionsReservedNamesProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Kiota.Builder.Refiners; 5 | public class TypeScriptExceptionsReservedNamesProvider : IReservedNamesProvider 6 | { 7 | private readonly Lazy> _reservedNames = new(static () => new(StringComparer.OrdinalIgnoreCase) 8 | { 9 | "cause", 10 | "columnNumber", 11 | "fileName", 12 | "lineNumber", 13 | "message", 14 | "name", 15 | "stack", 16 | "toString", 17 | "ResponseStatusCode", 18 | }); 19 | public HashSet ReservedNames => _reservedNames.Value; 20 | } 21 | -------------------------------------------------------------------------------- /it/php/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "integration/test", 3 | "description": "simple integration test project", 4 | "type": "library", 5 | "require": { 6 | "microsoft/kiota-serialization-text": "*", 7 | "microsoft/kiota-http-guzzle": "*", 8 | "microsoft/kiota-serialization-json": "*", 9 | "microsoft/kiota-authentication-phpleague": "*" 10 | }, 11 | "require-dev": { 12 | "phpstan/phpstan": "^1.2.0" 13 | }, 14 | "minimum-stability": "stable", 15 | "license": "MIT", 16 | "autoload": { 17 | "psr-4": { 18 | "Integration\\Test\\": "src/" 19 | } 20 | }, 21 | "autoload-dev": { 22 | "psr-4": { 23 | "Integration\\Test\\": "src/" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/CodeDOM/CodeEnumTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | using Kiota.Builder.CodeDOM; 4 | 5 | using Xunit; 6 | 7 | namespace Kiota.Builder.Tests.CodeDOM; 8 | public class CodeEnumTests 9 | { 10 | [Fact] 11 | public void EnumInits() 12 | { 13 | var root = CodeNamespace.InitRootNamespace(); 14 | var codeEnum = root.AddEnum(new CodeEnum 15 | { 16 | Name = "Enum", 17 | Documentation = new() 18 | { 19 | Description = "some description", 20 | }, 21 | Flags = true, 22 | }).First(); 23 | codeEnum.AddOption(new CodeEnumOption { Name = "option1" }); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Swift/CodeBlockEndWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Kiota.Builder.CodeDOM; 3 | 4 | namespace Kiota.Builder.Writers.Swift; 5 | public class CodeBlockEndWriter : ICodeElementWriter 6 | { 7 | public void WriteCodeElement(BlockEnd codeElement, LanguageWriter writer) 8 | { 9 | ArgumentNullException.ThrowIfNull(codeElement); 10 | ArgumentNullException.ThrowIfNull(writer); 11 | writer.CloseBlock(); 12 | if (codeElement?.Parent?.Parent is CodeNamespace && !(codeElement.Parent is CodeClass currentClass && currentClass.IsOfKind(CodeClassKind.BarrelInitializer))) 13 | { 14 | writer.CloseBlock(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/CSharp/CodeBlockEndWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Kiota.Builder.CodeDOM; 3 | 4 | namespace Kiota.Builder.Writers.CSharp; 5 | public class CodeBlockEndWriter : BaseElementWriter 6 | { 7 | public CodeBlockEndWriter(CSharpConventionService conventionService) : base(conventionService) { } 8 | public override void WriteCodeElement(BlockEnd codeElement, LanguageWriter writer) 9 | { 10 | ArgumentNullException.ThrowIfNull(writer); 11 | writer.CloseBlock(); 12 | if (codeElement?.Parent is CodeClass codeClass && codeClass.Parent is CodeNamespace) 13 | { 14 | writer.CloseBlock(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/IBlock.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Kiota.Builder.CodeDOM; 5 | 6 | /// 7 | /// Marker interface used for type searching. 8 | /// 9 | public interface IBlock 10 | { 11 | T? FindChildByName(string childName, bool findInChildElements = true) where T : ICodeElement; 12 | IEnumerable FindChildrenByName(string childName) where T : ICodeElement; 13 | void AddUsing(params CodeUsing[] codeUsings); 14 | CodeElement? Parent 15 | { 16 | get; set; 17 | } 18 | IEnumerable Usings 19 | { 20 | get; 21 | } 22 | void RenameChildElement(string oldName, string newName); 23 | } 24 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/Extensions/OpenApiReferenceExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.Extensions; 2 | 3 | using Microsoft.OpenApi.Models; 4 | 5 | using Xunit; 6 | 7 | namespace Kiota.Builder.Tests.Extensions; 8 | public class OpenApiReferenceExtensionsTests 9 | { 10 | [Fact] 11 | public void GetsClassName() 12 | { 13 | var reference = new OpenApiReference 14 | { 15 | Id = "microsoft.graph.user" 16 | }; 17 | Assert.Equal("user", reference.GetClassName()); 18 | } 19 | [Fact] 20 | public void GetsClassNameDefensive() 21 | { 22 | var reference = new OpenApiReference(); 23 | Assert.Empty(reference.GetClassName()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Extensions/IEnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Kiota.Builder.Extensions; 5 | 6 | public static class IEnumerableExtensions 7 | { 8 | /// 9 | /// Sums the values of an enumerable of integers, ignoring overflows. 10 | /// 11 | /// The values to sum. 12 | /// The sum of the values. 13 | internal static int SumUnchecked(this IEnumerable values) 14 | { 15 | if (values == null) 16 | return 0; 17 | unchecked 18 | { 19 | return values.Aggregate(0, static (acc, x) => acc + x); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/BaseElementWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Kiota.Builder.CodeDOM; 4 | 5 | namespace Kiota.Builder.Writers; 6 | public abstract class BaseElementWriter : ICodeElementWriter where TElement : CodeElement where TConventionsService : ILanguageConventionService 7 | { 8 | protected BaseElementWriter(TConventionsService conventionService) 9 | { 10 | conventions = conventionService ?? throw new ArgumentNullException(nameof(conventionService)); 11 | } 12 | protected TConventionsService conventions 13 | { 14 | get; init; 15 | } 16 | public abstract void WriteCodeElement(TElement codeElement, LanguageWriter writer); 17 | } 18 | -------------------------------------------------------------------------------- /scripts/get-release-notes.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | [string] 3 | [Parameter(Mandatory = $true)] 4 | $version, 5 | [string] 6 | [Parameter(Mandatory = $true)] 7 | $filePath 8 | ) 9 | 10 | $version = $version.TrimStart("v") 11 | 12 | $changeLogContent = Get-Content $filePath -Raw 13 | $headerLine = "## [$version]" 14 | $headerLineNumber = $changeLogContent.IndexOf("`n" , $changeLogContent.IndexOf($headerLine)) + 3 15 | $endLineNumber = $changeLogContent.IndexOf("## [", $headerLineNumber) - 3 16 | $releaseNotes = $changeLogContent.Substring($headerLineNumber, $endLineNumber - $headerLineNumber) 17 | $targetFile = Join-Path (Split-Path $filePath -Parent) "release-notes.txt" 18 | Set-Content -Path $targetFile -Value $releaseNotes -Verbose -------------------------------------------------------------------------------- /src/kiota/Rpc/ForwardedLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.Extensions.Logging; 4 | 5 | namespace kiota.Rpc; 6 | public class ForwardedLogger : ILogger 7 | { 8 | public List LogEntries { get; } = new(); 9 | 10 | public IDisposable? BeginScope(TState state) where TState : notnull 11 | { 12 | return null; 13 | } 14 | 15 | public bool IsEnabled(LogLevel logLevel) 16 | { 17 | return true; 18 | } 19 | 20 | public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) 21 | { 22 | LogEntries.Add(new(logLevel, formatter(state, exception))); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Validation/NoServerEntry.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Microsoft.OpenApi.Models; 3 | using Microsoft.OpenApi.Validations; 4 | 5 | namespace Kiota.Builder.Validation; 6 | 7 | public class NoServerEntry : ValidationRule 8 | { 9 | public NoServerEntry() : base(static (context, document) => 10 | { 11 | if (!document.Servers.Any() || string.IsNullOrEmpty(document.Servers.First().Url?.TrimEnd('/'))) 12 | context.CreateWarning(nameof(NoServerEntry), 13 | "A servers entry (v3) or host + basePath + schemes properties (v2) was not present in the OpenAPI description. The root URL will need to be set manually with the request adapter."); 14 | }) 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/CodePropertyTypeComparer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | using Kiota.Builder.CodeDOM; 4 | 5 | namespace Kiota.Builder.Writers; 6 | 7 | internal class CodePropertyTypeComparer : IComparer 8 | { 9 | private readonly CodeTypeComparer TypeComparer; 10 | public CodePropertyTypeComparer(bool orderByDesc = false) 11 | { 12 | TypeComparer = new CodeTypeComparer(orderByDesc); 13 | } 14 | public int Compare(CodeProperty? x, CodeProperty? y) 15 | { 16 | return (x, y) switch 17 | { 18 | (null, null) => 0, 19 | (null, _) => -1, 20 | (_, null) => 1, 21 | _ => TypeComparer.Compare(x?.Type, y?.Type), 22 | }; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "out": false, // set this to true to hide the "out" folder with the compiled JS files 5 | "dist": false // set this to true to hide the "dist" folder with the compiled JS files 6 | }, 7 | "search.exclude": { 8 | "out": true, // set this to false to include "out" folder in search results 9 | "dist": true // set this to false to include "dist" folder in search results 10 | }, 11 | // Turn off tsc task auto detection since we have the necessary tasks as npm scripts 12 | "typescript.tsc.autoDetect": "off", 13 | "cSpell.words": [ 14 | "Kiota" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/Kiota.Web/ComponentWithCancellationToken.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | 3 | namespace Kiota.Web; 4 | 5 | public abstract class ComponentWithCancellationToken : ComponentBase, IDisposable 6 | { 7 | private readonly CancellationTokenSource _cancellationTokenSource = new(); 8 | 9 | protected CancellationToken ComponentDetached => _cancellationTokenSource.Token; 10 | 11 | public void Dispose() 12 | { 13 | Dispose(true); 14 | GC.SuppressFinalize(this); 15 | } 16 | public virtual void Dispose(bool disposing) 17 | { 18 | if (_cancellationTokenSource != null) 19 | { 20 | _cancellationTokenSource.Cancel(); 21 | _cancellationTokenSource.Dispose(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Validation/MultipleServerEntries.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Microsoft.OpenApi.Models; 4 | using Microsoft.OpenApi.Validations; 5 | 6 | namespace Kiota.Builder.Validation; 7 | public class MultipleServerEntries : ValidationRule 8 | { 9 | public MultipleServerEntries() : base(static (context, document) => 10 | { 11 | if (document.Servers.GroupBy(static x => x.Url, StringComparer.OrdinalIgnoreCase).Count() > 1) 12 | context.CreateWarning(nameof(MultipleServerEntries), 13 | "Multiple servers entries were found in the OpenAPI description. Only the first one will be used. The root URL can be set manually with the request adapter."); 14 | }) 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /it/csharp/basic/KiotaMockServerTests.cs: -------------------------------------------------------------------------------- 1 | using App.Client; 2 | using Microsoft.Kiota.Http.HttpClientLibrary; 3 | using Microsoft.Kiota.Abstractions.Authentication; 4 | using App.Client.Models; 5 | 6 | namespace Kiota.IT.MockServerTests; 7 | public class KiotaMockServerTests 8 | { 9 | [Fact] 10 | public async Task BasicEndpointTest() 11 | { 12 | var requestAdapter = new HttpClientRequestAdapter(new AnonymousAuthenticationProvider()); 13 | requestAdapter.BaseUrl = "http://localhost:1080"; 14 | var client = new ApiClient(requestAdapter); 15 | 16 | Error error = await Assert.ThrowsAsync(() => client.Api.V1.Topics.GetAsync()); 17 | 18 | Assert.Equal("my-sample-id", error.Id); 19 | Assert.Equal(123, error.Code); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/media/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.github/workflows/abstractions-swift.yml: -------------------------------------------------------------------------------- 1 | name: Swift abstractions 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: [ main ] 7 | paths: ['abstractions/swift/**', '.github/workflows/**'] 8 | pull_request: 9 | paths: ['abstractions/swift/**', '.github/workflows/**'] 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | env: 15 | relativePath: ./abstractions/swift 16 | steps: 17 | - uses: actions/checkout@v3 18 | - uses: swift-actions/setup-swift@v1 19 | with: 20 | swift-version: '5.7' 21 | - name: Build SDK project 22 | run: swift build 23 | working-directory: ${{ env.relativePath }} 24 | - name: Run unit tests 25 | run: swift test 26 | working-directory: ${{ env.relativePath }} 27 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/CodeEnumOption.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.Extensions; 2 | 3 | namespace Kiota.Builder.CodeDOM; 4 | 5 | public class CodeEnumOption : CodeElement, IDocumentedElement, ITypeDefinition, IAlternativeName 6 | { 7 | /// 8 | public string SerializationName { get; set; } = string.Empty; 9 | public CodeDocumentation Documentation { get; set; } = new(); 10 | /// 11 | public bool IsNameEscaped 12 | { 13 | get => !string.IsNullOrEmpty(SerializationName); 14 | } 15 | /// 16 | public string WireName => IsNameEscaped ? SerializationName : Name; 17 | /// 18 | public string SymbolName 19 | { 20 | get => IsNameEscaped ? SerializationName.CleanupSymbolName() : Name; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Refiners/CSharpExceptionsReservedNamesProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Kiota.Builder.Refiners; 5 | public class CSharpExceptionsReservedNamesProvider : IReservedNamesProvider 6 | { 7 | private readonly Lazy> _reservedNames = new(static () => new(StringComparer.OrdinalIgnoreCase) 8 | { 9 | "data", 10 | "helpLink", 11 | "hResult", 12 | "innerException", 13 | "message", 14 | "source", 15 | "stacktrace", 16 | "targetSite", 17 | "GetBaseException", 18 | "GetObjectData", 19 | "GetType", 20 | "ToString", 21 | "ResponseStatusCode", 22 | }); 23 | public HashSet ReservedNames => _reservedNames.Value; 24 | } 25 | -------------------------------------------------------------------------------- /.github/workflows/dotnet-required-workaround.yml: -------------------------------------------------------------------------------- 1 | name: .NET # name must match the original workflow 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: [ main ] 7 | paths: ['abstractions/**', 'authentication/**', 'serialization/**', 'http/**', '**.md', '.vscode/**', '**.svg'] # must be the exact opposite of the original workflow 8 | pull_request: 9 | paths: ['abstractions/**', 'authentication/**', 'serialization/**', 'http/**', '**.md', '.vscode/**', '**.svg'] 10 | 11 | # https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks 12 | 13 | jobs: 14 | build: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - run: 'echo "No build required"' -------------------------------------------------------------------------------- /vscode/microsoft-kiota/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "parserOptions": { 5 | "ecmaVersion": 6, 6 | "sourceType": "module", 7 | "project": "./tsconfig.json" 8 | }, 9 | "plugins": [ 10 | "@typescript-eslint" 11 | ], 12 | "rules": { 13 | "@typescript-eslint/naming-convention": "warn", 14 | "@typescript-eslint/semi": "warn", 15 | "@typescript-eslint/no-floating-promises": "error", 16 | "@typescript-eslint/no-misused-promises": "error", 17 | "curly": "warn", 18 | "eqeqeq": "warn", 19 | "no-throw-literal": "warn", 20 | "semi": "off" 21 | }, 22 | "ignorePatterns": [ 23 | "out", 24 | "dist", 25 | "**/*.d.ts" 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/src/searchDescription.ts: -------------------------------------------------------------------------------- 1 | import { connectToKiota, KiotaSearchResult, KiotaSearchResultItem } from "./kiotaInterop"; 2 | import * as rpc from "vscode-jsonrpc/node"; 3 | import * as vscode from "vscode"; 4 | 5 | export function searchDescription(context: vscode.ExtensionContext, searchTerm: string): Promise | undefined> { 6 | return connectToKiota>(context, async (connection) => { 7 | const request = new rpc.RequestType( 8 | "Search" 9 | ); 10 | const result = await connection.sendRequest( 11 | request, 12 | searchTerm 13 | ); 14 | if(result) { 15 | return result.results; 16 | } 17 | return undefined; 18 | }); 19 | }; -------------------------------------------------------------------------------- /src/Kiota.Builder/Refiners/PhpExceptionsReservedNamesProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Kiota.Builder.Refiners; 5 | 6 | public class PhpExceptionsReservedNamesProvider : IReservedNamesProvider 7 | { 8 | private readonly Lazy> _reservedNames = new(static () => new(StringComparer.OrdinalIgnoreCase) 9 | { 10 | "message", 11 | "code", 12 | "file", 13 | "line", 14 | "response", 15 | "responseStatusCode", 16 | "getMessage", 17 | "getPrevious", 18 | "getCode", 19 | "getFile", 20 | "getLine", 21 | "getTrace", 22 | "getTraceAsString", 23 | "getResponseStatusCode", 24 | }); 25 | public HashSet ReservedNames => _reservedNames.Value; 26 | } 27 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/CodeDOM/CodeUnionTypeTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | using Kiota.Builder.CodeDOM; 4 | 5 | using Xunit; 6 | 7 | namespace Kiota.Builder.Tests.CodeDOM; 8 | public class CodeUnionTypeTests 9 | { 10 | [Fact] 11 | public void ClonesProperly() 12 | { 13 | var root = CodeNamespace.InitRootNamespace(); 14 | var type = new CodeUnionType 15 | { 16 | Name = "type1", 17 | }; 18 | type.AddType(new CodeType 19 | { 20 | Name = "subtype" 21 | }); 22 | var clone = type.Clone() as CodeUnionType; 23 | Assert.NotNull(clone); 24 | Assert.Single(clone.AllTypes); 25 | Assert.Single(clone.Types); 26 | Assert.Equal(type.AllTypes.First().Name, clone.AllTypes.First().Name); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Refiners/CodeUsingDeclarationNameComparer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.CodeAnalysis; 3 | 4 | using Kiota.Builder.CodeDOM; 5 | 6 | using static System.StringComparison; 7 | 8 | namespace Kiota.Builder.Refiners; 9 | public class CodeUsingDeclarationNameComparer : IEqualityComparer 10 | { 11 | public bool Equals(CodeUsing? x, CodeUsing? y) => 12 | x == null && y == null || 13 | x != null && 14 | y != null && 15 | GetHashCode(x) == GetHashCode(y); 16 | public int GetHashCode([DisallowNull] CodeUsing obj) => 17 | (string.IsNullOrEmpty(obj?.Name) ? 0 : obj.Name.GetHashCode(OrdinalIgnoreCase)) * 7 + 18 | (string.IsNullOrEmpty(obj?.Declaration?.Name) ? 0 : obj.Declaration.Name.GetHashCode(OrdinalIgnoreCase)); 19 | } 20 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.IntegrationTests/ModelWithDictionary.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.0 2 | info: 3 | title: "Dictionary API" 4 | version: "1.0.0" 5 | servers: 6 | - url: https://example.org/ 7 | paths: 8 | /resource: 9 | get: 10 | responses: 11 | 200: 12 | description: ok 13 | content: 14 | application/json: 15 | schema: 16 | $ref: "#/components/schemas/resource" 17 | components: 18 | schemas: 19 | resource: 20 | type: object 21 | properties: 22 | info: 23 | type: string 24 | # customSettings: Dictionary 25 | customSettings: 26 | type: object 27 | patternProperties: 28 | ".*": 29 | type: string 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/kiota/Rpc/IServer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using Kiota.Builder; 5 | 6 | namespace kiota.Rpc; 7 | internal interface IServer 8 | { 9 | string GetVersion(); 10 | Task> UpdateAsync(string output, CancellationToken cancellationToken); 11 | Task SearchAsync(string searchTerm, CancellationToken cancellationToken); 12 | Task ShowAsync(string descriptionPath, string[] includeFilters, string[] excludeFilters, CancellationToken cancellationToken); 13 | Task> GenerateAsync(string descriptionPath, string output, GenerationLanguage language, string[] includeFilters, string[] excludeFilters, string clientClassName, string clientNamespaceName, CancellationToken cancellationToken); 14 | } 15 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeElementOrderComparerWithExternalMethods.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | 3 | namespace Kiota.Builder; 4 | public class CodeElementOrderComparerWithExternalMethods : CodeElementOrderComparer 5 | { 6 | protected override int GetTypeFactor(CodeElement element) 7 | { 8 | return element switch 9 | { 10 | CodeUsing => 1, 11 | ClassDeclaration => 2, 12 | CodeProperty => 3, 13 | InterfaceDeclaration => 4, 14 | CodeMethod method when method.Parent is CodeInterface => 5, //methods are declared inside of interfaces 15 | BlockEnd => 6, 16 | CodeClass => 7, 17 | CodeInterface => 8, 18 | CodeIndexer => 9, 19 | CodeMethod => 10, 20 | _ => 0, 21 | }; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/CodeUsing.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kiota.Builder.CodeDOM; 4 | public class CodeUsing : CodeElement, ICloneable 5 | { 6 | private CodeType? declaration; 7 | public CodeType? Declaration 8 | { 9 | get => declaration; set 10 | { 11 | EnsureElementsAreChildren(value); 12 | declaration = value; 13 | } 14 | } 15 | public bool IsExternal 16 | { 17 | get => Declaration?.IsExternal ?? true; 18 | } 19 | public string Alias { get; set; } = string.Empty; 20 | public object Clone() 21 | { 22 | return new CodeUsing 23 | { 24 | Declaration = Declaration?.Clone() as CodeType, 25 | Alias = Alias, 26 | Name = Name, 27 | Parent = Parent, 28 | }; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/APIsGuru/APIEntry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace Kiota.Builder.SearchProviders.APIsGuru; 6 | 7 | public record ApiEntry(DateTimeOffset? added, string preferred, Dictionary versions); 8 | 9 | public record ApiVersion(DateTimeOffset? added, ApiInformation info, DateTimeOffset? updated, Uri swaggerUrl, Uri swaggerYamlUrl, string openApiVer); 10 | 11 | public record ApiInformation 12 | { 13 | public ApiContact? contact 14 | { 15 | get; set; 16 | } 17 | public string description { get; set; } = string.Empty; 18 | public string title { get; set; } = string.Empty; 19 | } 20 | 21 | public record ApiContact(string email, string name, Uri url); 22 | 23 | public record ApiOrigin(Uri url); 24 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/Authentication/PatAuthenticationProvider.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.Collections.Generic; 4 | using Microsoft.Extensions.Logging; 5 | 6 | namespace Kiota.Builder.SearchProviders.GitHub.Authentication; 7 | public class PatAuthenticationProvider : BaseAuthenticationProvider 8 | { 9 | public PatAuthenticationProvider(string clientId, string scope, IEnumerable validHosts, ILogger logger, ITokenStorageService StorageService) : 10 | base(clientId, scope, validHosts, logger, (_, _, validHosts) => new PatAccessTokenProvider 11 | { 12 | StorageService = StorageService, 13 | AllowedHostsValidator = new(validHosts), 14 | }, false) 15 | { 16 | ArgumentNullException.ThrowIfNull(StorageService); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/kiota/Authentication/GitHub/DeviceCode/DeviceCodeResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace kiota.Authentication.GitHub.DeviceCode; 5 | 6 | internal class GitHubDeviceCodeResponse 7 | { 8 | [JsonPropertyName("device_code")] 9 | public string? DeviceCode 10 | { 11 | get; set; 12 | } 13 | [JsonPropertyName("user_code")] 14 | public string? UserCode 15 | { 16 | get; set; 17 | } 18 | [JsonPropertyName("verification_uri")] 19 | public Uri? VerificationUri 20 | { 21 | get; set; 22 | } 23 | [JsonPropertyName("expires_in")] 24 | public uint ExpiresInSeconds 25 | { 26 | get; set; 27 | } 28 | [JsonPropertyName("interval")] 29 | public uint IntervalInSeconds 30 | { 31 | get; set; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/src/test/runTest.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | 3 | import { runTests } from '@vscode/test-electron'; 4 | 5 | async function main() { 6 | try { 7 | // The folder containing the Extension Manifest package.json 8 | // Passed to `--extensionDevelopmentPath` 9 | const extensionDevelopmentPath = path.resolve(__dirname, '../../'); 10 | 11 | // The path to test runner 12 | // Passed to --extensionTestsPath 13 | const extensionTestsPath = path.resolve(__dirname, './suite/index'); 14 | 15 | // Download VS Code, unzip it and run the integration test 16 | await runTests({ extensionDevelopmentPath, extensionTestsPath }); 17 | } catch (err) { 18 | console.error('Failed to run tests', err); 19 | process.exit(1); 20 | } 21 | } 22 | 23 | // eslint-disable-next-line @typescript-eslint/no-floating-promises 24 | main(); 25 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env 2 | WORKDIR /app 3 | 4 | COPY ./src ./kiota/src 5 | WORKDIR /app/kiota 6 | RUN dotnet publish ./src/kiota/kiota.csproj -c Release -p:TreatWarningsAsErrors=false 7 | 8 | FROM mcr.microsoft.com/dotnet/runtime:7.0 AS runtime 9 | WORKDIR /app 10 | 11 | COPY --from=build-env /app/kiota/src/kiota/bin/Release/net7.0 ./ 12 | 13 | VOLUME /app/output 14 | VOLUME /app/openapi.yml 15 | ENV KIOTA_CONTAINER=true DOTNET_TieredPGO=1 DOTNET_TC_QuickJitForLoops=1 16 | ENTRYPOINT ["dotnet", "kiota.dll"] 17 | LABEL description="# Welcome to Kiota Generator \ 18 | To start generating SDKs checkout [the getting started documentation](https://learn.microsoft.com/openapi/kiota/install#run-in-docker) \ 19 | [Source dockerfile](https://github.com/microsoft/kiota/blob/main/Dockerfile)" 20 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/src/test/suite/index.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import * as Mocha from 'mocha'; 3 | import {glob} from 'glob'; 4 | 5 | export async function run(): Promise { 6 | // Create the mocha test 7 | const mocha = new Mocha({ 8 | ui: 'tdd', 9 | color: true 10 | }); 11 | 12 | const testsRoot = path.resolve(__dirname, '..'); 13 | 14 | const files = await glob('**/**.test.js', { cwd: testsRoot }); 15 | 16 | // Add files to the test suite 17 | files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); 18 | 19 | 20 | try { 21 | // Run the mocha test 22 | mocha.run(failures => { 23 | if (failures > 0) { 24 | throw new Error(`${failures} tests failed.`); 25 | } 26 | }); 27 | } catch (err) { 28 | console.error(err); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/GitHubClient/Repos/Item/Item/Releases/ReleasesPostRequestBody_make_latest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | namespace Kiota.Builder.SearchProviders.GitHub.GitHubClient.Repos.Item.Item.Releases 4 | { 5 | /// Specifies whether this release should be set as the latest release for the repository. Drafts and prereleases cannot be set as latest. Defaults to `true` for newly published releases. `legacy` specifies that the latest release should be determined based on the release creation date and higher semantic version. 6 | public enum ReleasesPostRequestBody_make_latest 7 | { 8 | [EnumMember(Value = "true")] 9 | True, 10 | [EnumMember(Value = "false")] 11 | False, 12 | [EnumMember(Value = "legacy")] 13 | Legacy, 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Kiota.Generated/KiotaGenerated.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | latest 6 | true 7 | true 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Extensions/CodePropertiesEnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | using Kiota.Builder.CodeDOM; 6 | 7 | namespace Kiota.Builder.Extensions; 8 | 9 | internal static class CodePropertiesEnumerableExtensions 10 | { 11 | public static CodeProperty? FirstOrDefaultOfKind(this IEnumerable properties, params CodePropertyKind[] kinds) 12 | { 13 | ArgumentNullException.ThrowIfNull(properties); 14 | return properties.FirstOrDefault(x => x != null && x.IsOfKind(kinds)); 15 | } 16 | public static IEnumerable OfKind(this IEnumerable properties, params CodePropertyKind[] kinds) 17 | { 18 | ArgumentNullException.ThrowIfNull(properties); 19 | return properties.Where(x => x != null && x.IsOfKind(kinds)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/Authentication/AccessCodeResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Kiota.Builder.SearchProviders.GitHub.Authentication; 5 | 6 | public class AccessCodeResponse 7 | { 8 | [JsonPropertyName("access_token")] 9 | public string AccessToken { get; set; } = string.Empty; 10 | [JsonPropertyName("token_type")] 11 | public string TokenType { get; set; } = string.Empty; 12 | [JsonPropertyName("scope")] 13 | public string Scope { get; set; } = string.Empty; 14 | [JsonPropertyName("error")] 15 | public string Error { get; set; } = string.Empty; 16 | [JsonPropertyName("error_description")] 17 | public string ErrorDescription { get; set; } = string.Empty; 18 | [JsonPropertyName("error_uri")] 19 | public Uri? ErrorUri 20 | { 21 | get; set; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/CountLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.Extensions.Logging; 4 | 5 | namespace Kiota.Builder.Tests; 6 | 7 | internal class CountLogger : ILogger 8 | { 9 | public IDisposable BeginScope(TState state) where TState : notnull 10 | { 11 | throw new NotImplementedException(); 12 | } 13 | public bool IsEnabled(LogLevel logLevel) 14 | { 15 | throw new NotImplementedException(); 16 | } 17 | internal Dictionary Count { get; } = new(); 18 | public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) 19 | { 20 | if (Count.ContainsKey(logLevel)) 21 | Count[logLevel] += 1; 22 | else 23 | Count.Add(logLevel, 1); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /abstractions/README.md: -------------------------------------------------------------------------------- 1 | # Welcome to the Kiota abstractions section 2 | 3 | The Kiota abstractions are language specific libraries defining the basic constructs Kiota projects need once an SDK has been generated from an OpenAPI definition. 4 | Your project will need a reference to the abstraction package to build and run, the following languages are currently supported: 5 | 6 | - [Dotnet](https://github.com/microsoft/kiota-abstractions-dotnet) 7 | - [Java](https://github.com/microsoft/kiota-java/tree/main/components/abstractions) 8 | - [Go](https://github.com/microsoft/kiota-abstractions-go) 9 | - [Ruby](https://github.com/microsoft/kiota-abstractions-ruby) 10 | - [TypeScript](https://github.com/microsoft/kiota-typescript/tree/main/packages/abstractions) 11 | - [PHP](https://github.com/microsoft/kiota-abstractions-php) 12 | - [Python](https://github.com/microsoft/kiota-abstractions-python) 13 | -------------------------------------------------------------------------------- /abstractions/swift/Source/MicrosoftKiotaAbstractions/Authentication/AllowedHostsValidator.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | public class AllowedHostsValidator { 3 | private var validHostsIntl = Set() 4 | public init(validHosts: [String]) { 5 | self.validHosts = validHosts; 6 | } 7 | public var validHosts: [String] { get { 8 | return Array(validHostsIntl) 9 | 10 | } set (validHosts) { 11 | self.validHostsIntl = Set(validHosts.map { $0.lowercased() }) 12 | }} 13 | public func isUrlHostValid(url: URL) -> Bool { 14 | if let host = url.host { 15 | return validHostsIntl.contains(host.lowercased()) 16 | } 17 | return false 18 | } 19 | } 20 | public let isSchemeHttps = { (url: URL) -> Bool in 21 | if let scheme = url.scheme { 22 | return scheme.lowercased() == "https" 23 | } 24 | return false 25 | } -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Ruby/CodeBlockEndWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Kiota.Builder.CodeDOM; 3 | 4 | namespace Kiota.Builder.Writers.Ruby; 5 | public class CodeBlockEndWriter : BaseElementWriter 6 | { 7 | private const string End = "end"; 8 | public CodeBlockEndWriter(RubyConventionService conventionService) : base(conventionService) { } 9 | public override void WriteCodeElement(BlockEnd codeElement, LanguageWriter writer) 10 | { 11 | ArgumentNullException.ThrowIfNull(codeElement); 12 | ArgumentNullException.ThrowIfNull(writer); 13 | if (codeElement.Parent is CodeEnum) return; 14 | writer.CloseBlock(End); 15 | if (codeElement?.Parent is CodeClass codeClass && codeClass.Parent is CodeNamespace ns) 16 | { 17 | conventions.WriteNamespaceClosing(ns, writer); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.github/workflows/codeql-required-workaround.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" # name must match the original workflow 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: [ main ] 7 | paths: ['abstractions/**', 'authentication/**', 'serialization/**', 'http/**', '**.md', '.vscode/**', '**.svg'] # must be the exact opposite of the original workflow 8 | pull_request: 9 | paths: ['abstractions/**', 'authentication/**', 'serialization/**', 'http/**', '**.md', '.vscode/**', '**.svg'] 10 | 11 | # https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks 12 | 13 | jobs: 14 | analyze: #names must match the original workflow 15 | name: Analyze (csharp) 16 | runs-on: ubuntu-latest 17 | steps: 18 | - run: 'echo "No CodeQL Analysis required"' -------------------------------------------------------------------------------- /src/Kiota.Builder/Lock/StringIEnumerableDeepComparer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Kiota.Builder.Lock; 6 | /// 7 | /// A comparer that compares two of by their content. 8 | /// 9 | internal class StringIEnumerableDeepComparer : IEqualityComparer> 10 | { 11 | /// 12 | public bool Equals(IEnumerable? x, IEnumerable? y) 13 | { 14 | return x == null && y == null || x != null && y != null && GetHashCode(x) == GetHashCode(y); 15 | } 16 | /// 17 | public int GetHashCode(IEnumerable obj) 18 | { 19 | if (obj == null) return 0; 20 | return string.Join(",", obj.Order(StringComparer.OrdinalIgnoreCase)).GetHashCode(StringComparison.Ordinal); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | # See here for image contents: https://github.com/microsoft/vscode-dev-containers/blob/v0.245.2/containers/dotnet/.devcontainer/Dockerfile 2 | 3 | ARG VARIANT="7.0-bullseye-slim" 4 | FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT} 5 | 6 | # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 7 | ARG NODE_VERSION="none" 8 | RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi 9 | 10 | # [Optional] Uncomment this section to install additional OS packages. 11 | # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ 12 | # && apt-get -y install --no-install-recommends 13 | 14 | # [Optional] Uncomment this line to install global node packages. 15 | # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 -------------------------------------------------------------------------------- /vscode/microsoft-kiota/src/getKiotaVersion.ts: -------------------------------------------------------------------------------- 1 | import { connectToKiota } from "./kiotaInterop"; 2 | import * as rpc from "vscode-jsonrpc/node"; 3 | import * as vscode from "vscode"; 4 | 5 | export function getKiotaVersion(context: vscode.ExtensionContext, kiotaOutputChannel: vscode.LogOutputChannel): Promise { 6 | return connectToKiota(context, async (connection) => { 7 | const request = new rpc.RequestType0("GetVersion"); 8 | const result = await connection.sendRequest(request); 9 | if (result) { 10 | const version = result.split("+")[0]; 11 | if (version) { 12 | kiotaOutputChannel.info(`kiota: ${version}`); 13 | return version; 14 | } 15 | } 16 | kiotaOutputChannel.error(`kiota: ${vscode.l10n.t('not found')}`); 17 | kiotaOutputChannel.show(); 18 | return undefined; 19 | }); 20 | }; -------------------------------------------------------------------------------- /src/Kiota.Builder/PathSegmenters/PHPPathSegmenter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Kiota.Builder.CodeDOM; 4 | using Kiota.Builder.Extensions; 5 | 6 | namespace Kiota.Builder.PathSegmenters; 7 | public class PhpPathSegmenter : CommonPathSegmenter 8 | { 9 | public PhpPathSegmenter(string rootPath, string clientNamespaceName) : base(rootPath, clientNamespaceName) { } 10 | public override string FileSuffix => ".php"; 11 | public override string NormalizeNamespaceSegment(string segmentName) => segmentName.ToFirstCharacterUpperCase(); 12 | protected static new string GetLastFileNameSegment(CodeElement currentElement) => currentElement?.Name.Split(new char[] { '.', '\\' }, StringSplitOptions.RemoveEmptyEntries).Last() ?? string.Empty; 13 | public override string NormalizeFileName(CodeElement currentElement) => GetLastFileNameSegment(currentElement).ToFirstCharacterUpperCase(); 14 | } 15 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Java/JavaWriter.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.PathSegmenters; 2 | 3 | namespace Kiota.Builder.Writers.Java; 4 | public class JavaWriter : LanguageWriter 5 | { 6 | public JavaWriter(string rootPath, string clientNamespaceName) 7 | { 8 | PathSegmenter = new JavaPathSegmenter(rootPath, clientNamespaceName); 9 | var conventionService = new JavaConventionService(); 10 | AddOrReplaceCodeElementWriter(new CodeClassDeclarationWriter(conventionService)); 11 | AddOrReplaceCodeElementWriter(new CodeBlockEndWriter()); 12 | AddOrReplaceCodeElementWriter(new CodeEnumWriter(conventionService)); 13 | AddOrReplaceCodeElementWriter(new CodeMethodWriter(conventionService)); 14 | AddOrReplaceCodeElementWriter(new CodePropertyWriter(conventionService)); 15 | AddOrReplaceCodeElementWriter(new CodeTypeWriter(conventionService)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Kiota.Builder/PathSegmenters/PythonPathSegmenter.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | using Kiota.Builder.Extensions; 3 | 4 | namespace Kiota.Builder.PathSegmenters; 5 | public class PythonPathSegmenter : CommonPathSegmenter 6 | { 7 | public PythonPathSegmenter(string rootPath, string clientNamespaceName) : base(rootPath, clientNamespaceName) { } 8 | public override string FileSuffix => ".py"; 9 | public override string NormalizeFileName(CodeElement currentElement) 10 | { 11 | return currentElement switch 12 | { 13 | CodeNamespace => "__init__", 14 | _ => GetDefaultFileName(currentElement) 15 | }; 16 | } 17 | private static string GetDefaultFileName(CodeElement currentElement) => GetLastFileNameSegment(currentElement).ToSnakeCase(); 18 | public override string NormalizeNamespaceSegment(string segmentName) => segmentName.ToSnakeCase(); 19 | } 20 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/KiotaGeneratedTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using Xunit; 4 | 5 | public class KiotaGeneratedTests 6 | { 7 | [Fact] 8 | public void StaticallyGeneratedAssemblyVersion() 9 | { 10 | var topLevelFolder = Directory.GetParent(Path.GetDirectoryName(typeof(KiotaGeneratedTests).Assembly.Location)) 11 | .Parent 12 | .Parent 13 | .Parent 14 | .Parent 15 | .FullName; 16 | var csprojFile = Path.Join(topLevelFolder, "src", "Kiota.Builder", "Kiota.Builder.csproj"); 17 | 18 | var line = Array.Find(File.ReadAllLines(csprojFile), l => l.Contains("")); 19 | line = line.Trim(); 20 | line = line.Replace("", ""); 21 | var version = line.Replace("", ""); 22 | 23 | Assert.Equal(version, Kiota.Generated.KiotaVersion.Current()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Kiota.Builder/BaseStringComparisonComparer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Kiota.Builder; 5 | 6 | public abstract class BaseStringComparisonComparer : IComparer 7 | { 8 | public abstract int Compare(T? x, T? y); 9 | public int CompareStrings(string? x, string? y, StringComparer comparer) 10 | { 11 | return (x, y) switch 12 | { 13 | (null, null) => 0, 14 | (null, _) => -1, 15 | (_, null) => 1, 16 | #pragma warning disable CA1062 17 | _ => NormalizeComparisonResult(comparer.Compare(x, y)), 18 | #pragma warning restore CA1062 19 | }; 20 | } 21 | private static int NormalizeComparisonResult(int result) 22 | { 23 | if (result < 0) 24 | return -1; 25 | else if (result > 0) 26 | return 1; 27 | else 28 | return 0; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/Configuration/GenerationConfigurationTests.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.Configuration; 2 | using Xunit; 3 | 4 | namespace Kiota.Builder.Tests.Configuration; 5 | public class GenerationConfigurationTests 6 | { 7 | [Fact] 8 | public void Clones() 9 | { 10 | var generationConfiguration = new GenerationConfiguration 11 | { 12 | ClientClassName = "class1", 13 | IncludePatterns = null, 14 | }; 15 | var clone = generationConfiguration.Clone() as GenerationConfiguration; 16 | Assert.NotNull(clone); 17 | Assert.Equal(generationConfiguration.ClientClassName, clone.ClientClassName); 18 | Assert.NotNull(clone.IncludePatterns); 19 | Assert.Empty(clone.IncludePatterns); 20 | clone.ClientClassName = "class2"; 21 | Assert.NotEqual(generationConfiguration.ClientClassName, clone.ClientClassName); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Swift/SwiftWriter.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.PathSegmenters; 2 | 3 | namespace Kiota.Builder.Writers.Swift; 4 | public class SwiftWriter : LanguageWriter 5 | { 6 | public SwiftWriter(string rootPath, string clientNamespaceName) 7 | { 8 | PathSegmenter = new SwiftPathSegmenter(rootPath, clientNamespaceName); 9 | var conventionService = new SwiftConventionService(clientNamespaceName); 10 | AddOrReplaceCodeElementWriter(new CodeClassDeclarationWriter(conventionService)); 11 | AddOrReplaceCodeElementWriter(new CodeBlockEndWriter()); 12 | AddOrReplaceCodeElementWriter(new CodePropertyWriter(conventionService)); 13 | AddOrReplaceCodeElementWriter(new CodeNamespaceWriter(conventionService)); 14 | AddOrReplaceCodeElementWriter(new CodeEnumWriter(conventionService)); 15 | AddOrReplaceCodeElementWriter(new CodeMethodWriter(conventionService)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Php/PhpWriter.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.PathSegmenters; 2 | 3 | namespace Kiota.Builder.Writers.Php; 4 | public class PhpWriter : LanguageWriter 5 | { 6 | public PhpWriter(string rootPath, string clientNamespaceName, bool useBackingStore = false) 7 | { 8 | PathSegmenter = new PhpPathSegmenter(rootPath, clientNamespaceName); 9 | var conventionService = new PhpConventionService(); 10 | AddOrReplaceCodeElementWriter(new CodeClassDeclarationWriter(conventionService)); 11 | AddOrReplaceCodeElementWriter(new CodePropertyWriter(conventionService)); 12 | AddOrReplaceCodeElementWriter(new CodeMethodWriter(conventionService, useBackingStore)); 13 | AddOrReplaceCodeElementWriter(new CodeBlockEndWriter()); 14 | AddOrReplaceCodeElementWriter(new CodeEnumWriter(conventionService)); 15 | AddOrReplaceCodeElementWriter(new CodeTypeWriter(conventionService)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // See https://go.microsoft.com/fwlink/?LinkId=733558 2 | // for the documentation about the tasks.json format 3 | { 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "watch", 9 | "problemMatcher": "$ts-webpack-watch", 10 | "isBackground": true, 11 | "presentation": { 12 | "reveal": "never", 13 | "group": "watchers" 14 | }, 15 | "group": { 16 | "kind": "build", 17 | "isDefault": true 18 | } 19 | }, 20 | { 21 | "type": "npm", 22 | "script": "watch-tests", 23 | "problemMatcher": "$tsc-watch", 24 | "isBackground": true, 25 | "presentation": { 26 | "reveal": "never", 27 | "group": "watchers" 28 | }, 29 | "group": "build" 30 | }, 31 | { 32 | "label": "tasks: watch-tests", 33 | "dependsOn": [ 34 | "npm: watch", 35 | "npm: watch-tests" 36 | ], 37 | "problemMatcher": [] 38 | } 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /it/mockserver/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | io.kiota 8 | kiota-mock-server 9 | 0.0.1-SNAPSHOT 10 | 11 | 12 | 5.14.0 13 | 14 | 15 | 16 | 17 | 18 | org.mock-server 19 | mockserver-maven-plugin 20 | ${mockserver.version} 21 | 22 | 1080 23 | DEBUG 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/Authentication/AnonymousAuthenticationProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using Microsoft.Kiota.Abstractions; 6 | using Microsoft.Kiota.Abstractions.Authentication; 7 | 8 | namespace Kiota.Builder.SearchProviders.GitHub.Authentication; 9 | public class AnonymousAuthenticationProvider : IAuthenticationProvider 10 | { 11 | public virtual Task AuthenticateRequestAsync(RequestInformation request, Dictionary? additionalAuthenticationContext = null, CancellationToken cancellationToken = default) 12 | { 13 | ArgumentNullException.ThrowIfNull(request); 14 | request.Headers.Add("User-Agent", $"Kiota/{GetType().Assembly.GetName().Version}"); 15 | // request.Headers.Add("X-GitHub-Api-Version", "2022-11-28"); does not support cors today 16 | return Task.CompletedTask; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.github/workflows/auto-merge-dependabot.yml: -------------------------------------------------------------------------------- 1 | name: Auto-merge dependabot updates 2 | 3 | on: 4 | pull_request: 5 | branches: [ main ] 6 | 7 | permissions: 8 | pull-requests: write 9 | contents: write 10 | 11 | jobs: 12 | 13 | dependabot-merge: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | if: ${{ github.actor == 'dependabot[bot]' }} 18 | 19 | steps: 20 | - name: Dependabot metadata 21 | id: metadata 22 | uses: dependabot/fetch-metadata@v1.6.0 23 | with: 24 | github-token: "${{ secrets.GITHUB_TOKEN }}" 25 | 26 | - name: Enable auto-merge for Dependabot PRs 27 | # Only if version bump is not a major version change 28 | if: ${{steps.metadata.outputs.update-type != 'version-update:semver-major'}} 29 | run: gh pr merge --auto --merge "$PR_URL" 30 | env: 31 | PR_URL: ${{github.event.pull_request.html_url}} 32 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 33 | -------------------------------------------------------------------------------- /it/go/basic/go.mod: -------------------------------------------------------------------------------- 1 | module integrationtest 2 | 3 | go 1.20 4 | 5 | require ( 6 | github.com/microsoft/kiota-abstractions-go v0.19.0 7 | github.com/microsoft/kiota-serialization-form-go v0.9.0 8 | github.com/microsoft/kiota-serialization-json-go v0.9.0 9 | github.com/microsoft/kiota-serialization-text-go v0.7.0 10 | ) 11 | 12 | require ( 13 | github.com/cjlapao/common-go v0.0.39 // indirect 14 | github.com/davecgh/go-spew v1.1.1 // indirect 15 | github.com/go-logr/logr v1.2.3 // indirect 16 | github.com/go-logr/stdr v1.2.2 // indirect 17 | github.com/google/uuid v1.3.0 // indirect 18 | github.com/microsoft/kiota-http-go v0.16.1 // indirect 19 | github.com/pmezard/go-difflib v1.0.0 // indirect 20 | github.com/stretchr/testify v1.8.2 // indirect 21 | github.com/yosida95/uritemplate/v3 v3.0.2 // indirect 22 | go.opentelemetry.io/otel v1.14.0 // indirect 23 | go.opentelemetry.io/otel/trace v1.14.0 // indirect 24 | gopkg.in/yaml.v3 v3.0.1 // indirect 25 | ) 26 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Shell/ShellWriter.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.Writers.CSharp; 2 | 3 | namespace Kiota.Builder.Writers.Shell; 4 | class ShellWriter : CSharpWriter 5 | { 6 | public ShellWriter(string rootPath, string clientNamespaceName) : base(rootPath, clientNamespaceName) 7 | { 8 | var conventionService = new CSharpConventionService(); 9 | AddOrReplaceCodeElementWriter(new CodeClassDeclarationWriter(conventionService)); 10 | AddOrReplaceCodeElementWriter(new CodeBlockEndWriter(conventionService)); 11 | AddOrReplaceCodeElementWriter(new CodeEnumWriter(conventionService)); 12 | AddOrReplaceCodeElementWriter(new CodeIndexerWriter(conventionService)); 13 | AddOrReplaceCodeElementWriter(new ShellCodeMethodWriter(conventionService)); 14 | AddOrReplaceCodeElementWriter(new CodePropertyWriter(conventionService)); 15 | AddOrReplaceCodeElementWriter(new CodeTypeWriter(conventionService)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Refiners/JavaExceptionsReservedNamesProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Kiota.Builder.Refiners; 5 | public class JavaExceptionsReservedNamesProvider : IReservedNamesProvider 6 | { 7 | private readonly Lazy> _reservedNames = new(static () => new(StringComparer.OrdinalIgnoreCase) 8 | { 9 | "addSuppressed", 10 | "clone", 11 | "equals", 12 | "fillInStackTrace", 13 | "finalize", 14 | "getCause", 15 | "getClass", 16 | "getLocalizedMessage", 17 | "getMessage", 18 | "getStackTrace", 19 | "getSuppressed", 20 | "hashCode", 21 | "initCause", 22 | "notify", 23 | "notifyAll", 24 | "printStackTrace", 25 | "setStackTrace", 26 | "toString", 27 | "ResponseStatusCode", 28 | }); 29 | public HashSet ReservedNames => _reservedNames.Value; 30 | } 31 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/CodeDomExtensions.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | 3 | namespace Kiota.Builder.Tests; 4 | public static class CodeDomExtensions 5 | { 6 | public static void AddBackingStoreProperty(this CodeClass codeClass) 7 | { 8 | codeClass?.AddProperty(new CodeProperty 9 | { 10 | Name = "backingStore", 11 | Kind = CodePropertyKind.BackingStore, 12 | Type = new CodeType 13 | { 14 | Name = "BackingStore", 15 | }, 16 | }); 17 | } 18 | public static void AddAccessedProperty(this CodeMethod codeMethod) 19 | { 20 | codeMethod.AccessedProperty = new CodeProperty 21 | { 22 | Name = "someProperty", 23 | Type = new CodeType 24 | { 25 | Name = "string", 26 | }, 27 | }; 28 | (codeMethod.Parent as CodeClass)?.AddProperty(codeMethod.AccessedProperty); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /abstractions/swift/Source/MicrosoftKiotaAbstractions/Serialization/SerializationWriterFactoryRegistry.swift: -------------------------------------------------------------------------------- 1 | public enum SerializationWriterFactoryRegistryErrors : Error { 2 | case registrySupportsMultipleTypesGetOneFactory 3 | case factoryNotFoundForContentType 4 | } 5 | public class SerializationWriterFactoryRegistry : SerializationWriterFactory { 6 | public var contentTypeAssociatedFactories = [String:SerializationWriterFactory]() 7 | public func getValidContentType() throws -> String { 8 | throw SerializationWriterFactoryRegistryErrors.registrySupportsMultipleTypesGetOneFactory 9 | } 10 | public func getSerializationWriter(contentType: String) throws -> SerializationWriter { 11 | guard let factory = contentTypeAssociatedFactories[contentType] else { 12 | throw SerializationWriterFactoryRegistryErrors.factoryNotFoundForContentType 13 | } 14 | return try factory.getSerializationWriter(contentType: contentType) 15 | } 16 | } -------------------------------------------------------------------------------- /src/Kiota.Web/StringBuilderLogger.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace Kiota.Web; 4 | public class StringBuilderLogger : ILogger 5 | { 6 | private readonly StringBuilder _stringBuilder; 7 | private readonly LogLevel _logLevel; 8 | public StringBuilderLogger(StringBuilder stringBuilder, LogLevel logLevel) 9 | { 10 | ArgumentNullException.ThrowIfNull(stringBuilder); 11 | _stringBuilder = stringBuilder; 12 | _logLevel = logLevel; 13 | } 14 | public IDisposable? BeginScope(TState state) where TState : notnull => null; 15 | public bool IsEnabled(LogLevel logLevel) => logLevel != LogLevel.None && logLevel >= _logLevel; 16 | public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) 17 | { 18 | if (!IsEnabled(logLevel)) 19 | return; 20 | _stringBuilder.AppendLine(formatter(state, exception)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/ILanguageConventionService.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | 3 | namespace Kiota.Builder.Writers; 4 | public interface ILanguageConventionService 5 | { 6 | string GetAccessModifier(AccessModifier access); 7 | string StreamTypeName 8 | { 9 | get; 10 | } 11 | string VoidTypeName 12 | { 13 | get; 14 | } 15 | string DocCommentPrefix 16 | { 17 | get; 18 | } 19 | string ParseNodeInterfaceName 20 | { 21 | get; 22 | } 23 | string TempDictionaryVarName 24 | { 25 | get; 26 | } 27 | string GetTypeString(CodeTypeBase code, CodeElement targetElement, bool includeCollectionInformation = true, LanguageWriter? writer = null); 28 | string TranslateType(CodeType type); 29 | string GetParameterSignature(CodeParameter parameter, CodeElement targetElement, LanguageWriter? writer = null); 30 | void WriteShortDescription(string description, LanguageWriter writer); 31 | } 32 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/CodeDOM/CodeUsingComparerTests.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | using Kiota.Builder.Refiners; 3 | 4 | using Xunit; 5 | 6 | namespace Kiota.Builder.Tests.CodeDOM; 7 | public class CodeUsingComparerTests 8 | { 9 | [Fact] 10 | public void ComparesWithDeclaration() 11 | { 12 | var root = CodeNamespace.InitRootNamespace(); 13 | var cUsing = new CodeUsing 14 | { 15 | Name = "using1", 16 | }; 17 | cUsing.Declaration = new CodeType 18 | { 19 | Name = "type1" 20 | }; 21 | 22 | var cUsing2 = new CodeUsing 23 | { 24 | Name = "using2", 25 | }; 26 | cUsing2.Declaration = new CodeType 27 | { 28 | Name = "type2" 29 | }; 30 | var comparer = new CodeUsingComparer(true); 31 | Assert.False(comparer.Equals(cUsing, cUsing2)); 32 | Assert.NotEqual(0, comparer.GetHashCode(cUsing)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /it/go/basic/client_test.go: -------------------------------------------------------------------------------- 1 | package integrationtest 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | "integrationtest/client" 7 | "integrationtest/client/models" 8 | "testing" 9 | 10 | "github.com/microsoft/kiota-abstractions-go/authentication" 11 | http "github.com/microsoft/kiota-http-go" 12 | ) 13 | 14 | func TestMockServerBasic(t *testing.T) { 15 | httpAdapter, _ := http.NewNetHttpRequestAdapter(&authentication.AnonymousAuthenticationProvider{}) 16 | httpAdapter.SetBaseUrl("http://localhost:1080") 17 | client := client.NewApiClient(httpAdapter) 18 | 19 | _, err := client.Api().V1().Topics().Get(context.Background(), nil) 20 | 21 | target := &models.Error{} 22 | if errors.As(err, &target) { 23 | if *target.GetId() != "my-sample-id" { 24 | t.Errorf("Error Id incorrect %v\n", *target.GetId()) 25 | } 26 | if *target.GetCode() != 123 { 27 | t.Errorf("Error Code incorrect %v\n", *target.GetCode()) 28 | } 29 | } else { 30 | t.Errorf("Error is an incorrect type %v\n", err) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Kiota.Builder/OpenApiServerComparer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Text.RegularExpressions; 5 | using Microsoft.OpenApi.Models; 6 | 7 | namespace Kiota.Builder; 8 | 9 | internal partial class OpenApiServerComparer : IEqualityComparer 10 | { 11 | private static readonly Regex _protocolCleanupRegex = GetCleanupRegex(); 12 | [GeneratedRegex("^https?://", RegexOptions.IgnoreCase | RegexOptions.Compiled, 200)] 13 | private static partial Regex GetCleanupRegex(); 14 | public bool Equals(OpenApiServer? x, OpenApiServer? y) 15 | { 16 | return x != null && y != null && GetHashCode(x) == GetHashCode(y); 17 | } 18 | public int GetHashCode([DisallowNull] OpenApiServer obj) 19 | { 20 | if (string.IsNullOrEmpty(obj?.Url)) 21 | return 0; 22 | return _protocolCleanupRegex.Replace(obj.Url, string.Empty).GetHashCode(StringComparison.OrdinalIgnoreCase); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /it/csharp/dotnet.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net7.0 6 | enable 7 | enable 8 | App 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Refiners/CodeUsingComparer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | 5 | using Kiota.Builder.CodeDOM; 6 | 7 | namespace Kiota.Builder.Refiners; 8 | public class CodeUsingComparer : IEqualityComparer 9 | { 10 | private readonly bool _compareOnDeclaration; 11 | public CodeUsingComparer(bool compareOnDeclaration) 12 | { 13 | _compareOnDeclaration = compareOnDeclaration; 14 | } 15 | public bool Equals(CodeUsing? x, CodeUsing? y) 16 | { 17 | return (!_compareOnDeclaration || x?.Declaration == y?.Declaration) && (x?.Name?.Equals(y?.Name, StringComparison.Ordinal) ?? false); 18 | } 19 | 20 | public int GetHashCode([DisallowNull] CodeUsing obj) 21 | { 22 | return (_compareOnDeclaration ? (obj?.Declaration == null ? 0 : obj.Declaration.GetHashCode()) * 7 : 0) + 23 | (string.IsNullOrEmpty(obj?.Name) ? 0 : obj.Name.GetHashCode(StringComparison.Ordinal)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.IntegrationTests/InheritingErrors.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.3 2 | info: 3 | title: Kafka Instance API 4 | version: 0.13.0-SNAPSHOT 5 | paths: 6 | /api/v1/topics: 7 | get: 8 | summary: Retrieves a list of topics 9 | operationId: getTopics 10 | responses: 11 | "423": 12 | description: Example. 13 | content: 14 | application/json: 15 | schema: 16 | $ref: "#/components/schemas/Error" 17 | components: 18 | schemas: 19 | Error: 20 | allOf: 21 | - $ref: "#/components/schemas/ObjectReference" 22 | - description: General error response 23 | type: object 24 | properties: 25 | code: 26 | format: int32 27 | type: integer 28 | example: 123 29 | ObjectReference: 30 | type: object 31 | properties: 32 | id: 33 | description: Unique identifier. 34 | type: string 35 | example: my-sample-id 36 | -------------------------------------------------------------------------------- /abstractions/swift/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "PathKit", 6 | "repositoryURL": "https://github.com/kylef/PathKit.git", 7 | "state": { 8 | "branch": null, 9 | "revision": "3bfd2737b700b9a36565a8c94f4ad2b050a5e574", 10 | "version": "1.0.1" 11 | } 12 | }, 13 | { 14 | "package": "Spectre", 15 | "repositoryURL": "https://github.com/kylef/Spectre.git", 16 | "state": { 17 | "branch": null, 18 | "revision": "26cc5e9ae0947092c7139ef7ba612e34646086c7", 19 | "version": "0.10.1" 20 | } 21 | }, 22 | { 23 | "package": "URITemplate", 24 | "repositoryURL": "https://github.com/kylef/URITemplate.swift.git", 25 | "state": { 26 | "branch": null, 27 | "revision": "a309673fdf86e4919a0250730e461ac533a03b3a", 28 | "version": "3.0.1" 29 | } 30 | } 31 | ] 32 | }, 33 | "version": 1 34 | } 35 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/CSharp/CSharpWriter.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.PathSegmenters; 2 | 3 | namespace Kiota.Builder.Writers.CSharp; 4 | public class CSharpWriter : LanguageWriter 5 | { 6 | public CSharpWriter(string rootPath, string clientNamespaceName) 7 | { 8 | PathSegmenter = new CSharpPathSegmenter(rootPath, clientNamespaceName); 9 | var conventionService = new CSharpConventionService(); 10 | AddOrReplaceCodeElementWriter(new CodeClassDeclarationWriter(conventionService)); 11 | AddOrReplaceCodeElementWriter(new CodeBlockEndWriter(conventionService)); 12 | AddOrReplaceCodeElementWriter(new CodeEnumWriter(conventionService)); 13 | AddOrReplaceCodeElementWriter(new CodeIndexerWriter(conventionService)); 14 | AddOrReplaceCodeElementWriter(new CodeMethodWriter(conventionService)); 15 | AddOrReplaceCodeElementWriter(new CodePropertyWriter(conventionService)); 16 | AddOrReplaceCodeElementWriter(new CodeTypeWriter(conventionService)); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Logging/AggregateLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Microsoft.Extensions.Logging; 4 | 5 | namespace Kiota.Builder.Logging; 6 | public class AggregateLogger : ILogger 7 | { 8 | private readonly ILogger[] Loggers; 9 | public AggregateLogger(params ILogger[] loggers) 10 | { 11 | Loggers = loggers; 12 | } 13 | public IDisposable? BeginScope(TState state) where TState : notnull 14 | { 15 | return new AggregateScope(Loggers.Select(l => l.BeginScope(state)).Where(static s => s != null).Select(static x => x!).ToArray()); 16 | } 17 | public bool IsEnabled(LogLevel logLevel) 18 | { 19 | return Loggers.Any(l => l.IsEnabled(logLevel)); 20 | } 21 | public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) 22 | { 23 | foreach (var logger in Loggers) 24 | logger.Log(logLevel, eventId, state, exception, formatter); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/CodeFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Kiota.Builder.CodeDOM; 6 | 7 | public class CodeFile : CodeBlock 8 | { 9 | public IEnumerable AddElements(params T[] elements) where T : CodeElement 10 | { 11 | if (elements == null || elements.Any(static x => x == null)) 12 | throw new ArgumentNullException(nameof(elements)); 13 | if (!elements.Any()) 14 | throw new ArgumentOutOfRangeException(nameof(elements)); 15 | 16 | return AddRange(elements); 17 | } 18 | 19 | public IEnumerable AllUsingsFromChildElements => GetChildElements() 20 | .SelectMany(static x => x.GetChildElements()) 21 | .OfType() 22 | .SelectMany(static x => x.Usings); 23 | } 24 | public class CodeFileDeclaration : ProprietableBlockDeclaration 25 | { 26 | } 27 | 28 | public class CodeFileBlockEnd : BlockEnd 29 | { 30 | } 31 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Refiners/GoReservedNamesProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Kiota.Builder.Refiners; 5 | public class GoReservedNamesProvider : IReservedNamesProvider 6 | { 7 | private readonly Lazy> _reservedNames = new(() => new(StringComparer.OrdinalIgnoreCase) { 8 | "break", 9 | "case", 10 | "chan", 11 | "const", 12 | "continue", 13 | "default", 14 | "defer", 15 | "else", 16 | "fallthrough", 17 | "for", 18 | "func", 19 | "go", 20 | "goto", 21 | "if", 22 | "import", 23 | "interface", 24 | "map", 25 | "package", 26 | "range", 27 | "return", 28 | "select", 29 | "struct", 30 | "switch", 31 | "type", 32 | "var", 33 | "vendor", // cannot be used as a package name 34 | "BaseRequestBuilder" 35 | }); 36 | public HashSet ReservedNames => _reservedNames.Value; 37 | } 38 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/src/generateClient.ts: -------------------------------------------------------------------------------- 1 | import { connectToKiota, KiotaGenerationLanguage, KiotaLogEntry } from "./kiotaInterop"; 2 | import * as rpc from "vscode-jsonrpc/node"; 3 | import * as vscode from "vscode"; 4 | 5 | export function generateClient(context: vscode.ExtensionContext, descriptionPath: string, output: string, language: KiotaGenerationLanguage, includeFilters: string[], excludeFilters: string[], clientClassName: string, clientNamespaceName: string): Promise { 6 | return connectToKiota(context, async (connection) => { 7 | const request = new rpc.RequestType7( 8 | "Generate" 9 | ); 10 | return await connection.sendRequest( 11 | request, 12 | descriptionPath, 13 | output, 14 | language, 15 | includeFilters, 16 | excludeFilters, 17 | clientClassName, 18 | clientNamespaceName 19 | ); 20 | }); 21 | }; -------------------------------------------------------------------------------- /tests/Kiota.Web.Tests/KiotaWebGeneralTests.cs: -------------------------------------------------------------------------------- 1 | using Deque.AxeCore.Playwright; 2 | 3 | namespace Kiota.Web.Tests; 4 | 5 | [Collection(PlaywrightFixture.PlaywrightCollection)] 6 | public class KiotaWebGeneralTests : IAsyncDisposable 7 | { 8 | private readonly PlaywrightFixture playwrightFixture; 9 | public KiotaWebGeneralTests(PlaywrightFixture playwrightFixture) 10 | { 11 | this.playwrightFixture = playwrightFixture; 12 | } 13 | public async ValueTask DisposeAsync() 14 | { 15 | await playwrightFixture.DisposeAsync(); 16 | GC.SuppressFinalize(this); 17 | } 18 | [Fact] 19 | public async Task PassesAxeAccessibilityReview() 20 | { 21 | // Open a page and run test logic. 22 | await playwrightFixture.GotoPageAsync( 23 | playwrightFixture.DotnetUrl!, 24 | async (page) => 25 | { 26 | var axeResults = await page.RunAxe(); 27 | Assert.Empty(axeResults.Violations); 28 | }, 29 | Browser.Chromium); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Logging/FileLogLoggerProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.Extensions.Logging; 4 | 5 | namespace Kiota.Builder.Logging; 6 | 7 | public sealed class FileLogLoggerProvider : ILoggerProvider 8 | { 9 | private readonly LogLevel _logLevel; 10 | private readonly string _logFileDirectoryAbsolutePath; 11 | public FileLogLoggerProvider(string logFileDirectoryAbsolutePath, LogLevel logLevel) 12 | { 13 | _logLevel = logLevel; 14 | _logFileDirectoryAbsolutePath = logFileDirectoryAbsolutePath; 15 | } 16 | private readonly List _loggers = new(); 17 | public ILogger CreateLogger(string categoryName) 18 | { 19 | var instance = new FileLogLogger(_logFileDirectoryAbsolutePath, _logLevel, categoryName); 20 | _loggers.Add(instance); 21 | return instance; 22 | } 23 | public void Dispose() 24 | { 25 | foreach (var logger in _loggers) 26 | logger.Dispose(); 27 | GC.SuppressFinalize(this); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Ruby/RubyWriter.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.PathSegmenters; 2 | 3 | namespace Kiota.Builder.Writers.Ruby; 4 | public class RubyWriter : LanguageWriter 5 | { 6 | public RubyWriter(string rootPath, string clientNamespaceName) 7 | { 8 | PathSegmenter = new RubyPathSegmenter(rootPath, clientNamespaceName); 9 | var conventionService = new RubyConventionService(); 10 | var pathSegmenter = new RubyPathSegmenter(rootPath, clientNamespaceName); 11 | AddOrReplaceCodeElementWriter(new CodeClassDeclarationWriter(conventionService, clientNamespaceName, pathSegmenter)); 12 | AddOrReplaceCodeElementWriter(new CodeBlockEndWriter(conventionService)); 13 | AddOrReplaceCodeElementWriter(new CodeNamespaceWriter(conventionService, pathSegmenter)); 14 | AddOrReplaceCodeElementWriter(new CodeEnumWriter(conventionService)); 15 | AddOrReplaceCodeElementWriter(new CodeMethodWriter(conventionService)); 16 | AddOrReplaceCodeElementWriter(new CodePropertyWriter(conventionService)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Swift/CodeNamespaceWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | using Kiota.Builder.CodeDOM; 5 | 6 | namespace Kiota.Builder.Writers.Swift; 7 | public class CodeNamespaceWriter : BaseElementWriter 8 | { 9 | public CodeNamespaceWriter(SwiftConventionService conventionService) : base(conventionService) { } 10 | public override void WriteCodeElement(CodeNamespace codeElement, LanguageWriter writer) 11 | { 12 | ArgumentNullException.ThrowIfNull(codeElement); 13 | ArgumentNullException.ThrowIfNull(writer); 14 | var segments = codeElement.Name.Split("."); 15 | var lastSegment = segments.Last(); 16 | var parentNamespaces = string.Join('.', segments[..^1]); 17 | writer.WriteLine($"extension {parentNamespaces} {{"); 18 | writer.IncreaseIndent(); 19 | writer.WriteLine($"public struct {lastSegment} {{"); 20 | writer.WriteLine("}"); 21 | writer.DecreaseIndent(); 22 | writer.WriteLine("}"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /abstractions/swift/Source/MicrosoftKiotaAbstractions/RequestAdapter.swift: -------------------------------------------------------------------------------- 1 | public typealias ErrorMappings = [String:ParsableFactory] 2 | public typealias ResponseHandler = (Any, ErrorMappings) async throws -> DeserializationType 3 | public protocol RequestAdapter { 4 | func send(request: RequestInformation, ctor: ParsableFactory, responseHandler: ResponseHandler?, errorMappings: ErrorMappings?) async throws -> T? 5 | func sendCollection(request: RequestInformation, ctor: ParsableFactory, responseHandler: ResponseHandler?, errorMappings: ErrorMappings?) async throws -> [T]? 6 | func sendPrimitive(request: RequestInformation, responseHandler: ResponseHandler?, errorMappings: ErrorMappings?) async throws -> T? 7 | func sendNoContent(request: RequestInformation, responseHandler: ResponseHandler?, errorMappings: ErrorMappings?) async throws -> Void 8 | func enableBackingStore() throws 9 | var baseUrl: String { get set } 10 | var serializationWriterFactory: SerializationWriterFactory { get } 11 | } -------------------------------------------------------------------------------- /src/Kiota.Builder/PathSegmenters/SwiftPathSegmenter.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | using Kiota.Builder.Extensions; 3 | 4 | namespace Kiota.Builder.PathSegmenters; 5 | public class SwiftPathSegmenter : CommonPathSegmenter 6 | { 7 | public SwiftPathSegmenter(string rootPath, string clientNamespaceName) : base(rootPath, clientNamespaceName) { } 8 | public override string FileSuffix => ".swift"; 9 | public override string NormalizeNamespaceSegment(string segmentName) => segmentName.ToFirstCharacterUpperCase(); 10 | public override string NormalizeFileName(CodeElement currentElement) 11 | { 12 | var fileName = GetLastFileNameSegment(currentElement).ToFirstCharacterUpperCase(); 13 | var suffix = currentElement switch 14 | { 15 | CodeNamespace n => n.Name.GetNamespaceImportSymbol(string.Empty), 16 | CodeClass c => c.GetImmediateParentOfType().Name.GetNamespaceImportSymbol(string.Empty), 17 | _ => string.Empty, 18 | }; 19 | return fileName + suffix; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Go/GoWriter.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.PathSegmenters; 2 | 3 | namespace Kiota.Builder.Writers.Go; 4 | public class GoWriter : LanguageWriter 5 | { 6 | public GoWriter(string rootPath, string clientNamespaceName) 7 | { 8 | PathSegmenter = new GoPathSegmenter(rootPath, clientNamespaceName); 9 | var conventionService = new GoConventionService(); 10 | AddOrReplaceCodeElementWriter(new CodeClassDeclarationWriter(conventionService)); 11 | AddOrReplaceCodeElementWriter(new CodeInterfaceDeclarationWriter(conventionService)); 12 | AddOrReplaceCodeElementWriter(new CodeBlockEndWriter()); 13 | AddOrReplaceCodeElementWriter(new CodePropertyWriter(conventionService)); 14 | AddOrReplaceCodeElementWriter(new CodeEnumWriter(conventionService)); 15 | AddOrReplaceCodeElementWriter(new CodeMethodWriter(conventionService)); 16 | AddOrReplaceCodeElementWriter(new CodeFileBlockEndWriter()); 17 | AddOrReplaceCodeElementWriter(new CodeFileDeclarationWriter(conventionService)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Kiota.Web/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:35259", 7 | "sslPort": 44313 8 | } 9 | }, 10 | "profiles": { 11 | "Kiota.Web": { 12 | "commandName": "Project", 13 | "dotnetRunMessages": true, 14 | "launchBrowser": true, 15 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 16 | "applicationUrl": "https://localhost:7230;http://localhost:5130", 17 | "environmentVariables": { 18 | "ASPNETCORE_ENVIRONMENT": "Development" 19 | } 20 | }, 21 | "IIS Express": { 22 | "commandName": "IISExpress", 23 | "launchBrowser": true, 24 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /.github/workflows/deploy-kiota-dev.yml: -------------------------------------------------------------------------------- 1 | name: Deploy kiota.dev 2 | on: 3 | push: 4 | tags: ["v*"] 5 | 6 | jobs: 7 | publish_kiota_dev: 8 | name: Publish kiota.dev 9 | environment: 10 | name: kiota.dev 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - name: Setup .NET 15 | uses: actions/setup-dotnet@v3 16 | with: 17 | dotnet-version: 7.0.x 18 | - name: Restore workloads 19 | run: | 20 | dotnet workload restore 21 | dotnet workload install wasm-tools 22 | - name: Publish kiota.dev 23 | run: dotnet publish -c Release 24 | working-directory: ./src/Kiota.Web 25 | 26 | - uses: LanceMcCarthy/Action-AzureBlobUpload@v2 27 | name: Azure Blob Upload with Destination folder defined 28 | with: 29 | connection_string: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }} 30 | container_name: "$web" 31 | source_folder: src/Kiota.Web/bin/Release/net7.0/publish/wwwroot 32 | delete_if_exists: true 33 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/CodeDOM/CodeFunctionTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Kiota.Builder.CodeDOM; 4 | 5 | using Xunit; 6 | 7 | namespace Kiota.Builder.Tests.CodeDOM; 8 | 9 | public class CodeFunctionTests 10 | { 11 | [Fact] 12 | public void Defensive() 13 | { 14 | var method = new CodeMethod 15 | { 16 | Name = "class", 17 | ReturnType = new CodeType 18 | { 19 | Name = "string" 20 | } 21 | }; 22 | Assert.Throws(() => new CodeFunction(null)); 23 | Assert.Throws(() => new CodeFunction(method)); 24 | method.IsStatic = true; 25 | Assert.Throws(() => new CodeFunction(method)); 26 | var parentClass = new CodeClass(); 27 | method.Parent = parentClass; 28 | var function = new CodeFunction(method); 29 | Assert.Equal(method, function.OriginalLocalMethod); 30 | Assert.Equal(parentClass, function.OriginalMethodParentClass); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/Index/IndexRoot.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Kiota.Builder.SearchProviders.GitHub.Index; 5 | 6 | 7 | [JsonSerializable(typeof(IndexRoot))] 8 | internal partial class IndexRootJsonContext : JsonSerializerContext 9 | { 10 | } 11 | #pragma warning disable CA2227 12 | #pragma warning disable CA1002 13 | #pragma warning disable CA1056 14 | public class IndexRoot 15 | { 16 | public List Apis { get; set; } = new(); 17 | } 18 | public class IndexApiEntry 19 | { 20 | public string Name { get; set; } = string.Empty; 21 | public string Description { get; set; } = string.Empty; 22 | public string BaseURL { get; set; } = string.Empty; 23 | public List Properties { get; set; } = new(); 24 | } 25 | public class IndexApiProperty 26 | { 27 | public string Type { get; set; } = string.Empty; 28 | public string Url { get; set; } = string.Empty; 29 | } 30 | #pragma warning restore CA1056 31 | #pragma warning restore CA1002 32 | #pragma warning restore CA2227 33 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/NamespaceDifferentialTracker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Kiota.Builder.CodeDOM; 6 | 7 | public record NamespaceDifferentialTracker 8 | { 9 | public int UpwardsMovesCount 10 | { 11 | get; init; 12 | } 13 | public IEnumerable DownwardsSegments { get; init; } = Array.Empty(); 14 | private bool AnyUpwardsMove => UpwardsMovesCount > 0; 15 | private bool AnySegment => DownwardsSegments?.Any() ?? false; 16 | public NamespaceDifferentialTrackerState State => (AnyUpwardsMove, AnySegment) switch 17 | { 18 | (true, true) => NamespaceDifferentialTrackerState.UpwardsAndThenDownwards, 19 | (true, false) => NamespaceDifferentialTrackerState.Upwards, 20 | (false, true) => NamespaceDifferentialTrackerState.Downwards, 21 | (false, false) => NamespaceDifferentialTrackerState.Same, 22 | }; 23 | } 24 | public enum NamespaceDifferentialTrackerState 25 | { 26 | Upwards, 27 | Downwards, 28 | Same, 29 | UpwardsAndThenDownwards, 30 | } 31 | -------------------------------------------------------------------------------- /abstractions/swift/Source/MicrosoftKiotaAbstractions/Serialization/ParseNodeFactoryRegistry.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | public enum ParseNodeFactoryRegistryErrors : Error { 3 | case registrySupportsMultipleTypesGetOneFactory 4 | case factoryNotFoundForContentType 5 | case contentCannotBeNil 6 | } 7 | public class ParseNodeFactoryRegistry : ParseNodeFactory { 8 | public var contentTypeAssociatedFactories = [String:ParseNodeFactory]() 9 | public func getValidContentType() throws -> String { 10 | throw ParseNodeFactoryRegistryErrors.registrySupportsMultipleTypesGetOneFactory 11 | } 12 | public func getRootParseNode(contentType: String, content: Data?) throws -> ParseNode { 13 | guard let factory = contentTypeAssociatedFactories[contentType] else { 14 | throw ParseNodeFactoryRegistryErrors.factoryNotFoundForContentType 15 | } 16 | guard content != nil else { 17 | throw ParseNodeFactoryRegistryErrors.contentCannotBeNil 18 | } 19 | return try factory.getRootParseNode(contentType: contentType, content: content) 20 | } 21 | } -------------------------------------------------------------------------------- /it/do-clean.ps1: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env pwsh 2 | 3 | param( 4 | [Parameter(Mandatory = $true)][string]$language 5 | ) 6 | 7 | if ([string]::IsNullOrEmpty($language)) { 8 | Write-Error "Language is empty" 9 | exit 1 10 | } 11 | 12 | $scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition 13 | $testPath = Join-Path -Path $scriptPath -ChildPath $language 14 | 15 | Push-Location $testPath 16 | if ($language -eq "csharp") { 17 | Remove-Item obj -Recurse -ErrorAction SilentlyContinue 18 | } 19 | elseif ($language -eq "typescript") { 20 | Remove-Item node_modules -Recurse -ErrorAction SilentlyContinue 21 | Remove-Item dist -Recurse -ErrorAction SilentlyContinue 22 | } 23 | elseif ($language -eq "ruby") { 24 | Remove-Item vendor -Recurse -ErrorAction SilentlyContinue 25 | Remove-Item .git -Recurse -ErrorAction SilentlyContinue 26 | Remove-Item Gemfile.lock -ErrorAction SilentlyContinue 27 | } 28 | elseif ($language -eq "php") { 29 | Remove-Item vendor -Recurse -ErrorAction SilentlyContinue 30 | Remove-Item composer.lock -ErrorAction SilentlyContinue 31 | } 32 | Pop-Location 33 | -------------------------------------------------------------------------------- /src/Kiota.Builder/SearchProviders/GitHub/Authentication/PatAccessTokenProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using Microsoft.Kiota.Abstractions.Authentication; 6 | 7 | namespace Kiota.Builder.SearchProviders.GitHub.Authentication; 8 | 9 | public class PatAccessTokenProvider : IAccessTokenProvider 10 | { 11 | public AllowedHostsValidator AllowedHostsValidator { get; set; } = new(); 12 | public required ITokenStorageService StorageService 13 | { 14 | get; init; 15 | } 16 | public async Task GetAuthorizationTokenAsync(Uri uri, Dictionary? additionalAuthenticationContext = null, CancellationToken cancellationToken = default) 17 | { 18 | ArgumentNullException.ThrowIfNull(uri); 19 | if ("https".Equals(uri.Scheme, StringComparison.OrdinalIgnoreCase) && AllowedHostsValidator.IsUrlHostValid(uri)) 20 | return await StorageService.GetTokenAsync(cancellationToken).ConfigureAwait(false) ?? string.Empty; 21 | return string.Empty; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.IntegrationTests/ResponseWithMultipleReturnFormats.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.0 2 | info: 3 | title: "API that returns multiple response formats" 4 | version: "1.0.0" 5 | servers: 6 | - url: https://example.org/ 7 | paths: 8 | /report: 9 | get: 10 | responses: 11 | 200: 12 | description: ok 13 | content: 14 | application/json: {} # Response is JSON but no schema is defined 15 | text/csv: {} 16 | /reportWithSchema: 17 | get: 18 | responses: 19 | 200: 20 | description: ok 21 | content: 22 | application/json: # Response is JSON but no schema is defined 23 | schema: 24 | $ref: "#/components/schemas/weatherReport" 25 | text/csv: {} 26 | components: 27 | schemas: 28 | weatherReport: 29 | type: array 30 | items: 31 | type: object 32 | properties: 33 | date: 34 | type: string 35 | temperature: 36 | type: string 37 | conditions: 38 | type: string 39 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeDOM/IAlternativeName.cs: -------------------------------------------------------------------------------- 1 | namespace Kiota.Builder.CodeDOM; 2 | 3 | /// 4 | /// Defines a contract for elements that can have an alternative name for serialization. 5 | /// 6 | public interface IAlternativeName 7 | { 8 | /// 9 | /// Gets a value indicating whether the name is escaped/has an alternative for serialization. 10 | /// 11 | bool IsNameEscaped 12 | { 13 | get; 14 | } 15 | /// 16 | /// Gets the name to be used for serialization whether it is escaped or not. 17 | /// 18 | string WireName 19 | { 20 | get; 21 | } 22 | /// 23 | /// Gets or sets the name to be used for serialization. 24 | /// Language implementers: use WireName instead so you don't have to implement a comparison. 25 | /// 26 | string SerializationName 27 | { 28 | get; set; 29 | } 30 | /// 31 | /// Gets the symbol name of the element. 32 | /// 33 | string SymbolName 34 | { 35 | get; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /abstractions/swift/Source/MicrosoftKiotaAbstractions/Authentication/BaseBearerAuthenticationProvider.swift: -------------------------------------------------------------------------------- 1 | public class BaseBearerAuthenticationProvider : AuthenticationProvider { 2 | public init (accessTokenProvider: AccessTokenProvider) { 3 | accessTokenProviderIntl = accessTokenProvider 4 | } 5 | private var accessTokenProviderIntl: AccessTokenProvider 6 | public var accessTokenProvider: AccessTokenProvider { 7 | get { 8 | return accessTokenProviderIntl 9 | } 10 | } 11 | public let authorizationHeaderKey = "Authorization" 12 | public let authorizationHeaderValuePrefix = "Bearer " 13 | public func authenticateRequest(request: RequestInformation) async throws { 14 | if request.headers[authorizationHeaderKey] == nil { 15 | let url = try request.getUri() 16 | let tokenResult = try? await accessTokenProvider.getAuthenticationToken(url: url) 17 | if let token = tokenResult { 18 | request.headers[authorizationHeaderKey] = authorizationHeaderValuePrefix + token 19 | } 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/Kiota.Builder/Configuration/KiotaConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kiota.Builder.Configuration; 4 | 5 | #pragma warning disable CA2227 6 | #pragma warning disable CA1002 7 | public class KiotaConfiguration : ICloneable 8 | { 9 | public GenerationConfiguration Generation { get; set; } = new(); 10 | public SearchConfiguration Search { get; set; } = new(); 11 | public DownloadConfiguration Download { get; set; } = new(); 12 | public LanguagesInformation Languages { get; set; } = new(); 13 | public UpdateConfiguration Update { get; set; } = new(); 14 | 15 | public object Clone() 16 | { 17 | return new KiotaConfiguration 18 | { 19 | Generation = (GenerationConfiguration)Generation.Clone(), 20 | Search = (SearchConfiguration)Search.Clone(), 21 | Download = (DownloadConfiguration)Download.Clone(), 22 | Languages = (LanguagesInformation)Languages.Clone(), 23 | Update = (UpdateConfiguration)Update.Clone() 24 | }; 25 | } 26 | } 27 | #pragma warning restore CA1002 28 | #pragma warning restore CA2227 29 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Python/PythonWriter.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.PathSegmenters; 2 | 3 | namespace Kiota.Builder.Writers.Python; 4 | public class PythonWriter : LanguageWriter 5 | { 6 | public PythonWriter(string rootPath, string clientNamespaceName, bool usesBackingStore = false) 7 | { 8 | PathSegmenter = new PythonPathSegmenter(rootPath, clientNamespaceName); 9 | var conventionService = new PythonConventionService(); 10 | AddOrReplaceCodeElementWriter(new CodeClassDeclarationWriter(conventionService, clientNamespaceName)); 11 | AddOrReplaceCodeElementWriter(new CodeBlockEndWriter()); 12 | AddOrReplaceCodeElementWriter(new CodeEnumWriter(conventionService)); 13 | AddOrReplaceCodeElementWriter(new CodeMethodWriter(conventionService, clientNamespaceName, usesBackingStore)); 14 | AddOrReplaceCodeElementWriter(new CodePropertyWriter(conventionService, clientNamespaceName)); 15 | AddOrReplaceCodeElementWriter(new CodeTypeWriter(conventionService)); 16 | AddOrReplaceCodeElementWriter(new CodeNameSpaceWriter(conventionService)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Python/PythonCodeParameterOrderComparer.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | 3 | namespace Kiota.Builder.Writers.Python; 4 | public class PythonCodeParameterOrderComparer : BaseCodeParameterOrderComparer 5 | { 6 | // Non-default parameters must come before parameters with defaults in python. 7 | protected override int GetKindOrderHint(CodeParameterKind kind) 8 | { 9 | return kind switch 10 | { 11 | CodeParameterKind.RequestAdapter => 1, 12 | CodeParameterKind.RawUrl => 2, 13 | CodeParameterKind.PathParameters => 3, 14 | CodeParameterKind.Path => 4, 15 | CodeParameterKind.RequestConfiguration => 5, 16 | CodeParameterKind.RequestBody => 6, 17 | CodeParameterKind.ResponseHandler => 7, 18 | CodeParameterKind.Serializer => 8, 19 | CodeParameterKind.BackingStore => 9, 20 | CodeParameterKind.SetterValue => 10, 21 | CodeParameterKind.ParseNode => 11, 22 | CodeParameterKind.Custom => 12, 23 | _ => 13, 24 | }; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/Writers/Go/NamespaceExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | using Kiota.Builder.Writers.Go; 3 | 4 | using Xunit; 5 | 6 | namespace Kiota.Builder.Tests.Writers.Go; 7 | public class NamespaceExtensionsTests 8 | { 9 | [Fact] 10 | public void Defensive() 11 | { 12 | Assert.Equal(GoNamespaceExtensions.GetNamespaceImportSymbol(null), string.Empty); 13 | Assert.Equal(GoNamespaceExtensions.GetLastNamespaceSegment(null), string.Empty); 14 | Assert.Equal(GoNamespaceExtensions.GetInternalNamespaceImport(null), string.Empty); 15 | } 16 | [Fact] 17 | public void GetLastNamespaceSegment() 18 | { 19 | Assert.Equal("something", "github.com/microsoft/kiota.something".GetLastNamespaceSegment()); 20 | } 21 | [Fact] 22 | public void GetNamespaceImportSymbol() 23 | { 24 | var root = CodeNamespace.InitRootNamespace(); 25 | var main = root.AddNamespace("github.com/something"); 26 | Assert.Equal("i749ccebf37b522f21de9a46471b0aeb8823a49292ca8740fc820cf9bd340c846", main.GetNamespaceImportSymbol()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /abstractions/swift/MicrosoftKiotaAbstractions.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "MicrosoftKiotaAbstractions" 3 | s.version = "1.0.0" 4 | s.summary = "MicrosoftKiotaAbstractions provides the base infrastructure for the Kiota-generated SDKs to function. 5 | It defines multiple concepts related to abstract HTTP requests, serialization, and authentication. 6 | These concepts can then be implemented independently without tying the SDKs to any specific implementation. 7 | Kiota also provides default implementations for these concepts." 8 | s.homepage = "https://github.com/microsoft/kiota" 9 | s.license = { :type => "MIT" } 10 | s.authors = { "Microsoft" => "graphtooling+kiota@service.microsoft.com" } 11 | 12 | s.requires_arc = true 13 | s.swift_version = "5.0" 14 | s.osx.deployment_target = "10.9" 15 | s.ios.deployment_target = "9.0" 16 | s.watchos.deployment_target = "3.0" 17 | s.tvos.deployment_target = "9.0" 18 | s.source = { :git => "https://github.com/microsoft/kiota.git", :tag => s.version } 19 | s.source_files = "Source/*.swift" 20 | end -------------------------------------------------------------------------------- /vscode/microsoft-kiota/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that compiles the extension and then opens it inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Run Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "args": [ 13 | "--extensionDevelopmentPath=${workspaceFolder}" 14 | ], 15 | "outFiles": [ 16 | "${workspaceFolder}/dist/**/*.js" 17 | ], 18 | "preLaunchTask": "${defaultBuildTask}" 19 | }, 20 | { 21 | "name": "Extension Tests", 22 | "type": "extensionHost", 23 | "request": "launch", 24 | "args": [ 25 | "--extensionDevelopmentPath=${workspaceFolder}", 26 | "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" 27 | ], 28 | "outFiles": [ 29 | "${workspaceFolder}/out/**/*.js", 30 | "${workspaceFolder}/dist/**/*.js" 31 | ], 32 | "preLaunchTask": "tasks: watch-tests" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "omnisharp.enableRoslynAnalyzers": true, 3 | "markdownlint.config": { 4 | "MD028": false, 5 | "MD025": { 6 | "front_matter_title": "" 7 | } 8 | }, 9 | "cSpell.ignoreWords": [ 10 | "Todos", 11 | "azidentity", 12 | "getme", 13 | "gson", 14 | "kiotaabstractions", 15 | "msgraph", 16 | "okhttp", 17 | "okhttp3", 18 | "okhttplibrary", 19 | "println", 20 | "squareup", 21 | "todoclient" 22 | ], 23 | "cSpell.words": [ 24 | "allof", 25 | "apisguru", 26 | "autoload", 27 | "Contoso", 28 | "cref", 29 | "deprecable", 30 | "deserialization", 31 | "deserializers", 32 | "dumpautoload", 33 | "getenv", 34 | "ghes", 35 | "inheritdoc", 36 | "Kiota", 37 | "NETCOREAPP", 38 | "Nethttplibrary", 39 | "NETSTANDARD", 40 | "npmrc", 41 | "openapi", 42 | "phpleague", 43 | "samespaceprefix", 44 | "serializers" 45 | ], 46 | "java.configuration.updateBuildConfiguration": "automatic", 47 | "dotnet-test-explorer.testProjectPath": "tests/**/*.Tests.csproj", 48 | "editor.formatOnSave": true 49 | } 50 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiEnumValuesDescriptionExtensionTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | using Kiota.Builder.OpenApiExtensions; 4 | 5 | using Microsoft.OpenApi; 6 | using Microsoft.OpenApi.Writers; 7 | 8 | using Moq; 9 | 10 | using Xunit; 11 | 12 | namespace Kiota.Builder.Tests.OpenApiExtensions; 13 | 14 | public class OpenApiEnumValuesDescriptionExtensionTests 15 | { 16 | [Fact] 17 | public void NOOPTestForCoverage() 18 | { 19 | // This class is already covered by the convertion library tests 20 | var value = new OpenApiEnumValuesDescriptionExtension 21 | { 22 | EnumName = "some enum", 23 | ValuesDescriptions = new List 24 | { 25 | new EnumDescription 26 | { 27 | Value = "some value", 28 | }, 29 | }, 30 | }; 31 | var writer = new Mock(); 32 | value.Write(writer.Object, OpenApiSpecVersion.OpenApi3_0); 33 | writer.Verify(static x => x.WriteStartObject(), Times.AtLeastOnce()); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/Kiota.Builder/CodeElementOrderComparerPython.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | 3 | namespace Kiota.Builder; 4 | public class CodeElementOrderComparerPython : CodeElementOrderComparer 5 | { 6 | protected override int GetTypeFactor(CodeElement element) 7 | { 8 | return element switch 9 | { 10 | CodeUsing => 1, 11 | ClassDeclaration => 2, 12 | InterfaceDeclaration => 3, 13 | CodeMethod => 4, 14 | CodeIndexer => 5, 15 | CodeProperty => 6, 16 | CodeClass => 7, 17 | BlockEnd => 8, 18 | _ => 0, 19 | }; 20 | } 21 | protected override int methodKindWeight { get; } = 200; 22 | protected override int GetMethodKindFactor(CodeElement element) 23 | { 24 | if (element is CodeMethod method) 25 | return method.Kind switch 26 | { 27 | CodeMethodKind.ClientConstructor => 1, 28 | CodeMethodKind.Constructor => 0, 29 | CodeMethodKind.RawUrlConstructor => 3, 30 | _ => 2, 31 | }; 32 | return 0; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/SearchProviders/GitHub/Authentication/PatAuthenticationProviderTests.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using Kiota.Builder.SearchProviders.GitHub.Authentication; 4 | using Microsoft.Extensions.Logging; 5 | using Moq; 6 | using Xunit; 7 | 8 | namespace Kiota.Builder.Tests.SearchProviders.GitHub.Authentication; 9 | public class PatAuthenticationProviderTests 10 | { 11 | [Fact] 12 | public void Defensive() 13 | { 14 | Assert.Throws(() => new PatAuthenticationProvider(null, "foo", new string[] { "foo" }, new Mock().Object, new Mock().Object)); 15 | Assert.Throws(() => new PatAuthenticationProvider("foo", null, new string[] { "foo" }, new Mock().Object, new Mock().Object)); 16 | Assert.Throws(() => new PatAuthenticationProvider("foo", "foo", new string[] { "foo" }, null, new Mock().Object)); 17 | Assert.Throws(() => new PatAuthenticationProvider("foo", "foo", new string[] { "foo" }, new Mock().Object, null)); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /tests/Kiota.Builder.Tests/Writers/CommonLanguageConventionServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Kiota.Builder.CodeDOM; 4 | using Kiota.Builder.Writers.CSharp; 5 | 6 | using Moq; 7 | 8 | using Xunit; 9 | 10 | namespace Kiota.Builder.Tests.Writers; 11 | public class CommonLanguageConventionServiceTests 12 | { 13 | [Fact] 14 | public void TranslatesType() 15 | { 16 | var service = new CSharpConventionService(); 17 | var root = CodeNamespace.InitRootNamespace(); 18 | var unknownTypeMock = new Mock(); 19 | unknownTypeMock.Setup(x => x.Name).Returns("unkownType"); 20 | Assert.Throws(() => service.TranslateType(unknownTypeMock.Object)); 21 | var stringType = new CodeType 22 | { 23 | Name = "string" 24 | }; 25 | Assert.Equal("string", service.TranslateType(stringType)); 26 | var unionStringType = new CodeUnionType 27 | { 28 | Name = "unionString" 29 | }; 30 | unionStringType.AddType(stringType); 31 | Assert.Equal("string", service.TranslateType(unionStringType)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/Go/GoCodeParameterOrderComparer.cs: -------------------------------------------------------------------------------- 1 | using Kiota.Builder.CodeDOM; 2 | 3 | namespace Kiota.Builder.Writers.Go; 4 | 5 | public class GoCodeParameterOrderComparer : BaseCodeParameterOrderComparer 6 | { 7 | // Cancellation/context parameters must come before other parameters with defaults in Golang. 8 | protected override int GetKindOrderHint(CodeParameterKind kind) 9 | { 10 | return kind switch 11 | { 12 | CodeParameterKind.Cancellation => 0, 13 | CodeParameterKind.PathParameters => 1, 14 | CodeParameterKind.RawUrl => 2, 15 | CodeParameterKind.RequestAdapter => 3, 16 | CodeParameterKind.Path => 4, 17 | CodeParameterKind.RequestConfiguration => 5, 18 | CodeParameterKind.RequestBody => 6, 19 | CodeParameterKind.ResponseHandler => 7, 20 | CodeParameterKind.Serializer => 8, 21 | CodeParameterKind.BackingStore => 9, 22 | CodeParameterKind.SetterValue => 10, 23 | CodeParameterKind.ParseNode => 11, 24 | CodeParameterKind.Custom => 12, 25 | _ => 13, 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Writers/TypeScript/CodeEnumWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | using Kiota.Builder.CodeDOM; 5 | using Kiota.Builder.Extensions; 6 | 7 | namespace Kiota.Builder.Writers.TypeScript; 8 | public class CodeEnumWriter : BaseElementWriter 9 | { 10 | public CodeEnumWriter(TypeScriptConventionService conventionService) : base(conventionService) { } 11 | public override void WriteCodeElement(CodeEnum codeElement, LanguageWriter writer) 12 | { 13 | ArgumentNullException.ThrowIfNull(codeElement); 14 | ArgumentNullException.ThrowIfNull(writer); 15 | if (!codeElement.Options.Any()) 16 | return; 17 | 18 | conventions.WriteLongDescription(codeElement, writer); 19 | writer.WriteLine($"export enum {codeElement.Name.ToFirstCharacterUpperCase()} {{"); 20 | writer.IncreaseIndent(); 21 | codeElement.Options.ToList().ForEach(x => 22 | { 23 | conventions.WriteShortDescription(x.Documentation.Description, writer); 24 | writer.WriteLine($"{x.Name.ToFirstCharacterUpperCase()} = \"{x.WireName}\","); 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /vscode/microsoft-kiota/src/getLanguageInformation.ts: -------------------------------------------------------------------------------- 1 | import { connectToKiota, KiotaGenerationLanguage, LanguagesInformation } from "./kiotaInterop"; 2 | import * as rpc from "vscode-jsonrpc/node"; 3 | import * as vscode from "vscode"; 4 | 5 | export function getLanguageInformation(context: vscode.ExtensionContext, language?: KiotaGenerationLanguage, descriptionUrl?: string): Promise { 6 | if(language && descriptionUrl) { 7 | return connectToKiota(context, async (connection) => { 8 | const request = new rpc.RequestType2( 9 | "Info" 10 | ); 11 | return await connection.sendRequest( 12 | request, 13 | language, 14 | descriptionUrl 15 | ); 16 | }); 17 | } else { 18 | return connectToKiota(context, async (connection) => { 19 | const request = new rpc.RequestType0( 20 | "Info" 21 | ); 22 | return await connection.sendRequest( 23 | request 24 | ); 25 | }); 26 | } 27 | }; -------------------------------------------------------------------------------- /src/kiota/Authentication/GitHub/DeviceCode/DeviceCodeAuthenticationProvider.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Net.Http; 5 | using Kiota.Builder.SearchProviders.GitHub.Authentication; 6 | using Microsoft.Extensions.Logging; 7 | using Microsoft.Kiota.Abstractions.Authentication; 8 | 9 | namespace kiota.Authentication.GitHub.DeviceCode; 10 | 11 | public class DeviceCodeAuthenticationProvider : BaseAuthenticationProvider 12 | { 13 | public DeviceCodeAuthenticationProvider(string clientId, string scope, IEnumerable validHosts, HttpClient httpClient, Action messageCallback, ILogger logger) : 14 | base(clientId, scope, validHosts, logger, (clientId, scope, validHosts) => new AccessTokenProvider 15 | { 16 | ClientId = clientId, 17 | HttpClient = httpClient, 18 | MessageCallback = messageCallback, 19 | Scope = scope, 20 | AllowedHostsValidator = new AllowedHostsValidator(validHosts), 21 | }) 22 | { 23 | ArgumentNullException.ThrowIfNull(httpClient); 24 | ArgumentNullException.ThrowIfNull(messageCallback); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Kiota.Builder/Refiners/RubyReservedNamesProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Kiota.Builder.Refiners; 5 | public class RubyReservedNamesProvider : IReservedNamesProvider 6 | { 7 | private readonly Lazy> _reservedNames = new(() => new(StringComparer.OrdinalIgnoreCase) { 8 | "BEGIN", 9 | "END", 10 | "alias", 11 | "and", 12 | "begin", 13 | "break", 14 | "case", 15 | "class", 16 | "def", 17 | "module", 18 | "next", 19 | "nil", 20 | "not", 21 | "or", 22 | "redo", 23 | "rescue", 24 | "retry", 25 | "return", 26 | "elsif", 27 | "end", 28 | "false", 29 | "ensure", 30 | "for", 31 | "if", 32 | "true", 33 | "undef", 34 | "unless", 35 | "do", 36 | "else", 37 | "super", 38 | "then", 39 | "until", 40 | "when", 41 | "while", 42 | "defined?", 43 | "self", 44 | "BaseRequestBuilder", 45 | }); 46 | public HashSet ReservedNames => _reservedNames.Value; 47 | } 48 | --------------------------------------------------------------------------------