Skip to content

feat(types): allow file imports for schemas - #44

Merged
nfroidure merged 1 commit into
mainfrom
feat/file_imports
Nov 3, 2026
Merged

nfroidure merged 1 commit into
mainfrom
feat/file_imports

Conversation

@nfroidure

Copy link
Copy Markdown
Owner

No description provided.

@nfroidure
nfroidure requested a balanced review from Copilot November 3, 2026 12:58
@nfroidure nfroidure self-assigned this Nov 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Top-level imports remove generated types from the global scope under default settings, while alias collisions and reference-handling defects can produce invalid declarations or imports of nonexistent exports.

5 open issues
What changed in this PR

Adds cross-file JSON Schema references to the type-generation pipeline, supporting imports of root types and named definitions.

Changes:

  • Introduces import fragments and groups imports by source file.
  • Adds default exports when namespace exports are enabled.
  • Updates identifier handling and tests for external references.
File Description
src/​utils/​typeDefinitions.ts Treats dots as separators when building identifiers.
src/​utils/​jsonSchema.ts Creates external-reference imports and root default exports.
src/​utils/​fragments.ts Adds import fragments to the fragment model.
src/​index.ts Groups import fragments and emits import declarations.
src/​index.test.ts Tests external imports and updates export snapshots.
src/​__snapshots__/​index.test.ts.snap Updates callback identifiers affected by dot handling.

Review effort: Balanced

Comment thread src/index.ts Resolved
Comment thread src/index.ts Resolved
Comment thread src/index.ts Resolved
Comment thread src/utils/jsonSchema.ts Resolved
Comment thread src/utils/jsonSchema.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export function buildIdentifier(part: string): string {
const identifier = part
.replace(/[^a-z0-9-_ ]/gi, '')
.replace(/[^a-z0-9-_. ]/gi, '')
Comment thread src/index.ts
const fragments = await jsonSchemaToFragments(context, rootSchema);

if (
context.jsonSchemaOptions.alwaysAddDefs &&
Comment thread src/utils/jsonSchema.ts

if ('$ref' in schema && typeof schema.$ref === 'string') {
const referenceParts = relativeReferenceToNamespace(schema.$ref);
const [filePart, pointerPart] = schema.$ref.split('#');
Comment thread src/utils/jsonSchema.ts
Comment on lines 170 to +171
if ('$ref' in schema && typeof schema.$ref === 'string') {
const referenceParts = relativeReferenceToNamespace(schema.$ref);
const [filePart, pointerPart] = schema.$ref.split('#');
Comment thread src/utils/jsonSchema.ts

if ('$ref' in schema && typeof schema.$ref === 'string') {
const referenceParts = relativeReferenceToNamespace(schema.$ref);
const [filePart, pointerPart] = schema.$ref.split('#');
Comment thread src/utils/jsonSchema.ts
? relativeReferenceToNamespace(`#${pointerPart}`)
: [];

if (referenceParts.length && referenceParts[0] !== '$defs') {
Comment thread src/utils/jsonSchema.ts
Comment on lines +190 to +192
const baseIdentifier = buildIdentifier(
filePart + (isDefault ? '_default' : '_definitions'),
);
Comment thread src/utils/jsonSchema.ts Resolved
@nfroidure
nfroidure merged commit ac60f5e into main Nov 3, 2026
1 check passed
@nfroidure
nfroidure deleted the feat/file_imports branch November 3, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants