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

Conversation

erunion
Copy link
Member

@erunion erunion commented Feb 11, 2025

🐳 Context

Now that our fork of @apidevtools/swagger-parser has fully deviated and was moved here from our other repository I have built off of JonLuca's1 starting work over in APIDevTools/swagger-parser#253 and rewritten the library in TS.

This is all going to be the basis for a slew of forthcoming changes in order to support error levels.

Because this is a full rewrite, and a lot of things have changed, this will incur a major version bump.

🧰 Changes

  • Rewrote our OpenAPI parser in TS.
  • Added in dual support for CJS and ESM.
  • Resolved a number of test quirks and invalid false positive assertions.

Footnotes

  1. Because I adapted heavily from his draft PR of this rewrite over in the swagger-parser repository I've credited him as a co-author of this work.

@erunion erunion added the enhancement New feature or request label Feb 11, 2025
Copy link
Member

@kanadgupta kanadgupta left a comment

Choose a reason for hiding this comment

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

pushed up a couple smol changes to get tests passing again. i'm nervous about some of the uglier parts that we're now fully responsible for (e.g., the wild instance.method.apply stuff, the use of @jsdevtools/ono, etc.) but overall content with this

const fs = require('fs');
import fs from 'node:fs';

const __dirname = import.meta.dirname;
Copy link
Member

Choose a reason for hiding this comment

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

just a flag — import.meta.dirname only became available in node 20: https://nodejs.org/api/esm.html#importmetadirname

wouldn't be opposed to dropping support for node 18 since it EOLs in a couple months!

Copy link
Member Author

Choose a reason for hiding this comment

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

This script is an internal-only thing for refreshing a unit test dataset. Definitely open to dropping Node 18 support.

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

{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
// DOM is needed because `@apidevtools/json-schema-ref-parser` uses `window` and `location`.
Copy link
Member

Choose a reason for hiding this comment

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

thanks i hate it

@erunion erunion marked this pull request as ready for review February 13, 2025 19:26
@erunion erunion merged commit dec0e4b into main Feb 13, 2025
9 checks passed
@erunion erunion deleted the feat/parser-typescript-rewrite branch February 13, 2025 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants