Skip to content

Commit e8c6a0e

Browse files
authored
feat(openapi-ruleset-utilities): add type declaration files (#743)
This allows the package to integrate with TypeScript-developed rulesets that need to rely on the utilities in this package. Signed-off-by: Dustin Popp <[email protected]>
1 parent f3f6bd9 commit e8c6a0e

39 files changed

+620
-10
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Please make sure that your PR fulfills the following requirements:
1111
- [ ] Docs have been added / updated (for bug fixes / features)
1212
- [ ] Dependencies have been updated as needed
1313
- [ ] `.secrets.baseline` has been updated as needed
14-
- [ ] `npm run generate-utilities-docs` has been run if any files in `packages/utilities/src` have been updated
14+
- [ ] `npm run update-utilities` has been run if any files in `packages/utilities/src` have been updated
1515

1616
#### Checklist for adding a new validation rule:
1717
- [ ] Added new validation rule definition (packages/ruleset/src/rules/*.js, index.js)

package-lock.json

Lines changed: 22 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
"unlink": "npm run unlink --workspace packages/validator",
3030
"all": "npm run test && npm run lint",
3131
"format-readme-toc": "npx -y markdown-toc --maxdepth 5 -i README.md",
32-
"generate-utilities-docs": "scripts/generate-utilities-docs.js"
32+
"generate-utilities-docs": "scripts/generate-utilities-docs.js",
33+
"generate-utilities-types": "npm run generate-types -w packages/utilities",
34+
"update-utilities": "npm run generate-utilities-docs && npm run generate-utilities-types"
3335
},
3436
"devDependencies": {
3537
"@semantic-release/changelog": "^6.0.3",

packages/utilities/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"license": "Apache-2.0",
66
"private": false,
77
"main": "./src/index.js",
8+
"types": "./types/index.d.ts",
89
"repository": {
910
"type": "git",
1011
"url": "https://github.com/IBM/openapi-validator.git",
@@ -17,11 +18,13 @@
1718
"test-travis": "jest --silent --runInBand --no-colors --testNamePattern='^((?!@skip-ci).)*$' test",
1819
"lint": "eslint --cache --quiet --ext '.js' src test",
1920
"fix": "eslint --fix --ext '.js' src test",
21+
"generate-types": "tsc",
2022
"pkg": "echo no executables to build in this package"
2123
},
2224
"devDependencies": {
2325
"@stoplight/spectral-core": "^1.19.4",
24-
"jest": "^29.7.0"
26+
"jest": "^29.7.0",
27+
"typescript": "^5.8.3"
2528
},
2629
"engines": {
2730
"node": ">=16.0.0"

packages/utilities/tsconfig.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
// Used to auto-generate TS types for this utilities package,
3+
// so that it can be imported into other rulesets developed in TS.
4+
5+
"include": ["src/**/*"],
6+
"compilerOptions": {
7+
// Tells TypeScript to read JS files, as
8+
// normally they are ignored as source files.
9+
"allowJs": true,
10+
// Generate d.ts files.
11+
"declaration": true,
12+
// This compiler run should
13+
// only output d.ts files.
14+
"emitDeclarationOnly": true,
15+
// Types should go into this directory.
16+
// Removing this would place the .d.ts files
17+
// next to the .js files.
18+
"outDir": "types",
19+
// Go to js file when using IDE functions like
20+
// "Go to Definition" in VSCode.
21+
"declarationMap": true
22+
}
23+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright 2017 - 2024 IBM Corporation.
3+
* SPDX-License-Identifier: Apache2.0
4+
*/
5+
export const operations: string[];
6+
export const requestBodySchemas: string[];
7+
export const responseSchemas: string[];
8+
export const unresolvedRequestBodySchemas: string[];
9+
export const unresolvedResponseSchemas: string[];
10+
export declare let parameters: string[];
11+
export declare let patchOperations: string[];
12+
export declare let paths: string[];
13+
export declare let schemas: string[];
14+
export declare let securitySchemes: string[];
15+
export declare let unresolvedSchemas: string[];
16+
//# sourceMappingURL=index.d.ts.map

packages/utilities/types/collections/index.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
declare const _exports: {
2+
collections: {
3+
operations: string[];
4+
parameters: string[];
5+
patchOperations: string[];
6+
paths: string[];
7+
requestBodySchemas: string[];
8+
responseSchemas: string[];
9+
schemas: string[];
10+
securitySchemes: string[];
11+
unresolvedRequestBodySchemas: string[];
12+
unresolvedResponseSchemas: string[];
13+
unresolvedSchemas: string[];
14+
};
15+
validateComposedSchemas: typeof import("./utils/validate-composed-schemas");
16+
validateNestedSchemas: typeof import("./utils/validate-nested-schemas");
17+
validateSubschemas: typeof import("./utils/validate-subschemas");
18+
getNodes: typeof import("./utils/spectral-context-utils").getNodes;
19+
getResolvedSpec: typeof import("./utils/spectral-context-utils").getResolvedSpec;
20+
getUnresolvedSpec: typeof import("./utils/spectral-context-utils").getUnresolvedSpec;
21+
isObject: typeof import("./utils/is-object");
22+
schemaHasConstraint: typeof import("./utils/schema-has-constraint");
23+
schemaHasProperty: typeof import("./utils/schema-has-property");
24+
schemaLooselyHasConstraint: typeof import("./utils/schema-loosely-has-constraint");
25+
schemaRequiresProperty: typeof import("./utils/schema-requires-property");
26+
SchemaType: {
27+
ARRAY: symbol;
28+
BINARY: symbol;
29+
BOOLEAN: symbol;
30+
BYTE: symbol;
31+
DATE: symbol;
32+
DATE_TIME: symbol;
33+
DOUBLE: symbol;
34+
ENUMERATION: symbol;
35+
FLOAT: symbol;
36+
INT32: symbol;
37+
INT64: symbol;
38+
INTEGER: symbol;
39+
NUMBER: symbol;
40+
OBJECT: symbol;
41+
STRING: symbol;
42+
UNKNOWN: symbol;
43+
};
44+
getSchemaType: typeof import("./utils/get-schema-type").getSchemaType;
45+
isArraySchema: typeof import("./utils/get-schema-type").isArraySchema;
46+
isBinarySchema: typeof import("./utils/get-schema-type").isBinarySchema;
47+
isBooleanSchema: typeof import("./utils/get-schema-type").isBooleanSchema;
48+
isByteSchema: typeof import("./utils/get-schema-type").isByteSchema;
49+
isDateSchema: typeof import("./utils/get-schema-type").isDateSchema;
50+
isDateTimeSchema: typeof import("./utils/get-schema-type").isDateTimeSchema;
51+
isDoubleSchema: typeof import("./utils/get-schema-type").isDoubleSchema;
52+
isEnumerationSchema: typeof import("./utils/get-schema-type").isEnumerationSchema;
53+
isFloatSchema: typeof import("./utils/get-schema-type").isFloatSchema;
54+
isInt32Schema: typeof import("./utils/get-schema-type").isInt32Schema;
55+
isInt64Schema: typeof import("./utils/get-schema-type").isInt64Schema;
56+
isIntegerSchema: typeof import("./utils/get-schema-type").isIntegerSchema;
57+
isNumberSchema: typeof import("./utils/get-schema-type").isNumberSchema;
58+
isObjectSchema: typeof import("./utils/get-schema-type").isObjectSchema;
59+
isPrimitiveSchema: typeof import("./utils/get-schema-type").isPrimitiveSchema;
60+
isStringSchema: typeof import("./utils/get-schema-type").isStringSchema;
61+
schemaIsOfType: typeof import("./utils/get-schema-type").schemaIsOfType;
62+
collectFromComposedSchemas: typeof import("./utils/collect-from-composed-schemas");
63+
getExamplesForSchema: typeof import("./utils/get-examples-for-schema");
64+
getPropertyNamesForSchema: typeof import("./utils/get-property-names-for-schema");
65+
};
66+
export = _exports;
67+
//# sourceMappingURL=index.d.ts.map

packages/utilities/types/index.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export = collectFromComposedSchemas;
2+
/**
3+
* Copyright 2024 IBM Corporation.
4+
* SPDX-License-Identifier: Apache2.0
5+
*/
6+
/**
7+
* Returns an array of items collected by the provided `collector(schema) => item[]` function for a
8+
* simple or composite schema, and deduplicates primitives in the result. The collector function is
9+
* not run for `null` or `undefined` schemas.
10+
* @param {object} schema simple or composite OpenAPI 3.x schema object
11+
* @param {Function} collector a `(schema) => item[]` function to collect items from each simple schema
12+
* @param {boolean} includeSelf collect from the provided schema in addition to its composed schemas (defaults to `true`)
13+
* @param {boolean} includeNot collect from schemas composed with `not` (defaults to `false`)
14+
* @returns {Array} collected items
15+
*/
16+
declare function collectFromComposedSchemas(schema: object, collector: Function, includeSelf?: boolean, includeNot?: boolean): any[];
17+
//# sourceMappingURL=collect-from-composed-schemas.d.ts.map

0 commit comments

Comments
 (0)