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

Cannot use 'in' operator to search for 'required' in true #259

Closed
felixfbecker opened this issue Sep 22, 2019 · 4 comments
Closed

Cannot use 'in' operator to search for 'required' in true #259

felixfbecker opened this issue Sep 22, 2019 · 4 comments

Comments

@felixfbecker
Copy link

Getting this error when upgrading to 7.1:


TypeError: Cannot use 'in' operator to search for 'required' in true
--
  | [2019-09-09T06:16:07Z]     at /buildkite/builds/buildkite-agent-7b9d66c86c-qjbr5-1/sourcegraph/.golang/sourcegraph/src/github.com/sourcegraph/sourcegraph/node_modules/json-schema-to-typescript/dist/src/normalizer.js:23:22
  | [2019-09-09T06:16:07Z]     at /buildkite/builds/buildkite-agent-7b9d66c86c-qjbr5-1/sourcegraph/.golang/sourcegraph/src/github.com/sourcegraph/sourcegraph/node_modules/json-schema-to-typescript/dist/src/normalizer.js:80:62
  | [2019-09-09T06:16:07Z]     at traverse (/buildkite/builds/buildkite-agent-7b9d66c86c-qjbr5-1/sourcegraph/.golang/sourcegraph/src/github.com/sourcegraph/sourcegraph/node_modules/json-schema-to-typescript/dist/src/utils.js:92:5)
  | [2019-09-09T06:16:07Z]     at traverse (/buildkite/builds/buildkite-agent-7b9d66c86c-qjbr5-1/sourcegraph/.golang/sourcegraph/src/github.com/sourcegraph/sourcegraph/node_modules/json-schema-to-typescript/dist/src/utils.js:117:13)
  | [2019-09-09T06:16:07Z]     at /buildkite/builds/buildkite-agent-7b9d66c86c-qjbr5-1/sourcegraph/.golang/sourcegraph/src/github.com/sourcegraph/sourcegraph/node_modules/json-schema-to-typescript/dist/src/utils.js:84:13
  | [2019-09-09T06:16:07Z]     at Array.forEach (<anonymous>)
  | [2019-09-09T06:16:07Z]     at traverseObjectKeys (/buildkite/builds/buildkite-agent-7b9d66c86c-qjbr5-1/sourcegraph/.golang/sourcegraph/src/github.com/sourcegraph/sourcegraph/node_modules/json-schema-to-typescript/dist/src/utils.js:82:22)
  | [2019-09-09T06:16:07Z]     at Object.traverse (/buildkite/builds/buildkite-agent-7b9d66c86c-qjbr5-1/sourcegraph/.golang/sourcegraph/src/github.com/sourcegraph/sourcegraph/node_modules/json-schema-to-typescript/dist/src/utils.js:103:9)
  | [2019-09-09T06:16:07Z]     at /buildkite/builds/buildkite-agent-7b9d66c86c-qjbr5-1/sourcegraph/.golang/sourcegraph/src/github.com/sourcegraph/sourcegraph/node_modules/json-schema-to-typescript/dist/src/normalizer.js:80:17
  | [2019-09-09T06:16:07Z]     at Map.forEach (<anonymous>)
  | [2019-09-09T06:16:07Z]     at Object.normalize (/buildkite/builds/buildkite-agent-7b9d66c86c-qjbr5-1/sourcegraph/.golang/sourcegraph/src/github.com/sourcegraph/sourcegraph/node_modules/json-schema-to-typescript/dist/src/normalizer.js:79:11)
  | [2019-09-09T06:16:07Z]     at Object.<anonymous> (/buildkite/builds/buildkite-agent-7b9d66c86c-qjbr5-1/sourcegraph/.golang/sourcegraph/src/github.com/sourcegraph/sourcegraph/node_modules/json-schema-to-typescript/dist/src/index.js:119:78)
  | [2019-09-09T06:16:07Z]     at step (/buildkite/builds/buildkite-agent-7b9d66c86c-qjbr5-1/sourcegraph/.golang/sourcegraph/src/github.com/sourcegraph/sourcegraph/node_modules/json-schema-to-typescript/dist/src/index.js:56:23)
  | [2019-09-09T06:16:07Z]     at Object.next (/buildkite/builds/buildkite-agent-7b9d66c86c-qjbr5-1/sourcegraph/.golang/sourcegraph/src/github.com/sourcegraph/sourcegraph/node_modules/json-schema-to-typescript/dist/src/index.js:37:53)
  | [2019-09-09T06:16:07Z]     at /buildkite/builds/buildkite-agent-7b9d66c86c-qjbr5-1/sourcegraph/.golang/sourcegraph/src/github.com/sourcegraph/sourcegraph/node_modules/json-schema-to-typescript/dist/src/index.js:31:71
  | [2019-09-09T06:16:07Z]     at new Promise (<anonymous>)


To reproduce, check out https://github.com/sourcegraph/sourcegraph/pull/5083 and run yarn in the root. The calls are in the Gulpfile and the schemas are in the schema/ directory.

@eseliger
Copy link

eseliger commented Dec 2, 2019

Acccording to the spec, items can be true either, so this is an edge-case

https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.9.3.1.1

@LutzR
Copy link

LutzR commented Feb 26, 2020

Hello,

issue seems to be, that the if-condition is in the wrong order:
if (!('required' in schema) && isObjectType(schema))
if schema is not an object this results in error.

This way it would work:
if (isObjectType(schema) && !('required' in schema))

@bcherny
Copy link
Owner

bcherny commented Mar 8, 2020

@LutzR Want to put up a PR?

LutzR pushed a commit to LutzR/json-schema-to-typescript that referenced this issue Mar 19, 2020
@LutzR
Copy link

LutzR commented Mar 19, 2020

@bcherny I created Pull-Request #284 for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants