feat: Add optional system collections support #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request introduces an optional
--includeSystemCollections
CLI flag to include Directus system collections in the generated TypeScript definitions. By default, the tool only generates types for user-defined collections discovered throughspec.paths
. With this new flag enabled, we also checkspec.components.schemas
forx-collection
fields, adding those collections to the final output.Changes
--includeSystemCollections
boolean flag (defaultfalse
).spec.components.schemas
that have anx-collection
property are included in the generated types.paths
andcomponents.schemas
), we now gather all collections first in acollections
object and only write them out once at the end. This avoids repetitive entries without heavily modifying the existingif (spec.paths)
logic, keeping the original structure intact.Reasoning Behind the Logic Change
Initially, collections were appended directly to the output
source
as they were discovered. With the addition of system collections (and thus a second method of discovering them), it became possible to generate the same collection twice. To fix this without diverging too much from the original approach, I switched to a two-step process:This preserves most of the original logic while simply deferring when we write to
source
.Testing
--includeSystemCollections
flag.Documentation
--includeSystemCollections
option and its usage.Impact
1.1.0
) since this is a backward-compatible enhancement.Thank you for this project, hope you understand why this will help!