Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

☄ New command line arg: additional-data #1772

Merged
merged 8 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added support for no-content responses in python abstractions and http packages. [#1630](https://github.com/microsoft/kiota/issues/1459)
- Added support for vendor-specific content types in python. [#1631](https://github.com/microsoft/kiota/issues/1463)
- Simplified field deserializers for json in Python. [#1632](https://github.com/microsoft/kiota/issues/1492)
- Added a `--additional-data` argument to generate the AdditionalData properties [#1772](https://github.com/microsoft/kiota/issues/1772)

### Changed

Expand Down
9 changes: 9 additions & 0 deletions docs/using.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ kiota (--openapi | -d) <path>
[(--namespace-name | -n) <name>]
[(--log-level | --ll) <level>]
[--backing-store | -b]
[--additional-data | --ad]
[(--serializer | -s) <classes>]
[(--deserializer | --ds) <classes>]
[--clean-output | --co]
Expand Down Expand Up @@ -61,6 +62,14 @@ Enables backing store for models. Defaults to `false`.
kiota --backing-store
```

### `--additional-data (--ad)`

Will include the 'AdditionalData' property for generated models. Defaults to 'true'.

```shell
kiota --additional-data false
```

### `--class-name (-c)`

The class name to use for the core client class. Defaults to `ApiClient`.
Expand Down
1 change: 1 addition & 0 deletions src/Kiota.Builder/GenerationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class GenerationConfiguration {
public GenerationLanguage Language { get; set; } = GenerationLanguage.CSharp;
public string ApiRootUrl { get; set; }
public bool UsesBackingStore { get; set; }
public bool IncludeAdditionalData { get; set; } = true;
public HashSet<string> Serializers { get; set; } = new(StringComparer.OrdinalIgnoreCase){
"Microsoft.Kiota.Serialization.Json.JsonSerializationWriterFactory",
"Microsoft.Kiota.Serialization.Text.TextSerializationWriterFactory"
Expand Down
6 changes: 5 additions & 1 deletion src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,11 @@ private CodeTypeBase GetCodeTypeForMapping(OpenApiUrlTreeNode currentNode, strin
};
}
private void CreatePropertiesForModelClass(OpenApiUrlTreeNode currentNode, OpenApiSchema schema, CodeNamespace ns, CodeClass model) {
AddSerializationMembers(model, schema?.AdditionalPropertiesAllowed ?? false, config.UsesBackingStore);

var includeAdditionalDataProperties = config.IncludeAdditionalData &&
(schema?.AdditionalPropertiesAllowed ?? false);

AddSerializationMembers(model, includeAdditionalDataProperties, config.UsesBackingStore);
if(schema?.Properties?.Any() ?? false)
{
model.AddProperty(schema
Expand Down
5 changes: 4 additions & 1 deletion src/kiota/KiotaCommandHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
Expand All @@ -23,6 +23,7 @@ internal class KiotaCommandHandler : ICommandHandler
public Option<string> NamespaceOption { get;set; }
public Option<LogLevel> LogLevelOption { get;set; }
public Option<bool> BackingStoreOption { get;set; }
public Option<bool> AdditionalDataOption { get;set; }
public Option<List<string>> SerializerOption { get;set; }
public Option<List<string>> DeserializerOption { get;set; }
public Option<bool> CleanOutputOption { get;set; }
Expand All @@ -37,6 +38,7 @@ public async Task<int> InvokeAsync(InvocationContext context)
GenerationLanguage language = context.ParseResult.GetValueForOption(LanguageOption);
string openapi = context.ParseResult.GetValueForOption(DescriptionOption);
bool backingStore = context.ParseResult.GetValueForOption(BackingStoreOption);
bool includeAdditionalData = context.ParseResult.GetValueForOption(AdditionalDataOption);
string className = context.ParseResult.GetValueForOption(ClassOption);
LogLevel logLevel = context.ParseResult.GetValueForOption(LogLevelOption);
string namespaceName = context.ParseResult.GetValueForOption(NamespaceOption);
Expand All @@ -50,6 +52,7 @@ public async Task<int> InvokeAsync(InvocationContext context)
AssignIfNotNullOrEmpty(className, (c, s) => c.ClientClassName = s);
AssignIfNotNullOrEmpty(namespaceName, (c, s) => c.ClientNamespaceName = s);
Configuration.UsesBackingStore = backingStore;
Configuration.IncludeAdditionalData = includeAdditionalData;
Configuration.Language = language;
if(serializer?.Any() ?? false)
Configuration.Serializers = serializer.Select(x => x.TrimQuotes()).ToHashSet(StringComparer.OrdinalIgnoreCase);
Expand Down
7 changes: 6 additions & 1 deletion src/kiota/KiotaHost.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.Linq;
Expand Down Expand Up @@ -47,6 +47,9 @@ public RootCommand GetRootCommand()
var backingStoreOption = new Option<bool>("--backing-store", () => defaultConfiguration.UsesBackingStore, "Enables backing store for models.");
backingStoreOption.AddAlias("-b");

var additionalDataOption = new Option<bool>("--additional-data", () => defaultConfiguration.IncludeAdditionalData, "Will include the 'AdditionalData' property for models.");
additionalDataOption.AddAlias("--ad");

var serializerOption = new Option<List<string>>(
"--serializer",
() => defaultConfiguration.Serializers.ToList(),
Expand Down Expand Up @@ -78,6 +81,7 @@ public RootCommand GetRootCommand()
namespaceOption,
logLevelOption,
backingStoreOption,
additionalDataOption,
serializerOption,
deserializerOption,
cleanOutputOption,
Expand All @@ -92,6 +96,7 @@ public RootCommand GetRootCommand()
NamespaceOption = namespaceOption,
LogLevelOption = logLevelOption,
BackingStoreOption = backingStoreOption,
AdditionalDataOption = additionalDataOption,
SerializerOption = serializerOption,
DeserializerOption = deserializerOption,
CleanOutputOption = cleanOutputOption,
Expand Down