Skip to content

hidi: --csdl-filter keeps every type, action and function, so a filtered CSDL still converts to the whole model #933

Open

Description

@kazo0

Summary

hidi transform --csdl … --csdl-filter <sets> only filters the EntityContainer. CsdlFilter.xslt keeps the matching EntitySet and Singleton elements and copies everything else unchanged: every entity, complex and enum type, every action and function, and every navigation property. On a large model, the result is still the whole model, and a client generated from it fails or is huge.

(Filed here because that's where hidi's source and CsdlFilter.xslt live; the NuGet package's project URL still points at microsoft/OpenAPI.NET.)

Repro

Dataverse Web API v9.2 $metadata (6.2 MB: 725 entity sets, 1,427 types, 16,005 navigation properties), Microsoft.OpenApi.Hidi 3.10.2, Kiota 1.38.0:

hidi transform --csdl metadata.xml --csdl-filter accounts,contacts -o out.yaml -f yaml -v 3.0 --co
kiota generate -l CSharp -c DataverseClient -n Issue.Client -d out.yaml -o out
Step Result
hidi, unfiltered 50 s, 79 MB
hidi, --csdl-filter accounts,contacts 4 s, 10.1 MB, 342 paths
kiota on the filtered document Fails after 89 s: The type does not contain any information … Reference Id: Microsoft.Dynamics.CRM.crmbaseentity (microsoft/kiota#6087)

The fixes below were applied one at a time, with the same filter and these conversion settings (--sp settings.json):

{ "OpenApiConvertSettings": { "EnablePagination": true, "EnableCount": true, "EnableNavigationPropertyPath": false, "EnableOperationPath": false, "EnableOperationImportPath": false } }
CSDL change before hidi Kiota result
Empty base types (crmbaseentity, crmmodelbaseentity) removed The chain of references starting at #/components/schemas/Microsoft.Dynamics.CRM.syncerror is nested too deeply to resolve, caused by the navigation properties
Plus navigation properties that leave account and contact removed Fails on Microsoft.Dynamics.CRM.AuditDetail. Every *CollectionResponse derives from the shared BaseCollectionPaginationCountResponse, so Kiota takes in every type that has one, including types only the other 723 sets, the actions and the functions use
Only the types the two sets reach kept; no other sets, actions or functions hidi writes 89 KB in 0.6 s; Kiota generates 15 files (262 KB) in 0.9 s. That client was tested against the live service

Proposal

Have --csdl-filter (or a companion option) keep only what the kept sets and singletons reach:

  • the kept sets' entity types, their base types, and the entity types derived from them (so type casts still work);
  • complex, enum and type-definition types reached through properties;
  • bound actions and functions on kept types only, and unbound imports only when named;
  • navigation properties whose target is kept. For navigation properties that leave the kept set, either drop them (opt-in) or keep their targets transitively.

The reachability trim we used is about 130 lines of Python over ElementTree (it doesn't follow derived types or bound operations yet). Happy to share it.

Related

  • microsoft/OpenAPI.NET#2665 covers the same need at the OpenAPI level (CreateFilteredDocument). It concluded that the OpenAPI filter already trims as much as it can, because navigation properties link the models together. That makes the CSDL, before conversion, the place to cut.
  • #65 asked how to filter a Dataverse CSDL and was answered with a hand-written XSLT. #389 is the same size problem on Business Central.
  • Minor, from reading the XSLT: it matches set names with contains($entitySetOrSingleton, @Name), a substring test. With --csdl-filter accounts, a set named count or account would also be kept.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions