Subject: XData + Aurelius: Swagger/OpenAPI fails when entity contains TDynamicProperties (EJsonGeneratorNotFound)
Hello,
we are using Aurelius with XData, including dynamic fields via
FireDacMySqlConnection.DefineMappingSetup(TMappingExplorer.DefaultInstance);
Dynamic properties work correctly inside Aurelius ORM.
The problem occurs only when an entity containing TDynamicProperties is used as a return type in an XData service.
Example service:
function GetOrders: TObjectList<Tc_order>;
The moment Swagger/OpenAPI tries to generate the schema, XData crashes with:
Stack trace excerpt:
XData.JSchema.Generators.TJSchemaGenerators.Get
XData.JSchema.Generators.TJSchemaGenerators.ProcessRef
XData.OpenAPI.Builder.TOpenApiBuilder.BuildSchema
XData.OpenAPI.Builder.TOpenApiBuilder.Build
SwaggerDocument(...)
OpenAPI generation fails even before the service is called.
Entity example (simplified):
type
Tc_Order = class
private
[XDataExcludeProperty]
[JsonIgnore]
FDynCon: TDynamicProperties;
[XDataExcludeProperty]
[JsonIgnore]
property DynCon: TDynamicProperties read FDynCon;
…
end;
We tried all combinations:
- exclude attribute on field
- exclude attribute on property
- exclude on both
- remove property, leave only field
- replace type with TValue, TObject, Variant
- wrap the dynamic properties into another class
- return DTO without dynamic fields
The result is always the same:
Swagger/OpenAPI generator tries to reflect TDynamicProperties = TDictionary<string, TValue>
→ and crashes on TDictionary<string, TValue>.TItem, because TValue has no JSON generator registered.
Even when both property and field are marked with [XDataExcludeProperty] and [JsonIgnore], the generator still attempts to inspect the type.
Important notes:
- ORM functionality works fine
- Methods execute correctly when Swagger is disabled
- The crash happens only during OpenAPI/Swagger schema generation
- XData attempts to generate schema for TValue, even though it is excluded
Questions:
- What is the correct way to completely exclude
TDynamicPropertiesfrom OpenAPI/Swagger generation so XData does not inspect it at all? - Is there a recommended pattern for using
TDynamicPropertieswith XData entities? - Should a custom JSON generator be registered for
TValue, or is this type intentionally unsupported? - Is wrapping the entity into a DTO the only supported solution, or is there a built-in mechanism to hide dynamic properties?
Minimal reproducible example:
This minimal entity is enough to trigger the error:
type
TTestEntity = class
private
[XDataExcludeProperty]
property DynCon: TDynamicProperties read FDynCon;
end;
Calling:
function GetAll: TObjectList<TTestEntity>;
→ Immediately results in:
Any guidance on the proper way to exclude or handle TDynamicProperties in XData OpenAPI generation would be greatly appreciated.
Thank you!