Skip to content

Commit aa5ae76

Browse files
committed
for swagger
1 parent 57e8ebd commit aa5ae76

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

sandbox/SingleContainedApp/Program.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,19 @@ public class Program : ConsoleAppBase
221221
{
222222
static async Task Main(string[] args)
223223
{
224-
await Host.CreateDefaultBuilder().RunConsoleAppFrameworkAsync<MyFirstBatch>(args, new ConsoleAppOptions
224+
//args = new[] { "-m", "a ", "-b", "False" };
225+
226+
await Host.CreateDefaultBuilder().RunConsoleAppFrameworkAsync<Program>(args, new ConsoleAppOptions
225227
{
226228
//StrictOption = true, // default is false.
227229
//ShowDefaultCommand = false, // default is true
228230
});
229231

230232
}
231233

232-
public void Hello([Option("m", "Message to display.")]string message)
234+
public void Hello([Option(null, "Message to display.")]string message, bool b)
233235
{
234-
Console.WriteLine(message);
236+
Console.WriteLine(message + b);
235237
}
236238
}
237239
}

sandbox/WebHostingApp/Program.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ public void Foo()
2424
Context.Logger.LogInformation("foo bar baz");
2525
}
2626

27+
[Command("", "my descp")]
28+
public void Bar(bool a, bool b = false, bool c = true)
29+
{
30+
Context.Logger.LogInformation((a, b, c).ToString());
31+
}
32+
2733
public void Sum(int x, int y)
2834
{
2935
Context.Logger.LogInformation((x + y).ToString());

src/ConsoleAppFramework.WebHosting/Swagger/SwaggerDefinitionBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ Schemas.Parameter[] BuildParameters(IDictionary<string, Schema> definitions, Xml
182182
@in = "formData",
183183
type = swaggerDataType,
184184
description = parameterXmlComment,
185-
required = !x.IsOptional,
186-
@default = defaultObjectExample ?? ((x.IsOptional) ? defaultValue : null),
185+
required = (x.ParameterType == typeof(bool)) ? false : !x.IsOptional,
186+
@default = defaultObjectExample ?? ((x.IsOptional) ? defaultValue : (x.ParameterType == typeof(bool) ? (object)false : null)),
187187
items = items,
188188
@enum = enums,
189189
collectionFormat = "multi", // csv or multi

src/ConsoleAppFramework/OptionAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ public OptionAttribute(int index, string description)
2424
public OptionAttribute(string shortName)
2525
{
2626
this.Index = -1;
27-
this.ShortName = shortName;
27+
this.ShortName = string.IsNullOrWhiteSpace(shortName) ? null : shortName;
2828
this.Description = null;
2929
}
3030

3131
public OptionAttribute(string? shortName, string description)
3232
{
3333
this.Index = -1;
34-
this.ShortName = shortName;
34+
this.ShortName = string.IsNullOrWhiteSpace(shortName) ? null : shortName;
3535
this.Description = description;
3636
}
3737
}

0 commit comments

Comments
 (0)