From 95fd826835ecb335e3d0e8512cd4abfaba690c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Thu, 23 Nov 2023 19:11:58 +0000 Subject: [PATCH 01/17] Initial draft specs --- specs/kiota.config.md | 240 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 specs/kiota.config.md diff --git a/specs/kiota.config.md b/specs/kiota.config.md new file mode 100644 index 0000000000..18f2c1726d --- /dev/null +++ b/specs/kiota.config.md @@ -0,0 +1,240 @@ +# Kiota Config + +Kiota generates client code for an API and stores parameters in a kiota.lock file. A project can contain multiple API clients, but they are independently managed. Kiota has no awareness that an app has a dependency on multiple APIs, even though that is a core use case. + +## Status + +| Date | Version | Author | Status | +| ------------------- | ------- | ---------------- | ------ | +| November 22nd, 2023 | v0.2 | Sébastien Levert | Draft | +| September 24th, 2023 | v0.1 | Darrel Miller | Draft | + +## Current Challenges + +- Client code generation is not reproducible if API description changes +- Kiota doesn’t have a good solution for APIs that use multiple security schemes. +- Kiota doesn’t provide any support for generating auth providers with the required permissions, partially because currently we generate one client for APIs that use different schemes. How would we know which auth provider to generate. +- Kiota doesn’t have a good story for acquiring a client identifier. e.g. apikey or OAuth2 ClientId. This could be possible if the OpenIDConnect URL pointed to a dynamic registration endpoint. +- If an application has multiple kiota clients, there is currently no way perform operations that correspond to all of the clients. + +We have previously described Kiota's approach to managing API dependencies as consistent with the way people manage packages in a project. However, currently our tooling doesn't behave that way. We treat each dependency independently. + +## Proposal + +We should introduce a new Kiota.config file that holds the input parameters required to generate the API Client code. Currently kiota.lock is used to capture what the parameters were at the time of generation and can be used to regenerate based on the parameters in the file. This creates a mixture of purposes for the file. + +We did consider creating one kiota.config file as as a peer of the language project file, however, for someone who wants to generate multiple clients for an API in different languages, this would be a bit annoying. An alternative would be to allow the kiota.config file to move further up the folder structure and support generation in multiple languages from a single file. This is more consistent with what [TypeSpec](https://aka.ms/typespec) are doing and would be helpful for generating CLI and docs as well as a library. + +Here is an example of what the kiota.config file could look like. + +```json +{ + "name": "My application", + "version": "2.0", + "apis": { + "Graph": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://.../openapi.yaml", + "includePatterns": ["/me/chats#GET", "/me#GET"], + "excludePatterns": [], + "outputs": [ + { + "language": "csharp", + "outputPath": "./generated/graph", + "clientClassName": "GraphClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", + "authenticationParameters": { + "clientId": "guid" + }, + "usesBackingStore": true, + "includeAdditionalData": true + } + } + ] + }, + "BusinessCentral": { + "descriptionHash": "810CF81EFDB5D8E065...", + "descriptionLocation": "https://.../bcoas1.0.yaml", + "includePatterns": ["/companies#GET"], + "excludePatterns": [], + "outputs": [ + { + "language": "csharp", + "outputPath": "./generated/business-central" + }, + { + "language": "python", + "outputPath": "./generated/python/business-central" + }, + { + "language": "csharp", + "outputPath": "./generated/business-central-app", + "features": { + "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", + "authenticationParameters": { + "clientId": "guid" + } + } + } + ] + } + } +} +``` + +Note that in this example we added suggestions for new parameters related to authentication. If we are to improve the generation experience so that we read the security schemes information from the OpenAPI, then we will need to have some place to configure what providers we will use for those schemes. + +The [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01.html) file can be used as a replacement for the kiota.lock file as a place to capture a snapshot of what information was used to perform code generation and what APIs that gives the application access to. + +## Tooling commands to manage Kiota.config + +| Command | Example | Description | +| ------------------- | ------- | ---------------- | +| init | kiota init --name | Creates a kiota.config file | +| add api | kiota add api --name --openapi | Adds an entry for an API with passed parameters and default values | +| add output | kiota add output --name MyApi --lang python --outputPath ./pythonClient | Adds information about a new output artifact that should be generated | +| generate | kiota generate | Outputs kiota.apimanifest and source for each of the output objects | + +In the past we have had both a generate and an update comment. This is because if it was the first time running, generate would set defaults for all the properties that were not set on the command line. However, now that we have add output, it can be used to set the defaults and generate can just read from the kiota.config file. + +## Scenarios using the command line tool + +### Get started to generate an API + +```bash +kiota init --name Myapp +kiota add api --name MyApi --openapi // Can we add using -k ? +kiota add output --name MyApi --lang csharp --outputPath ./csharpClient +kiota generate +``` + +### Add a second language to generate an API + +```bash +kiota add output --name MyApi --lang python --outputPath ./pythonClient +kiota generate --name MyApi --lang python // Generate just the Python client for MyApi +``` + +### Remove a language + +```bash +kiota remove output --name MyApi --lang python +``` + +### Remove an API + +```bash +kiota remove api --name MyApi +``` + +## JSON Schema for Kiota.Config + +```json +{ + "$schema": "", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "apis": { + "type": "object", + "patternProperties": { + ".*": { + "type": "object", + "properties": { + "descriptionLocation": { + "type": "string" + }, + "descriptionHash": { + "type": "string" + } + }, + "descriptionHash": { + "type": "string" + }, + "descriptionLocation": { + "type": "string" + }, + "includePatterns": { + "type": "array", + "items": { + "type": "string" + } + }, + "excludePatterns": { + "type": "array", + "items": { + "type": "string" + } + }, + "baseUrl": { + "type": "string" + }, + "output": { + "type": "array", + "items": { + "type": "object", + "properties": { + "language": { + "type": "string" + }, + "outputPath": { + "type": "string" + }, + "clientClassName": { + "type": "string" + }, + "clientNamespaceName": { + "type": "string" + }, + "features": { + "type": "object", + "properties": { + "authenticationProvider": { + "type": "string" + }, + "authenticationParameters": { + "type": "object" + } + }, + "structuredMediaTypes": { + "type": "object", + "patternProperties": { + ".*": { + "type": "object", + "properties": { + "serializer": { + "type": "string" + }, + "deserializer": { + "type": "string" + } + } + } + } + }, + "usesBackingStore": { + "type": "boolean" + }, + "includeAdditionalData": { + "type": "boolean" + } + } + } + } + } + }, + "disabledValidationRules": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } +} +``` From accf42025abaa84e8e6ac12fa14024d3b1685c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Mon, 27 Nov 2023 16:58:17 +0000 Subject: [PATCH 02/17] Updated specs --- specs/kiota.config.md | 94 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 83 insertions(+), 11 deletions(-) diff --git a/specs/kiota.config.md b/specs/kiota.config.md index 18f2c1726d..1097c38df8 100644 --- a/specs/kiota.config.md +++ b/specs/kiota.config.md @@ -4,10 +4,10 @@ Kiota generates client code for an API and stores parameters in a kiota.lock fil ## Status -| Date | Version | Author | Status | -| ------------------- | ------- | ---------------- | ------ | -| November 22nd, 2023 | v0.2 | Sébastien Levert | Draft | -| September 24th, 2023 | v0.1 | Darrel Miller | Draft | +| Date | Version | Author | Status | +| -- | -- | -- | -- | +| November 22nd, 2023 | v0.2 | Sébastien Levert | Draft | +| September 24th, 2023 | v0.1 | Darrel Miller | Draft | ## Current Challenges @@ -44,9 +44,11 @@ Here is an example of what the kiota.config file could look like. "clientClassName": "GraphClient", "clientNamespaceName": "Contoso.GraphApp", "features": { - "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", - "authenticationParameters": { - "clientId": "guid" + "authentication": { + "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", + "authenticationParameters": { + "clientId": "guid" + } }, "usesBackingStore": true, "includeAdditionalData": true @@ -72,9 +74,11 @@ Here is an example of what the kiota.config file could look like. "language": "csharp", "outputPath": "./generated/business-central-app", "features": { - "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", - "authenticationParameters": { - "clientId": "guid" + "authentication": { + "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", + "authenticationParameters": { + "clientId": "guid" + } } } } @@ -94,11 +98,79 @@ The [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01. | ------------------- | ------- | ---------------- | | init | kiota init --name | Creates a kiota.config file | | add api | kiota add api --name --openapi | Adds an entry for an API with passed parameters and default values | -| add output | kiota add output --name MyApi --lang python --outputPath ./pythonClient | Adds information about a new output artifact that should be generated | +| add output | kiota add output --api-name --lang python --outputPath ./pythonClient | Adds information about a new output artifact that should be generated | | generate | kiota generate | Outputs kiota.apimanifest and source for each of the output objects | In the past we have had both a generate and an update comment. This is because if it was the first time running, generate would set defaults for all the properties that were not set on the command line. However, now that we have add output, it can be used to set the defaults and generate can just read from the kiota.config file. +## Commands + +### kiota init + +`kiota init` creates a new kiota.config file with the passed parameters. If the file already exists, it should error out and report it to the user. The initialization process has a single required parameter, the name of the application. + +> [!NOTE] +> If a project only needs a single API, using `kiota init` is not required as generating code using the `kiota generate` command should generate a `kiota.config` file with values coming from the `kiota generate` command. See [kiota generate](#kiota-generate) for more information. + +| Parameters | Required | Example | Description | +| -- | -- | -- | -- | +| `--app-name \| -n` | Yes | My application | Name of the application | + +#### Using `kiota init` + +```bash +kiota init --app-name "My application" +``` + +```json +// Creates the following kiota.config file +{ + "name": "My application", + "version": "1.0" +} +``` + +### kiota add api + +`kiota add api` allows a developer to add a new API to the kiota.config file. The command will add a new entry to the apis section of the kiota.config file. The command has two required parameters, the name of the API (key of the api map) and the location of the OpenAPI description. The command also has two optional parameters, the include and exclude patterns. If provided, these will be used to filter the paths that are included in the generation process. If not provided, all paths will be assumed. + +When executing, a new API entry will be added and will use the `--api-name` parameter as the key for the map. When loading the OpenAPI description, it will generate a hash of the description to enable change detection of the description and save it as part of the `descriptionHash` property. It will also store the location of the description in the `descriptionLocation` property. If `--include-path` or `--exclude-path` are provided, they will be stored in the `includePatterns` and `excludePatterns` properties respectively. + +| Parameters | Required | Example | Description | +| -- | -- | -- | -- | +| `--api-name \| -n` | Yes | graph | Name of the API | +| `--open-api \| -d` | Yes | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | +| `--include-path \| -i` | No | /me/chats#GET | A glob pattern to include paths from generation. Accepts multiple values. Defaults to no value which includes everything. | +| `--exclude-path \| -e` | No | \*\*/users/\*\* | A glob pattern to exclude paths from generation. Accepts multiple values. Defaults to no value which excludes nothing. | + +#### Using `kiota add api` + +```bash +kiota add api --api-name "graph" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "/me/chats#GET" --include-path "/me#GET" +``` + +```json +// Adds the following to the kiota.config file +"graph": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://.../openapi.yaml", + "includePatterns": ["/me/chats#GET", "/me#GET"], + "excludePatterns": [] +} +``` + +### kiota generate + +In scenarios where a developer only needs a single API or doesn't want to go through the ceremony of executing `kiota init`, it's possible to use `kiota generate` as it will create a `kiota.config` file with the values coming from the command parameters. + +#### Using `kiota generate` + +```bash +``` + +```json +``` + ## Scenarios using the command line tool ### Get started to generate an API From 84c7d5eee3433f4277a8a3fbb203ea3b4a688ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Thu, 30 Nov 2023 16:30:03 +0000 Subject: [PATCH 03/17] Polishing spec + updated json schema --- specs/kiota.config.md | 483 +++++++++++++++++++++++++++++++++++------- 1 file changed, 409 insertions(+), 74 deletions(-) diff --git a/specs/kiota.config.md b/specs/kiota.config.md index 1097c38df8..906a8fd653 100644 --- a/specs/kiota.config.md +++ b/specs/kiota.config.md @@ -6,6 +6,7 @@ Kiota generates client code for an API and stores parameters in a kiota.lock fil | Date | Version | Author | Status | | -- | -- | -- | -- | +| November 30th, 2023 | v0.3 | Sébastien Levert | Final Draft | | November 22nd, 2023 | v0.2 | Sébastien Levert | Draft | | September 24th, 2023 | v0.1 | Darrel Miller | Draft | @@ -30,17 +31,16 @@ Here is an example of what the kiota.config file could look like. ```json { "name": "My application", - "version": "2.0", "apis": { "Graph": { "descriptionHash": "9EDF8506CB74FE44...", "descriptionLocation": "https://.../openapi.yaml", "includePatterns": ["/me/chats#GET", "/me#GET"], "excludePatterns": [], - "outputs": [ + "clients": [ { "language": "csharp", - "outputPath": "./generated/graph", + "outputPath": "./generated/graph/csharp", "clientClassName": "GraphClient", "clientNamespaceName": "Contoso.GraphApp", "features": { @@ -96,25 +96,27 @@ The [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01. | Command | Example | Description | | ------------------- | ------- | ---------------- | -| init | kiota init --name | Creates a kiota.config file | -| add api | kiota add api --name --openapi | Adds an entry for an API with passed parameters and default values | -| add output | kiota add output --api-name --lang python --outputPath ./pythonClient | Adds information about a new output artifact that should be generated | +| init | kiota init --name `appName` | Creates a kiota.config file | +| api add | kiota api add --name `apiName` --openapi | Adds an entry for an API with passed parameters and default values | +| api delete | kiota api delete --api-name `apiName` | Removes the entire API entry with the provided name. | +| output add | kiota output add --api-name `apiName` --lang python --outputPath ./pythonClient | Adds information about a new output artifact that should be generated | +| output delete | kiota output delete --api-name `apiName` --client-name `clientName` | Removes the specified output. Has optional parameters to allow deleting the generated output. | | generate | kiota generate | Outputs kiota.apimanifest and source for each of the output objects | -In the past we have had both a generate and an update comment. This is because if it was the first time running, generate would set defaults for all the properties that were not set on the command line. However, now that we have add output, it can be used to set the defaults and generate can just read from the kiota.config file. +In the past we have had both a generate and an update comment. This is because if it was the first time running, generate would set defaults for all the properties that were not set on the command line. However, now that we have output add, it can be used to set the defaults and generate can just read from the kiota.config file. ## Commands ### kiota init -`kiota init` creates a new kiota.config file with the passed parameters. If the file already exists, it should error out and report it to the user. The initialization process has a single required parameter, the name of the application. +`kiota init` creates a new kiota.config file with the provided parameters. If the file already exists, it should error out and report it to the user. The initialization process has a single required parameter, the name of the application. > [!NOTE] -> If a project only needs a single API, using `kiota init` is not required as generating code using the `kiota generate` command should generate a `kiota.config` file with values coming from the `kiota generate` command. See [kiota generate](#kiota-generate) for more information. +> If a project only needs a single API, using `kiota init` is not mandatory as generating code using the `kiota generate` command could generate a `kiota.config` file with values coming from the `kiota generate` command (if no `kiota.config` is present). See [kiota generate](#kiota-generate) for more information. | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--app-name \| -n` | Yes | My application | Name of the application | +| `--app-name \| --an` | Yes | My application | Name of the application | #### Using `kiota init` @@ -122,34 +124,33 @@ In the past we have had both a generate and an update comment. This is because i kiota init --app-name "My application" ``` -```json +```jsonc // Creates the following kiota.config file { - "name": "My application", - "version": "1.0" + "name": "My application" } ``` -### kiota add api +### kiota api add -`kiota add api` allows a developer to add a new API to the kiota.config file. The command will add a new entry to the apis section of the kiota.config file. The command has two required parameters, the name of the API (key of the api map) and the location of the OpenAPI description. The command also has two optional parameters, the include and exclude patterns. If provided, these will be used to filter the paths that are included in the generation process. If not provided, all paths will be assumed. +`kiota api add` allows a developer to add a new API to the `kiota.config` file. The command will add a new entry to the `apis` section of the `kiota.config` file. The command has two required parameters, the name of the API (key of the apis map) and the location of the OpenAPI description. The command also has two optional parameters, the include and exclude patterns. If provided, these will be used to filter the paths that are included in the future generation process. If not provided, all paths will be assumed. When executing, a new API entry will be added and will use the `--api-name` parameter as the key for the map. When loading the OpenAPI description, it will generate a hash of the description to enable change detection of the description and save it as part of the `descriptionHash` property. It will also store the location of the description in the `descriptionLocation` property. If `--include-path` or `--exclude-path` are provided, they will be stored in the `includePatterns` and `excludePatterns` properties respectively. | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--api-name \| -n` | Yes | graph | Name of the API | -| `--open-api \| -d` | Yes | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | +| `--api-name \| --api` | Yes | graph | Name of the API | +| `--openapi \| -d` | Yes | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | | `--include-path \| -i` | No | /me/chats#GET | A glob pattern to include paths from generation. Accepts multiple values. Defaults to no value which includes everything. | | `--exclude-path \| -e` | No | \*\*/users/\*\* | A glob pattern to exclude paths from generation. Accepts multiple values. Defaults to no value which excludes nothing. | -#### Using `kiota add api` +#### Using `kiota api add` ```bash -kiota add api --api-name "graph" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "/me/chats#GET" --include-path "/me#GET" +kiota api add --api-name "graph" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "/me/chats#GET" --include-path "/me#GET" ``` -```json +```jsonc // Adds the following to the kiota.config file "graph": { "descriptionHash": "9EDF8506CB74FE44...", @@ -159,46 +160,382 @@ kiota add api --api-name "graph" --openapi "https://raw.githubusercontent.com/mi } ``` +The resulting `kiota.config` file will look like this: + +```jsonc +{ + "name": "My application", + "apis": { + "graph": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://.../openapi.yaml", + "includePatterns": ["/me/chats#GET", "/me#GET"], + "excludePatterns": [] + } + } +} +``` + +### kiota api delete + +`kiota api delete` allows a developer to delete an existing API from the `kiota.config` file. The command will remove the entry from the `apis` section of the `kiota.config` file. The command has one required parameter, the name of the API (key of the apis map). The command also has one optional parameter, the ability to remove generated clients. If provided, kiota will delete the folder specified at the `outputPath` from the client configuration. + +| Parameters | Required | Example | Description | +| -- | -- | -- | -- | +| `--api-name \| --api` | Yes | graph | Name of the API | +| `--clean-output \| --co` | No | | Cleans the generated clients from the API | + +#### Using kiota api delete + +```bash +kiota api delete --api-name "graph" --clean-output +``` + +```jsonc +// Removes the following from the kiota.config file +"graph": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://.../openapi.yaml", + "includePatterns": ["/me/chats#GET", "/me#GET"], + "excludePatterns": [], + "clients": { + // All clients + } +} +``` + +The resulting `kiota.config` file will look like this: + +```jsonc +{ + "name": "My application", + "apis": {} +} +``` + +### kiota client add + +`kiota client add` allows a developer to add a new client for a specified API to the `kiota.config` file. The command will add a new entry to the `clients` section of the `kiota.config` file. The command has two required parameters, the name of the API (key of the apis map) and the location of the OpenAPI description. The command also has two optional parameters, the include and exclude patterns. If provided, these will be used to filter the paths that are included in the future generation process. If not provided, all paths will be assumed. The `kiota client add` command will never automatically invoke `kiota generate`. + +| Parameters | Required | Example | Description | +| -- | -- | -- | -- | +| `--api-name \| --api` | Yes | graph | Name of the API | +| `--client-name \| --cn` | No | graphDelegated | Name of the client. Unique within the parent API. If not provided, defaults to --class-name or its default. | +| `--language \| -l` | Yes | csharp | The target language for the generated code files or for the information. | +| `--class-name \| -c` | No | GraphClient | The name of the client class. Defaults to `Client`. | +| `--namespace-name \| -n` | No | Contoso.GraphApp | The namespace of the client class. Defaults to `Microsoft.Graph`. | +| `--backing-store \| -b` | No | | Defaults to `false` | +| `--exclude-backward-compatible \| --ebc` | No | | Whether to exclude the code generated only for backward compatibility reasons or not. Defaults to `false`. | +| `--serializer \| -s` | No | `Contoso.Json.CustomSerializer` | One or more module names that implements ISerializationWriterFactory. Default are documented [here](https://learn.microsoft.com/openapi/kiota/using#--serializer--s). | +| `--deserializer \| --ds` | No | `Contoso.Json.CustomDeserializer` | One or more module names that implements IParseNodeFactory. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--deserializer---ds). | +| `--structured-mime-types \| -m` | No | `application/json` |Any valid MIME type which will match a request body type or a response type in the OpenAPI description. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--structured-mime-types--m). | +| `--output \| -o` | No | ./generated/graph/csharp | The output directory or file path for the generated code files. Defaults to `./output`. | + +> [!NOTE] +> It is not required to use the CLI to ad a new clients. It is possible to add a new client by adding a new entry in the `clients` section of the `kiota.config` file. See [kiota.config](#kiotaconfig) for more information. + +#### Using kiota client add + +```bash +kiota client add --api-name "graph" --client-name "graphDelegated" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" +``` + +```jsonc +// Adds the following to the kiota.config file +"clients": { + "graphDelegated": { + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + // Adding for future visibility, but not required for now + /*"authentication": { + "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", + "authenticationParameters": { + "clientId": "guid" + }, + },*/ + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } + } +} +``` + +The resulting `kiota.config` file will look like this: + +```jsonc +{ + "name": "My application", + "apis": { + "graph": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://.../openapi.yaml", + "includePatterns": ["/me/chats#GET", "/me#GET"], + "excludePatterns": [], + "clients": { + "graphDelegated": { + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + // Adding for future visibility, but not required for now + /*"authentication": { + "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", + "authenticationParameters": { + "clientId": "guid" + }, + },*/ + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } + } + } + } + } +} +``` + +### kiota client delete + +`kiota api client` allows a developer to delete an existing client from the `kiota.config` file. The command will remove the entry from the `clients` section of parent API within the `kiota.config` file. The command has two required parameters, the name of the API and the name of the client. The command also has one optional parameter, the ability to remove the generated client. If provided, kiota will delete the folder specified at the `outputPath` from the client configuration. + +| Parameters | Required | Example | Description | +| -- | -- | -- | -- | +| `--api-name \| --api` | Yes | graph | Name of the API | +| `--client-name \| --cn` | Yes | graphDelegated | Name of the client | +| `--clean-output \| --co` | No | | Cleans the generated client | + +#### Using kiota client delete + +```bash +kiota client delete --api-name "graph" --client-name "graphDelegated" --clean-output +``` + +```jsonc +// Removes the following from the kiota.config file +"graphDelegated": { + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + // Adding for future visibility, but not required for now + /*"authentication": { + "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", + "authenticationParameters": { + "clientId": "guid" + }, + },*/ + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } +} +``` + +The resulting `kiota.config` file will look like this: + +```jsonc +{ + "name": "My application", + "version": "1.0", + "apis": { + "graph": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://.../openapi.yaml", + "includePatterns": ["/me/chats#GET", "/me#GET"], + "excludePatterns": [], + "clients": { } + } + } +} +``` + ### kiota generate -In scenarios where a developer only needs a single API or doesn't want to go through the ceremony of executing `kiota init`, it's possible to use `kiota generate` as it will create a `kiota.config` file with the values coming from the command parameters. +Now that we have a `kiota.config` file, all the parameters required to generate the code are stored in the file. The `kiota generate` command will read the `kiota.config` file and generate the code for each of the clients. + +It's also possible to specify for which API and client the code should be generated. This is useful when a project contains multiple APIs and clients. The `kiota generate --api-name "MyAPI" --client-name "MyClient"` command will read the `kiota.config` file and generate the code for the specified API and client. If it can't find the specified API or client, it will throw an error. + +In scenarios where a developer only needs a single API or doesn't want to go through the ceremony of executing `kiota init`, it's possible to use `kiota generate` and initialize a `kiota.config` file with the values coming from the command parameters. No breaking changes are required to the existing `kiota generate` command. + +#### kiota generate Parameters -#### Using `kiota generate` +> [!INFO] +> This list is only the new parameters that `kiota generate` should support. + +| Parameters | Required | Example | Description | +| -- | -- | -- | -- | +| `--app-name \| --an` | No | My application | Name of the application | +| `--api-name \| --api` | No | graph | Name of the API | +| `--client-name \| --cn` | No | graphDelegated | Name of the client. Unique within the parent API. | + +#### Using `kiota generate` with all parameters ```bash +kiota generate --app-name "My Application" --api-name "graph" --client-name "graphDelegated" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "/me/chats#GET" --include-path "/me#GET" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" ``` ```json +{ + "name": "My application", + "apis": { + "graph": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://.../openapi.yaml", + "includePatterns": ["/me/chats#GET", "/me#GET"], + "excludePatterns": [], + "clients": { + "graphDelegated": { + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + // Adding for future visibility, but not required for now + /*"authentication": { + "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", + "authenticationParameters": { + "clientId": "guid" + }, + },*/ + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } + } + } + } + } +} ``` -## Scenarios using the command line tool +#### Using kiota generate with parameters inferred from the kiota.config file + +```bash +kiota generate +``` + +#### Using kiota generate with parameters inferred from the kiota.config file for a single API + +```bash +kiota generate --api-name "graph" --client-name "graphDelegated" +``` + +#### Using kiota generate with parameters inferred when there are no kiota.config file + +```bash +kiota generate --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "/me/chats#GET" --include-path "/me#GET" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" +``` + +```json +// This file gets generated and then `kiota generate` is executed based on these parameters +{ + "name": "Contoso.GraphApp", // Inferred from the provided --namespace-name or its default value + "apis": { + "https://graph.microsoft.com/v1.0": { // Inferred from the first server entry in the OpenAPI description + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://.../openapi.yaml", + "includePatterns": ["/me/chats#GET", "/me#GET"], + "excludePatterns": [], + "clients": { + "GraphClient": { // Inferred from the provided --class-name or its default value + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + // Adding for future visibility, but not required for now + /*"authentication": { + "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", + "authenticationParameters": { + "clientId": "guid" + }, + },*/ + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } + } + } + } + } +} +``` + +## End-to-end scenarios using the CLI ### Get started to generate an API ```bash -kiota init --name Myapp -kiota add api --name MyApi --openapi // Can we add using -k ? -kiota add output --name MyApi --lang csharp --outputPath ./csharpClient +kiota init --app-name "My Application" +kiota api add --api-name "My API" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" +kiota client add --api-name "My API" --clientName "graphDelegated" --language csharp --outputPath ./csharpClient kiota generate ``` ### Add a second language to generate an API ```bash -kiota add output --name MyApi --lang python --outputPath ./pythonClient -kiota generate --name MyApi --lang python // Generate just the Python client for MyApi +kiota client add --api-name "My API" --clientName "graphPython" --language python --outputPath ./pythonClient +kiota generate --api-name "My API" --client-name "graphPython" ``` -### Remove a language +### Remove a language and delete the generated code ```bash -kiota remove output --name MyApi --lang python +kiota client delete --api-name "My API" --client=name "graphPython" --clean-output ``` ### Remove an API ```bash -kiota remove api --name MyApi +kiota api delete --name "My Api" --clean-output ``` ## JSON Schema for Kiota.Config @@ -245,54 +582,52 @@ kiota remove api --name MyApi "baseUrl": { "type": "string" }, - "output": { - "type": "array", - "items": { - "type": "object", - "properties": { - "language": { - "type": "string" - }, - "outputPath": { - "type": "string" - }, - "clientClassName": { - "type": "string" - }, - "clientNamespaceName": { - "type": "string" - }, - "features": { - "type": "object", - "properties": { - "authenticationProvider": { - "type": "string" - }, - "authenticationParameters": { - "type": "object" - } + "clients": { + "type": "object", + "patternProperties": { + ".*": { + "type": "object", + "properties": { + "language": { + "type": "string" + }, + "outputPath": { + "type": "string" + }, + "clientClassName": { + "type": "string" }, - "structuredMediaTypes": { + "clientNamespaceName": { + "type": "string" + }, + "features": { "type": "object", - "patternProperties": { - ".*": { - "type": "object", - "properties": { - "serializer": { - "type": "string" - }, - "deserializer": { - "type": "string" - } + "properties": { + "structuredMediaTypes": { + "type": "array", + "items": { + "type": "string" + } + }, + "serializers": { + "type": "array", + "items": { + "type": "string" + } + }, + "deserializers": { + "type": "array", + "items": { + "type": "string" } + }, + "usesBackingStore": { + "type": "boolean" + }, + "includeAdditionalData": { + "type": "boolean" } } - }, - "usesBackingStore": { - "type": "boolean" - }, - "includeAdditionalData": { - "type": "boolean" } } } From a89ce5cd7ce98fc26c4eea0caf0cb314c4b76588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Thu, 30 Nov 2023 16:39:05 +0000 Subject: [PATCH 04/17] Removing the initial commands table. --- specs/kiota.config.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/specs/kiota.config.md b/specs/kiota.config.md index 906a8fd653..083fb6a702 100644 --- a/specs/kiota.config.md +++ b/specs/kiota.config.md @@ -92,19 +92,6 @@ Note that in this example we added suggestions for new parameters related to aut The [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01.html) file can be used as a replacement for the kiota.lock file as a place to capture a snapshot of what information was used to perform code generation and what APIs that gives the application access to. -## Tooling commands to manage Kiota.config - -| Command | Example | Description | -| ------------------- | ------- | ---------------- | -| init | kiota init --name `appName` | Creates a kiota.config file | -| api add | kiota api add --name `apiName` --openapi | Adds an entry for an API with passed parameters and default values | -| api delete | kiota api delete --api-name `apiName` | Removes the entire API entry with the provided name. | -| output add | kiota output add --api-name `apiName` --lang python --outputPath ./pythonClient | Adds information about a new output artifact that should be generated | -| output delete | kiota output delete --api-name `apiName` --client-name `clientName` | Removes the specified output. Has optional parameters to allow deleting the generated output. | -| generate | kiota generate | Outputs kiota.apimanifest and source for each of the output objects | - -In the past we have had both a generate and an update comment. This is because if it was the first time running, generate would set defaults for all the properties that were not set on the command line. However, now that we have output add, it can be used to set the defaults and generate can just read from the kiota.config file. - ## Commands ### kiota init From 47da551a8e1a1b999097547390c425f5330500cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Thu, 30 Nov 2023 16:40:46 +0000 Subject: [PATCH 05/17] markdown edits --- specs/kiota.config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/kiota.config.md b/specs/kiota.config.md index 083fb6a702..2a36381a05 100644 --- a/specs/kiota.config.md +++ b/specs/kiota.config.md @@ -377,7 +377,7 @@ In scenarios where a developer only needs a single API or doesn't want to go thr #### kiota generate Parameters -> [!INFO] +> [!IMPORTANT] > This list is only the new parameters that `kiota generate` should support. | Parameters | Required | Example | Description | From 4f8ba43362ef70612bc5db33ceb4b8af409db157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Thu, 30 Nov 2023 16:42:55 +0000 Subject: [PATCH 06/17] Updating code blocks to support comments --- specs/kiota.config.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/specs/kiota.config.md b/specs/kiota.config.md index 2a36381a05..c35d8f4472 100644 --- a/specs/kiota.config.md +++ b/specs/kiota.config.md @@ -111,7 +111,7 @@ The [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01. kiota init --app-name "My application" ``` -```jsonc +```javascript // Creates the following kiota.config file { "name": "My application" @@ -137,7 +137,7 @@ When executing, a new API entry will be added and will use the `--api-name` para kiota api add --api-name "graph" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "/me/chats#GET" --include-path "/me#GET" ``` -```jsonc +```javascript // Adds the following to the kiota.config file "graph": { "descriptionHash": "9EDF8506CB74FE44...", @@ -149,7 +149,7 @@ kiota api add --api-name "graph" --openapi "https://raw.githubusercontent.com/mi The resulting `kiota.config` file will look like this: -```jsonc +```javascript { "name": "My application", "apis": { @@ -178,7 +178,7 @@ The resulting `kiota.config` file will look like this: kiota api delete --api-name "graph" --clean-output ``` -```jsonc +```javascript // Removes the following from the kiota.config file "graph": { "descriptionHash": "9EDF8506CB74FE44...", @@ -193,7 +193,7 @@ kiota api delete --api-name "graph" --clean-output The resulting `kiota.config` file will look like this: -```jsonc +```javascript { "name": "My application", "apis": {} @@ -227,7 +227,7 @@ The resulting `kiota.config` file will look like this: kiota client add --api-name "graph" --client-name "graphDelegated" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" ``` -```jsonc +```javascript // Adds the following to the kiota.config file "clients": { "graphDelegated": { @@ -261,7 +261,7 @@ kiota client add --api-name "graph" --client-name "graphDelegated" --language cs The resulting `kiota.config` file will look like this: -```jsonc +```javascript { "name": "My application", "apis": { @@ -351,7 +351,7 @@ kiota client delete --api-name "graph" --client-name "graphDelegated" --clean-ou The resulting `kiota.config` file will look like this: -```jsonc +```javascript { "name": "My application", "version": "1.0", @@ -392,7 +392,7 @@ In scenarios where a developer only needs a single API or doesn't want to go thr kiota generate --app-name "My Application" --api-name "graph" --client-name "graphDelegated" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "/me/chats#GET" --include-path "/me#GET" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" ``` -```json +```javascript { "name": "My application", "apis": { @@ -452,7 +452,7 @@ kiota generate --api-name "graph" --client-name "graphDelegated" kiota generate --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "/me/chats#GET" --include-path "/me#GET" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" ``` -```json +```javascript // This file gets generated and then `kiota generate` is executed based on these parameters { "name": "Contoso.GraphApp", // Inferred from the provided --namespace-name or its default value From 36b10fd16dcdbc29070421fd22124427629b316f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Wed, 6 Dec 2023 20:15:24 +0000 Subject: [PATCH 07/17] Initial restructuring of the spec --- specs/cli/client-add.md | 165 +++++++++ specs/cli/client-edit.md | 160 ++++++++ specs/cli/client-generate.md | 66 ++++ specs/cli/client-remove.md | 49 +++ specs/cli/config-init.md | 28 ++ specs/cli/config-migrate.md | 0 specs/index.md | 19 + specs/kiota.config.md | 634 -------------------------------- specs/scenarios/kiota-config.md | 194 ++++++++++ specs/schemas/kiota.config.md | 107 ++++++ 10 files changed, 788 insertions(+), 634 deletions(-) create mode 100644 specs/cli/client-add.md create mode 100644 specs/cli/client-edit.md create mode 100644 specs/cli/client-generate.md create mode 100644 specs/cli/client-remove.md create mode 100644 specs/cli/config-init.md create mode 100644 specs/cli/config-migrate.md create mode 100644 specs/index.md delete mode 100644 specs/kiota.config.md create mode 100644 specs/scenarios/kiota-config.md create mode 100644 specs/schemas/kiota.config.md diff --git a/specs/cli/client-add.md b/specs/cli/client-add.md new file mode 100644 index 0000000000..b4930d054a --- /dev/null +++ b/specs/cli/client-add.md @@ -0,0 +1,165 @@ +# kiota client add + +## Description + +`kiota client add` allows a developer to add a new API client to the `kiota.config` file. If no `kiota.config` file is found, a new `kiota.config` file would be created. The command will add a new entry to the `clients` section of the `kiota.config` file. Once this is done, a local copy of the OpenAPI description is generated and kepts in the . + +When executing, a new API entry will be added and will use the `--client-name` parameter as the key for the map. When loading the OpenAPI description, it will generate a hash of the description to enable change detection of the description and save it as part of the `descriptionHash` property. It will also store the location of the description in the `descriptionLocation` property. If `--include-path` or `--exclude-path` are provided, they will be stored in the `includePatterns` and `excludePatterns` properties respectively. + +Every time an API client is added, a copy of the OpenAPI description file will be stored in the `./.kiota` folder. The file will be named using the hash of the description. This will allow the CLI to detect changes in the description and avoid downloading the description again if it hasn't changed. + +At the same time, an [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01.html#section-2.5-3) file will be generated (if non existing) or edited (if already existing) to represent the surface of the API being used. This file will be named `apimanifest.json` and will be stored in the `./.kiota` folder. This file will be used to generate the code files. + +Once the `kiota.config` file is generated, the OpenAPI description file is saved locally and the API Manifest is available, the code generation will be executed. + +## Parameters + +| Parameters | Required | Example | Description | +| -- | -- | -- | -- | +| `--client-name \| --cn` | Yes | graphDelegated | Name of the client. Unique within the parent API. If not provided, defaults to --class-name or its default. | +| `--openapi \| -d` | Yes | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | +| `--include-path \| -i` | No | /me/chats#GET | A glob pattern to include paths from generation. Accepts multiple values. Defaults to no value which includes everything. | +| `--exclude-path \| -e` | No | \*\*/users/\*\* | A glob pattern to exclude paths from generation. Accepts multiple values. Defaults to no value which excludes nothing. | +| `--language \| -l` | Yes | csharp | The target language for the generated code files or for the information. | +| `--class-name \| -c` | No | GraphClient | The name of the client class. Defaults to `Client`. | +| `--namespace-name \| -n` | No | Contoso.GraphApp | The namespace of the client class. Defaults to `Microsoft.Graph`. | +| `--backing-store \| -b` | No | | Defaults to `false` | +| `--exclude-backward-compatible \| --ebc` | No | | Whether to exclude the code generated only for backward compatibility reasons or not. Defaults to `false`. | +| `--serializer \| -s` | No | `Contoso.Json.CustomSerializer` | One or more module names that implements ISerializationWriterFactory. Default are documented [here](https://learn.microsoft.com/openapi/kiota/using#--serializer--s). | +| `--deserializer \| --ds` | No | `Contoso.Json.CustomDeserializer` | One or more module names that implements IParseNodeFactory. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--deserializer---ds). | +| `--structured-mime-types \| -m` | No | `application/json` |Any valid MIME type which will match a request body type or a response type in the OpenAPI description. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--structured-mime-types--m). | +| `--output \| -o` | No | ./generated/graph/csharp | The output directory or file path for the generated code files. Defaults to `./output`. | + +> [!NOTE] +> It is not required to use the CLI to add new clients. It is possible to add a new client by adding a new entry in the `clients` section of the `kiota.config` file. See the [kiota.config schema](../schemas/kiota.config.md) for more information. + +## Using `kiota client add` + +```bash +kiota client add --client-name "graphDelegated" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "**/users/**" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" +``` + +```json +"clients": { + "graphDelegated": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "includePatterns": ["**/users/**"], + "excludePatterns": [], + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } + } +} +``` + +_The resulting `kiota.config` file will look like this:_ + +```json +{ + "version": "1.0.0", + "clients": { + "graphDelegated": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "includePatterns": ["**/users/**"], + "excludePatterns": [], + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } + } + } +} +``` + +_The resulting `apimanifest.json` file will look like this:_ + +```json +{ + "publisher": { + "name": "Microsoft Graph", + "contactEmail": "graphsdkpub@microsoft.com" + }, + "apiDependencies": { + "graphDelegated": { + "apiDescriptionUrl": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "apiDeploymentBaseUrl": "https://graph.microsoft.com", + "apiDescriptionVersion": "v1.0", + "requests": [ + { + "method": "GET", + "uriTemplate": "/users" + }, + { + "method": "POST", + "uriTemplate": "/users" + }, + { + "method": "GET", + "uriTemplate": "/users/$count" + }, + { + "method": "GET", + "uriTemplate": "/users/{user-id}" + }, + { + "method": "PATCH", + "uriTemplate": "/users/{user-id}" + }, + { + "method": "DELETE", + "uriTemplate": "/users/{user-id}" + } + ] + } + } +} +``` + +## File structure +```bash +/ + └─.kiota + └─kiota.config + └─apimanifest.json + └─definitions + └─9EDF8506CB74FE44.yaml + └─generated + └─graph + └─csharp + └─... # Generated code files + └─GraphClient.cs +``` + +## Open Questions + +- [ ] How do we determine the `name` and `contactEmail` of the `publisher` in the API Manifest? kiota config --global? +- [ ] Can we automatically generate all `authorizationRequirements` for the endpoints selected or these are left to the developers to add? \ No newline at end of file diff --git a/specs/cli/client-edit.md b/specs/cli/client-edit.md new file mode 100644 index 0000000000..a46a89030a --- /dev/null +++ b/specs/cli/client-edit.md @@ -0,0 +1,160 @@ +# kiota client edit + +## Description + +`kiota client update` allows a developer to edit an existing API client int the `kiota.config` file. If either the `kiota.config` file or if the `--client-name` client can't be found within the `kiota.config` file, the command should error out and let the developer know. + +When executing, the API entry defined by the `--client-name` parameter will be modified. All parameters should be supported and the only required one is `--client-name`. All others are optional as they would only modify the configuration of the API client. If the OpenAPI description location changed, a new hash of the description will be generated saved as part of the `descriptionHash` property. If `--include-path` or `--exclude-path` are provided, they will be stored in the `includePatterns` and `excludePatterns` properties respectively and would trigger an update to the [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01.html#section-2.5-3). + +Once the `kiota.config` file and the API Manifest are updated, the code generation will be executed based on the newly updated API client configuration. + +## Parameters + +| Parameters | Required | Example | Description | +| -- | -- | -- | -- | +| `--client-name \| --cn` | Yes | graphDelegated | Name of the client. Unique within the parent API. If not provided, defaults to --class-name or its default. | +| `--openapi \| -d` | No | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | +| `--include-path \| -i` | No | /me/chats#GET | A glob pattern to include paths from generation. Accepts multiple values. Defaults to no value which includes everything. | +| `--exclude-path \| -e` | No | \*\*/users/\*\* | A glob pattern to exclude paths from generation. Accepts multiple values. Defaults to no value which excludes nothing. | +| `--language \| -l` | No | csharp | The target language for the generated code files or for the information. | +| `--class-name \| -c` | No | GraphClient | The name of the client class. Defaults to `Client`. | +| `--namespace-name \| -n` | No | Contoso.GraphApp | The namespace of the client class. Defaults to `Microsoft.Graph`. | +| `--backing-store \| -b` | No | | Defaults to `false` | +| `--exclude-backward-compatible \| --ebc` | No | | Whether to exclude the code generated only for backward compatibility reasons or not. Defaults to `false`. | +| `--serializer \| -s` | No | `Contoso.Json.CustomSerializer` | One or more module names that implements ISerializationWriterFactory. Default are documented [here](https://learn.microsoft.com/openapi/kiota/using#--serializer--s). | +| `--deserializer \| --ds` | No | `Contoso.Json.CustomDeserializer` | One or more module names that implements IParseNodeFactory. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--deserializer---ds). | +| `--structured-mime-types \| -m` | No | `application/json` |Any valid MIME type which will match a request body type or a response type in the OpenAPI description. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--structured-mime-types--m). | +| `--output \| -o` | No | ./generated/graph/csharp | The output directory or file path for the generated code files. Defaults to `./output`. | + +> [!NOTE] +> It is not required to use the CLI to edit clients. It is possible to edit a client by modifying its entry in the `clients` section of the `kiota.config` file. See the [kiota.config schema](../schemas/kiota.config.md) for more information. + +## Using `kiota client edit` + +```bash +kiota client edit --client-name "graphDelegated" --class-name "GraphServiceClient" --exclude-path "/users/$count" +``` + +```json +``` + +```json +"clients": { + "graphDelegated": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "includePatterns": ["**/users/**"], + "excludePatterns": ["/users/$count"], + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphServiceClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } + } +} +``` + +_The resulting `kiota.config` file will look like this:_ + +```json +{ + "version": "1.0.0", + "clients": { + "graphDelegated": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "includePatterns": ["**/users/**"], + "excludePatterns": [], + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphServiceClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } + } + } +} +``` + +_The resulting `apimanifest.json` file will look like this:_ + +```json +{ + "publisher": { + "name": "Microsoft Graph", + "contactEmail": "graphsdkpub@microsoft.com" + }, + "apiDependencies": { + "graphDelegated": { + "apiDescriptionUrl": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "apiDeploymentBaseUrl": "https://graph.microsoft.com", + "apiDescriptionVersion": "v1.0", + "requests": [ + { + "method": "GET", + "uriTemplate": "/users" + }, + { + "method": "POST", + "uriTemplate": "/users" + }, + { + "method": "GET", + "uriTemplate": "/users/{user-id}" + }, + { + "method": "PATCH", + "uriTemplate": "/users/{user-id}" + }, + { + "method": "DELETE", + "uriTemplate": "/users/{user-id}" + } + ] + } + } +} +``` + +## File structure +```bash +/ + └─.kiota + └─kiota.config + └─apimanifest.json + └─definitions + └─9EDF8506CB74FE44.yaml + └─generated + └─graph + └─csharp + └─... # Generated code files + └─GraphClient.cs +``` + +## Open Questions + +- [ ] How do we determine the `name` and `contactEmail` of the `publisher` in the API Manifest? kiota config --global? +- [ ] Can we automatically generate all `authorizationRequirements` for the endpoints selected or these are left to the developers to add? \ No newline at end of file diff --git a/specs/cli/client-generate.md b/specs/cli/client-generate.md new file mode 100644 index 0000000000..5fd86967fc --- /dev/null +++ b/specs/cli/client-generate.md @@ -0,0 +1,66 @@ +# kiota client generate + +Now that we have a `kiota.config` file, all the parameters required to generate the code are stored in the file. The `kiota generate` command will read the `kiota.config` file and generate the code for each of the clients. + +It's also possible to specify for which API and client the code should be generated. This is useful when a project contains multiple APIs and clients. The `kiota generate --api-name "MyAPI" --client-name "MyClient"` command will read the `kiota.config` file and generate the code for the specified API and client. If it can't find the specified API or client, it will throw an error. + +In scenarios where a developer only needs a single API or doesn't want to go through the ceremony of executing `kiota init`, it's possible to use `kiota generate` and initialize a `kiota.config` file with the values coming from the command parameters. No breaking changes are required to the existing `kiota generate` command. + +#### kiota generate Parameters + +> [!IMPORTANT] +> This list is only the new parameters that `kiota generate` should support. + +| Parameters | Required | Example | Description | +| -- | -- | -- | -- | +| `--app-name \| --an` | No | My application | Name of the application | +| `--api-name \| --api` | No | graph | Name of the API | +| `--client-name \| --cn` | No | graphDelegated | Name of the client. Unique within the parent API. | + +#### Using `kiota generate` with all parameters + +```bash +kiota generate --app-name "My Application" --api-name "graph" --client-name "graphDelegated" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "/me/chats#GET" --include-path "/me#GET" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" +``` + +```javascript +{ + "name": "My application", + "apis": { + "graph": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://.../openapi.yaml", + "includePatterns": ["/me/chats#GET", "/me#GET"], + "excludePatterns": [], + "clients": { + "graphDelegated": { + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + // Adding for future visibility, but not required for now + /*"authentication": { + "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", + "authenticationParameters": { + "clientId": "guid" + }, + },*/ + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } + } + } + } + } +} +``` \ No newline at end of file diff --git a/specs/cli/client-remove.md b/specs/cli/client-remove.md new file mode 100644 index 0000000000..d7d857cd6e --- /dev/null +++ b/specs/cli/client-remove.md @@ -0,0 +1,49 @@ +# kiota client remove + +## Description + +`kiota client remove` allows a developer to remove an existing client from the `kiota.config` file. The command will remove the entry from the `clients` section of `kiota.config` file. The command has a single required parameters; the name of the client. + +The command also has one optional parameter, the ability to remove the generated client. If provided, kiota will delete the folder and its content specified at the `outputPath` from the client configuration. It will also remove the local version of the OpenAPI description file (specified by the `descriptionHash` property). The API Manifest is also updated to remove the dependency from the list of dependencies. + +| Parameters | Required | Example | Description | +| -- | -- | -- | -- | +| `--client-name \| --cn` | Yes | graphDelegated | Name of the client | +| `--clean-output \| --co` | No | | Cleans the generated client | + +#### Using kiota client remove + +```bash +kiota client remove --client-name "graphDelegated" --clean-output +``` + +The resulting `kiota.config` file will look like this: + +```json +{ + "version": "1.0.0", + "clients": { } +} +``` + +_The resulting `apimanifest.json` file will look like this:_ + +```json +{ + "publisher": { + "name": "Microsoft Graph", + "contactEmail": "graphsdkpub@microsoft.com" + }, + "apiDependencies": { } +} +``` + +## File structure +```bash +/ + └─.kiota + └─kiota.config + └─apimanifest.json + └─generated + └─graph +``` \ No newline at end of file diff --git a/specs/cli/config-init.md b/specs/cli/config-init.md new file mode 100644 index 0000000000..f4f3d3c12a --- /dev/null +++ b/specs/cli/config-init.md @@ -0,0 +1,28 @@ +# `kiota config init` + +## Description + +`kiota config init` creates a new kiota.config file with the provided parameters. If the file already exists, it should error out and report it to the user. As the file gets created, it should be adding a `version` property with the value of the `kiota.config` current schema version. + +When `kiota config init` is executed, a `kiota.config` file would be created in the current directory where the command is being executed. If the user wants to create the file in a different directory, they should use the `--config-file` global parameter. + +> [!NOTE] +> If a project only needs a single API, using `kiota config init` is not mandatory as generating code using the `kiota client generate` command could generate a `kiota.config` file with values coming from the `kiota client generate` command (if no `kiota.config` is present). See [kiota client generate](./client-generate.md) for more information. + +## Parameters + +| Parameters | Required | Example | Description | +| -- | -- | -- | -- | +| `--config-file \| --cf` | No | ../../kiota.config | Path to an existing `kiota.config` file. Defaults to `./` | + +## Using `kiota config init` + +```bash +kiota config init +``` +_Results in the following `kiota.config` file:_ +```json +{ + "version": "1.0.0", +} +``` \ No newline at end of file diff --git a/specs/cli/config-migrate.md b/specs/cli/config-migrate.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/specs/index.md b/specs/index.md new file mode 100644 index 0000000000..fa305ee49d --- /dev/null +++ b/specs/index.md @@ -0,0 +1,19 @@ +# Kiota Specification Repository + +This repository contains the specifications for the Kiota project. The goal of this repository is to provide a place to discuss and document the Kiota project. It will evolve over time as the project evolves. +config.md) + +## CLI + +* [kiota client add](./cli/client-add.md) +* [kiota client edit](./cli/client-edit.md) +* [kiota client update](./cli/client-update.md) +* [kiota client generate](./cli/client-generate.md) +* [kiota init](./cli/init.md) +* [kiota migrate](./cli/migrate.md) + +## Extension + +## Scenarios + +* [Kiota.Config](./scenarios/kiota. \ No newline at end of file diff --git a/specs/kiota.config.md b/specs/kiota.config.md deleted file mode 100644 index c35d8f4472..0000000000 --- a/specs/kiota.config.md +++ /dev/null @@ -1,634 +0,0 @@ -# Kiota Config - -Kiota generates client code for an API and stores parameters in a kiota.lock file. A project can contain multiple API clients, but they are independently managed. Kiota has no awareness that an app has a dependency on multiple APIs, even though that is a core use case. - -## Status - -| Date | Version | Author | Status | -| -- | -- | -- | -- | -| November 30th, 2023 | v0.3 | Sébastien Levert | Final Draft | -| November 22nd, 2023 | v0.2 | Sébastien Levert | Draft | -| September 24th, 2023 | v0.1 | Darrel Miller | Draft | - -## Current Challenges - -- Client code generation is not reproducible if API description changes -- Kiota doesn’t have a good solution for APIs that use multiple security schemes. -- Kiota doesn’t provide any support for generating auth providers with the required permissions, partially because currently we generate one client for APIs that use different schemes. How would we know which auth provider to generate. -- Kiota doesn’t have a good story for acquiring a client identifier. e.g. apikey or OAuth2 ClientId. This could be possible if the OpenIDConnect URL pointed to a dynamic registration endpoint. -- If an application has multiple kiota clients, there is currently no way perform operations that correspond to all of the clients. - -We have previously described Kiota's approach to managing API dependencies as consistent with the way people manage packages in a project. However, currently our tooling doesn't behave that way. We treat each dependency independently. - -## Proposal - -We should introduce a new Kiota.config file that holds the input parameters required to generate the API Client code. Currently kiota.lock is used to capture what the parameters were at the time of generation and can be used to regenerate based on the parameters in the file. This creates a mixture of purposes for the file. - -We did consider creating one kiota.config file as as a peer of the language project file, however, for someone who wants to generate multiple clients for an API in different languages, this would be a bit annoying. An alternative would be to allow the kiota.config file to move further up the folder structure and support generation in multiple languages from a single file. This is more consistent with what [TypeSpec](https://aka.ms/typespec) are doing and would be helpful for generating CLI and docs as well as a library. - -Here is an example of what the kiota.config file could look like. - -```json -{ - "name": "My application", - "apis": { - "Graph": { - "descriptionHash": "9EDF8506CB74FE44...", - "descriptionLocation": "https://.../openapi.yaml", - "includePatterns": ["/me/chats#GET", "/me#GET"], - "excludePatterns": [], - "clients": [ - { - "language": "csharp", - "outputPath": "./generated/graph/csharp", - "clientClassName": "GraphClient", - "clientNamespaceName": "Contoso.GraphApp", - "features": { - "authentication": { - "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", - "authenticationParameters": { - "clientId": "guid" - } - }, - "usesBackingStore": true, - "includeAdditionalData": true - } - } - ] - }, - "BusinessCentral": { - "descriptionHash": "810CF81EFDB5D8E065...", - "descriptionLocation": "https://.../bcoas1.0.yaml", - "includePatterns": ["/companies#GET"], - "excludePatterns": [], - "outputs": [ - { - "language": "csharp", - "outputPath": "./generated/business-central" - }, - { - "language": "python", - "outputPath": "./generated/python/business-central" - }, - { - "language": "csharp", - "outputPath": "./generated/business-central-app", - "features": { - "authentication": { - "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", - "authenticationParameters": { - "clientId": "guid" - } - } - } - } - ] - } - } -} -``` - -Note that in this example we added suggestions for new parameters related to authentication. If we are to improve the generation experience so that we read the security schemes information from the OpenAPI, then we will need to have some place to configure what providers we will use for those schemes. - -The [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01.html) file can be used as a replacement for the kiota.lock file as a place to capture a snapshot of what information was used to perform code generation and what APIs that gives the application access to. - -## Commands - -### kiota init - -`kiota init` creates a new kiota.config file with the provided parameters. If the file already exists, it should error out and report it to the user. The initialization process has a single required parameter, the name of the application. - -> [!NOTE] -> If a project only needs a single API, using `kiota init` is not mandatory as generating code using the `kiota generate` command could generate a `kiota.config` file with values coming from the `kiota generate` command (if no `kiota.config` is present). See [kiota generate](#kiota-generate) for more information. - -| Parameters | Required | Example | Description | -| -- | -- | -- | -- | -| `--app-name \| --an` | Yes | My application | Name of the application | - -#### Using `kiota init` - -```bash -kiota init --app-name "My application" -``` - -```javascript -// Creates the following kiota.config file -{ - "name": "My application" -} -``` - -### kiota api add - -`kiota api add` allows a developer to add a new API to the `kiota.config` file. The command will add a new entry to the `apis` section of the `kiota.config` file. The command has two required parameters, the name of the API (key of the apis map) and the location of the OpenAPI description. The command also has two optional parameters, the include and exclude patterns. If provided, these will be used to filter the paths that are included in the future generation process. If not provided, all paths will be assumed. - -When executing, a new API entry will be added and will use the `--api-name` parameter as the key for the map. When loading the OpenAPI description, it will generate a hash of the description to enable change detection of the description and save it as part of the `descriptionHash` property. It will also store the location of the description in the `descriptionLocation` property. If `--include-path` or `--exclude-path` are provided, they will be stored in the `includePatterns` and `excludePatterns` properties respectively. - -| Parameters | Required | Example | Description | -| -- | -- | -- | -- | -| `--api-name \| --api` | Yes | graph | Name of the API | -| `--openapi \| -d` | Yes | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | -| `--include-path \| -i` | No | /me/chats#GET | A glob pattern to include paths from generation. Accepts multiple values. Defaults to no value which includes everything. | -| `--exclude-path \| -e` | No | \*\*/users/\*\* | A glob pattern to exclude paths from generation. Accepts multiple values. Defaults to no value which excludes nothing. | - -#### Using `kiota api add` - -```bash -kiota api add --api-name "graph" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "/me/chats#GET" --include-path "/me#GET" -``` - -```javascript -// Adds the following to the kiota.config file -"graph": { - "descriptionHash": "9EDF8506CB74FE44...", - "descriptionLocation": "https://.../openapi.yaml", - "includePatterns": ["/me/chats#GET", "/me#GET"], - "excludePatterns": [] -} -``` - -The resulting `kiota.config` file will look like this: - -```javascript -{ - "name": "My application", - "apis": { - "graph": { - "descriptionHash": "9EDF8506CB74FE44...", - "descriptionLocation": "https://.../openapi.yaml", - "includePatterns": ["/me/chats#GET", "/me#GET"], - "excludePatterns": [] - } - } -} -``` - -### kiota api delete - -`kiota api delete` allows a developer to delete an existing API from the `kiota.config` file. The command will remove the entry from the `apis` section of the `kiota.config` file. The command has one required parameter, the name of the API (key of the apis map). The command also has one optional parameter, the ability to remove generated clients. If provided, kiota will delete the folder specified at the `outputPath` from the client configuration. - -| Parameters | Required | Example | Description | -| -- | -- | -- | -- | -| `--api-name \| --api` | Yes | graph | Name of the API | -| `--clean-output \| --co` | No | | Cleans the generated clients from the API | - -#### Using kiota api delete - -```bash -kiota api delete --api-name "graph" --clean-output -``` - -```javascript -// Removes the following from the kiota.config file -"graph": { - "descriptionHash": "9EDF8506CB74FE44...", - "descriptionLocation": "https://.../openapi.yaml", - "includePatterns": ["/me/chats#GET", "/me#GET"], - "excludePatterns": [], - "clients": { - // All clients - } -} -``` - -The resulting `kiota.config` file will look like this: - -```javascript -{ - "name": "My application", - "apis": {} -} -``` - -### kiota client add - -`kiota client add` allows a developer to add a new client for a specified API to the `kiota.config` file. The command will add a new entry to the `clients` section of the `kiota.config` file. The command has two required parameters, the name of the API (key of the apis map) and the location of the OpenAPI description. The command also has two optional parameters, the include and exclude patterns. If provided, these will be used to filter the paths that are included in the future generation process. If not provided, all paths will be assumed. The `kiota client add` command will never automatically invoke `kiota generate`. - -| Parameters | Required | Example | Description | -| -- | -- | -- | -- | -| `--api-name \| --api` | Yes | graph | Name of the API | -| `--client-name \| --cn` | No | graphDelegated | Name of the client. Unique within the parent API. If not provided, defaults to --class-name or its default. | -| `--language \| -l` | Yes | csharp | The target language for the generated code files or for the information. | -| `--class-name \| -c` | No | GraphClient | The name of the client class. Defaults to `Client`. | -| `--namespace-name \| -n` | No | Contoso.GraphApp | The namespace of the client class. Defaults to `Microsoft.Graph`. | -| `--backing-store \| -b` | No | | Defaults to `false` | -| `--exclude-backward-compatible \| --ebc` | No | | Whether to exclude the code generated only for backward compatibility reasons or not. Defaults to `false`. | -| `--serializer \| -s` | No | `Contoso.Json.CustomSerializer` | One or more module names that implements ISerializationWriterFactory. Default are documented [here](https://learn.microsoft.com/openapi/kiota/using#--serializer--s). | -| `--deserializer \| --ds` | No | `Contoso.Json.CustomDeserializer` | One or more module names that implements IParseNodeFactory. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--deserializer---ds). | -| `--structured-mime-types \| -m` | No | `application/json` |Any valid MIME type which will match a request body type or a response type in the OpenAPI description. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--structured-mime-types--m). | -| `--output \| -o` | No | ./generated/graph/csharp | The output directory or file path for the generated code files. Defaults to `./output`. | - -> [!NOTE] -> It is not required to use the CLI to ad a new clients. It is possible to add a new client by adding a new entry in the `clients` section of the `kiota.config` file. See [kiota.config](#kiotaconfig) for more information. - -#### Using kiota client add - -```bash -kiota client add --api-name "graph" --client-name "graphDelegated" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" -``` - -```javascript -// Adds the following to the kiota.config file -"clients": { - "graphDelegated": { - "language": "csharp", - "outputPath": "./generated/graph/csharp", - "clientClassName": "GraphClient", - "clientNamespaceName": "Contoso.GraphApp", - "features": { - // Adding for future visibility, but not required for now - /*"authentication": { - "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", - "authenticationParameters": { - "clientId": "guid" - }, - },*/ - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true - } - } -} -``` - -The resulting `kiota.config` file will look like this: - -```javascript -{ - "name": "My application", - "apis": { - "graph": { - "descriptionHash": "9EDF8506CB74FE44...", - "descriptionLocation": "https://.../openapi.yaml", - "includePatterns": ["/me/chats#GET", "/me#GET"], - "excludePatterns": [], - "clients": { - "graphDelegated": { - "language": "csharp", - "outputPath": "./generated/graph/csharp", - "clientClassName": "GraphClient", - "clientNamespaceName": "Contoso.GraphApp", - "features": { - // Adding for future visibility, but not required for now - /*"authentication": { - "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", - "authenticationParameters": { - "clientId": "guid" - }, - },*/ - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true - } - } - } - } - } -} -``` - -### kiota client delete - -`kiota api client` allows a developer to delete an existing client from the `kiota.config` file. The command will remove the entry from the `clients` section of parent API within the `kiota.config` file. The command has two required parameters, the name of the API and the name of the client. The command also has one optional parameter, the ability to remove the generated client. If provided, kiota will delete the folder specified at the `outputPath` from the client configuration. - -| Parameters | Required | Example | Description | -| -- | -- | -- | -- | -| `--api-name \| --api` | Yes | graph | Name of the API | -| `--client-name \| --cn` | Yes | graphDelegated | Name of the client | -| `--clean-output \| --co` | No | | Cleans the generated client | - -#### Using kiota client delete - -```bash -kiota client delete --api-name "graph" --client-name "graphDelegated" --clean-output -``` - -```jsonc -// Removes the following from the kiota.config file -"graphDelegated": { - "language": "csharp", - "outputPath": "./generated/graph/csharp", - "clientClassName": "GraphClient", - "clientNamespaceName": "Contoso.GraphApp", - "features": { - // Adding for future visibility, but not required for now - /*"authentication": { - "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", - "authenticationParameters": { - "clientId": "guid" - }, - },*/ - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true - } -} -``` - -The resulting `kiota.config` file will look like this: - -```javascript -{ - "name": "My application", - "version": "1.0", - "apis": { - "graph": { - "descriptionHash": "9EDF8506CB74FE44...", - "descriptionLocation": "https://.../openapi.yaml", - "includePatterns": ["/me/chats#GET", "/me#GET"], - "excludePatterns": [], - "clients": { } - } - } -} -``` - -### kiota generate - -Now that we have a `kiota.config` file, all the parameters required to generate the code are stored in the file. The `kiota generate` command will read the `kiota.config` file and generate the code for each of the clients. - -It's also possible to specify for which API and client the code should be generated. This is useful when a project contains multiple APIs and clients. The `kiota generate --api-name "MyAPI" --client-name "MyClient"` command will read the `kiota.config` file and generate the code for the specified API and client. If it can't find the specified API or client, it will throw an error. - -In scenarios where a developer only needs a single API or doesn't want to go through the ceremony of executing `kiota init`, it's possible to use `kiota generate` and initialize a `kiota.config` file with the values coming from the command parameters. No breaking changes are required to the existing `kiota generate` command. - -#### kiota generate Parameters - -> [!IMPORTANT] -> This list is only the new parameters that `kiota generate` should support. - -| Parameters | Required | Example | Description | -| -- | -- | -- | -- | -| `--app-name \| --an` | No | My application | Name of the application | -| `--api-name \| --api` | No | graph | Name of the API | -| `--client-name \| --cn` | No | graphDelegated | Name of the client. Unique within the parent API. | - -#### Using `kiota generate` with all parameters - -```bash -kiota generate --app-name "My Application" --api-name "graph" --client-name "graphDelegated" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "/me/chats#GET" --include-path "/me#GET" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" -``` - -```javascript -{ - "name": "My application", - "apis": { - "graph": { - "descriptionHash": "9EDF8506CB74FE44...", - "descriptionLocation": "https://.../openapi.yaml", - "includePatterns": ["/me/chats#GET", "/me#GET"], - "excludePatterns": [], - "clients": { - "graphDelegated": { - "language": "csharp", - "outputPath": "./generated/graph/csharp", - "clientClassName": "GraphClient", - "clientNamespaceName": "Contoso.GraphApp", - "features": { - // Adding for future visibility, but not required for now - /*"authentication": { - "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", - "authenticationParameters": { - "clientId": "guid" - }, - },*/ - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true - } - } - } - } - } -} -``` - -#### Using kiota generate with parameters inferred from the kiota.config file - -```bash -kiota generate -``` - -#### Using kiota generate with parameters inferred from the kiota.config file for a single API - -```bash -kiota generate --api-name "graph" --client-name "graphDelegated" -``` - -#### Using kiota generate with parameters inferred when there are no kiota.config file - -```bash -kiota generate --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "/me/chats#GET" --include-path "/me#GET" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" -``` - -```javascript -// This file gets generated and then `kiota generate` is executed based on these parameters -{ - "name": "Contoso.GraphApp", // Inferred from the provided --namespace-name or its default value - "apis": { - "https://graph.microsoft.com/v1.0": { // Inferred from the first server entry in the OpenAPI description - "descriptionHash": "9EDF8506CB74FE44...", - "descriptionLocation": "https://.../openapi.yaml", - "includePatterns": ["/me/chats#GET", "/me#GET"], - "excludePatterns": [], - "clients": { - "GraphClient": { // Inferred from the provided --class-name or its default value - "language": "csharp", - "outputPath": "./generated/graph/csharp", - "clientClassName": "GraphClient", - "clientNamespaceName": "Contoso.GraphApp", - "features": { - // Adding for future visibility, but not required for now - /*"authentication": { - "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", - "authenticationParameters": { - "clientId": "guid" - }, - },*/ - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true - } - } - } - } - } -} -``` - -## End-to-end scenarios using the CLI - -### Get started to generate an API - -```bash -kiota init --app-name "My Application" -kiota api add --api-name "My API" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" -kiota client add --api-name "My API" --clientName "graphDelegated" --language csharp --outputPath ./csharpClient -kiota generate -``` - -### Add a second language to generate an API - -```bash -kiota client add --api-name "My API" --clientName "graphPython" --language python --outputPath ./pythonClient -kiota generate --api-name "My API" --client-name "graphPython" -``` - -### Remove a language and delete the generated code - -```bash -kiota client delete --api-name "My API" --client=name "graphPython" --clean-output -``` - -### Remove an API - -```bash -kiota api delete --name "My Api" --clean-output -``` - -## JSON Schema for Kiota.Config - -```json -{ - "$schema": "", - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "apis": { - "type": "object", - "patternProperties": { - ".*": { - "type": "object", - "properties": { - "descriptionLocation": { - "type": "string" - }, - "descriptionHash": { - "type": "string" - } - }, - "descriptionHash": { - "type": "string" - }, - "descriptionLocation": { - "type": "string" - }, - "includePatterns": { - "type": "array", - "items": { - "type": "string" - } - }, - "excludePatterns": { - "type": "array", - "items": { - "type": "string" - } - }, - "baseUrl": { - "type": "string" - }, - "clients": { - "type": "object", - "patternProperties": { - ".*": { - "type": "object", - "properties": { - "language": { - "type": "string" - }, - "outputPath": { - "type": "string" - }, - "clientClassName": { - "type": "string" - }, - "clientNamespaceName": { - "type": "string" - }, - "features": { - "type": "object", - "properties": { - "structuredMediaTypes": { - "type": "array", - "items": { - "type": "string" - } - }, - "serializers": { - "type": "array", - "items": { - "type": "string" - } - }, - "deserializers": { - "type": "array", - "items": { - "type": "string" - } - }, - "usesBackingStore": { - "type": "boolean" - }, - "includeAdditionalData": { - "type": "boolean" - } - } - } - } - } - } - } - }, - "disabledValidationRules": { - "type": "array", - "items": { - "type": "string" - } - } - } - } - } -} -``` diff --git a/specs/scenarios/kiota-config.md b/specs/scenarios/kiota-config.md new file mode 100644 index 0000000000..cc52a50ed2 --- /dev/null +++ b/specs/scenarios/kiota-config.md @@ -0,0 +1,194 @@ +# Kiota Config + +Kiota generates client code for an API and stores parameters in a kiota.lock file. A project can contain multiple API clients, but they are independently managed. Kiota has no awareness that an app has a dependency on multiple APIs, even though that is a core use case. + +## Status + +| Date | Version | Author | Status | +| -- | -- | -- | -- | +| November 30th, 2023 | v0.3 | Sébastien Levert | Final Draft | +| November 22nd, 2023 | v0.2 | Sébastien Levert | Draft | +| September 24th, 2023 | v0.1 | Darrel Miller | Draft | + +## Current Challenges + +- Client code generation is not reproducible if API description changes +- Kiota doesn’t have a good solution for APIs that use multiple security schemes. +- Kiota doesn’t provide any support for generating auth providers with the required permissions, partially because currently we generate one client for APIs that use different schemes. How would we know which auth provider to generate. +- Kiota doesn’t have a good story for acquiring a client identifier. e.g. apikey or OAuth2 ClientId. This could be possible if the OpenIDConnect URL pointed to a dynamic registration endpoint. +- If an application has multiple kiota clients, there is currently no way perform operations that correspond to all of the clients. + +We have previously described Kiota's approach to managing API dependencies as consistent with the way people manage packages in a project. However, currently our tooling doesn't behave that way. We treat each dependency independently. + +## Proposal + +We should introduce a new Kiota.config file that holds the input parameters required to generate the API Client code. Currently kiota.lock is used to capture what the parameters were at the time of generation and can be used to regenerate based on the parameters in the file. This creates a mixture of purposes for the file. + +We did consider creating one kiota.config file as as a peer of the language project file, however, for someone who wants to generate multiple clients for an API in different languages, this would be a bit annoying. An alternative would be to allow the kiota.config file to move further up the folder structure and support generation in multiple languages from a single file. This is more consistent with what [TypeSpec](https://aka.ms/typespec) are doing and would be helpful for generating CLI and docs as well as a library. + +Here is an example of what the kiota.config file could look like. + +```json +{ + "name": "My application", + "apis": { + "Graph": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://.../openapi.yaml", + "includePatterns": ["/me/chats#GET", "/me#GET"], + "excludePatterns": [], + "clients": [ + { + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + "authentication": { + "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", + "authenticationParameters": { + "clientId": "guid" + } + }, + "usesBackingStore": true, + "includeAdditionalData": true + } + } + ] + }, + "BusinessCentral": { + "descriptionHash": "810CF81EFDB5D8E065...", + "descriptionLocation": "https://.../bcoas1.0.yaml", + "includePatterns": ["/companies#GET"], + "excludePatterns": [], + "outputs": [ + { + "language": "csharp", + "outputPath": "./generated/business-central" + }, + { + "language": "python", + "outputPath": "./generated/python/business-central" + }, + { + "language": "csharp", + "outputPath": "./generated/business-central-app", + "features": { + "authentication": { + "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", + "authenticationParameters": { + "clientId": "guid" + } + } + } + } + ] + } + } +} +``` + +Note that in this example we added suggestions for new parameters related to authentication. If we are to improve the generation experience so that we read the security schemes information from the OpenAPI, then we will need to have some place to configure what providers we will use for those schemes. + +The [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01.html) file can be used as a replacement for the kiota.lock file as a place to capture a snapshot of what information was used to perform code generation and what APIs that gives the application access to. + +## Commands + +* [kiota config init](../cli/init.md) +* [kiota client add](../cli/client-add.md) +* [kiota client edit](../cli/client-edit.md) +* [kiota client generate](../cli/client-remove.md) +* [kiota client remove](../cli/client-remove.md) + +## End-to-end experience + +#### Using kiota generate with parameters inferred from the kiota.config file + +```bash +kiota generate +``` + +#### Using kiota generate with parameters inferred from the kiota.config file for a single API + +```bash +kiota generate --api-name "graph" --client-name "graphDelegated" +``` + +#### Using kiota generate with parameters inferred when there are no kiota.config file + +```bash +kiota generate --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "/me/chats#GET" --include-path "/me#GET" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" +``` + +```javascript +// This file gets generated and then `kiota generate` is executed based on these parameters +{ + "name": "Contoso.GraphApp", // Inferred from the provided --namespace-name or its default value + "apis": { + "https://graph.microsoft.com/v1.0": { // Inferred from the first server entry in the OpenAPI description + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://.../openapi.yaml", + "includePatterns": ["/me/chats#GET", "/me#GET"], + "excludePatterns": [], + "clients": { + "GraphClient": { // Inferred from the provided --class-name or its default value + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + // Adding for future visibility, but not required for now + /*"authentication": { + "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", + "authenticationParameters": { + "clientId": "guid" + }, + },*/ + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } + } + } + } + } +} +``` + +## End-to-end scenarios using the CLI + +### Get started to generate an API + +```bash +kiota init --app-name "My Application" +kiota api add --api-name "My API" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" +kiota client add --api-name "My API" --clientName "graphDelegated" --language csharp --outputPath ./csharpClient +kiota generate +``` + +### Add a second language to generate an API + +```bash +kiota client add --api-name "My API" --clientName "graphPython" --language python --outputPath ./pythonClient +kiota generate --api-name "My API" --client-name "graphPython" +``` + +### Remove a language and delete the generated code + +```bash +kiota client delete --api-name "My API" --client=name "graphPython" --clean-output +``` + +### Remove an API + +```bash +kiota api delete --name "My Api" --clean-output +``` diff --git a/specs/schemas/kiota.config.md b/specs/schemas/kiota.config.md new file mode 100644 index 0000000000..a3ff5308ce --- /dev/null +++ b/specs/schemas/kiota.config.md @@ -0,0 +1,107 @@ +## JSON Schema for kiota.config + +```json +{ + "$schema": "", + "type": "object", + "properties": { + "version": { + "type": "string" + }, + "apis": { + "type": "object", + "patternProperties": { + ".*": { + "type": "object", + "properties": { + "descriptionLocation": { + "type": "string" + }, + "descriptionHash": { + "type": "string" + } + }, + "descriptionHash": { + "type": "string" + }, + "descriptionLocation": { + "type": "string" + }, + "includePatterns": { + "type": "array", + "items": { + "type": "string" + } + }, + "excludePatterns": { + "type": "array", + "items": { + "type": "string" + } + }, + "baseUrl": { + "type": "string" + }, + "clients": { + "type": "object", + "patternProperties": { + ".*": { + "type": "object", + "properties": { + "language": { + "type": "string" + }, + "outputPath": { + "type": "string" + }, + "clientClassName": { + "type": "string" + }, + "clientNamespaceName": { + "type": "string" + }, + "features": { + "type": "object", + "properties": { + "structuredMediaTypes": { + "type": "array", + "items": { + "type": "string" + } + }, + "serializers": { + "type": "array", + "items": { + "type": "string" + } + }, + "deserializers": { + "type": "array", + "items": { + "type": "string" + } + }, + "usesBackingStore": { + "type": "boolean" + }, + "includeAdditionalData": { + "type": "boolean" + } + } + } + } + } + } + } + }, + "disabledValidationRules": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } +} +``` \ No newline at end of file From e805390877d75a9559ead9b47f3d85f8ed63640d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Thu, 7 Dec 2023 19:23:26 +0000 Subject: [PATCH 08/17] Updated version of the spec --- specs/cli/client-add.md | 64 +++++------ specs/cli/client-edit.md | 74 ++++++------- specs/cli/client-generate.md | 73 ++++--------- specs/cli/client-remove.md | 11 +- specs/cli/config-init.md | 19 ++-- specs/cli/config-migrate.md | 185 ++++++++++++++++++++++++++++++++ specs/index.md | 8 +- specs/scenarios/kiota-config.md | 108 ++++--------------- specs/schemas/kiota.config.md | 4 +- 9 files changed, 323 insertions(+), 223 deletions(-) diff --git a/specs/cli/client-add.md b/specs/cli/client-add.md index b4930d054a..3f085e5607 100644 --- a/specs/cli/client-add.md +++ b/specs/cli/client-add.md @@ -2,7 +2,7 @@ ## Description -`kiota client add` allows a developer to add a new API client to the `kiota.config` file. If no `kiota.config` file is found, a new `kiota.config` file would be created. The command will add a new entry to the `clients` section of the `kiota.config` file. Once this is done, a local copy of the OpenAPI description is generated and kepts in the . +`kiota client add` allows a developer to add a new API client to the `kiota-config.json` file. If no `kiota-config.json` file is found, a new `kiota-config.json` file would be created. The command will add a new entry to the `clients` section of the `kiota-config.json` file. Once this is done, a local copy of the OpenAPI description is generated and kepts in the . When executing, a new API entry will be added and will use the `--client-name` parameter as the key for the map. When loading the OpenAPI description, it will generate a hash of the description to enable change detection of the description and save it as part of the `descriptionHash` property. It will also store the location of the description in the `descriptionLocation` property. If `--include-path` or `--exclude-path` are provided, they will be stored in the `includePatterns` and `excludePatterns` properties respectively. @@ -10,12 +10,13 @@ Every time an API client is added, a copy of the OpenAPI description file will b At the same time, an [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01.html#section-2.5-3) file will be generated (if non existing) or edited (if already existing) to represent the surface of the API being used. This file will be named `apimanifest.json` and will be stored in the `./.kiota` folder. This file will be used to generate the code files. -Once the `kiota.config` file is generated, the OpenAPI description file is saved locally and the API Manifest is available, the code generation will be executed. +Once the `kiota-config.json` file is generated, the OpenAPI description file is saved locally and the API Manifest is available, the code generation will be executed. ## Parameters | Parameters | Required | Example | Description | | -- | -- | -- | -- | +| `--config-location \| --cl` | No | ./.kiota/kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./.kiota/kiota-config.json`. | | `--client-name \| --cn` | Yes | graphDelegated | Name of the client. Unique within the parent API. If not provided, defaults to --class-name or its default. | | `--openapi \| -d` | Yes | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | | `--include-path \| -i` | No | /me/chats#GET | A glob pattern to include paths from generation. Accepts multiple values. Defaults to no value which includes everything. | @@ -28,10 +29,11 @@ Once the `kiota.config` file is generated, the OpenAPI description file is saved | `--serializer \| -s` | No | `Contoso.Json.CustomSerializer` | One or more module names that implements ISerializationWriterFactory. Default are documented [here](https://learn.microsoft.com/openapi/kiota/using#--serializer--s). | | `--deserializer \| --ds` | No | `Contoso.Json.CustomDeserializer` | One or more module names that implements IParseNodeFactory. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--deserializer---ds). | | `--structured-mime-types \| -m` | No | `application/json` |Any valid MIME type which will match a request body type or a response type in the OpenAPI description. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--structured-mime-types--m). | +| `--skip-generation \| --sg` | No | true | When specified, the generation would be skipped. Defaults to false. | | `--output \| -o` | No | ./generated/graph/csharp | The output directory or file path for the generated code files. Defaults to `./output`. | > [!NOTE] -> It is not required to use the CLI to add new clients. It is possible to add a new client by adding a new entry in the `clients` section of the `kiota.config` file. See the [kiota.config schema](../schemas/kiota.config.md) for more information. +> It is not required to use the CLI to add new clients. It is possible to add a new client by adding a new entry in the `clients` section of the `kiota-config.json` file. See the [kiota-config.json schema](../schemas/kiota-config.json.md) for more information. ## Using `kiota client add` @@ -39,37 +41,39 @@ Once the `kiota.config` file is generated, the OpenAPI description file is saved kiota client add --client-name "graphDelegated" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "**/users/**" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" ``` -```json -"clients": { - "graphDelegated": { - "descriptionHash": "9EDF8506CB74FE44...", - "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", - "includePatterns": ["**/users/**"], - "excludePatterns": [], - "language": "csharp", - "outputPath": "./generated/graph/csharp", - "clientClassName": "GraphClient", - "clientNamespaceName": "Contoso.GraphApp", - "features": { - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true +```jsonc +{ + "clients": { + "graphDelegated": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "includePatterns": ["**/users/**"], + "excludePatterns": [], + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } } } } ``` -_The resulting `kiota.config` file will look like this:_ +_The resulting `kiota-config.json` file will look like this:_ -```json +```jsonc { "version": "1.0.0", "clients": { @@ -102,7 +106,7 @@ _The resulting `kiota.config` file will look like this:_ _The resulting `apimanifest.json` file will look like this:_ -```json +```jsonc { "publisher": { "name": "Microsoft Graph", @@ -148,7 +152,7 @@ _The resulting `apimanifest.json` file will look like this:_ ```bash / └─.kiota - └─kiota.config + └─kiota-config.json └─apimanifest.json └─definitions └─9EDF8506CB74FE44.yaml diff --git a/specs/cli/client-edit.md b/specs/cli/client-edit.md index a46a89030a..6968831f40 100644 --- a/specs/cli/client-edit.md +++ b/specs/cli/client-edit.md @@ -2,16 +2,17 @@ ## Description -`kiota client update` allows a developer to edit an existing API client int the `kiota.config` file. If either the `kiota.config` file or if the `--client-name` client can't be found within the `kiota.config` file, the command should error out and let the developer know. +`kiota client update` allows a developer to edit an existing API client int the `kiota-config.json` file. If either the `kiota-config.json` file or if the `--client-name` client can't be found within the `kiota-config.json` file, the command should error out and let the developer know. When executing, the API entry defined by the `--client-name` parameter will be modified. All parameters should be supported and the only required one is `--client-name`. All others are optional as they would only modify the configuration of the API client. If the OpenAPI description location changed, a new hash of the description will be generated saved as part of the `descriptionHash` property. If `--include-path` or `--exclude-path` are provided, they will be stored in the `includePatterns` and `excludePatterns` properties respectively and would trigger an update to the [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01.html#section-2.5-3). -Once the `kiota.config` file and the API Manifest are updated, the code generation will be executed based on the newly updated API client configuration. +Once the `kiota-config.json` file and the API Manifest are updated, the code generation will be executed based on the newly updated API client configuration. ## Parameters | Parameters | Required | Example | Description | | -- | -- | -- | -- | +| `--config-location \| --cl` | No | ./.kiota/kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./.kiota/kiota-config.json`. | | `--client-name \| --cn` | Yes | graphDelegated | Name of the client. Unique within the parent API. If not provided, defaults to --class-name or its default. | | `--openapi \| -d` | No | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | | `--include-path \| -i` | No | /me/chats#GET | A glob pattern to include paths from generation. Accepts multiple values. Defaults to no value which includes everything. | @@ -24,10 +25,11 @@ Once the `kiota.config` file and the API Manifest are updated, the code generati | `--serializer \| -s` | No | `Contoso.Json.CustomSerializer` | One or more module names that implements ISerializationWriterFactory. Default are documented [here](https://learn.microsoft.com/openapi/kiota/using#--serializer--s). | | `--deserializer \| --ds` | No | `Contoso.Json.CustomDeserializer` | One or more module names that implements IParseNodeFactory. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--deserializer---ds). | | `--structured-mime-types \| -m` | No | `application/json` |Any valid MIME type which will match a request body type or a response type in the OpenAPI description. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--structured-mime-types--m). | +| `--skip-generation \| --sg` | No | true | When specified, the generation would be skipped. Defaults to false. | | `--output \| -o` | No | ./generated/graph/csharp | The output directory or file path for the generated code files. Defaults to `./output`. | > [!NOTE] -> It is not required to use the CLI to edit clients. It is possible to edit a client by modifying its entry in the `clients` section of the `kiota.config` file. See the [kiota.config schema](../schemas/kiota.config.md) for more information. +> It is not required to use the CLI to edit clients. It is possible to edit a client by modifying its entry in the `clients` section of the `kiota-config.json` file. See the [kiota-config.json schema](../schemas/kiota-config.json.md) for more information. ## Using `kiota client edit` @@ -35,40 +37,39 @@ Once the `kiota.config` file and the API Manifest are updated, the code generati kiota client edit --client-name "graphDelegated" --class-name "GraphServiceClient" --exclude-path "/users/$count" ``` -```json -``` - -```json -"clients": { - "graphDelegated": { - "descriptionHash": "9EDF8506CB74FE44...", - "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", - "includePatterns": ["**/users/**"], - "excludePatterns": ["/users/$count"], - "language": "csharp", - "outputPath": "./generated/graph/csharp", - "clientClassName": "GraphServiceClient", - "clientNamespaceName": "Contoso.GraphApp", - "features": { - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true +```jsonc +{ + "clients": { + "graphDelegated": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "includePatterns": ["**/users/**"], + "excludePatterns": ["/users/$count"], + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphServiceClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } } } } ``` -_The resulting `kiota.config` file will look like this:_ +_The resulting `kiota-config.json` file will look like this:_ -```json +```jsonc { "version": "1.0.0", "clients": { @@ -101,7 +102,7 @@ _The resulting `kiota.config` file will look like this:_ _The resulting `apimanifest.json` file will look like this:_ -```json +```jsonc { "publisher": { "name": "Microsoft Graph", @@ -143,7 +144,7 @@ _The resulting `apimanifest.json` file will look like this:_ ```bash / └─.kiota - └─kiota.config + └─kiota-config.json └─apimanifest.json └─definitions └─9EDF8506CB74FE44.yaml @@ -152,9 +153,4 @@ _The resulting `apimanifest.json` file will look like this:_ └─csharp └─... # Generated code files └─GraphClient.cs -``` - -## Open Questions - -- [ ] How do we determine the `name` and `contactEmail` of the `publisher` in the API Manifest? kiota config --global? -- [ ] Can we automatically generate all `authorizationRequirements` for the endpoints selected or these are left to the developers to add? \ No newline at end of file +``` \ No newline at end of file diff --git a/specs/cli/client-generate.md b/specs/cli/client-generate.md index 5fd86967fc..73a6274eb9 100644 --- a/specs/cli/client-generate.md +++ b/specs/cli/client-generate.md @@ -1,66 +1,37 @@ # kiota client generate -Now that we have a `kiota.config` file, all the parameters required to generate the code are stored in the file. The `kiota generate` command will read the `kiota.config` file and generate the code for each of the clients. +## Description -It's also possible to specify for which API and client the code should be generated. This is useful when a project contains multiple APIs and clients. The `kiota generate --api-name "MyAPI" --client-name "MyClient"` command will read the `kiota.config` file and generate the code for the specified API and client. If it can't find the specified API or client, it will throw an error. +Now that we have a `kiota-config.json` file, all the parameters required to generate the code are stored in the file. The `kiota client generate` command will read the `kiota-config.json` file and generate the code for each of the available clients. -In scenarios where a developer only needs a single API or doesn't want to go through the ceremony of executing `kiota init`, it's possible to use `kiota generate` and initialize a `kiota.config` file with the values coming from the command parameters. No breaking changes are required to the existing `kiota generate` command. +It's also possible to specify for which API and client the code should be generated. This is useful when a project contains multiple clients. The `kiota client generate --client-name "MyClient"` command will read the `kiota-config.json` file and generate the code for the specified client. If it can't find the specified API or client, it will throw an error. -#### kiota generate Parameters +In general cases, the `kiota client generate` command will generate the code for all the clients in the `kiota-config.json` file based on the cached OpenAPI description. If the `--refresh` parameter is provided, the command will refresh the cached OpenAPI description(s), update the different `descriptionHash` and then generate the code for the specified clients. -> [!IMPORTANT] -> This list is only the new parameters that `kiota generate` should support. +## Parameters | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--app-name \| --an` | No | My application | Name of the application | -| `--api-name \| --api` | No | graph | Name of the API | +| `--config-location \| --cl` | No | ./.kiota/kiota-config.json | A location where to find the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./.kiota/kiota-config.json`. | | `--client-name \| --cn` | No | graphDelegated | Name of the client. Unique within the parent API. | +| `--refresh \| -r` | No | true | Provided when refreshing the description(s) is required. | -#### Using `kiota generate` with all parameters +## Usage + +### Using `kiota client generate` for a single API client + +```bash +kiota client generate --client-name "graphDelegated" +``` + +### Using `kiota client generate` for all API clients ```bash -kiota generate --app-name "My Application" --api-name "graph" --client-name "graphDelegated" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "/me/chats#GET" --include-path "/me#GET" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" +kiota client generate ``` -```javascript -{ - "name": "My application", - "apis": { - "graph": { - "descriptionHash": "9EDF8506CB74FE44...", - "descriptionLocation": "https://.../openapi.yaml", - "includePatterns": ["/me/chats#GET", "/me#GET"], - "excludePatterns": [], - "clients": { - "graphDelegated": { - "language": "csharp", - "outputPath": "./generated/graph/csharp", - "clientClassName": "GraphClient", - "clientNamespaceName": "Contoso.GraphApp", - "features": { - // Adding for future visibility, but not required for now - /*"authentication": { - "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", - "authenticationParameters": { - "clientId": "guid" - }, - },*/ - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true - } - } - } - } - } -} -``` \ No newline at end of file +### Using `kiota client generate` for all API clients and refresh their descriptions + +```bash +kiota client generate +``` diff --git a/specs/cli/client-remove.md b/specs/cli/client-remove.md index d7d857cd6e..32cb2fea46 100644 --- a/specs/cli/client-remove.md +++ b/specs/cli/client-remove.md @@ -2,12 +2,13 @@ ## Description -`kiota client remove` allows a developer to remove an existing client from the `kiota.config` file. The command will remove the entry from the `clients` section of `kiota.config` file. The command has a single required parameters; the name of the client. +`kiota client remove` allows a developer to remove an existing client from the `kiota-config.json` file. The command will remove the entry from the `clients` section of `kiota-config.json` file. The command has a single required parameters; the name of the client. The command also has one optional parameter, the ability to remove the generated client. If provided, kiota will delete the folder and its content specified at the `outputPath` from the client configuration. It will also remove the local version of the OpenAPI description file (specified by the `descriptionHash` property). The API Manifest is also updated to remove the dependency from the list of dependencies. | Parameters | Required | Example | Description | | -- | -- | -- | -- | +| `--config-location \| --cl` | No | ./.kiota/kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./.kiota/kiota-config.json`. | | `--client-name \| --cn` | Yes | graphDelegated | Name of the client | | `--clean-output \| --co` | No | | Cleans the generated client | @@ -17,9 +18,9 @@ The command also has one optional parameter, the ability to remove the generated kiota client remove --client-name "graphDelegated" --clean-output ``` -The resulting `kiota.config` file will look like this: +The resulting `kiota-config.json` file will look like this: -```json +```jsonc { "version": "1.0.0", "clients": { } @@ -28,7 +29,7 @@ The resulting `kiota.config` file will look like this: _The resulting `apimanifest.json` file will look like this:_ -```json +```jsonc { "publisher": { "name": "Microsoft Graph", @@ -42,7 +43,7 @@ _The resulting `apimanifest.json` file will look like this:_ ```bash / └─.kiota - └─kiota.config + └─kiota-config.json └─apimanifest.json └─generated └─graph diff --git a/specs/cli/config-init.md b/specs/cli/config-init.md index f4f3d3c12a..3e1bc6fa09 100644 --- a/specs/cli/config-init.md +++ b/specs/cli/config-init.md @@ -2,27 +2,34 @@ ## Description -`kiota config init` creates a new kiota.config file with the provided parameters. If the file already exists, it should error out and report it to the user. As the file gets created, it should be adding a `version` property with the value of the `kiota.config` current schema version. +`kiota config init` creates a new kiota-config.json file with the provided parameters. If the file already exists, it should error out and report it to the user. As the file gets created, it should be adding a `version` property with the value of the `kiota-config.json` current schema version. -When `kiota config init` is executed, a `kiota.config` file would be created in the current directory where the command is being executed. If the user wants to create the file in a different directory, they should use the `--config-file` global parameter. +When `kiota config init` is executed, a `kiota-config.json` file would be created in the current directory where the command is being executed. If the user wants to create the file in a different directory, they should use the `--config-file` global parameter. > [!NOTE] -> If a project only needs a single API, using `kiota config init` is not mandatory as generating code using the `kiota client generate` command could generate a `kiota.config` file with values coming from the `kiota client generate` command (if no `kiota.config` is present). See [kiota client generate](./client-generate.md) for more information. +> If a project only needs a single API, using `kiota config init` is not mandatory as generating code using the `kiota client generate` command could generate a `kiota-config.json` file with values coming from the `kiota client generate` command (if no `kiota-config.json` is present). See [kiota client generate](./client-generate.md) for more information. ## Parameters | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-file \| --cf` | No | ../../kiota.config | Path to an existing `kiota.config` file. Defaults to `./` | +| `--config-file \| --cf` | No | ../../kiota-config.json | Path to an existing `kiota-config.json` file. Defaults to `./` | ## Using `kiota config init` ```bash kiota config init ``` -_Results in the following `kiota.config` file:_ -```json +_Results in the following `kiota-config.json` file:_ +```jsonc { "version": "1.0.0", } +``` + +## File structure +```bash +/ + └─.kiota + └─kiota-config.json ``` \ No newline at end of file diff --git a/specs/cli/config-migrate.md b/specs/cli/config-migrate.md index e69de29bb2..26f67bfc84 100644 --- a/specs/cli/config-migrate.md +++ b/specs/cli/config-migrate.md @@ -0,0 +1,185 @@ +# `kiota config migrate` + +This command is valuable in cases where a code base was created with Kiota v1.0 and needs to be migrated to the latest version of Kiota. The `kiota config migrate` command will identify and locate the closest `kiota-config.json` file available. If a file can't be found, it would initialize a new `kiota-config.json` file. Then, it would identify all `kiota-lock.json` files that are within this folder structure and add each of them to the `kiota-config.json` file. Adding the clients to the `kiota-config.json` file would not trigger the generation as it only affects the `kiota-config.json` file. The `kiota client generate` command would need to be executed to generate the code for the clients. + +## Parameters + +| Parameters | Required | Example | Description | +| -- | -- | -- | -- | +| `--config-location \| --cl` | No | ./.kiota/kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./.kiota/kiota-config.json`. | +| `--lock-location \| --ll` | No | ./output/pythonClient/kiota-lock.json | Location of the `kiota-lock.json` file. If not specified, all `kiota-lock.json` files within in the current directory tree will be used. | +| `--client-name \| --cn` | No | graphDelegated | Used with `--lock-location`, it would allow to specify a name for the API client. Else, name is auto-generated as a concatenation of the `language` and `clientClassName`. | + +## Using `kiota config migrate` + +Assuming the following folder structure: +```bash +/ + └─generated + └─graph + └─csharp + └─... # Generated code files + └─GraphClient.cs + └─kiota-lock.json + └─python + └─... # Generated code files + └─graph_client.py + └─kiota-lock.json +``` + +```bash +kiota config migrate +``` + +_The resulting `kiota-config.json` file will look like this:_ + +```jsonc +{ + "version": "1.0.0", + "clients": { + "csharpGraphServiceClient": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "includePatterns": ["**/users/**"], + "excludePatterns": [], + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphServiceClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } + }, + "pythonGraphServiceClient": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "includePatterns": ["**/users/**"], + "excludePatterns": [], + "language": "python", + "outputPath": "./generated/graph/python", + "clientClassName": "GraphServiceClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } + } + } +} +``` + +_The resulting `apimanifest.json` file will look like this:_ + +```jsonc +{ + "publisher": { + "name": "Microsoft Graph", + "contactEmail": "graphsdkpub@microsoft.com" + }, + "apiDependencies": { + "graphDelegated": { + "apiDescriptionUrl": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "apiDeploymentBaseUrl": "https://graph.microsoft.com", + "apiDescriptionVersion": "v1.0", + "requests": [ + { + "method": "GET", + "uriTemplate": "/users" + }, + { + "method": "POST", + "uriTemplate": "/users" + }, + { + "method": "GET", + "uriTemplate": "/users/$count" + }, + { + "method": "GET", + "uriTemplate": "/users/{user-id}" + }, + { + "method": "PATCH", + "uriTemplate": "/users/{user-id}" + }, + { + "method": "DELETE", + "uriTemplate": "/users/{user-id}" + } + ] + } + } +} +``` + +## Using `kiota config migrate` for a specific `kiota-lock.json` file and a specific client name + +Assuming the following folder structure: +```bash +/ + └─generated + └─graph + └─csharp + └─... # Generated code files + └─GraphClient.cs + └─kiota-lock.json + └─python + └─... # Generated code files + └─graph_client.py + └─kiota-lock.json +``` + +```bash +kiota config migrate --lock-location ./generated/graph/csharp/kiota-lock.json --client-name graphDelegated +``` + +_The resulting `kiota-config.json` file will look like this:_ + +```jsonc +{ + "version": "1.0.0", + "clients": { + "graphDelegated": { + "descriptionHash": "9EDF8506CB74FE44...", + "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "includePatterns": ["**/users/**"], + "excludePatterns": [], + "language": "csharp", + "outputPath": "./generated/graph/csharp", + "clientClassName": "GraphServiceClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } + } + } +} \ No newline at end of file diff --git a/specs/index.md b/specs/index.md index fa305ee49d..efa47455b1 100644 --- a/specs/index.md +++ b/specs/index.md @@ -7,13 +7,13 @@ config.md) * [kiota client add](./cli/client-add.md) * [kiota client edit](./cli/client-edit.md) -* [kiota client update](./cli/client-update.md) +* [kiota client remove](./cli/client-remove.md) * [kiota client generate](./cli/client-generate.md) -* [kiota init](./cli/init.md) -* [kiota migrate](./cli/migrate.md) +* [kiota config init](./cli/config-init.md) +* [kiota config migrate](./cli/config-migrate.md) ## Extension ## Scenarios -* [Kiota.Config](./scenarios/kiota. \ No newline at end of file +* [Kiota Config](./scenarios/kiota.config.md) \ No newline at end of file diff --git a/specs/scenarios/kiota-config.md b/specs/scenarios/kiota-config.md index cc52a50ed2..34372e89ae 100644 --- a/specs/scenarios/kiota-config.md +++ b/specs/scenarios/kiota-config.md @@ -1,34 +1,24 @@ # Kiota Config -Kiota generates client code for an API and stores parameters in a kiota.lock file. A project can contain multiple API clients, but they are independently managed. Kiota has no awareness that an app has a dependency on multiple APIs, even though that is a core use case. - -## Status - -| Date | Version | Author | Status | -| -- | -- | -- | -- | -| November 30th, 2023 | v0.3 | Sébastien Levert | Final Draft | -| November 22nd, 2023 | v0.2 | Sébastien Levert | Draft | -| September 24th, 2023 | v0.1 | Darrel Miller | Draft | +Kiota generates client code for an API and stores parameters in a kiota-lock.json file. A project can contain multiple API clients, but they are independently managed. Kiota has no awareness that an app has a dependency on multiple APIs, even though that is a core use case. ## Current Challenges - Client code generation is not reproducible if API description changes -- Kiota doesn’t have a good solution for APIs that use multiple security schemes. -- Kiota doesn’t provide any support for generating auth providers with the required permissions, partially because currently we generate one client for APIs that use different schemes. How would we know which auth provider to generate. -- Kiota doesn’t have a good story for acquiring a client identifier. e.g. apikey or OAuth2 ClientId. This could be possible if the OpenIDConnect URL pointed to a dynamic registration endpoint. -- If an application has multiple kiota clients, there is currently no way perform operations that correspond to all of the clients. +- Kiota doesn't have an obvious solution for APIs that use multiple security schemes. +- Kiota doesn't have an obvious solution for projects utilizing multiple APIs. We have previously described Kiota's approach to managing API dependencies as consistent with the way people manage packages in a project. However, currently our tooling doesn't behave that way. We treat each dependency independently. ## Proposal -We should introduce a new Kiota.config file that holds the input parameters required to generate the API Client code. Currently kiota.lock is used to capture what the parameters were at the time of generation and can be used to regenerate based on the parameters in the file. This creates a mixture of purposes for the file. +We should introduce a new Kiota.config file that holds the input parameters required to generate the API Client code. Currently kiota-lock.json is used to capture what the parameters were at the time of generation and can be used to regenerate based on the parameters in the file. This creates a mixture of purposes for the file. -We did consider creating one kiota.config file as as a peer of the language project file, however, for someone who wants to generate multiple clients for an API in different languages, this would be a bit annoying. An alternative would be to allow the kiota.config file to move further up the folder structure and support generation in multiple languages from a single file. This is more consistent with what [TypeSpec](https://aka.ms/typespec) are doing and would be helpful for generating CLI and docs as well as a library. +We did consider creating one kiota-config.json file as as a peer of the language project file, however, for someone who wants to generate multiple clients for an API in different languages, this would be a bit annoying. An alternative would be to allow the kiota-config.json file to move further up the folder structure and support generation in multiple languages from a single file. This is more consistent with what [TypeSpec](https://aka.ms/typespec) are doing and would be helpful for generating CLI and docs as well as a library. -Here is an example of what the kiota.config file could look like. +Here is an example of what the kiota-config.json file could look like. -```json +```jsonc { "name": "My application", "apis": { @@ -90,105 +80,51 @@ Here is an example of what the kiota.config file could look like. Note that in this example we added suggestions for new parameters related to authentication. If we are to improve the generation experience so that we read the security schemes information from the OpenAPI, then we will need to have some place to configure what providers we will use for those schemes. -The [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01.html) file can be used as a replacement for the kiota.lock file as a place to capture a snapshot of what information was used to perform code generation and what APIs that gives the application access to. +The [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01.html) file can be used as a replacement for the kiota-lock.json file as a place to capture a snapshot of what information was used to perform code generation and what APIs that gives the application access to. ## Commands * [kiota config init](../cli/init.md) * [kiota client add](../cli/client-add.md) * [kiota client edit](../cli/client-edit.md) -* [kiota client generate](../cli/client-remove.md) +* [kiota client generate](../cli/client-generate.md) * [kiota client remove](../cli/client-remove.md) ## End-to-end experience -#### Using kiota generate with parameters inferred from the kiota.config file +### Migrate a project that uses Kiota v1.x ```bash -kiota generate +kiota config migrate ``` -#### Using kiota generate with parameters inferred from the kiota.config file for a single API +### Get started to generate an API client ```bash -kiota generate --api-name "graph" --client-name "graphDelegated" +kiota client init +kiota client add --client-name "graphDelegated" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --language csharp --output "./csharpClient" ``` -#### Using kiota generate with parameters inferred when there are no kiota.config file +### Add a second API client ```bash -kiota generate --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "/me/chats#GET" --include-path "/me#GET" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" +kiota client add --clientName "graphPython" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --language python --outputPath ./pythonClient ``` -```javascript -// This file gets generated and then `kiota generate` is executed based on these parameters -{ - "name": "Contoso.GraphApp", // Inferred from the provided --namespace-name or its default value - "apis": { - "https://graph.microsoft.com/v1.0": { // Inferred from the first server entry in the OpenAPI description - "descriptionHash": "9EDF8506CB74FE44...", - "descriptionLocation": "https://.../openapi.yaml", - "includePatterns": ["/me/chats#GET", "/me#GET"], - "excludePatterns": [], - "clients": { - "GraphClient": { // Inferred from the provided --class-name or its default value - "language": "csharp", - "outputPath": "./generated/graph/csharp", - "clientClassName": "GraphClient", - "clientNamespaceName": "Contoso.GraphApp", - "features": { - // Adding for future visibility, but not required for now - /*"authentication": { - "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", - "authenticationParameters": { - "clientId": "guid" - }, - },*/ - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true - } - } - } - } - } -} -``` - -## End-to-end scenarios using the CLI - -### Get started to generate an API +### Edit an API client ```bash -kiota init --app-name "My Application" -kiota api add --api-name "My API" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" -kiota client add --api-name "My API" --clientName "graphDelegated" --language csharp --outputPath ./csharpClient -kiota generate -``` - -### Add a second language to generate an API - -```bash -kiota client add --api-name "My API" --clientName "graphPython" --language python --outputPath ./pythonClient -kiota generate --api-name "My API" --client-name "graphPython" +kiota client edit --client-name "graphDelegated" --class-name "GraphServiceClient" --exclude-path "/users/$count" ``` ### Remove a language and delete the generated code ```bash -kiota client delete --api-name "My API" --client=name "graphPython" --clean-output +kiota client delete --client=name "graphPython" --clean-output ``` -### Remove an API +### Generate code for all API clients ```bash -kiota api delete --name "My Api" --clean-output -``` +kiota client generate +``` \ No newline at end of file diff --git a/specs/schemas/kiota.config.md b/specs/schemas/kiota.config.md index a3ff5308ce..c48437a85b 100644 --- a/specs/schemas/kiota.config.md +++ b/specs/schemas/kiota.config.md @@ -1,6 +1,6 @@ -## JSON Schema for kiota.config +## JSON Schema for kiota-config.json -```json +```jsonc { "$schema": "", "type": "object", From f304b137c0f964db19e7ea6dc64d6d29f7cca50b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Fri, 8 Dec 2023 18:01:27 +0000 Subject: [PATCH 09/17] Updating specs based on review comments --- specs/cli/client-add.md | 61 ++++-------------- specs/cli/client-edit.md | 10 +-- specs/cli/client-generate.md | 2 +- specs/cli/client-remove.md | 6 +- specs/cli/config-init.md | 2 +- specs/cli/config-migrate.md | 86 ++++++++++++++++++++++--- specs/index.md | 6 +- specs/scenarios/kiota-config.md | 73 ++++++++-------------- specs/schemas/kiota-config.json | 87 ++++++++++++++++++++++++++ specs/schemas/kiota.config.md | 107 -------------------------------- 10 files changed, 217 insertions(+), 223 deletions(-) create mode 100644 specs/schemas/kiota-config.json delete mode 100644 specs/schemas/kiota.config.md diff --git a/specs/cli/client-add.md b/specs/cli/client-add.md index 3f085e5607..ef65baa62b 100644 --- a/specs/cli/client-add.md +++ b/specs/cli/client-add.md @@ -2,23 +2,24 @@ ## Description -`kiota client add` allows a developer to add a new API client to the `kiota-config.json` file. If no `kiota-config.json` file is found, a new `kiota-config.json` file would be created. The command will add a new entry to the `clients` section of the `kiota-config.json` file. Once this is done, a local copy of the OpenAPI description is generated and kepts in the . +`kiota client add` allows a developer to add a new API client to the `kiota-config.json` file. If no `kiota-config.json` file is found, a new `kiota-config.json` file would be created in thr current working directory. The command will add a new entry to the `clients` section of the `kiota-config.json` file. Once this is done, a local copy of the OpenAPI description is generated and kept in the `.kiota/descriptions` folder. When executing, a new API entry will be added and will use the `--client-name` parameter as the key for the map. When loading the OpenAPI description, it will generate a hash of the description to enable change detection of the description and save it as part of the `descriptionHash` property. It will also store the location of the description in the `descriptionLocation` property. If `--include-path` or `--exclude-path` are provided, they will be stored in the `includePatterns` and `excludePatterns` properties respectively. -Every time an API client is added, a copy of the OpenAPI description file will be stored in the `./.kiota` folder. The file will be named using the hash of the description. This will allow the CLI to detect changes in the description and avoid downloading the description again if it hasn't changed. +Every time an API client is added, a copy of the OpenAPI description file will be stored in the `./.kiota/{client-name}` folder. The files will be named using the API client name. This will allow the CLI to detect changes in the description and avoid downloading the description again if it hasn't changed. -At the same time, an [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01.html#section-2.5-3) file will be generated (if non existing) or edited (if already existing) to represent the surface of the API being used. This file will be named `apimanifest.json` and will be stored in the `./.kiota` folder. This file will be used to generate the code files. +At the same time, an [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01.html#section-2.5-3) file will be generated (if non existing) or edited (if already existing) to represent the surface of the API being used. This file will be named `apimanifest.json` and next to the `kiota-config.json`. This file will be used to generate the code files. -Once the `kiota-config.json` file is generated, the OpenAPI description file is saved locally and the API Manifest is available, the code generation will be executed. +Once the `kiota-config.json` file is generated and the OpenAPI description file is saved locally, the code generation will be executed and then the API Manifest would become available. ## Parameters | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cl` | No | ./.kiota/kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./.kiota/kiota-config.json`. | +| `--config-location \| --cl` | No | ./kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./kiota-config.json`. | | `--client-name \| --cn` | Yes | graphDelegated | Name of the client. Unique within the parent API. If not provided, defaults to --class-name or its default. | | `--openapi \| -d` | Yes | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | +| `--search-key \| --sk` | No | github::microsoftgraph/msgraph-metadata/graph.microsoft.com/v1.0 | The search key used to locate the OpenAPI description. | | `--include-path \| -i` | No | /me/chats#GET | A glob pattern to include paths from generation. Accepts multiple values. Defaults to no value which includes everything. | | `--exclude-path \| -e` | No | \*\*/users/\*\* | A glob pattern to exclude paths from generation. Accepts multiple values. Defaults to no value which excludes nothing. | | `--language \| -l` | Yes | csharp | The target language for the generated code files or for the information. | @@ -41,36 +42,6 @@ Once the `kiota-config.json` file is generated, the OpenAPI description file is kiota client add --client-name "graphDelegated" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "**/users/**" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" ``` -```jsonc -{ - "clients": { - "graphDelegated": { - "descriptionHash": "9EDF8506CB74FE44...", - "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", - "includePatterns": ["**/users/**"], - "excludePatterns": [], - "language": "csharp", - "outputPath": "./generated/graph/csharp", - "clientClassName": "GraphClient", - "clientNamespaceName": "Contoso.GraphApp", - "features": { - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true - } - } - } -} -``` - _The resulting `kiota-config.json` file will look like this:_ ```jsonc @@ -108,12 +79,9 @@ _The resulting `apimanifest.json` file will look like this:_ ```jsonc { - "publisher": { - "name": "Microsoft Graph", - "contactEmail": "graphsdkpub@microsoft.com" - }, "apiDependencies": { "graphDelegated": { + "x-ms-apiDescriptionHash": "9EDF8506CB74FE44...", "apiDescriptionUrl": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", "apiDeploymentBaseUrl": "https://graph.microsoft.com", "apiDescriptionVersion": "v1.0", @@ -152,18 +120,13 @@ _The resulting `apimanifest.json` file will look like this:_ ```bash / └─.kiota - └─kiota-config.json - └─apimanifest.json └─definitions - └─9EDF8506CB74FE44.yaml + └─graphDelegated.yaml └─generated └─graph └─csharp └─... # Generated code files - └─GraphClient.cs -``` - -## Open Questions - -- [ ] How do we determine the `name` and `contactEmail` of the `publisher` in the API Manifest? kiota config --global? -- [ ] Can we automatically generate all `authorizationRequirements` for the endpoints selected or these are left to the developers to add? \ No newline at end of file + └─GraphClient.cs + └─apimanifest.json + └─kiota-config.json +``` \ No newline at end of file diff --git a/specs/cli/client-edit.md b/specs/cli/client-edit.md index 6968831f40..f7567efbba 100644 --- a/specs/cli/client-edit.md +++ b/specs/cli/client-edit.md @@ -12,7 +12,7 @@ Once the `kiota-config.json` file and the API Manifest are updated, the code gen | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cl` | No | ./.kiota/kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./.kiota/kiota-config.json`. | +| `--config-location \| --cl` | No | ./kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./kiota-config.json`. | | `--client-name \| --cn` | Yes | graphDelegated | Name of the client. Unique within the parent API. If not provided, defaults to --class-name or its default. | | `--openapi \| -d` | No | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | | `--include-path \| -i` | No | /me/chats#GET | A glob pattern to include paths from generation. Accepts multiple values. Defaults to no value which includes everything. | @@ -144,13 +144,13 @@ _The resulting `apimanifest.json` file will look like this:_ ```bash / └─.kiota - └─kiota-config.json - └─apimanifest.json └─definitions - └─9EDF8506CB74FE44.yaml + └─graphDelegated.yaml └─generated └─graph └─csharp └─... # Generated code files - └─GraphClient.cs + └─GraphClient.cs + └─apimanifest.json + └─kiota-config.json ``` \ No newline at end of file diff --git a/specs/cli/client-generate.md b/specs/cli/client-generate.md index 73a6274eb9..0ae06afe91 100644 --- a/specs/cli/client-generate.md +++ b/specs/cli/client-generate.md @@ -12,7 +12,7 @@ In general cases, the `kiota client generate` command will generate the code for | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cl` | No | ./.kiota/kiota-config.json | A location where to find the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./.kiota/kiota-config.json`. | +| `--config-location \| --cl` | No | ./kiota-config.json | A location where to find the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./kiota-config.json`. | | `--client-name \| --cn` | No | graphDelegated | Name of the client. Unique within the parent API. | | `--refresh \| -r` | No | true | Provided when refreshing the description(s) is required. | diff --git a/specs/cli/client-remove.md b/specs/cli/client-remove.md index 32cb2fea46..fdc8fc3520 100644 --- a/specs/cli/client-remove.md +++ b/specs/cli/client-remove.md @@ -8,7 +8,7 @@ The command also has one optional parameter, the ability to remove the generated | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cl` | No | ./.kiota/kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./.kiota/kiota-config.json`. | +| `--config-location \| --cl` | No | ./kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./kiota-config.json`. | | `--client-name \| --cn` | Yes | graphDelegated | Name of the client | | `--clean-output \| --co` | No | | Cleans the generated client | @@ -43,8 +43,8 @@ _The resulting `apimanifest.json` file will look like this:_ ```bash / └─.kiota - └─kiota-config.json - └─apimanifest.json └─generated └─graph + └─kiota-config.json + └─apimanifest.json ``` \ No newline at end of file diff --git a/specs/cli/config-init.md b/specs/cli/config-init.md index 3e1bc6fa09..939e7c3705 100644 --- a/specs/cli/config-init.md +++ b/specs/cli/config-init.md @@ -13,7 +13,7 @@ When `kiota config init` is executed, a `kiota-config.json` file would be create | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-file \| --cf` | No | ../../kiota-config.json | Path to an existing `kiota-config.json` file. Defaults to `./` | +| `--config-location \| --cf` | No | ../../ | Path to a folder containing an existing `kiota-config.json` file. Defaults to `./` | ## Using `kiota config init` diff --git a/specs/cli/config-migrate.md b/specs/cli/config-migrate.md index 26f67bfc84..ac418d206c 100644 --- a/specs/cli/config-migrate.md +++ b/specs/cli/config-migrate.md @@ -6,8 +6,8 @@ This command is valuable in cases where a code base was created with Kiota v1.0 | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cl` | No | ./.kiota/kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./.kiota/kiota-config.json`. | -| `--lock-location \| --ll` | No | ./output/pythonClient/kiota-lock.json | Location of the `kiota-lock.json` file. If not specified, all `kiota-lock.json` files within in the current directory tree will be used. | +| `--config-location \| --cl` | No | ./kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./kiota-config.json`. | +| `--lock-location \| --ll` | No | ./output/pythonClient/kiota-lock.json | Location of the `kiota-lock.json` file. If not specified, all `kiota-lock.json` files within in the current directory tree will be used. In the case where conflicting API client names are created, the user would be prompted for a new client name | | `--client-name \| --cn` | No | graphDelegated | Used with `--lock-location`, it would allow to specify a name for the API client. Else, name is auto-generated as a concatenation of the `language` and `clientClassName`. | ## Using `kiota config migrate` @@ -91,12 +91,41 @@ _The resulting `apimanifest.json` file will look like this:_ ```jsonc { - "publisher": { - "name": "Microsoft Graph", - "contactEmail": "graphsdkpub@microsoft.com" - }, "apiDependencies": { - "graphDelegated": { + "csharpGraphServiceClient": { + "x-ms-apiDescriptionHash": "9EDF8506CB74FE44...", + "apiDescriptionUrl": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "apiDeploymentBaseUrl": "https://graph.microsoft.com", + "apiDescriptionVersion": "v1.0", + "requests": [ + { + "method": "GET", + "uriTemplate": "/users" + }, + { + "method": "POST", + "uriTemplate": "/users" + }, + { + "method": "GET", + "uriTemplate": "/users/$count" + }, + { + "method": "GET", + "uriTemplate": "/users/{user-id}" + }, + { + "method": "PATCH", + "uriTemplate": "/users/{user-id}" + }, + { + "method": "DELETE", + "uriTemplate": "/users/{user-id}" + } + ] + }, + "pythonGraphServiceClient": { + "x-ms-apiDescriptionHash": "9EDF8506CB74FE44...", "apiDescriptionUrl": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", "apiDeploymentBaseUrl": "https://graph.microsoft.com", "apiDescriptionVersion": "v1.0", @@ -131,6 +160,27 @@ _The resulting `apimanifest.json` file will look like this:_ } ``` + +_The resulting file structure will look like this:_ + +```bash +/ + └─.kiota + └─definitions + └─csharpGraphServiceClient.yaml + └─pythonGraphServiceClient.yaml + └─generated + └─graph + └─csharp + └─... # Generated code files + └─GraphClient.cs + └─python + └─... # Generated code files + └─graph_client.py + └─apimanifest.json + └─kiota-config.json +``` + ## Using `kiota config migrate` for a specific `kiota-lock.json` file and a specific client name Assuming the following folder structure: @@ -182,4 +232,24 @@ _The resulting `kiota-config.json` file will look like this:_ } } } -} \ No newline at end of file +} +``` + + +```bash +/ + └─.kiota + └─definitions + └─graphDelegated.yaml + └─generated + └─graph + └─csharp + └─... # Generated code files + └─GraphClient.cs + └─python + └─... # Generated code files + └─graph_client.py + └─kiota-lock.json + └─apimanifest.json + └─kiota-config.json +``` \ No newline at end of file diff --git a/specs/index.md b/specs/index.md index efa47455b1..e040b18428 100644 --- a/specs/index.md +++ b/specs/index.md @@ -16,4 +16,8 @@ config.md) ## Scenarios -* [Kiota Config](./scenarios/kiota.config.md) \ No newline at end of file +* [Kiota Config](./scenarios/kiota.config.md) + +## Schemas + +* [kiota-config.json](./schemas/kiota-config.json) \ No newline at end of file diff --git a/specs/scenarios/kiota-config.md b/specs/scenarios/kiota-config.md index 34372e89ae..6a5b3acbd8 100644 --- a/specs/scenarios/kiota-config.md +++ b/specs/scenarios/kiota-config.md @@ -20,59 +20,36 @@ Here is an example of what the kiota-config.json file could look like. ```jsonc { - "name": "My application", - "apis": { - "Graph": { - "descriptionHash": "9EDF8506CB74FE44...", - "descriptionLocation": "https://.../openapi.yaml", - "includePatterns": ["/me/chats#GET", "/me#GET"], + "version": "1.0.0", + "clients": { + "graphDelegated": { + "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "includePatterns": ["**/users/**"], "excludePatterns": [], - "clients": [ - { - "language": "csharp", - "outputPath": "./generated/graph/csharp", - "clientClassName": "GraphClient", - "clientNamespaceName": "Contoso.GraphApp", - "features": { - "authentication": { - "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", - "authenticationParameters": { - "clientId": "guid" - } - }, - "usesBackingStore": true, - "includeAdditionalData": true - } - } - ] + "language": "csharp", + "outputPath": "./generated/graph", + "clientClassName": "GraphClient", + "clientNamespaceName": "Contoso.GraphApp", + "features": { + "serializers": [ + "Contoso.Json.CustomSerializer" + ], + "deserializers": [ + "Contoso.Json.CustomDeserializer" + ], + "structuredMimeTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true + } }, - "BusinessCentral": { - "descriptionHash": "810CF81EFDB5D8E065...", + "businessCentral": { "descriptionLocation": "https://.../bcoas1.0.yaml", "includePatterns": ["/companies#GET"], "excludePatterns": [], - "outputs": [ - { - "language": "csharp", - "outputPath": "./generated/business-central" - }, - { - "language": "python", - "outputPath": "./generated/python/business-central" - }, - { - "language": "csharp", - "outputPath": "./generated/business-central-app", - "features": { - "authentication": { - "authenticationProvider": "Microsoft.Kiota.Authentication.AzureAuthProvider", - "authenticationParameters": { - "clientId": "guid" - } - } - } - } - ] + "language": "csharp", + "outputPath": "./generated/businessCentral" } } } diff --git a/specs/schemas/kiota-config.json b/specs/schemas/kiota-config.json new file mode 100644 index 0000000000..09290bfb3e --- /dev/null +++ b/specs/schemas/kiota-config.json @@ -0,0 +1,87 @@ +{ + "$schema": "", + "type": "object", + "properties": { + "version": { + "type": "string" + }, + "clients": { + "type": "object", + "patternProperties": { + ".*": { + "type": "object", + "properties": { + "descriptionLocation": { + "type": "string" + } + }, + "descriptionLocation": { + "type": "string" + }, + "includePatterns": { + "type": "array", + "items": { + "type": "string" + } + }, + "excludePatterns": { + "type": "array", + "items": { + "type": "string" + } + }, + "baseUrl": { + "type": "string" + }, + "language": { + "type": "string" + }, + "outputPath": { + "type": "string" + }, + "clientClassName": { + "type": "string" + }, + "clientNamespaceName": { + "type": "string" + }, + "features": { + "type": "object", + "properties": { + "structuredMediaTypes": { + "type": "array", + "items": { + "type": "string" + } + }, + "serializers": { + "type": "array", + "items": { + "type": "string" + } + }, + "deserializers": { + "type": "array", + "items": { + "type": "string" + } + }, + "usesBackingStore": { + "type": "boolean" + }, + "includeAdditionalData": { + "type": "boolean" + } + } + } + } + }, + "disabledValidationRules": { + "type": "array", + "items": { + "type": "string" + } + } + } + } +} diff --git a/specs/schemas/kiota.config.md b/specs/schemas/kiota.config.md deleted file mode 100644 index c48437a85b..0000000000 --- a/specs/schemas/kiota.config.md +++ /dev/null @@ -1,107 +0,0 @@ -## JSON Schema for kiota-config.json - -```jsonc -{ - "$schema": "", - "type": "object", - "properties": { - "version": { - "type": "string" - }, - "apis": { - "type": "object", - "patternProperties": { - ".*": { - "type": "object", - "properties": { - "descriptionLocation": { - "type": "string" - }, - "descriptionHash": { - "type": "string" - } - }, - "descriptionHash": { - "type": "string" - }, - "descriptionLocation": { - "type": "string" - }, - "includePatterns": { - "type": "array", - "items": { - "type": "string" - } - }, - "excludePatterns": { - "type": "array", - "items": { - "type": "string" - } - }, - "baseUrl": { - "type": "string" - }, - "clients": { - "type": "object", - "patternProperties": { - ".*": { - "type": "object", - "properties": { - "language": { - "type": "string" - }, - "outputPath": { - "type": "string" - }, - "clientClassName": { - "type": "string" - }, - "clientNamespaceName": { - "type": "string" - }, - "features": { - "type": "object", - "properties": { - "structuredMediaTypes": { - "type": "array", - "items": { - "type": "string" - } - }, - "serializers": { - "type": "array", - "items": { - "type": "string" - } - }, - "deserializers": { - "type": "array", - "items": { - "type": "string" - } - }, - "usesBackingStore": { - "type": "boolean" - }, - "includeAdditionalData": { - "type": "boolean" - } - } - } - } - } - } - } - }, - "disabledValidationRules": { - "type": "array", - "items": { - "type": "string" - } - } - } - } - } -} -``` \ No newline at end of file From 8bd8d950b1c6e20a8a29e5902c3a8dca0234ed7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Fri, 8 Dec 2023 18:03:23 +0000 Subject: [PATCH 10/17] Updating code blocks --- specs/cli/client-edit.md | 32 +------------------------------- specs/cli/client-remove.md | 4 ---- specs/cli/config-init.md | 4 +++- specs/cli/config-migrate.md | 1 - 4 files changed, 4 insertions(+), 37 deletions(-) diff --git a/specs/cli/client-edit.md b/specs/cli/client-edit.md index f7567efbba..7da4cd696c 100644 --- a/specs/cli/client-edit.md +++ b/specs/cli/client-edit.md @@ -37,36 +37,6 @@ Once the `kiota-config.json` file and the API Manifest are updated, the code gen kiota client edit --client-name "graphDelegated" --class-name "GraphServiceClient" --exclude-path "/users/$count" ``` -```jsonc -{ - "clients": { - "graphDelegated": { - "descriptionHash": "9EDF8506CB74FE44...", - "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", - "includePatterns": ["**/users/**"], - "excludePatterns": ["/users/$count"], - "language": "csharp", - "outputPath": "./generated/graph/csharp", - "clientClassName": "GraphServiceClient", - "clientNamespaceName": "Contoso.GraphApp", - "features": { - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true - } - } - } -} -``` - _The resulting `kiota-config.json` file will look like this:_ ```jsonc @@ -77,7 +47,7 @@ _The resulting `kiota-config.json` file will look like this:_ "descriptionHash": "9EDF8506CB74FE44...", "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", "includePatterns": ["**/users/**"], - "excludePatterns": [], + "excludePatterns": ["/users/$count"], "language": "csharp", "outputPath": "./generated/graph/csharp", "clientClassName": "GraphServiceClient", diff --git a/specs/cli/client-remove.md b/specs/cli/client-remove.md index fdc8fc3520..34ad30b1e7 100644 --- a/specs/cli/client-remove.md +++ b/specs/cli/client-remove.md @@ -31,10 +31,6 @@ _The resulting `apimanifest.json` file will look like this:_ ```jsonc { - "publisher": { - "name": "Microsoft Graph", - "contactEmail": "graphsdkpub@microsoft.com" - }, "apiDependencies": { } } ``` diff --git a/specs/cli/config-init.md b/specs/cli/config-init.md index 939e7c3705..b9df504fda 100644 --- a/specs/cli/config-init.md +++ b/specs/cli/config-init.md @@ -20,7 +20,9 @@ When `kiota config init` is executed, a `kiota-config.json` file would be create ```bash kiota config init ``` -_Results in the following `kiota-config.json` file:_ + +_The resulting `kiota-config.json` file will look like this:_ + ```jsonc { "version": "1.0.0", diff --git a/specs/cli/config-migrate.md b/specs/cli/config-migrate.md index ac418d206c..788eaa8639 100644 --- a/specs/cli/config-migrate.md +++ b/specs/cli/config-migrate.md @@ -160,7 +160,6 @@ _The resulting `apimanifest.json` file will look like this:_ } ``` - _The resulting file structure will look like this:_ ```bash From a0fcaeb45ed7a81790cd5ab86235c9a7f0db07ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Fri, 8 Dec 2023 18:11:40 +0000 Subject: [PATCH 11/17] Updates to the --config-location param --- specs/cli/client-add.md | 2 +- specs/cli/client-edit.md | 2 +- specs/cli/client-generate.md | 2 +- specs/cli/client-remove.md | 2 +- specs/cli/config-init.md | 2 +- specs/cli/config-migrate.md | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/specs/cli/client-add.md b/specs/cli/client-add.md index ef65baa62b..fad5f1f1d1 100644 --- a/specs/cli/client-add.md +++ b/specs/cli/client-add.md @@ -16,7 +16,7 @@ Once the `kiota-config.json` file is generated and the OpenAPI description file | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cl` | No | ./kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./kiota-config.json`. | +| `--config-location \| --cl` | No | ../../ | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use the defaults. Defaults to `./`. | | `--client-name \| --cn` | Yes | graphDelegated | Name of the client. Unique within the parent API. If not provided, defaults to --class-name or its default. | | `--openapi \| -d` | Yes | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | | `--search-key \| --sk` | No | github::microsoftgraph/msgraph-metadata/graph.microsoft.com/v1.0 | The search key used to locate the OpenAPI description. | diff --git a/specs/cli/client-edit.md b/specs/cli/client-edit.md index 7da4cd696c..b802dc94cb 100644 --- a/specs/cli/client-edit.md +++ b/specs/cli/client-edit.md @@ -12,7 +12,7 @@ Once the `kiota-config.json` file and the API Manifest are updated, the code gen | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cl` | No | ./kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./kiota-config.json`. | +| `--config-location \| --cl` | No | ../../ | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use the defaults. Defaults to `./`. | | `--client-name \| --cn` | Yes | graphDelegated | Name of the client. Unique within the parent API. If not provided, defaults to --class-name or its default. | | `--openapi \| -d` | No | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | | `--include-path \| -i` | No | /me/chats#GET | A glob pattern to include paths from generation. Accepts multiple values. Defaults to no value which includes everything. | diff --git a/specs/cli/client-generate.md b/specs/cli/client-generate.md index 0ae06afe91..c86b27cfdb 100644 --- a/specs/cli/client-generate.md +++ b/specs/cli/client-generate.md @@ -12,7 +12,7 @@ In general cases, the `kiota client generate` command will generate the code for | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cl` | No | ./kiota-config.json | A location where to find the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./kiota-config.json`. | +| `--config-location \| --cl` | No | ../../ | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use the defaults. Defaults to `./`. | | `--client-name \| --cn` | No | graphDelegated | Name of the client. Unique within the parent API. | | `--refresh \| -r` | No | true | Provided when refreshing the description(s) is required. | diff --git a/specs/cli/client-remove.md b/specs/cli/client-remove.md index 34ad30b1e7..2f3f3ba58d 100644 --- a/specs/cli/client-remove.md +++ b/specs/cli/client-remove.md @@ -8,7 +8,7 @@ The command also has one optional parameter, the ability to remove the generated | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cl` | No | ./kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./kiota-config.json`. | +| `--config-location \| --cl` | No | ../../ | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use the defaults. Defaults to `./`. | | `--client-name \| --cn` | Yes | graphDelegated | Name of the client | | `--clean-output \| --co` | No | | Cleans the generated client | diff --git a/specs/cli/config-init.md b/specs/cli/config-init.md index b9df504fda..9f93a90ff3 100644 --- a/specs/cli/config-init.md +++ b/specs/cli/config-init.md @@ -13,7 +13,7 @@ When `kiota config init` is executed, a `kiota-config.json` file would be create | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cf` | No | ../../ | Path to a folder containing an existing `kiota-config.json` file. Defaults to `./` | +| `--config-location \| --cl` | No | ../../ | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use the defaults. Defaults to `./`. | ## Using `kiota config init` diff --git a/specs/cli/config-migrate.md b/specs/cli/config-migrate.md index 788eaa8639..b3db2c9598 100644 --- a/specs/cli/config-migrate.md +++ b/specs/cli/config-migrate.md @@ -6,7 +6,7 @@ This command is valuable in cases where a code base was created with Kiota v1.0 | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cl` | No | ./kiota-config.json | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use `./kiota-config.json`. | +| `--config-location \| --cl` | No | ../../ | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use the defaults. Defaults to `./`. | | `--lock-location \| --ll` | No | ./output/pythonClient/kiota-lock.json | Location of the `kiota-lock.json` file. If not specified, all `kiota-lock.json` files within in the current directory tree will be used. In the case where conflicting API client names are created, the user would be prompted for a new client name | | `--client-name \| --cn` | No | graphDelegated | Used with `--lock-location`, it would allow to specify a name for the API client. Else, name is auto-generated as a concatenation of the `language` and `clientClassName`. | From 130dfd168ac39ec3bdb8228e1433b892273dfc50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Fri, 8 Dec 2023 18:13:51 +0000 Subject: [PATCH 12/17] Update to the migrate conflict use case --- specs/cli/config-migrate.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/specs/cli/config-migrate.md b/specs/cli/config-migrate.md index b3db2c9598..734bc39353 100644 --- a/specs/cli/config-migrate.md +++ b/specs/cli/config-migrate.md @@ -2,12 +2,14 @@ This command is valuable in cases where a code base was created with Kiota v1.0 and needs to be migrated to the latest version of Kiota. The `kiota config migrate` command will identify and locate the closest `kiota-config.json` file available. If a file can't be found, it would initialize a new `kiota-config.json` file. Then, it would identify all `kiota-lock.json` files that are within this folder structure and add each of them to the `kiota-config.json` file. Adding the clients to the `kiota-config.json` file would not trigger the generation as it only affects the `kiota-config.json` file. The `kiota client generate` command would need to be executed to generate the code for the clients. +In the case where conflicting API client names would be migrated, the command will error out and invite the user to re-run the command providing more context for the `--client-name` parameter. + ## Parameters | Parameters | Required | Example | Description | | -- | -- | -- | -- | | `--config-location \| --cl` | No | ../../ | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use the defaults. Defaults to `./`. | -| `--lock-location \| --ll` | No | ./output/pythonClient/kiota-lock.json | Location of the `kiota-lock.json` file. If not specified, all `kiota-lock.json` files within in the current directory tree will be used. In the case where conflicting API client names are created, the user would be prompted for a new client name | +| `--lock-location \| --ll` | No | ./output/pythonClient/kiota-lock.json | Location of the `kiota-lock.json` file. If not specified, all `kiota-lock.json` files within in the current directory tree will be used. | | `--client-name \| --cn` | No | graphDelegated | Used with `--lock-location`, it would allow to specify a name for the API client. Else, name is auto-generated as a concatenation of the `language` and `clientClassName`. | ## Using `kiota config migrate` From f955ef4165673873e2fe9f1dc0e3e742a54f7e28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Wed, 20 Dec 2023 18:48:31 +0000 Subject: [PATCH 13/17] Updating based on review --- specs/cli/client-add.md | 21 +++++++-------------- specs/cli/client-edit.md | 20 +++++++------------- specs/cli/config-migrate.md | 27 +++------------------------ specs/scenarios/kiota-config.md | 16 +++++----------- specs/schemas/kiota-config.json | 12 ------------ 5 files changed, 22 insertions(+), 74 deletions(-) diff --git a/specs/cli/client-add.md b/specs/cli/client-add.md index fad5f1f1d1..32b0858e8c 100644 --- a/specs/cli/client-add.md +++ b/specs/cli/client-add.md @@ -4,7 +4,7 @@ `kiota client add` allows a developer to add a new API client to the `kiota-config.json` file. If no `kiota-config.json` file is found, a new `kiota-config.json` file would be created in thr current working directory. The command will add a new entry to the `clients` section of the `kiota-config.json` file. Once this is done, a local copy of the OpenAPI description is generated and kept in the `.kiota/descriptions` folder. -When executing, a new API entry will be added and will use the `--client-name` parameter as the key for the map. When loading the OpenAPI description, it will generate a hash of the description to enable change detection of the description and save it as part of the `descriptionHash` property. It will also store the location of the description in the `descriptionLocation` property. If `--include-path` or `--exclude-path` are provided, they will be stored in the `includePatterns` and `excludePatterns` properties respectively. +When executing, a new API entry will be added and will use the `--client-name` parameter as the key for the map. When loading the OpenAPI description, it will store the location of the description in the `descriptionLocation` property. If `--include-path` or `--exclude-path` are provided, they will be stored in the `includePatterns` and `excludePatterns` properties respectively. Every time an API client is added, a copy of the OpenAPI description file will be stored in the `./.kiota/{client-name}` folder. The files will be named using the API client name. This will allow the CLI to detect changes in the description and avoid downloading the description again if it hasn't changed. @@ -29,7 +29,7 @@ Once the `kiota-config.json` file is generated and the OpenAPI description file | `--exclude-backward-compatible \| --ebc` | No | | Whether to exclude the code generated only for backward compatibility reasons or not. Defaults to `false`. | | `--serializer \| -s` | No | `Contoso.Json.CustomSerializer` | One or more module names that implements ISerializationWriterFactory. Default are documented [here](https://learn.microsoft.com/openapi/kiota/using#--serializer--s). | | `--deserializer \| --ds` | No | `Contoso.Json.CustomDeserializer` | One or more module names that implements IParseNodeFactory. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--deserializer---ds). | -| `--structured-mime-types \| -m` | No | `application/json` |Any valid MIME type which will match a request body type or a response type in the OpenAPI description. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--structured-mime-types--m). | +| `--structured-media-types \| -m` | No | `application/json` |Any valid media type which will match a request body type or a response type in the OpenAPI description. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--structured-mime-types--m). | | `--skip-generation \| --sg` | No | true | When specified, the generation would be skipped. Defaults to false. | | `--output \| -o` | No | ./generated/graph/csharp | The output directory or file path for the generated code files. Defaults to `./output`. | @@ -49,7 +49,6 @@ _The resulting `kiota-config.json` file will look like this:_ "version": "1.0.0", "clients": { "graphDelegated": { - "descriptionHash": "9EDF8506CB74FE44...", "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", "includePatterns": ["**/users/**"], "excludePatterns": [], @@ -58,17 +57,11 @@ _The resulting `kiota-config.json` file will look like this:_ "clientClassName": "GraphClient", "clientNamespaceName": "Contoso.GraphApp", "features": { - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true + "structuredMediaTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true } } } diff --git a/specs/cli/client-edit.md b/specs/cli/client-edit.md index b802dc94cb..495ec082df 100644 --- a/specs/cli/client-edit.md +++ b/specs/cli/client-edit.md @@ -24,7 +24,7 @@ Once the `kiota-config.json` file and the API Manifest are updated, the code gen | `--exclude-backward-compatible \| --ebc` | No | | Whether to exclude the code generated only for backward compatibility reasons or not. Defaults to `false`. | | `--serializer \| -s` | No | `Contoso.Json.CustomSerializer` | One or more module names that implements ISerializationWriterFactory. Default are documented [here](https://learn.microsoft.com/openapi/kiota/using#--serializer--s). | | `--deserializer \| --ds` | No | `Contoso.Json.CustomDeserializer` | One or more module names that implements IParseNodeFactory. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--deserializer---ds). | -| `--structured-mime-types \| -m` | No | `application/json` |Any valid MIME type which will match a request body type or a response type in the OpenAPI description. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--structured-mime-types--m). | +| `--structured-media-types \| -m` | No | `application/json` |Any valid media type which will match a request body type or a response type in the OpenAPI description. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--structured-mime-types--m). | | `--skip-generation \| --sg` | No | true | When specified, the generation would be skipped. Defaults to false. | | `--output \| -o` | No | ./generated/graph/csharp | The output directory or file path for the generated code files. Defaults to `./output`. | @@ -44,7 +44,6 @@ _The resulting `kiota-config.json` file will look like this:_ "version": "1.0.0", "clients": { "graphDelegated": { - "descriptionHash": "9EDF8506CB74FE44...", "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", "includePatterns": ["**/users/**"], "excludePatterns": ["/users/$count"], @@ -53,17 +52,11 @@ _The resulting `kiota-config.json` file will look like this:_ "clientClassName": "GraphServiceClient", "clientNamespaceName": "Contoso.GraphApp", "features": { - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true + "structuredMediaTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true } } } @@ -80,6 +73,7 @@ _The resulting `apimanifest.json` file will look like this:_ }, "apiDependencies": { "graphDelegated": { + "x-ms-apiDescriptionHash": "9EDF8506CB74FE44...", "apiDescriptionUrl": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", "apiDeploymentBaseUrl": "https://graph.microsoft.com", "apiDescriptionVersion": "v1.0", diff --git a/specs/cli/config-migrate.md b/specs/cli/config-migrate.md index 734bc39353..e97fd50ce5 100644 --- a/specs/cli/config-migrate.md +++ b/specs/cli/config-migrate.md @@ -40,7 +40,6 @@ _The resulting `kiota-config.json` file will look like this:_ "version": "1.0.0", "clients": { "csharpGraphServiceClient": { - "descriptionHash": "9EDF8506CB74FE44...", "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", "includePatterns": ["**/users/**"], "excludePatterns": [], @@ -49,13 +48,7 @@ _The resulting `kiota-config.json` file will look like this:_ "clientClassName": "GraphServiceClient", "clientNamespaceName": "Contoso.GraphApp", "features": { - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ + "structuredMediaTypes": [ "application/json" ], "usesBackingStore": true, @@ -63,7 +56,6 @@ _The resulting `kiota-config.json` file will look like this:_ } }, "pythonGraphServiceClient": { - "descriptionHash": "9EDF8506CB74FE44...", "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", "includePatterns": ["**/users/**"], "excludePatterns": [], @@ -72,13 +64,7 @@ _The resulting `kiota-config.json` file will look like this:_ "clientClassName": "GraphServiceClient", "clientNamespaceName": "Contoso.GraphApp", "features": { - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ + "structuredMediaTypes": [ "application/json" ], "usesBackingStore": true, @@ -210,7 +196,6 @@ _The resulting `kiota-config.json` file will look like this:_ "version": "1.0.0", "clients": { "graphDelegated": { - "descriptionHash": "9EDF8506CB74FE44...", "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", "includePatterns": ["**/users/**"], "excludePatterns": [], @@ -219,13 +204,7 @@ _The resulting `kiota-config.json` file will look like this:_ "clientClassName": "GraphServiceClient", "clientNamespaceName": "Contoso.GraphApp", "features": { - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ + "structuredMediaTypes": [ "application/json" ], "usesBackingStore": true, diff --git a/specs/scenarios/kiota-config.md b/specs/scenarios/kiota-config.md index 6a5b3acbd8..8c713ba392 100644 --- a/specs/scenarios/kiota-config.md +++ b/specs/scenarios/kiota-config.md @@ -31,17 +31,11 @@ Here is an example of what the kiota-config.json file could look like. "clientClassName": "GraphClient", "clientNamespaceName": "Contoso.GraphApp", "features": { - "serializers": [ - "Contoso.Json.CustomSerializer" - ], - "deserializers": [ - "Contoso.Json.CustomDeserializer" - ], - "structuredMimeTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true + "structuredMediaTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true } }, "businessCentral": { diff --git a/specs/schemas/kiota-config.json b/specs/schemas/kiota-config.json index 09290bfb3e..70389af1f6 100644 --- a/specs/schemas/kiota-config.json +++ b/specs/schemas/kiota-config.json @@ -54,18 +54,6 @@ "type": "string" } }, - "serializers": { - "type": "array", - "items": { - "type": "string" - } - }, - "deserializers": { - "type": "array", - "items": { - "type": "string" - } - }, "usesBackingStore": { "type": "boolean" }, From 5d0d73aaa493c8d635dfc69362790ec25f59e94c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Wed, 10 Jan 2024 20:37:21 +0000 Subject: [PATCH 14/17] Addressing PR comments --- specs/cli/client-add.md | 20 ++++----- specs/cli/client-edit.md | 16 +++---- specs/cli/client-generate.md | 1 - specs/cli/client-remove.md | 1 - specs/cli/config-init.md | 4 +- specs/cli/config-migrate.md | 39 +++++++--------- specs/schemas/kiota-config.json | 80 +++++++++++++++------------------ 7 files changed, 68 insertions(+), 93 deletions(-) diff --git a/specs/cli/client-add.md b/specs/cli/client-add.md index 32b0858e8c..d7cd0d8cc8 100644 --- a/specs/cli/client-add.md +++ b/specs/cli/client-add.md @@ -16,7 +16,6 @@ Once the `kiota-config.json` file is generated and the OpenAPI description file | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cl` | No | ../../ | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use the defaults. Defaults to `./`. | | `--client-name \| --cn` | Yes | graphDelegated | Name of the client. Unique within the parent API. If not provided, defaults to --class-name or its default. | | `--openapi \| -d` | Yes | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | | `--search-key \| --sk` | No | github::microsoftgraph/msgraph-metadata/graph.microsoft.com/v1.0 | The search key used to locate the OpenAPI description. | @@ -27,14 +26,12 @@ Once the `kiota-config.json` file is generated and the OpenAPI description file | `--namespace-name \| -n` | No | Contoso.GraphApp | The namespace of the client class. Defaults to `Microsoft.Graph`. | | `--backing-store \| -b` | No | | Defaults to `false` | | `--exclude-backward-compatible \| --ebc` | No | | Whether to exclude the code generated only for backward compatibility reasons or not. Defaults to `false`. | -| `--serializer \| -s` | No | `Contoso.Json.CustomSerializer` | One or more module names that implements ISerializationWriterFactory. Default are documented [here](https://learn.microsoft.com/openapi/kiota/using#--serializer--s). | -| `--deserializer \| --ds` | No | `Contoso.Json.CustomDeserializer` | One or more module names that implements IParseNodeFactory. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--deserializer---ds). | | `--structured-media-types \| -m` | No | `application/json` |Any valid media type which will match a request body type or a response type in the OpenAPI description. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--structured-mime-types--m). | | `--skip-generation \| --sg` | No | true | When specified, the generation would be skipped. Defaults to false. | -| `--output \| -o` | No | ./generated/graph/csharp | The output directory or file path for the generated code files. Defaults to `./output`. | +| `--output \| -o` | No | ./generated/graph/csharp | The output directory or file path for the generated code files. This is relative to the location of `kiota-config.json`. Defaults to `./output`. | > [!NOTE] -> It is not required to use the CLI to add new clients. It is possible to add a new client by adding a new entry in the `clients` section of the `kiota-config.json` file. See the [kiota-config.json schema](../schemas/kiota-config.json.md) for more information. +> It is not required to use the CLI to add new clients. It is possible to add a new client by adding a new entry in the `clients` section of the `kiota-config.json` file. See the [kiota-config.json schema](../schemas/kiota-config.json) for more information. Using `kiota client generate --client-name myClient` would be required to generate the code files. ## Using `kiota client add` @@ -56,13 +53,11 @@ _The resulting `kiota-config.json` file will look like this:_ "outputPath": "./generated/graph/csharp", "clientClassName": "GraphClient", "clientNamespaceName": "Contoso.GraphApp", - "features": { - "structuredMediaTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true - } + "structuredMediaTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true } } } @@ -75,6 +70,7 @@ _The resulting `apimanifest.json` file will look like this:_ "apiDependencies": { "graphDelegated": { "x-ms-apiDescriptionHash": "9EDF8506CB74FE44...", + "x-ms-kiotaVersion": "1.11.0", "apiDescriptionUrl": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", "apiDeploymentBaseUrl": "https://graph.microsoft.com", "apiDescriptionVersion": "v1.0", diff --git a/specs/cli/client-edit.md b/specs/cli/client-edit.md index 495ec082df..0a6897c1c7 100644 --- a/specs/cli/client-edit.md +++ b/specs/cli/client-edit.md @@ -12,7 +12,6 @@ Once the `kiota-config.json` file and the API Manifest are updated, the code gen | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cl` | No | ../../ | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use the defaults. Defaults to `./`. | | `--client-name \| --cn` | Yes | graphDelegated | Name of the client. Unique within the parent API. If not provided, defaults to --class-name or its default. | | `--openapi \| -d` | No | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | | `--include-path \| -i` | No | /me/chats#GET | A glob pattern to include paths from generation. Accepts multiple values. Defaults to no value which includes everything. | @@ -22,8 +21,6 @@ Once the `kiota-config.json` file and the API Manifest are updated, the code gen | `--namespace-name \| -n` | No | Contoso.GraphApp | The namespace of the client class. Defaults to `Microsoft.Graph`. | | `--backing-store \| -b` | No | | Defaults to `false` | | `--exclude-backward-compatible \| --ebc` | No | | Whether to exclude the code generated only for backward compatibility reasons or not. Defaults to `false`. | -| `--serializer \| -s` | No | `Contoso.Json.CustomSerializer` | One or more module names that implements ISerializationWriterFactory. Default are documented [here](https://learn.microsoft.com/openapi/kiota/using#--serializer--s). | -| `--deserializer \| --ds` | No | `Contoso.Json.CustomDeserializer` | One or more module names that implements IParseNodeFactory. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--deserializer---ds). | | `--structured-media-types \| -m` | No | `application/json` |Any valid media type which will match a request body type or a response type in the OpenAPI description. Default are documented [here](https://learn.microsoft.com/en-us/openapi/kiota/using#--structured-mime-types--m). | | `--skip-generation \| --sg` | No | true | When specified, the generation would be skipped. Defaults to false. | | `--output \| -o` | No | ./generated/graph/csharp | The output directory or file path for the generated code files. Defaults to `./output`. | @@ -51,13 +48,11 @@ _The resulting `kiota-config.json` file will look like this:_ "outputPath": "./generated/graph/csharp", "clientClassName": "GraphServiceClient", "clientNamespaceName": "Contoso.GraphApp", - "features": { - "structuredMediaTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true - } + "structuredMediaTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true } } } @@ -74,6 +69,7 @@ _The resulting `apimanifest.json` file will look like this:_ "apiDependencies": { "graphDelegated": { "x-ms-apiDescriptionHash": "9EDF8506CB74FE44...", + "x-ms-kiotaVersion": "1.11.0", "apiDescriptionUrl": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", "apiDeploymentBaseUrl": "https://graph.microsoft.com", "apiDescriptionVersion": "v1.0", diff --git a/specs/cli/client-generate.md b/specs/cli/client-generate.md index c86b27cfdb..5b5888a7c7 100644 --- a/specs/cli/client-generate.md +++ b/specs/cli/client-generate.md @@ -12,7 +12,6 @@ In general cases, the `kiota client generate` command will generate the code for | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cl` | No | ../../ | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use the defaults. Defaults to `./`. | | `--client-name \| --cn` | No | graphDelegated | Name of the client. Unique within the parent API. | | `--refresh \| -r` | No | true | Provided when refreshing the description(s) is required. | diff --git a/specs/cli/client-remove.md b/specs/cli/client-remove.md index 2f3f3ba58d..caa83f1360 100644 --- a/specs/cli/client-remove.md +++ b/specs/cli/client-remove.md @@ -8,7 +8,6 @@ The command also has one optional parameter, the ability to remove the generated | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cl` | No | ../../ | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use the defaults. Defaults to `./`. | | `--client-name \| --cn` | Yes | graphDelegated | Name of the client | | `--clean-output \| --co` | No | | Cleans the generated client | diff --git a/specs/cli/config-init.md b/specs/cli/config-init.md index 9f93a90ff3..f91a85e310 100644 --- a/specs/cli/config-init.md +++ b/specs/cli/config-init.md @@ -11,9 +11,7 @@ When `kiota config init` is executed, a `kiota-config.json` file would be create ## Parameters -| Parameters | Required | Example | Description | -| -- | -- | -- | -- | -| `--config-location \| --cl` | No | ../../ | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use the defaults. Defaults to `./`. | +None. ## Using `kiota config init` diff --git a/specs/cli/config-migrate.md b/specs/cli/config-migrate.md index e97fd50ce5..9283c5ce04 100644 --- a/specs/cli/config-migrate.md +++ b/specs/cli/config-migrate.md @@ -8,7 +8,6 @@ In the case where conflicting API client names would be migrated, the command wi | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--config-location \| --cl` | No | ../../ | A location where to find or create the `kiota-config.json` file. When not specified it will find an ancestor `kiota-config.json` file and if not found, will use the defaults. Defaults to `./`. | | `--lock-location \| --ll` | No | ./output/pythonClient/kiota-lock.json | Location of the `kiota-lock.json` file. If not specified, all `kiota-lock.json` files within in the current directory tree will be used. | | `--client-name \| --cn` | No | graphDelegated | Used with `--lock-location`, it would allow to specify a name for the API client. Else, name is auto-generated as a concatenation of the `language` and `clientClassName`. | @@ -47,13 +46,11 @@ _The resulting `kiota-config.json` file will look like this:_ "outputPath": "./generated/graph/csharp", "clientClassName": "GraphServiceClient", "clientNamespaceName": "Contoso.GraphApp", - "features": { - "structuredMediaTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true - } + "structuredMediaTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true }, "pythonGraphServiceClient": { "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", @@ -63,13 +60,11 @@ _The resulting `kiota-config.json` file will look like this:_ "outputPath": "./generated/graph/python", "clientClassName": "GraphServiceClient", "clientNamespaceName": "Contoso.GraphApp", - "features": { - "structuredMediaTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true - } + "structuredMediaTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true } } } @@ -82,6 +77,7 @@ _The resulting `apimanifest.json` file will look like this:_ "apiDependencies": { "csharpGraphServiceClient": { "x-ms-apiDescriptionHash": "9EDF8506CB74FE44...", + "x-ms-kiotaVersion": "1.11.0", "apiDescriptionUrl": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", "apiDeploymentBaseUrl": "https://graph.microsoft.com", "apiDescriptionVersion": "v1.0", @@ -114,6 +110,7 @@ _The resulting `apimanifest.json` file will look like this:_ }, "pythonGraphServiceClient": { "x-ms-apiDescriptionHash": "9EDF8506CB74FE44...", + "x-ms-kiotaVersion": "1.11.0", "apiDescriptionUrl": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", "apiDeploymentBaseUrl": "https://graph.microsoft.com", "apiDescriptionVersion": "v1.0", @@ -203,13 +200,11 @@ _The resulting `kiota-config.json` file will look like this:_ "outputPath": "./generated/graph/csharp", "clientClassName": "GraphServiceClient", "clientNamespaceName": "Contoso.GraphApp", - "features": { - "structuredMediaTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true - } + "structuredMediaTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true } } } diff --git a/specs/schemas/kiota-config.json b/specs/schemas/kiota-config.json index 70389af1f6..a4797a7f3e 100644 --- a/specs/schemas/kiota-config.json +++ b/specs/schemas/kiota-config.json @@ -13,53 +13,45 @@ "properties": { "descriptionLocation": { "type": "string" - } - }, - "descriptionLocation": { - "type": "string" - }, - "includePatterns": { - "type": "array", - "items": { + }, + "includePatterns": { + "type": "array", + "items": { + "type": "string" + } + }, + "excludePatterns": { + "type": "array", + "items": { + "type": "string" + } + }, + "baseUrl": { "type": "string" - } - }, - "excludePatterns": { - "type": "array", - "items": { + }, + "language": { "type": "string" - } - }, - "baseUrl": { - "type": "string" - }, - "language": { - "type": "string" - }, - "outputPath": { - "type": "string" - }, - "clientClassName": { - "type": "string" - }, - "clientNamespaceName": { - "type": "string" - }, - "features": { - "type": "object", - "properties": { - "structuredMediaTypes": { - "type": "array", - "items": { - "type": "string" - } - }, - "usesBackingStore": { - "type": "boolean" - }, - "includeAdditionalData": { - "type": "boolean" + }, + "outputPath": { + "type": "string" + }, + "clientClassName": { + "type": "string" + }, + "clientNamespaceName": { + "type": "string" + }, + "structuredMediaTypes": { + "type": "array", + "items": { + "type": "string" } + }, + "usesBackingStore": { + "type": "boolean" + }, + "includeAdditionalData": { + "type": "boolean" } } } From 1a43310c07996bbbad77f7481245a2e077446b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Wed, 10 Jan 2024 20:49:47 +0000 Subject: [PATCH 15/17] Removing the class-name parameter to rely on client-name only --- specs/cli/client-add.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/specs/cli/client-add.md b/specs/cli/client-add.md index d7cd0d8cc8..6fead368bf 100644 --- a/specs/cli/client-add.md +++ b/specs/cli/client-add.md @@ -16,13 +16,12 @@ Once the `kiota-config.json` file is generated and the OpenAPI description file | Parameters | Required | Example | Description | | -- | -- | -- | -- | -| `--client-name \| --cn` | Yes | graphDelegated | Name of the client. Unique within the parent API. If not provided, defaults to --class-name or its default. | +| `--client-name \| --cn` | Yes | graphDelegated | Name of the client and the client class. Unique within the parent API. Defaults to `Client` | | `--openapi \| -d` | Yes | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | | `--search-key \| --sk` | No | github::microsoftgraph/msgraph-metadata/graph.microsoft.com/v1.0 | The search key used to locate the OpenAPI description. | | `--include-path \| -i` | No | /me/chats#GET | A glob pattern to include paths from generation. Accepts multiple values. Defaults to no value which includes everything. | | `--exclude-path \| -e` | No | \*\*/users/\*\* | A glob pattern to exclude paths from generation. Accepts multiple values. Defaults to no value which excludes nothing. | | `--language \| -l` | Yes | csharp | The target language for the generated code files or for the information. | -| `--class-name \| -c` | No | GraphClient | The name of the client class. Defaults to `Client`. | | `--namespace-name \| -n` | No | Contoso.GraphApp | The namespace of the client class. Defaults to `Microsoft.Graph`. | | `--backing-store \| -b` | No | | Defaults to `false` | | `--exclude-backward-compatible \| --ebc` | No | | Whether to exclude the code generated only for backward compatibility reasons or not. Defaults to `false`. | From 7e7525f24ab723678cf2d459daa4087499838001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Fri, 19 Jan 2024 18:53:38 +0000 Subject: [PATCH 16/17] Updated the logic for client config hash --- specs/cli/client-add.md | 10 +++++----- specs/cli/client-edit.md | 10 +++++----- specs/cli/client-generate.md | 2 +- specs/cli/config-migrate.md | 14 +++++++------- specs/scenarios/kiota-config.md | 6 +++--- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/specs/cli/client-add.md b/specs/cli/client-add.md index 6fead368bf..3e4e9e7e9c 100644 --- a/specs/cli/client-add.md +++ b/specs/cli/client-add.md @@ -17,7 +17,7 @@ Once the `kiota-config.json` file is generated and the OpenAPI description file | Parameters | Required | Example | Description | | -- | -- | -- | -- | | `--client-name \| --cn` | Yes | graphDelegated | Name of the client and the client class. Unique within the parent API. Defaults to `Client` | -| `--openapi \| -d` | Yes | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | +| `--openapi \| -d` | Yes | https://aka.ms/graph/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | | `--search-key \| --sk` | No | github::microsoftgraph/msgraph-metadata/graph.microsoft.com/v1.0 | The search key used to locate the OpenAPI description. | | `--include-path \| -i` | No | /me/chats#GET | A glob pattern to include paths from generation. Accepts multiple values. Defaults to no value which includes everything. | | `--exclude-path \| -e` | No | \*\*/users/\*\* | A glob pattern to exclude paths from generation. Accepts multiple values. Defaults to no value which excludes nothing. | @@ -35,7 +35,7 @@ Once the `kiota-config.json` file is generated and the OpenAPI description file ## Using `kiota client add` ```bash -kiota client add --client-name "graphDelegated" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --include-path "**/users/**" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" +kiota client add --client-name "graphDelegated" --openapi "https://aka.ms/graph/v1.0/openapi.yaml" --include-path "**/users/**" --language csharp --class-name "GraphClient" --namespace-name "Contoso.GraphApp" --backing-store --exclude-backward-compatible --serializer "Contoso.Json.CustomSerializer" --deserializer "Contoso.Json.CustomDeserializer" -structured-mime-types "application/json" --output "./generated/graph/csharp" ``` _The resulting `kiota-config.json` file will look like this:_ @@ -45,7 +45,7 @@ _The resulting `kiota-config.json` file will look like this:_ "version": "1.0.0", "clients": { "graphDelegated": { - "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "descriptionLocation": "https://aka.ms/graph/v1.0/openapi.yaml", "includePatterns": ["**/users/**"], "excludePatterns": [], "language": "csharp", @@ -68,9 +68,9 @@ _The resulting `apimanifest.json` file will look like this:_ { "apiDependencies": { "graphDelegated": { - "x-ms-apiDescriptionHash": "9EDF8506CB74FE44...", + "x-ms-kiotaHash": "9EDF8506CB74FE44...", "x-ms-kiotaVersion": "1.11.0", - "apiDescriptionUrl": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "apiDescriptionUrl": "https://aka.ms/graph/v1.0/openapi.yaml", "apiDeploymentBaseUrl": "https://graph.microsoft.com", "apiDescriptionVersion": "v1.0", "requests": [ diff --git a/specs/cli/client-edit.md b/specs/cli/client-edit.md index 0a6897c1c7..e0260d9163 100644 --- a/specs/cli/client-edit.md +++ b/specs/cli/client-edit.md @@ -4,7 +4,7 @@ `kiota client update` allows a developer to edit an existing API client int the `kiota-config.json` file. If either the `kiota-config.json` file or if the `--client-name` client can't be found within the `kiota-config.json` file, the command should error out and let the developer know. -When executing, the API entry defined by the `--client-name` parameter will be modified. All parameters should be supported and the only required one is `--client-name`. All others are optional as they would only modify the configuration of the API client. If the OpenAPI description location changed, a new hash of the description will be generated saved as part of the `descriptionHash` property. If `--include-path` or `--exclude-path` are provided, they will be stored in the `includePatterns` and `excludePatterns` properties respectively and would trigger an update to the [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01.html#section-2.5-3). +When executing, the API entry defined by the `--client-name` parameter will be modified. All parameters should be supported and the only required one is `--client-name`. All others are optional as they would only modify the configuration of the API client. If the OpenAPI description location changed or any properties of the client entry in `kiota-config.json`, a new hash will be generated and and would trigger an update to the [API Manifest](https://www.ietf.org/archive/id/draft-miller-api-manifest-01.html#section-2.5-3). Once the `kiota-config.json` file and the API Manifest are updated, the code generation will be executed based on the newly updated API client configuration. @@ -13,7 +13,7 @@ Once the `kiota-config.json` file and the API Manifest are updated, the code gen | Parameters | Required | Example | Description | | -- | -- | -- | -- | | `--client-name \| --cn` | Yes | graphDelegated | Name of the client. Unique within the parent API. If not provided, defaults to --class-name or its default. | -| `--openapi \| -d` | No | https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | +| `--openapi \| -d` | No | https://aka.ms/graph/v1.0/openapi.yaml | The location of the OpenAPI description in JSON or YAML format to use to generate the SDK. Accepts a URL or a local path. | | `--include-path \| -i` | No | /me/chats#GET | A glob pattern to include paths from generation. Accepts multiple values. Defaults to no value which includes everything. | | `--exclude-path \| -e` | No | \*\*/users/\*\* | A glob pattern to exclude paths from generation. Accepts multiple values. Defaults to no value which excludes nothing. | | `--language \| -l` | No | csharp | The target language for the generated code files or for the information. | @@ -41,7 +41,7 @@ _The resulting `kiota-config.json` file will look like this:_ "version": "1.0.0", "clients": { "graphDelegated": { - "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "descriptionLocation": "https://aka.ms/graph/v1.0/openapi.yaml", "includePatterns": ["**/users/**"], "excludePatterns": ["/users/$count"], "language": "csharp", @@ -68,9 +68,9 @@ _The resulting `apimanifest.json` file will look like this:_ }, "apiDependencies": { "graphDelegated": { - "x-ms-apiDescriptionHash": "9EDF8506CB74FE44...", + "x-ms-kiotaHash": "9EDF8506CB74FE44...", "x-ms-kiotaVersion": "1.11.0", - "apiDescriptionUrl": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "apiDescriptionUrl": "https://aka.ms/graph/v1.0/openapi.yaml", "apiDeploymentBaseUrl": "https://graph.microsoft.com", "apiDescriptionVersion": "v1.0", "requests": [ diff --git a/specs/cli/client-generate.md b/specs/cli/client-generate.md index 5b5888a7c7..2496254acc 100644 --- a/specs/cli/client-generate.md +++ b/specs/cli/client-generate.md @@ -6,7 +6,7 @@ Now that we have a `kiota-config.json` file, all the parameters required to gene It's also possible to specify for which API and client the code should be generated. This is useful when a project contains multiple clients. The `kiota client generate --client-name "MyClient"` command will read the `kiota-config.json` file and generate the code for the specified client. If it can't find the specified API or client, it will throw an error. -In general cases, the `kiota client generate` command will generate the code for all the clients in the `kiota-config.json` file based on the cached OpenAPI description. If the `--refresh` parameter is provided, the command will refresh the cached OpenAPI description(s), update the different `descriptionHash` and then generate the code for the specified clients. +In general cases, the `kiota client generate` command will generate the code for all the clients in the `kiota-config.json` file based on the cached OpenAPI description. If the `--refresh` parameter is provided, the command will refresh the cached OpenAPI description(s), update the different `x-ms-kiotaHash` in the API Manifest and then generate the code for the specified clients. ## Parameters diff --git a/specs/cli/config-migrate.md b/specs/cli/config-migrate.md index 9283c5ce04..1214bc1190 100644 --- a/specs/cli/config-migrate.md +++ b/specs/cli/config-migrate.md @@ -39,7 +39,7 @@ _The resulting `kiota-config.json` file will look like this:_ "version": "1.0.0", "clients": { "csharpGraphServiceClient": { - "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "descriptionLocation": "https://aka.ms/graph/v1.0/openapi.yaml", "includePatterns": ["**/users/**"], "excludePatterns": [], "language": "csharp", @@ -53,7 +53,7 @@ _The resulting `kiota-config.json` file will look like this:_ "includeAdditionalData": true }, "pythonGraphServiceClient": { - "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "descriptionLocation": "https://aka.ms/graph/v1.0/openapi.yaml", "includePatterns": ["**/users/**"], "excludePatterns": [], "language": "python", @@ -76,9 +76,9 @@ _The resulting `apimanifest.json` file will look like this:_ { "apiDependencies": { "csharpGraphServiceClient": { - "x-ms-apiDescriptionHash": "9EDF8506CB74FE44...", + "x-ms-kiotaHash": "9EDF8506CB74FE44...", "x-ms-kiotaVersion": "1.11.0", - "apiDescriptionUrl": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "apiDescriptionUrl": "https://aka.ms/graph/v1.0/openapi.yaml", "apiDeploymentBaseUrl": "https://graph.microsoft.com", "apiDescriptionVersion": "v1.0", "requests": [ @@ -109,9 +109,9 @@ _The resulting `apimanifest.json` file will look like this:_ ] }, "pythonGraphServiceClient": { - "x-ms-apiDescriptionHash": "9EDF8506CB74FE44...", + "x-ms-kiotaHash": "9EDF8506CB74FE44...", "x-ms-kiotaVersion": "1.11.0", - "apiDescriptionUrl": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "apiDescriptionUrl": "https://aka.ms/graph/v1.0/openapi.yaml", "apiDeploymentBaseUrl": "https://graph.microsoft.com", "apiDescriptionVersion": "v1.0", "requests": [ @@ -193,7 +193,7 @@ _The resulting `kiota-config.json` file will look like this:_ "version": "1.0.0", "clients": { "graphDelegated": { - "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "descriptionLocation": "https://aka.ms/graph/v1.0/openapi.yaml", "includePatterns": ["**/users/**"], "excludePatterns": [], "language": "csharp", diff --git a/specs/scenarios/kiota-config.md b/specs/scenarios/kiota-config.md index 8c713ba392..cf7291f4b7 100644 --- a/specs/scenarios/kiota-config.md +++ b/specs/scenarios/kiota-config.md @@ -23,7 +23,7 @@ Here is an example of what the kiota-config.json file could look like. "version": "1.0.0", "clients": { "graphDelegated": { - "descriptionLocation": "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml", + "descriptionLocation": "https://aka.ms/graph/v1.0/openapi.yaml", "includePatterns": ["**/users/**"], "excludePatterns": [], "language": "csharp", @@ -73,13 +73,13 @@ kiota config migrate ```bash kiota client init -kiota client add --client-name "graphDelegated" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --language csharp --output "./csharpClient" +kiota client add --client-name "graphDelegated" --openapi "https://aka.ms/graph/v1.0/openapi.yaml" --language csharp --output "./csharpClient" ``` ### Add a second API client ```bash -kiota client add --clientName "graphPython" --openapi "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml" --language python --outputPath ./pythonClient +kiota client add --clientName "graphPython" --openapi "https://aka.ms/graph/v1.0/openapi.yaml" --language python --outputPath ./pythonClient ``` ### Edit an API client From a76aaca58585d2a2d1698006e24e0a3c351c5f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Levert?= Date: Fri, 19 Jan 2024 18:55:54 +0000 Subject: [PATCH 17/17] Removed the useless features node --- specs/scenarios/kiota-config.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/specs/scenarios/kiota-config.md b/specs/scenarios/kiota-config.md index cf7291f4b7..17e57e6b09 100644 --- a/specs/scenarios/kiota-config.md +++ b/specs/scenarios/kiota-config.md @@ -30,13 +30,11 @@ Here is an example of what the kiota-config.json file could look like. "outputPath": "./generated/graph", "clientClassName": "GraphClient", "clientNamespaceName": "Contoso.GraphApp", - "features": { - "structuredMediaTypes": [ - "application/json" - ], - "usesBackingStore": true, - "includeAdditionalData": true - } + "structuredMediaTypes": [ + "application/json" + ], + "usesBackingStore": true, + "includeAdditionalData": true }, "businessCentral": { "descriptionLocation": "https://.../bcoas1.0.yaml",