Skip to content

Commit

Permalink
clean up generateJsonSchemaTypes
Browse files Browse the repository at this point in the history
- Remove needless dep json-schema-ref-parser
- Use stricter options
  • Loading branch information
sqs committed Dec 28, 2023
1 parent d8c3130 commit d4dfc4d
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 48 deletions.
1 change: 0 additions & 1 deletion lib/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@opencodegraph/schema": "workspace:*"
},
"devDependencies": {
"json-schema-ref-parser": "^9.0.9",
"json-schema-to-typescript": "^13.1.1"
}
}
2 changes: 1 addition & 1 deletion lib/protocol/src/opencodegraph-protocol.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface RequestMessage {
* User settings sent by the client to the provider.
*/
export interface ProviderSettings {
[k: string]: unknown
[k: string]: unknown | undefined
}
export interface ResponseMessage {
result?: unknown
Expand Down
24 changes: 2 additions & 22 deletions lib/schema/dev/generateJsonSchemaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,15 @@
import { readFile } from 'fs/promises'
import path from 'path'
import { pathToFileURL } from 'url'
import { type ResolverOptions } from 'json-schema-ref-parser'
import { compile as compileJSONSchema } from 'json-schema-to-typescript'

/**
* Allow json-schema-ref-parser to resolve the v7 draft of JSON Schema
* using a local copy of the spec for offline development.
*/
const draftV7resolver: ResolverOptions = {
order: 1,
read: () => readFile(path.join(__dirname, 'json-schema-draft-07.schema.json')),
canRead: file => file.url === 'http://json-schema.org/draft-07/schema',
}

async function generateSchema(schemaPath: string, preamble?: string): Promise<void> {
const schema = await readFile(schemaPath, 'utf8')
const types = await compileJSONSchema(JSON.parse(schema), 'settings.schema', {
bannerComment: '', // no eslint-disable
cwd: path.dirname(schemaPath),
$refOptions: {
resolve: {
draftV7resolver,
// There should be no reason to make network calls during this process. If there
// are, we've broken the dev env for offline development and increased dev startup
// time.
//
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
http: false as any,
},
},
additionalProperties: false,
strictIndexSignatures: true,
})

if (preamble) {
Expand Down
1 change: 0 additions & 1 deletion lib/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"prepublishOnly": "tsc --build --clean && pnpm run build"
},
"devDependencies": {
"json-schema-ref-parser": "^9.0.9",
"json-schema-to-typescript": "^13.1.1"
}
}
23 changes: 0 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d4dfc4d

Please sign in to comment.