Skip to content

Commit e427192

Browse files
committed
Expand handling of empty and boolean schemas
1 parent 7e1cf0e commit e427192

5 files changed

Lines changed: 38 additions & 5 deletions

File tree

lib/OpenApi.CSharp/CSharpInlineSchemas.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public class CSharpInlineSchemas(CSharpSchemaOptions options, DocumentRegistry d
3434
var schemaInfo = CSharpTypeInfo.From(schema);
3535
CSharpInlineDefinition result = schemaInfo switch
3636
{
37+
{ Info.EffectiveSchema.BoolValue: false } => new(options.Find(TypeAnnotation.Common.Object, "never")),
38+
{ Info.EffectiveSchema.BoolValue: true } => new(options.Find(TypeAnnotation.Common.Object, "any")),
39+
{ Info.Annotations.Count: 0 } => new(options.Find(TypeAnnotation.Common.Object, "any")),
40+
3741
// Dictionary
3842
{ TypeAnnotation: { AllowsObject: true }, Properties: { Count: 0 }, AdditionalProperties: JsonSchema dictionaryValueSchema } =>
3943
new(options.ToMapType(ToInlineDataType(dictionaryValueSchema).Text), IsEnumerable: true),

lib/OpenApi.TypeScript/TypeScriptInlineSchemas.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,13 @@ private TypeScriptInlineDefinition ForceConvertIntoInlineDataType(JsonSchemaInfo
103103
var typeInfo = TypeScriptTypeInfo.From(schemaInfo);
104104
TypeScriptInlineDefinition result = typeInfo switch
105105
{
106-
{ TypeAnnotation.AllowsArray: true, Items: null } => ArrayToInline(null),
107-
{ Items: JsonSchema items } => ArrayToInline(items),
108106
{ Info.EffectiveSchema.BoolValue: false } => new TypeScriptInlineDefinition("never", [], false, false),
109107
{ Info.EffectiveSchema.BoolValue: true } => new TypeScriptInlineDefinition("unknown", [], true, false),
108+
{ Info.Annotations.Count: 0 } =>
109+
new TypeScriptInlineDefinition("unknown", [], true, false),
110+
111+
{ TypeAnnotation.AllowsArray: true, Items: null } => ArrayToInline(null),
112+
{ Items: JsonSchema items } => ArrayToInline(items),
110113
{ TypeAnnotation: v3_0.TypeKeyword { OpenApiType: var primitiveType }, Format: var format } =>
111114
new(options.Find(TypeAnnotation.ToPrimitiveTypeString(primitiveType), format), []),
112115
{ TypeAnnotation.AllowsNumber: true, Format: var format } =>

lib/TestApp/Any/Controllers.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Text.Json.Nodes;
2+
3+
namespace DarkPatterns.OpenApiCodegen.Server.Mvc.TestApp.Any;
4+
5+
public class DataController : DataControllerBase
6+
{
7+
protected override Task<GetDataActionResult> GetData()
8+
{
9+
throw new NotImplementedException();
10+
}
11+
12+
protected override Task<PutDataActionResult> PutData(JsonNode putDataBody)
13+
{
14+
throw new NotImplementedException();
15+
}
16+
}

lib/TestApp/OpenApiCodegen.Server.Mvc.TestApp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<ItemGroup>
1414
<OpenApiSchemaClient Include="$(SolutionRoot)schemas\all-of.yaml" Link="Clients\AllOf\all-of.yaml" />
1515
<OpenApiSchemaMvcServer Include="$(SolutionRoot)schemas\all-of.yaml" Link="AllOf\all-of.yaml" PathPrefix="/all-of" />
16+
<OpenApiSchemaMvcServer Include="$(SolutionRoot)schemas\any.yaml" Link="Any\any.yaml" PathPrefix="/any" />
1617
<OpenApiSchemaMvcServer Include="$(SolutionRoot)schemas\enum.yaml" Link="Enum\enum.yaml" PathPrefix="/enum" />
1718
<OpenApiSchemaMvcServer Include="$(SolutionRoot)schemas\controller-extension.yaml" Link="ControllerExtensions\controller-extension.yaml" PathPrefix="/controller-extensions" />
1819
<OpenApiSchemaMvcServer Include="$(SolutionRoot)schemas\csharp-name-override.yaml" Link="CSharpNameOverride\csharp-name-override.yaml" PathPrefix="/csharp-name-override" />

schemas/any.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ paths:
1212
description: Gets any kind of JSON data
1313
content:
1414
application/json:
15-
schema:
16-
type: object
17-
format: any
15+
schema: {}
16+
put:
17+
operationId: putData
18+
requestBody:
19+
required: true
20+
content:
21+
application/json:
22+
schema: {}
23+
responses:
24+
'200':
25+
description: Data received
26+

0 commit comments

Comments
 (0)