Skip to content

Commit

Permalink
fix(schema): skip function types (not in js-schema), related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gadicc committed Sep 18, 2023
1 parent e117529 commit b772399
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"prettier": "2.8.8",
"semantic-release": "19.0.5",
"ts-jest": "29.1.1",
"ts-json-schema-generator": "0.98.0",
"ts-json-schema-generator": "1.3.0",
"ts-node": "10.9.1",
"typescript": "5.2.2"
}
Expand Down
19 changes: 19 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"$comment": "DO NOT EDIT THIS FILE. It is generated automatically from typescript interfaces in the project. To update, run `yarn schema`.",
"definitions": {
"Logger": {
"type": "object",
"properties": {
"info": {},
"warn": {},
"error": {},
"debug": {}
},
"required": [
"info",
"warn",
"error",
"debug"
],
"additionalProperties": false
},
"YahooFinanceOptions": {
"type": "object",
"properties": {
Expand All @@ -16,6 +32,9 @@
},
"validation": {
"$ref": "#/definitions/ValidationOptions"
},
"logger": {
"$ref": "#/definitions/Logger"
}
},
"additionalProperties": false
Expand Down
12 changes: 7 additions & 5 deletions scripts/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import {
Config,
} from "ts-json-schema-generator";

// @ts-ignore
// @ts-expect-error: no types
import schemaWalker from "oas-schema-walker";
import walkerCallback from "./schema/postWalker.js";

import yfNumberTypeFormatter from "./schema/TypeFormatter/yfNumberTypeFormatter.js";
import yfReferenceTypeFormatter from "./schema/TypeFormatter/yfReferenceTypeFormatter.js";
import yfFunctionIgnorer from "./schema/TypeFormatter/yfFunctionIgnorer.js";

//const OUTPUT_PATH = "schema.json";
const OUTPUT_PATH = process.stdout;
Expand All @@ -34,7 +35,8 @@ const formatter = createFormatter(
config.encodeRefs ?? true
)
)
.addTypeFormatter(new yfNumberTypeFormatter());
.addTypeFormatter(new yfNumberTypeFormatter())
.addTypeFormatter(new yfFunctionIgnorer());
}
);

Expand All @@ -52,9 +54,9 @@ const schema = {
..._schema,
};

// @ts-ignore
for (let key of Object.keys(schema.definitions)) {
// @ts-ignore
// @ts-expect-error: no types
for (const key of Object.keys(schema.definitions)) {
// @ts-expect-error: no types
schemaWalker.walkSchema(schema.definitions[key], {}, {}, walkerCallback);
}

Expand Down
20 changes: 20 additions & 0 deletions scripts/schema/TypeFormatter/yfFunctionIgnorer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
BaseType,
FunctionType,
Definition,
SubTypeFormatter,
} from "ts-json-schema-generator";

export default class yfNumberTypeFormatter implements SubTypeFormatter {
public supportsType(type: FunctionType): boolean {
return type instanceof FunctionType;
}

public getDefinition(): Definition {
return {};
}

public getChildren(): BaseType[] {
return [];
}
}
2 changes: 2 additions & 0 deletions src/lib/getCrumb.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { ExtendedCookieJar } from "./cookieJar.js";

describe("getCrumb", () => {
const { logger } = options;
if (!logger) throw new Error("logger was unset");

let cookieJar: ExtendedCookieJar;
beforeAll(() => {
consoleSilent();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface YahooFinanceOptions {
cookieJar?: ExtendedCookieJar;
queue?: QueueOptions;
validation?: ValidationOptions;
logger: Logger;
logger?: Logger;
}

const options: YahooFinanceOptions = {
Expand Down
13 changes: 12 additions & 1 deletion src/lib/setGlobalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function setGlobalConfig(
_config: YahooFinanceOptions
): void {
// Instances (e.g. cookieJar) don't validate well :)
const { cookieJar, ...config } = _config;
const { cookieJar, logger, ...config } = _config;

validateAndCoerceTypes({
object: config,
Expand All @@ -24,6 +24,17 @@ export default function setGlobalConfig(
throw new Error("cookieJar must be an instance of ExtendedCookieJar");
this._opts.cookieJar = cookieJar;
}
if (logger) {
if (typeof logger.info !== "function")
throw new Error("logger.info must be a function");
if (typeof logger.warn !== "function")
throw new Error("logger.warn must be a function");
if (typeof logger.error !== "function")
throw new Error("logger.error must be a function");
if (typeof logger.debug !== "function")
throw new Error("logger.debug must be a function");
this._opts.logger = logger;
}
}

type Obj = Record<string, any>;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/yahooFinanceFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ async function yahooFinanceFetch(
if (needsCrumb) {
if (!this._opts.cookieJar) throw new Error("No cookieJar set");

if (!this._opts.logger) throw new Error("Logger was unset.");

const crumb = await getCrumb(
this._opts.cookieJar,
fetchFunc,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"esModuleInterop": true
},

"include": ["./src/**/*"],
"include": ["./src/**/*", "./scripts/**/*"],
"exclude": ["./src/**/*.spec.ts"],

"ts-node": {
Expand Down
82 changes: 53 additions & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,11 @@
expect "^29.0.0"
pretty-format "^29.0.0"

"@types/json-schema@^7.0.12":
version "7.0.13"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.13.tgz#02c24f4363176d2d18fc8b70b9f3c54aba178a85"
integrity sha512-RbSSoHliUbnXj3ny0CNFOoxrIDV6SUGyStHsvDqosw6CkdPV8TtWGlfecuK4ToyMEAql6pzNxgCFKanovUzlgQ==

"@types/json-schema@^7.0.9":
version "7.0.9"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d"
Expand Down Expand Up @@ -2131,6 +2136,13 @@ brace-expansion@^1.1.7:
balanced-match "^1.0.0"
concat-map "0.0.1"

brace-expansion@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae"
integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==
dependencies:
balanced-match "^1.0.0"

braces@^3.0.1:
version "3.0.2"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
Expand Down Expand Up @@ -2440,10 +2452,10 @@ combined-stream@^1.0.8:
dependencies:
delayed-stream "~1.0.0"

commander@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-9.0.0.tgz#86d58f24ee98126568936bd1d3574e0308a99a40"
integrity sha512-JJfP2saEKbQqvW+FI93OYUB4ByV5cizMpFMiiJI8xDbBvQvSkIk0VvQdn1CZ8mqAO8Loq2h0gYTYtDFUZUeERw==
commander@^11.0.0:
version "11.0.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-11.0.0.tgz#43e19c25dbedc8256203538e8d7e9346877a6f67"
integrity sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==

common-ancestor-path@^1.0.1:
version "1.0.1"
Expand Down Expand Up @@ -3294,6 +3306,17 @@ glob@^7.2.0:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^8.0.3:
version "8.1.0"
resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e"
integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^5.0.1"
once "^1.3.0"

globals@^11.1.0:
version "11.12.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
Expand Down Expand Up @@ -4287,13 +4310,6 @@ json5@^2.1.2:
dependencies:
minimist "^1.2.5"

json5@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.0.tgz#2dfefe720c6ba525d9ebd909950f0515316c89a3"
integrity sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==
dependencies:
minimist "^1.2.5"

json5@^2.2.3:
version "2.2.3"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
Expand Down Expand Up @@ -4736,6 +4752,13 @@ minimatch@^3.0.5, minimatch@^3.1.2:
dependencies:
brace-expansion "^1.1.7"

minimatch@^5.0.1:
version "5.1.6"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96"
integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==
dependencies:
brace-expansion "^2.0.1"

minimist-options@4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/minimist-options/-/minimist-options-4.1.0.tgz#c0655713c53a8a2ebd77ffa247d342c40f010619"
Expand Down Expand Up @@ -5810,10 +5833,10 @@ safe-buffer@~5.2.0:
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==

safe-stable-stringify@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/safe-stable-stringify/-/safe-stable-stringify-2.3.1.tgz#ab67cbe1fe7d40603ca641c5e765cb942d04fc73"
integrity sha512-kYBSfT+troD9cDA85VDnHZ1rpHC50O0g1e6WlGHVCz/g+JS+9WKLj+XwFYyR8UbrZN8ll9HUpDAAddY58MGisg==
safe-stable-stringify@^2.4.3:
version "2.4.3"
resolved "https://registry.yarnpkg.com/safe-stable-stringify/-/safe-stable-stringify-2.4.3.tgz#138c84b6f6edb3db5f8ef3ef7115b8f55ccbf886"
integrity sha512-e2bDA2WJT0wxseVd4lsDP4+3ONX6HpMXQa1ZhFQ7SU+GjvORCmShbCMltrtIDfkYhVHrOcPtj+KhmDBdPdZD1g==

"safer-buffer@>= 2.1.2 < 3.0.0":
version "2.1.2"
Expand Down Expand Up @@ -6358,17 +6381,18 @@ ts-jest@29.1.1:
semver "^7.5.3"
yargs-parser "^21.0.1"

ts-json-schema-generator@0.98.0:
version "0.98.0"
resolved "https://registry.yarnpkg.com/ts-json-schema-generator/-/ts-json-schema-generator-0.98.0.tgz#5aa957f45ba4b662a53ffafe86164e6e218942fa"
integrity sha512-emurTxAKkhk9a/i0Rfg5WkT5Hbg7MaL9VlxQXsWScBun0aXVl99gr06sEcHm3EJ8As4Ji51J7VJGEg6wrER/Kg==
ts-json-schema-generator@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/ts-json-schema-generator/-/ts-json-schema-generator-1.3.0.tgz#0d5c672cce47e4c438323e3bd85f2be72f62d0ac"
integrity sha512-Y2smEgpxtWat8ICaLbUENXZ/o/SqvVy85X48V/7qOarOTu6XgVs+lr6k0OPFljVhZX5gEMrGPT3q7Ql7JKnexw==
dependencies:
"@types/json-schema" "^7.0.9"
commander "^9.0.0"
glob "^7.2.0"
json5 "^2.2.0"
safe-stable-stringify "^2.3.1"
typescript "~4.5.4"
"@types/json-schema" "^7.0.12"
commander "^11.0.0"
glob "^8.0.3"
json5 "^2.2.3"
normalize-path "^3.0.0"
safe-stable-stringify "^2.4.3"
typescript "~5.1.6"

ts-node@10.9.1:
version "10.9.1"
Expand Down Expand Up @@ -6453,10 +6477,10 @@ typescript@5.2.2:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.2.2.tgz#5ebb5e5a5b75f085f22bc3f8460fba308310fa78"
integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==

typescript@~4.5.4:
version "4.5.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.5.tgz#d8c953832d28924a9e3d37c73d729c846c5896f3"
integrity sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==
typescript@~5.1.6:
version "5.1.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274"
integrity sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==

uglify-js@^3.1.4:
version "3.12.5"
Expand Down

0 comments on commit b772399

Please sign in to comment.