Skip to content
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

clean up generateJsonSchemaTypes #6

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.