-
Notifications
You must be signed in to change notification settings - Fork 667
[heft-json-schema-typings-plugin] Implementation of a Heft plugin that generates TypeScript typings from JSON schemata. #5272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
bc48f7e
Clean temp/sass-ts.
iclanton 1dec3d0
Add an option to the typings generator to override the write function.
iclanton 9a35045
Normalize the test schema filenames in node-core-library.
iclanton b5c585e
fixup! Normalize the test schema filenames in node-core-library.
iclanton f2cd0b6
fixup! Normalize the test schema filenames in node-core-library.
iclanton 056e92f
Initial implementation of the json-schema-typings-plugin.
iclanton 68d0d83
fixup! Initial implementation of the json-schema-typings-plugin.
iclanton 5de5b40
Ensure path paramters don't contain backslashes.
iclanton 62af941
fixup! Initial implementation of the json-schema-typings-plugin.
iclanton cbac99f
Rush update.
iclanton 0a5fc4d
fixup! Initial implementation of the json-schema-typings-plugin.
iclanton 521cc08
fixup! Rush update.
iclanton ff2a599
fixup! Initial implementation of the json-schema-typings-plugin.
iclanton c498ca7
fixup! Rush update.
iclanton 5d14f5c
fixup! Initial implementation of the json-schema-typings-plugin.
iclanton 967f96b
fixup! Rush update.
iclanton bc28620
fixup! Initial implementation of the json-schema-typings-plugin.
iclanton 19aba59
fixup! Initial implementation of the json-schema-typings-plugin.
iclanton bf9d43f
Update repo readme.
iclanton f8fcf48
fixup! Initial implementation of the json-schema-typings-plugin.
iclanton 0a7e95e
Revert "Ensure path paramters don't contain backslashes."
iclanton 13597d5
Simplify the schema testing.
iclanton 1ea0ae3
Don't include the eslint-disable header.
iclanton 62aea76
Revert "Add an option to the typings generator to override the write …
iclanton ce5aa23
fixup! Revert "Add an option to the typings generator to override the…
iclanton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
build-tests/heft-json-schema-typings-plugin-test/config/heft.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "$schema": "https://developer.microsoft.com/json-schemas/heft/v0/heft.schema.json", | ||
|
|
||
| "extends": "local-node-rig/profiles/default/config/heft.json", | ||
|
|
||
| "phasesByName": { | ||
| "build": { | ||
| "cleanFiles": [{ "includeGlobs": ["temp/schema-dts"] }], | ||
|
|
||
| "tasksByName": { | ||
| "json-schema-typings": { | ||
| "taskPlugin": { | ||
| "pluginPackage": "@rushstack/heft-json-schema-typings-plugin", | ||
| "pluginName": "json-schema-typings-plugin", | ||
| "options": { | ||
| "srcFolder": "node_modules/@rushstack/node-core-library/src/test/test-data/test-schemas", | ||
| "generatedTsFolders": ["temp/schema-dts"] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
build-tests/heft-json-schema-typings-plugin-test/config/jest.config.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "extends": "local-node-rig/profiles/default/config/jest.config.json" | ||
| } |
7 changes: 7 additions & 0 deletions
7
build-tests/heft-json-schema-typings-plugin-test/config/rig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| // The "rig.json" file directs tools to look for their config files in an external package. | ||
| // Documentation for this system: https://www.npmjs.com/package/@rushstack/rig-package | ||
| "$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json", | ||
|
|
||
| "rigPackageName": "local-node-rig" | ||
| } |
18 changes: 18 additions & 0 deletions
18
build-tests/heft-json-schema-typings-plugin-test/eslint.config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
| // See LICENSE in the project root for license information. | ||
|
|
||
| const nodeTrustedToolProfile = require('local-node-rig/profiles/default/includes/eslint/flat/profile/node-trusted-tool'); | ||
| const friendlyLocalsMixin = require('local-node-rig/profiles/default/includes/eslint/flat/mixins/friendly-locals'); | ||
|
|
||
| module.exports = [ | ||
| ...nodeTrustedToolProfile, | ||
| ...friendlyLocalsMixin, | ||
| { | ||
| files: ['**/*.ts', '**/*.tsx'], | ||
| languageOptions: { | ||
| parserOptions: { | ||
| tsconfigRootDir: __dirname | ||
| } | ||
| } | ||
| } | ||
| ]; |
19 changes: 19 additions & 0 deletions
19
build-tests/heft-json-schema-typings-plugin-test/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "name": "heft-json-schema-typings-plugin-test", | ||
| "description": "This project illustrates configuring Jest reporters in a minimal Heft project", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "scripts": { | ||
| "build": "heft build --clean", | ||
| "start": "heft build-watch", | ||
| "_phase:build": "heft run --only build -- --clean", | ||
| "_phase:test": "heft run --only test -- --clean" | ||
| }, | ||
| "devDependencies": { | ||
| "@rushstack/heft-json-schema-typings-plugin": "workspace:*", | ||
| "@rushstack/heft": "workspace:*", | ||
| "@rushstack/node-core-library": "workspace:*", | ||
| "eslint": "~9.25.1", | ||
| "local-node-rig": "workspace:*" | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
build-tests/heft-json-schema-typings-plugin-test/src/test/JsonSchemaTypingsGenerator.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
| // See LICENSE in the project root for license information. | ||
|
|
||
| import { FileSystem, type FolderItem, PackageJsonLookup } from '@rushstack/node-core-library'; | ||
|
|
||
| async function getFolderItemsAsync( | ||
| absolutePath: string, | ||
| relativePath: string | ||
| ): Promise<Record<string, string>> { | ||
| const folderQueue: [string, string][] = [[absolutePath, relativePath]]; | ||
| const results: [string, string][] = []; | ||
| for (const [folderAbsolutePath, folderRelativePath] of folderQueue) { | ||
| const folderItems: FolderItem[] = await FileSystem.readFolderItemsAsync(folderAbsolutePath); | ||
| for (const item of folderItems) { | ||
| const itemName: string = item.name; | ||
| const itemAbsolutePath: string = `${folderAbsolutePath}/${itemName}`; | ||
| const itemRelativePath: string = `${folderRelativePath}/${itemName}`; | ||
| if (item.isDirectory()) { | ||
| folderQueue.push([itemAbsolutePath, itemRelativePath]); | ||
| } else { | ||
| const itemContents: string = await FileSystem.readFileAsync(itemAbsolutePath); | ||
| results.push([itemRelativePath, itemContents]); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| results.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)); | ||
| return Object.fromEntries(results); | ||
| } | ||
|
|
||
| describe('json-schema-typings-plugin', () => { | ||
| it('should generate typings for JSON Schemas', async () => { | ||
| const rootFolder: string | undefined = PackageJsonLookup.instance.tryGetPackageFolderFor(__dirname); | ||
| if (!rootFolder) { | ||
| throw new Error('Could not find root folder for the test'); | ||
| } | ||
|
|
||
| const folderItems: Record<string, string> = await getFolderItemsAsync( | ||
| `${rootFolder}/temp/schema-dts`, | ||
| '.' | ||
| ); | ||
| expect(folderItems).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
185 changes: 185 additions & 0 deletions
185
...schema-typings-plugin-test/src/test/__snapshots__/JsonSchemaTypingsGenerator.test.ts.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`json-schema-typings-plugin should generate typings for JSON Schemas 1`] = ` | ||
| Object { | ||
| "./test-invalid-additional.schema.json.d.ts": "// This file was generated by a tool. Modifying it will produce unexpected behavior | ||
|
|
||
| export interface TestInvalidAdditional { | ||
| [k: string]: unknown; | ||
| } | ||
| ", | ||
| "./test-invalid-format.schema.json.d.ts": "// This file was generated by a tool. Modifying it will produce unexpected behavior | ||
|
|
||
| export interface TestInvalidFormat { | ||
| [k: string]: unknown; | ||
| } | ||
| ", | ||
| "./test-schema-draft-04.schema.json.d.ts": "// This file was generated by a tool. Modifying it will produce unexpected behavior | ||
|
|
||
| export interface TestSchemaFile { | ||
| exampleString: string; | ||
| exampleLink?: string; | ||
| exampleArray: string[]; | ||
| /** | ||
| * Description for exampleOneOf - this is a very long description to show in an error message | ||
| */ | ||
| exampleOneOf?: Type1 | Type2; | ||
| exampleUniqueObjectArray?: { | ||
| field2?: string; | ||
| field3?: string; | ||
| }[]; | ||
| } | ||
| /** | ||
| * Description for type1 | ||
| */ | ||
| export interface Type1 { | ||
| /** | ||
| * Description for field1 | ||
| */ | ||
| field1: string; | ||
| } | ||
| /** | ||
| * Description for type2 | ||
| */ | ||
| export interface Type2 { | ||
| /** | ||
| * Description for field2 | ||
| */ | ||
| field2: string; | ||
| /** | ||
| * Description for field3 | ||
| */ | ||
| field3: string; | ||
| } | ||
| ", | ||
| "./test-schema-draft-07.schema.json.d.ts": "// This file was generated by a tool. Modifying it will produce unexpected behavior | ||
|
|
||
| export interface TestSchemaFile { | ||
| exampleString: string; | ||
| exampleLink?: string; | ||
| exampleArray: string[]; | ||
| /** | ||
| * Description for exampleOneOf - this is a very long description to show in an error message | ||
| */ | ||
| exampleOneOf?: Type1 | Type2; | ||
| exampleUniqueObjectArray?: { | ||
| field2?: string; | ||
| field3?: string; | ||
| }[]; | ||
| } | ||
| /** | ||
| * Description for type1 | ||
| */ | ||
| export interface Type1 { | ||
| /** | ||
| * Description for field1 | ||
| */ | ||
| field1: string; | ||
| } | ||
| /** | ||
| * Description for type2 | ||
| */ | ||
| export interface Type2 { | ||
| /** | ||
| * Description for field2 | ||
| */ | ||
| field2: string; | ||
| /** | ||
| * Description for field3 | ||
| */ | ||
| field3: string; | ||
| } | ||
| ", | ||
| "./test-schema-invalid.schema.json.d.ts": "// This file was generated by a tool. Modifying it will produce unexpected behavior | ||
|
|
||
| export interface HttpExampleComSchemasTestSchemaNestedChildSchemaJson { | ||
| [k: string]: unknown; | ||
| } | ||
| ", | ||
| "./test-schema-nested-child.schema.json.d.ts": "// This file was generated by a tool. Modifying it will produce unexpected behavior | ||
|
|
||
| export interface HttpExampleComSchemasTestSchemaNestedChildSchemaJson { | ||
| [k: string]: unknown; | ||
| } | ||
| ", | ||
| "./test-schema-nested.schema.json.d.ts": "// This file was generated by a tool. Modifying it will produce unexpected behavior | ||
|
|
||
| export interface TestSchemaFile { | ||
| exampleString: string; | ||
| exampleLink?: string; | ||
| exampleArray: string[]; | ||
| /** | ||
| * Description for exampleOneOf - this is a very long description to show in an error message | ||
| */ | ||
| exampleOneOf?: Type1 | Type2; | ||
| exampleUniqueObjectArray?: Type2[]; | ||
| } | ||
| /** | ||
| * Description for type1 | ||
| */ | ||
| export interface Type1 { | ||
| /** | ||
| * Description for field1 | ||
| */ | ||
| field1: string; | ||
| } | ||
| /** | ||
| * Description for type2 | ||
| */ | ||
| export interface Type2 { | ||
| /** | ||
| * Description for field2 | ||
| */ | ||
| field2: string; | ||
| /** | ||
| * Description for field3 | ||
| */ | ||
| field3: string; | ||
| } | ||
| ", | ||
| "./test-schema.schema.json.d.ts": "// This file was generated by a tool. Modifying it will produce unexpected behavior | ||
|
|
||
| export interface TestSchemaFile { | ||
| exampleString: string; | ||
| exampleLink?: string; | ||
| exampleArray: string[]; | ||
| /** | ||
| * Description for exampleOneOf - this is a very long description to show in an error message | ||
| */ | ||
| exampleOneOf?: Type1 | Type2; | ||
| exampleUniqueObjectArray?: { | ||
| field2?: string; | ||
| field3?: string; | ||
| }[]; | ||
| } | ||
| /** | ||
| * Description for type1 | ||
| */ | ||
| export interface Type1 { | ||
| /** | ||
| * Description for field1 | ||
| */ | ||
| field1: string; | ||
| } | ||
| /** | ||
| * Description for type2 | ||
| */ | ||
| export interface Type2 { | ||
| /** | ||
| * Description for field2 | ||
| */ | ||
| field2: string; | ||
| /** | ||
| * Description for field3 | ||
| */ | ||
| field3: string; | ||
| } | ||
| ", | ||
| "./test-valid.schema.json.d.ts": "// This file was generated by a tool. Modifying it will produce unexpected behavior | ||
|
|
||
| export interface TestValid { | ||
| [k: string]: unknown; | ||
| } | ||
| ", | ||
| } | ||
| `; |
3 changes: 3 additions & 0 deletions
3
build-tests/heft-json-schema-typings-plugin-test/tsconfig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "extends": "./node_modules/local-node-rig/profiles/default/tsconfig-base.json" | ||
| } |
10 changes: 10 additions & 0 deletions
10
...eft-json-schema-typings-plugin/user-ianc-json-schema-typings-plugin_2025-07-07-20-54.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@rushstack/heft-json-schema-typings-plugin", | ||
| "comment": "Initial release.", | ||
| "type": "minor" | ||
| } | ||
| ], | ||
| "packageName": "@rushstack/heft-json-schema-typings-plugin" | ||
| } |
10 changes: 10 additions & 0 deletions
10
...hanges/@rushstack/heft-web-rig/user-ianc-json-schema-typings-plugin_2025-07-07-22-05.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@rushstack/heft-web-rig", | ||
| "comment": "Clean the temp/sass-ts folder.", | ||
| "type": "minor" | ||
| } | ||
| ], | ||
| "packageName": "@rushstack/heft-web-rig" | ||
| } |
10 changes: 10 additions & 0 deletions
10
...s/@rushstack/node-core-library/user-ianc-json-schema-typings-plugin_2025-07-07-20-54.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@rushstack/node-core-library", | ||
| "comment": "", | ||
| "type": "none" | ||
| } | ||
| ], | ||
| "packageName": "@rushstack/node-core-library" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.