Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 7 additions & 6 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,21 @@ All new code must include unit tests following the pattern used in `Refitter.Tes
public class MyFeatureTests
{
private const string OpenApiSpec = @"..."; // OpenAPI specification

[Fact]
public async Task Can_Generate_Code()
{
string generatedCode = await GenerateCode();
generatedCode.Should().NotBeNullOrWhiteSpace();
}

[Fact]
public async Task Generated_Code_Contains_Expected_Pattern()
{
string generatedCode = await GenerateCode();
generatedCode.Should().Contain("ExpectedPattern");
}

[Fact]
public async Task Can_Build_Generated_Code()
{
Expand Down Expand Up @@ -146,12 +146,13 @@ dotnet run --project src/Refitter --configuration Release --framework net9.0 --

### Recent CLI Options Added
- `--use-apizr`: Integration with Apizr library for request options
- `--use-dynamic-querystring-parameters`: Enable dynamic query string parameter wrapping
- `--use-dynamic-querystring-parameters`: Enable dynamic query string parameter wrapping
- `--use-polymorphic-serialization`: Use System.Text.Json polymorphic serialization
- `--disposable`: Generate IDisposable clients
- `--collection-format`: Control query parameter collection formatting (Multi/Csv/Ssv/Tsv/Pipes)
- `--no-banner`: Hide donation banner in CLI output
- `--integer-type`: Set the .NET type for OpenAPI integers without a format specifier (Int32/Int64)
- `--custom-template-directory`: Custom directory with NSwag fluid templates for code generation. Default is null which uses the default NSwag templates. See https://github.com/RicoSuter/NSwag/wiki/Templates
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

### Working with OpenAPI Specifications
- Test resources are located in `src/Refitter.Tests/Resources/V2/` and `src/Refitter.Tests/Resources/V3/`
Expand Down Expand Up @@ -187,7 +188,7 @@ dotnet run --project src/Refitter --configuration Release --framework net9.0 --

### Expected Build Times
- Package restore: ~65 seconds
- Debug build: ~15 seconds
- Debug build: ~15 seconds
- Release build: ~22 seconds
- Full test suite: ~284 seconds (4 minutes 44 seconds)
- Code formatting: ~19-23 seconds
Expand All @@ -211,4 +212,4 @@ dotnet run --project src/Refitter --configuration Release --framework net9.0 --
- CLI code generation: 1-10 seconds depending on OpenAPI spec complexity
- Source generator: Runs during build time, adds minimal overhead
- Test execution: Allow full test suite to complete (~5 minutes)
- Build process: Complete clean build takes ~2-3 minutes including restore
- Build process: Complete clean build takes ~2-3 minutes including restore
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ OPTIONS:
--disposable Generate refit clients that implement IDisposable
--no-inline-json-converters Don't inline JsonConverter attributes for enum properties. When disabled, enum properties will not have [JsonConverter(typeof(JsonStringEnumConverter))] attributes
--integer-type int The .NET type to use for OpenAPI integer types without a format specifier. Common values: 'int' (default), 'long'
--custom-template-directory Custom directory with NSwag fluid templates for code generation. Default is null which uses the default NSwag templates. See https://github.com/RicoSuter/NSwag/wiki/Templates
```

To generate code from an OpenAPI specifications file, run the following:
Expand Down Expand Up @@ -296,7 +297,8 @@ The following is an example `.refitter` file
"excludedTypeNames": [
"ExcludedTypeFoo",
"ExcludedTypeBar"
]
],
"customTemplateDirectory": "./path/to/directory/" // Optional. See https://github.com/RicoSuter/NSwag/wiki/Templates
}
}
```
Expand Down
123 changes: 62 additions & 61 deletions docs/docfx_project/articles/cli-tool.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/docfx_project/articles/refitter-file-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ The following is an example `.refitter` file
"excludedTypeNames": [
"ExcludedTypeFoo",
"ExcludedTypeBar"
]
],
"customTemplateDirectory": "./path/to/directory/" //Optional. See https://github.com/RicoSuter/NSwag/wiki/Templates
}
}
```
Expand Down
4 changes: 4 additions & 0 deletions docs/json-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@
},
"propertyNameGenerator": {
"$ref": "#/definitions/IPropertyNameGenerator"
},
"customTemplateDirectory": {
"description": "Custom directory with NSwag fluid templates for code generation. Default is null which uses the default NSwag templates. See https://github.com/RicoSuter/NSwag/wiki/Templates",
"type": "string"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions src/Refitter.Core/CSharpClientGeneratorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public CustomCSharpClientGenerator Create()
GenerateNativeRecords =
settings.ImmutableRecords ||
settings.CodeGeneratorSettings?.GenerateNativeRecords is true,
TemplateDirectory = settings.CustomTemplateDirectory,
}
};

Expand Down
7 changes: 7 additions & 0 deletions src/Refitter.Core/Settings/CodeGeneratorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,11 @@ Gets or sets a value indicating whether named/referenced any schemas should be i
"Gets or sets a value indicating whether to inline JsonConverter attributes for enum properties (default: true). When set to false, enum properties will not have [JsonConverter(typeof(JsonStringEnumConverter))] attributes."
)]
public bool InlineJsonConverters { get; set; } = true;

/// <summary>
/// Gets or sets a directory path which contains liquid templates for NSwag. If null or empty, uses default
/// templates.
/// </summary>
[Description("Custom directory with NSwag fluid templates for code generation. Default is null which uses the default NSwag templates. See https://github.com/RicoSuter/NSwag/wiki/Templates")]
public string? CustomTemplateDirectory { get; set; }
}
7 changes: 7 additions & 0 deletions src/Refitter.Core/Settings/RefitGeneratorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,11 @@ payloads with (yet) unknown types are offered by newer versions of an API
[Description("The collection format to use for array query parameters. Default is CollectionFormat.Multi.")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public CollectionFormat CollectionFormat { get; set; } = CollectionFormat.Multi;

/// <summary>
/// Gets or sets a directory path which contains liquid templates for NSwag. If null or empty, uses default
/// templates.
/// </summary>
[Description("Custom directory with NSwag fluid templates for code generation. Default is null which uses the default NSwag templates. See https://github.com/RicoSuter/NSwag/wiki/Templates")]
public string? CustomTemplateDirectory { get; set; }
}
4 changes: 3 additions & 1 deletion src/Refitter.MSBuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ The following is an example `.refitter` file
"excludedTypeNames": [
"ExcludedTypeFoo",
"ExcludedTypeBar"
]
],
"customTemplateDirectory": "./path/to/directory/" // Optional. See https://github.com/RicoSuter/NSwag/wiki/Templates
}
}
```
Expand Down Expand Up @@ -241,3 +242,4 @@ The following is an example `.refitter` file
- `generateDefaultValues` - Default is true
- `inlineNamedAny` - Default is false
- `excludedTypeNames` - Default is empty
- `customTemplateDirectory` - Custom directory with NSwag fluid templates for code generation. Default is null which uses the default NSwag templates. See https://github.com/RicoSuter/NSwag/wiki/Templates
3 changes: 2 additions & 1 deletion src/Refitter.SourceGenerator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ The following is an example `.refitter` file
"excludedTypeNames": [
"ExcludedTypeFoo",
"ExcludedTypeBar"
]
],
"customTemplateDirectory": "./path/to/directory/" // Optional. See https://github.com/RicoSuter/NSwag/wiki/Templates
}
}
```
Expand Down
16 changes: 16 additions & 0 deletions src/Refitter.Tests/CustomCSharpGeneratorSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ public async Task Can_Generate_With_Immutable_Records(SampleOpenSpecifications v
generatedCode.Should().Contain("[JsonConstructor]");
}

[Test]
[Arguments(SampleOpenSpecifications.SwaggerPetstoreJsonV3, "SwaggerPetstore.json")]
[Arguments(SampleOpenSpecifications.SwaggerPetstoreYamlV3, "SwaggerPetstore.yaml")]
[Arguments(SampleOpenSpecifications.SwaggerPetstoreJsonV2, "SwaggerPetstore.json")]
[Arguments(SampleOpenSpecifications.SwaggerPetstoreYamlV2, "SwaggerPetstore.yaml")]
public async Task Can_Generate_With_CustomTemplates(SampleOpenSpecifications version, string filename)
{
var settings = new RefitGeneratorSettings();
settings.ReturnIApiResponse = true;
settings.CustomTemplateDirectory = "./Templates/";
var generatedCode = await GenerateCode(version, filename, settings);
generatedCode.Should().Contain("/* Example Custom Template Texte */");
generatedCode.Should().Contain("public partial class Pet");
}


private static async Task<string> GenerateCode(
SampleOpenSpecifications version,
string filename,
Expand Down
Loading
Loading