Skip to content

Feature/pppp 1117 make apiexplorer optional #19

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

Merged
merged 2 commits into from
Jul 19, 2024
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bld/
#wwwroot/

# Visual Studio 2017 auto generated files
Generated\ Files/
**/Generated/

# MSTest test Results
[Tt]est[Rr]esult*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<!-- If you want to see genereted code, then please uncomment EmitCompilerGeneratedFiles and CompilerGeneratedFilesOutputPath blocks -->
<!-- <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath> -->
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>-->
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"IncludeVersionParameterInActionSignature": false,
"OpenApiSupportedVersionsExtension": "x-supported-api-versions",
"DateTimeVersionFormat": "yyyy-MM-dd",
"ApiAuthorizationPoliciesExtension": "x-authorization-policies"
"ApiAuthorizationPoliciesExtension": "x-authorization-policies",
"GenerateApiExplorer": false
}
8 changes: 4 additions & 4 deletions Dojo.OpenApiGenerator/AutoApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void Execute(GeneratorExecutionContext context)
_autoApiGeneratorSettings = AutoApiGeneratorSettings.GetAutoApiGeneratorSettings(_projectDir);
var projectNamespace = context.GetProjectDefaultNamespace();
var apisToOverride = new List<string>();
GenerateApiConfiguratorSourceCode(context, projectNamespace);

GenerateApiConfiguratorSourceCode(context, projectNamespace, _autoApiGeneratorSettings.GenerateApiExplorer);
GenerateInheritedApiVersionAttributeSourceCode(context, projectNamespace);
GenerateApisSourceCode(context, apisToOverride, projectNamespace);
}
Expand All @@ -89,12 +89,12 @@ private void GenerateApisSourceCode(GeneratorExecutionContext context, ICollecti
GenerateApiVersionsSourceCode(context, projectNamespace);
}

private void GenerateApiConfiguratorSourceCode(GeneratorExecutionContext context, string projectNamespace)
private void GenerateApiConfiguratorSourceCode(GeneratorExecutionContext context, string projectNamespace, bool generateApiExplorer)
{
_apiConfiguratorTemplateString ??= Templates.ReadTemplate(Templates.ApiConfiguratorTemplate);

const string fileName = "ApiConfigurator.g.cs";
var source = _stubbleBuilder.Render(_apiConfiguratorTemplateString, new BasicClass(projectNamespace));
var source = _stubbleBuilder.Render(_apiConfiguratorTemplateString, new BasicClass(projectNamespace, generateApiExplorer));

context.AddSource(fileName, SourceText.From(source, Encoding.UTF8));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ namespace {{ProjectNamespace}}.Generated.StartupConfiguration
bool assumeDefaultVersionWhenUnspecified = true,
bool reportApiVersions = true)
{
services
var versioningBuilder = services
.AddApiVersioning(options =>
{
options.AssumeDefaultVersionWhenUnspecified = assumeDefaultVersionWhenUnspecified;
options.DefaultApiVersion = defaultVersion ?? ApiVersion.Default;
options.ApiVersionReader = versionReader ?? new HeaderApiVersionReader(versionHeaderName);
options.ReportApiVersions = reportApiVersions;
})
.AddMvc()
.AddApiExplorer();
.AddMvc();

{{#GenerateApiExplorer}}
versioningBuilder.AddApiExplorer();
{{/GenerateApiExplorer}}

foreach (var apiVersion in ApiConstants.ApiVersions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ namespace Dojo.OpenApiGenerator.Configuration
internal class AutoApiGeneratorSettings
{
public string VersionParameterName { get; set; }

public bool IncludeVersionParameterInActionSignature { get; set; }

public string OpenApiSupportedVersionsExtension { get; set; }

public string DateTimeVersionFormat { get; set; }

public string ApiAuthorizationPoliciesExtension { get; set; }

public bool GenerateApiExplorer { get; set; } = true;

public static AutoApiGeneratorSettings GetAutoApiGeneratorSettings(string projectDir)
{
var settingFilePath = $"{projectDir}/{Constants.AutoApiGeneratorSettingsFile}";
Expand Down
5 changes: 4 additions & 1 deletion Dojo.OpenApiGenerator/Models/BasicClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
{
internal class BasicClass : BaseGeneratedCodeModel
{
public BasicClass(string projectNamespace) : base(projectNamespace)
public BasicClass(string projectNamespace, bool generateApiExplorer = false) : base(projectNamespace)
{
GenerateApiExplorer = generateApiExplorer;
}

public bool GenerateApiExplorer { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@
"Sec2"
]
*/
"ApiAuthorizationPoliciesExtension": "x-authorization-policies"
"ApiAuthorizationPoliciesExtension": "x-authorization-policies",
/* This will prevent swagger open api explorer generation*/
"GenerateApiExplorer": false
}