Skip to content

Support customizing filename in M.E.ApiDescription.Server tool #56974

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
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal sealed class GetDocumentCommand : ProjectCommandBase
private CommandOption _output;
private CommandOption _openApiVersion;
private CommandOption _documentName;
private CommandOption _projectNameOverride;

public GetDocumentCommand(IConsole console) : base(console)
{
Expand All @@ -32,6 +33,7 @@ public override void Configure(CommandLineApplication command)
_output = command.Option("--output <Directory>", Resources.OutputDescription);
_openApiVersion = command.Option("--openapi-version <Version>", Resources.OpenApiVersionDescription);
_documentName = command.Option("--document-name <Name>", Resources.DocumentNameDescription);
_projectNameOverride = command.Option("--projectName-override <Name>", Resources.ProjectNameOverrideDescription);
}

protected override void Validate()
Expand Down Expand Up @@ -142,6 +144,7 @@ protected override int Execute()
DocumentName = _documentName.Value(),
ProjectName = ProjectName.Value(),
Reporter = Reporter,
ProjectNameOverride = _projectNameOverride.Value()
};

return new GetDocumentCommandWorker(context).Process();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ public class GetDocumentCommandContext
// Generates all documents if not provided.
public string DocumentName { get; set; }

//Override the default projectName
//By default if document name == v1 => output = projectName.json
//else projectName_documentName.json
public string ProjectNameOverride { get; set; }

public IReporter Reporter { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ private bool GetDocuments(IServiceProvider services)
_context.OutputDirectory,
generateMethod,
service,
generateWithVersionMethod);
generateWithVersionMethod,
_context.ProjectNameOverride);
if (filePath == null)
{
return false;
Expand Down Expand Up @@ -308,7 +309,8 @@ private string GetDocument(
string outputDirectory,
MethodInfo generateMethod,
object service,
MethodInfo? generateWithVersionMethod)
MethodInfo? generateWithVersionMethod,
string projectNameOverride)
{
_reporter.WriteInformation(Resources.FormatGeneratingDocument(documentName));

Expand Down Expand Up @@ -352,7 +354,7 @@ private string GetDocument(
return null;
}

var filePath = GetDocumentPath(documentName, projectName, outputDirectory);
var filePath = GetDocumentPath(documentName, projectName, outputDirectory, projectNameOverride);
_reporter.WriteInformation(Resources.FormatWritingDocument(documentName, filePath));
try
{
Expand All @@ -371,9 +373,16 @@ private string GetDocument(
return filePath;
}

private static string GetDocumentPath(string documentName, string projectName, string outputDirectory)
private static string GetDocumentPath(string documentName, string projectName, string outputDirectory, string projectNameOverride)
{
string path;

//Override the default projectName with the one provided
if (!string.IsNullOrWhiteSpace(projectNameOverride))
{
projectName = projectNameOverride;
}

if (string.Equals(DefaultDocumentName, documentName, StringComparison.Ordinal))
{
// Leave default document name out of the filename.
Expand Down
59 changes: 31 additions & 28 deletions src/Tools/GetDocumentInsider/src/Resources.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

<!--
Microsoft ResX Schema
Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -209,4 +209,7 @@
<data name="VersionedGenerateMethod" xml:space="preserve">
<value>Using discovered `GenerateAsync` overload with version parameter.</value>
</data>
</root>
<data name="ProjectNameOverrideDescription" xml:space="preserve">
<value>Custom projectName that replace the default one, used to generate OpenAPI JSON file</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/Tools/dotnet-getdocument/src/ProjectOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public void Configure(CommandLineApplication command)
Platform = command.Option("--platform <Target>", Resources.PlatformDescription);
ProjectName = command.Option("--project <Name>", Resources.ProjectDescription);
RuntimeFrameworkVersion = command.Option("--runtime <RUNTIME_IDENTIFIER>", Resources.RuntimeDescription);
command.Option("--prefix-output", Resources.PrefixDescription);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this changes? I believe the options in GetDocumentCommand is sufficient for this case.

command.Option("--file-list <Path>", Resources.FileListDescription);
command.Option("--output <Directory>", Resources.OutputDescription);
command.Option("--openapi-version <Version>", Resources.OpenApiVersionDescription);
command.Option("--document-name <Name>", Resources.DocumentNameDescription);
command.Option("--projectName-override <Name>", Resources.ProjectNameOverrideDescription);
}

public void Validate()
Expand Down
15 changes: 15 additions & 0 deletions src/Tools/dotnet-getdocument/src/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,19 @@
<data name="QuietDescription" xml:space="preserve">
<value>Suppresses all output except warnings and errors.</value>
</data>
<data name="FileListDescription" xml:space="preserve">
<value>The path where the list of document files should be written. Required.</value>
</data>
<data name="OutputDescription" xml:space="preserve">
<value>The directory where the document files should be written. Required.</value>
</data>
<data name="OpenApiVersionDescription" xml:space="preserve">
<value>The OpenAPI spec version to use when generating the document. Optional.</value>
</data>
<data name="DocumentNameDescription" xml:space="preserve">
<value>The name of the OpenAPI document to generate. Optional.</value>
</data>
<data name="ProjectNameOverrideDescription" xml:space="preserve">
<value>Custom projectName that replace the default one, used to generate OpenAPI JSON file</value>
</data>
</root>
Loading