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

feat(parser): rewriting the library in typescript #932

Merged
merged 11 commits into from
Feb 13, 2025
Merged
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": ["@readme/eslint-config", "@readme/eslint-config/typescript", "@readme/eslint-config/esm"],
"root": true
"root": true,
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"editor.formatOnSave": true,
}
2,804 changes: 1,661 additions & 1,143 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"./packages/*"
],
"devDependencies": {
"@readme/eslint-config": "^14.0.0",
"@readme/eslint-config": "^14.2.0",
"@vitest/coverage-v8": "^3.0.4",
"alex": "^11.0.1",
"eslint": "^8.57.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/oas-normalize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
"eslint": "^8.57.0",
"nock": "^14.0.0",
"tsup": "^8.0.2",
"typescript": "^5.1.6"
"typescript": "^5.1.6",
"vitest": "^3.0.5"
},
"prettier": "@readme/eslint-config/prettier"
}
16 changes: 7 additions & 9 deletions packages/oas-normalize/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { Options } from './lib/types.js';
import type { ParserOptions } from '@readme/openapi-parser';
import type { OpenAPI, OpenAPIV2, OpenAPIV3 } from 'openapi-types';

import fs from 'node:fs';

import openapiParser from '@readme/openapi-parser';
import { OpenAPIParser } from '@readme/openapi-parser';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

considering this is now a named import:

  • i'm increasingly of the belief that we should make this a breaking change (and we consider dropping node 18 support in the process)
  • we should make sure the README for this package is updated accordingly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was already planning on making all of this a breaking change once the warning work is in

planning on doing a docs only followup after merging this

import postmanToOpenAPI from '@readme/postman-to-openapi';
import converter from 'swagger2openapi';

Expand Down Expand Up @@ -108,9 +109,8 @@ export default class OASNormalize {

return schema;
})
.then(schema => openapiParser.bundle(schema))
.then(schema => new OpenAPIParser().bundle(schema))
.then(bundle => {
// @ts-expect-error The typings on the parser are messed up rigth now while a rewrite is in progress.
this.cache.bundle = bundle;
return bundle;
});
Expand All @@ -134,9 +134,8 @@ export default class OASNormalize {

return schema;
})
.then(schema => openapiParser.dereference(schema))
.then(schema => new OpenAPIParser().dereference(schema))
.then(dereferenced => {
// @ts-expect-error The typings on the parser are messed up rigth now while a rewrite is in progress.
this.cache.deref = dereferenced;
return dereferenced;
});
Expand Down Expand Up @@ -181,7 +180,7 @@ export default class OASNormalize {
*/
async validate(
opts: {
parser?: openapiParser.Options;
parser?: ParserOptions;
} = {},
): Promise<true> {
const parserOptions = opts.parser || {};
Expand All @@ -208,7 +207,7 @@ export default class OASNormalize {
}

/**
* `openapiParser.validate()` dereferences schemas at the same time as validation, mutating
* `OpenAPIParser.validate()` dereferences schemas at the same time as validation, mutating
* the supplied parameter in the process, and does not give us an option to disable this.
* As we already have a dereferencing method on this library, and this method just needs to
* tell us if the API definition is valid or not, we need to clone the schema before
Expand All @@ -217,8 +216,7 @@ export default class OASNormalize {
// eslint-disable-next-line try-catch-failsafe/json-parse
const clonedSchema = JSON.parse(JSON.stringify(schema));

// @ts-expect-error The typings on the parser are messed up rigth now while a rewrite is in progress.
return openapiParser.validate(clonedSchema, parserOptions).then(() => {
return new OpenAPIParser().validate(clonedSchema, parserOptions).then(() => {
// The API definition, whatever its format or specification, is valid.
return true;
});
Expand Down
3 changes: 2 additions & 1 deletion packages/oas-to-har/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"jest-expect-har": "^7.1.0",
"tsup": "^8.0.2",
"type-fest": "^4.18.3",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"vitest": "^3.0.5"
},
"prettier": "@readme/eslint-config/prettier"
}
3 changes: 2 additions & 1 deletion packages/oas-to-snippet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"oas": "file:../oas",
"tsup": "^8.0.2",
"type-fest": "^4.18.3",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"vitest": "^3.0.5"
},
"prettier": "@readme/eslint-config/prettier"
}
3 changes: 2 additions & 1 deletion packages/oas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
"@types/memoizee": "^0.4.11",
"@types/node": "^22.7.6",
"tsup": "^8.0.2",
"typescript": "^5.4.4"
"typescript": "^5.4.4",
"vitest": "^3.0.5"
},
"prettier": "@readme/eslint-config/prettier"
}
27 changes: 0 additions & 27 deletions packages/parser/.editorconfig

This file was deleted.

47 changes: 4 additions & 43 deletions packages/parser/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,49 +1,10 @@
{
"root": true,
"extends": [
"@readme/eslint-config",
"@readme/eslint-config/typescript",
],
"env": {
"browser": true,
"node": true
},
"rules": {
"camelcase": ["error", { "allow": ["OpenAPIV3_1"] }],
"lines-between-class-members": "off",
"no-continue": "off",
"no-plusplus": "off",
"no-restricted-syntax": "off",
"no-underscore-dangle": "off",
"no-use-before-define": "off",
"prefer-rest-params": "off",
"prefer-spread": "off"
"prefer-spread": "off",
},
"overrides": [
{
// The typings in this file are pretty bad right now, when we have native types we can
// remove this.
"files": ["lib/index.d.ts"],
"rules": {
"@typescript-eslint/consistent-indexed-object-style": "off",
"@typescript-eslint/consistent-type-imports": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/sort-type-constituents": "off",
"eslint-comments/no-unused-disable": "off",
"lines-between-class-members": "off",
"max-classes-per-file": "off",
"quotes": "off",
"typescript-sort-keys/interface": "off"
}
},
{
// These can all get removed when the library is moved over to native TS.
"files": ["*.js"],
"rules": {
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "off",
"eslint-comments/no-unused-disable": "off",
"func-names": "off"
}
}
]
}
26 changes: 0 additions & 26 deletions packages/parser/.gitattributes

This file was deleted.

32 changes: 0 additions & 32 deletions packages/parser/.github/dependabot.yml

This file was deleted.

39 changes: 0 additions & 39 deletions packages/parser/.github/workflows/ci.yml

This file was deleted.

19 changes: 0 additions & 19 deletions packages/parser/.github/workflows/lint-pr-title.yml

This file was deleted.

44 changes: 0 additions & 44 deletions packages/parser/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions packages/parser/.npmignore

This file was deleted.

1 change: 0 additions & 1 deletion packages/parser/.npmrc

This file was deleted.

5 changes: 0 additions & 5 deletions packages/parser/.vscode/settings.json

This file was deleted.

Loading
Loading