Skip to content

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

Merged
erunion merged 11 commits intomainfrom
feat/parser-typescript-rewrite
Feb 13, 2025
Merged

feat(parser): rewriting the library in typescript#932
erunion merged 11 commits intomainfrom
feat/parser-typescript-rewrite

Conversation

@erunion
Copy link
Copy Markdown
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.

Co-authored-by: JonLuca De Caro <hello@jonlu.ca>
@erunion erunion added the enhancement New feature or request label Feb 11, 2025
Copy link
Copy Markdown
Contributor

@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
Copy Markdown
Contributor

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
Copy Markdown
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 fs from 'node:fs';

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

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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks i hate it

Comment thread packages/parser/src/index.ts
@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
@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