Skip to content
Open
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
1 change: 1 addition & 0 deletions examples/OpenApiCodeGenerator.Examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The local showcase spec is intentionally compact and demonstrates:
- `allOf` inheritance
- `oneOf` discriminator generation
- `anyOf` union generation
- `oneOf` with inline object variants (hoisted to named records with `[JsonDerivedType]`)
- string enums and inline enums
- arrays, nullable fields, and `additionalProperties`
- `deprecated` schemas and properties emitted with `[Obsolete]`
Expand Down
30 changes: 8 additions & 22 deletions examples/OpenApiCodeGenerator.Examples/output/showcase-openapi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,6 @@ public enum Status
Failed
}

[JsonConverter(typeof(JsonStringEnumConverter<CircleShapeType>))]
public enum CircleShapeType
{
[JsonStringEnumMemberName("circle")]
Circle
}

[JsonConverter(typeof(JsonStringEnumConverter<RectangleShapeType>))]
public enum RectangleShapeType
{
[JsonStringEnumMemberName("rectangle")]
Rectangle
}

/// <summary>
/// Strongly typed UUID alias.
/// </summary>
Expand Down Expand Up @@ -297,22 +283,16 @@ public partial record DeliveryRecord : DeliveryBase

}

public partial record Circle
public partial record Circle : Shape
{
[JsonPropertyName("shapeType")]
public required CircleShapeType ShapeType { get; init; }

[Range(0d, 1000d)]
[JsonPropertyName("radius")]
public required double Radius { get; init; }

}

public partial record Rectangle
public partial record Rectangle : Shape
{
[JsonPropertyName("shapeType")]
public required RectangleShapeType ShapeType { get; init; }

[JsonPropertyName("width")]
public required double Width { get; init; }

Expand Down Expand Up @@ -360,6 +340,12 @@ public partial record Notification
[JsonPropertyName("contact")]
public required ContactMethod Contact { get; init; }

/// <summary>
/// oneOf with mixed ref and inline object variants. The inline object is hoisted to a named record and the union is emitted as an abstract record with [JsonDerivedType] attributes.
/// </summary>
[JsonPropertyName("escalation")]
public required object Escalation { get; init; }

/// <summary>
/// Superseded by contact; retained for backward compatibility.
/// </summary>
Expand Down
18 changes: 18 additions & 0 deletions examples/OpenApiCodeGenerator.Examples/specs/showcase-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,31 @@ components:
- record
- preferredShape
- contact
- escalation
properties:
record:
$ref: '#/components/schemas/DeliveryRecord'
preferredShape:
$ref: '#/components/schemas/Shape'
contact:
$ref: '#/components/schemas/ContactMethod'
escalation:
description: >-
oneOf with mixed ref and inline object variants. The inline object
is hoisted to a named record and the union is emitted as an abstract
record with [JsonDerivedType] attributes.
oneOf:
- $ref: '#/components/schemas/EmailContact'
- type: object
description: Inline escalation variant hoisted to a named record.
required:
- phone
properties:
phone:
type: string
pattern: '^\+?[0-9]{6,15}$'
afterHours:
type: boolean
legacyChannel:
type: string
deprecated: true
Expand Down
Loading