Skip to content

Commit

Permalink
Add new configuration options to CodeGeneratorSettings
Browse files Browse the repository at this point in the history
Added three new properties to CodeGeneratorSettings: GenerateDefaultValues, InlineNamedAny, and ExcludedTypeNames. GenerateDefaultValues will manage whether to generate default values for properties, InlineNamedAny indicates whether to inline any named/referenced schemas or generate them as a class, and ExcludedTypeNames will store excluded type names. These changes give users more control over code generation, making the tool more flexible to accommodate different project requirements. The README files have been updated to include these new options.
  • Loading branch information
christianhelle committed Oct 12, 2023
1 parent eef96ca commit a4f5799
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ The following is an example `.refitter` file
"inlineNamedArrays": false,
"generateOptionalPropertiesAsNullable": false,
"generateNullableReferenceTypes": false,
"generateNativeRecords": false
"generateNativeRecords": false,
"generateDefaultValues": true,
"inlineNamedAny": false,
"excludedTypeNames": [
"ExcludedTypeFoo",
"ExcludedTypeBar"
]
}
}
```
Expand Down Expand Up @@ -249,6 +255,9 @@ The following is an example `.refitter` file
- `generateOptionalPropertiesAsNullable` - Default is false,
- `generateNullableReferenceTypes` - Default is false,
- `generateNativeRecords` - Default is false
- `generateDefaultValues` - Default is true
- `inlineNamedAny` - Default is false
- `excludedTypeNames` - Default is empty


# Using the generated code
Expand Down
15 changes: 15 additions & 0 deletions src/Refitter.Core/Settings/CodeGeneratorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,19 @@ public class CodeGeneratorSettings
/// Generate C# 9.0 record types instead of record-like classes.
/// </summary>
public bool GenerateNativeRecords { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to generate default values for properties (when JSON Schema default is set, default: true).
/// </summary>
public bool GenerateDefaultValues { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether named/referenced any schemas should be inlined or generated as class.
/// </summary>
public bool InlineNamedAny { get; set; }

/// <summary>
/// Gets or sets the excluded type names (must be defined in an import or other namespace).
/// </summary>
public string[] ExcludedTypeNames { get; set; } = Array.Empty<string>();
}
15 changes: 12 additions & 3 deletions src/Refitter.SourceGenerator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ The following is an example `.refitter` file
"inlineNamedArrays": false,
"generateOptionalPropertiesAsNullable": false,
"generateNullableReferenceTypes": false,
"generateNativeRecords": false
"generateNativeRecords": false,
"generateDefaultValues": true,
"inlineNamedAny": false,
"excludedTypeNames": [
"ExcludedTypeFoo",
"ExcludedTypeBar"
]
}
}
```
Expand All @@ -120,7 +126,7 @@ The following is an example `.refitter` file
- `includeTags` - A collection of tags to use a filter for including endpoints that contain this tag.
- `includePathMatches` - A collection of regular expressions used to filter paths.
- `generateDeprecatedOperations` - a boolean indicating whether deprecated operations should be generated or skipped. Default is `true`
- `operationNameTemplate` - Generate operation names using pattern. This must contain the string {operationName}. An example usage of this could be `{operationName}Async` to suffix all method names with Async. When using multipleIinterfaces=ByEndpoint, This is name of the Execute() method in the interface
- `operationNameTemplate` - Generate operation names using pattern. This must contain the string {operationName}. An example usage of this could be `{operationName}Async` to suffix all method names with Async
- `optionalParameters` - Generate non-required parameters as nullable optional parameters
- `dependencyInjectionSettings` - Setting this will generated extension methods to `IServiceCollection` for configuring Refit clients
- `baseUrl` - Used as the HttpClient base address. Leave this blank to manually set the base URL
Expand Down Expand Up @@ -155,4 +161,7 @@ The following is an example `.refitter` file
- `inlineNamedArrays` - Default is false,
- `generateOptionalPropertiesAsNullable` - Default is false,
- `generateNullableReferenceTypes` - Default is false,
- `generateNativeRecords` - Default is false
- `generateNativeRecords` - Default is false
- `generateDefaultValues` - Default is true
- `inlineNamedAny` - Default is false
- `excludedTypeNames` - Default is empty

0 comments on commit a4f5799

Please sign in to comment.