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

fix: allow other properties on schemas with refs whilst still generating a shared type #521

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
31 changes: 22 additions & 9 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
.DS_Store
.editorconfig
.eslintignore
.eslintrc.config.js
.eslintrc.js
.eslintrc.json
.github
.gitignore
.idea
.nvmrc
.prettierignore
.prettierrc
.vscode
npm-debug.log
yarn-error.log
node_modules
*.map
example
test
dist/test
circle.yml
.yarn
.yarnrc.yml
ARCHITECTURE.md
circle.yml
CONTRIBUTING.md
.editorconfig
dist/test
example
node_modules
npm-debug.log
package-lock.json
test
tsconfig.json
yarn-error.log
yarn.lock

*.map
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
11 changes: 8 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/node_modules/.bin/ava ./dist/test/test.js",
"cwd": "${workspaceRoot}"
"program": "${workspaceRoot}/node_modules/.bin/ava",
"args": ["./dist/test/test.js"],
"cwd": "${workspaceRoot}",
"console": "integratedTerminal",
"env": {
"VERBOSE": "true"
}
},
{
"type": "node",
Expand All @@ -17,4 +22,4 @@
"sourceMaps": true
}
]
}
}
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const DEFAULT_OPTIONS: Options = {
unknownAny: true
}

export function compileFromFile (filename: string, options: Partial<Options> = DEFAULT_OPTIONS): Promise<string> {
export function compileFromFile(filename: string, options: Partial<Options> = DEFAULT_OPTIONS): Promise<string> {
const contents = Try(
() => readFileSync(filename),
() => {
Expand All @@ -123,13 +123,13 @@ export function compileFromFile (filename: string, options: Partial<Options> = D
return compile(schema, stripExtension(filename), {cwd: dirname(filename), ...options})
}

export async function compile (schema: JSONSchema4, name: string, options: Partial<Options> = {}): Promise<string> {
export async function compile(schema: JSONSchema4, name: string, options: Partial<Options> = {}): Promise<string> {
validateOptions(options)

const _options = merge({}, DEFAULT_OPTIONS, options)

const start = Date.now()
function time () {
function time() {
return `(${Date.now() - start}ms)`
}

Expand All @@ -141,7 +141,7 @@ export async function compile (schema: JSONSchema4, name: string, options: Parti
// Initial clone to avoid mutating the input
const _schema = cloneDeep(schema)

const {dereferencedPaths, dereferencedSchema} = await dereference(_schema, _options)
const {dereferencedPaths, dereferencedSchema, refMap} = await dereference(_schema, _options)
if (process.env.VERBOSE) {
if (isDeepStrictEqual(_schema, dereferencedSchema)) {
log('green', 'dereferencer', time(), '✅ No change')
Expand All @@ -167,7 +167,7 @@ export async function compile (schema: JSONSchema4, name: string, options: Parti
const normalized = normalize(linked, dereferencedPaths, name, _options)
log('yellow', 'normalizer', time(), '✅ Result:', normalized)

const parsed = parse(normalized, _options)
const parsed = parse(normalized, _options, dereferencedPaths, refMap)
log('blue', 'parser', time(), '✅ Result:', parsed)

const optimized = optimize(parsed, _options)
Expand Down