Closed tjosepo closed 3 weeks ago
Yeah, I think that's a good idea. I am wondering if we could leverage a package like @stoplight/http-spec. They also have a fork of @apidevtools/json-schema-ref-parser which appears to work in the browser but I am not sure if they use poly fills for it (probably?).
I think we might able to use this http-spec
as for some cli
-tool to generate HttpHandler
stubs from a Postman collection file :)
Thanks for opening this, @tjosepo. I would love to see Source working in the browser for OpenAPI. Our best approach here is to find packages that can provide us with parsing while not relying on Node.js native modules.
@weyert, http-spec
looks interesting. Do you have some usage examples of how it parses the OAS documents? I'd love to see those.
@kettanaito @tjosepo @weyert I believe a better solution would be to provide an initialization command that generates the JSON string for the specification
needed by const specification = await SwaggerParser.dereference(document)
, which can then be passed as an argument to fromOpenApi
. What do you think?
@VobileLiuZhiwu OpenAPI specifications can have circular references, but JSON strings do not support circular references. Because of this, I don't think this approach is suitable. :/
I love the approach @tjosepo has chosen in #51. The changes will be automatically published tomorrow.
This has been released in v0.3.0!
Make sure to always update to the latest version (npm i @mswjs/source@latest
) to get the newest features and bug fixes.
Predictable release automation by @ossjs/release.
Description
The function
fromOpenApi
currently doesn't work on the browser without a lot of Node.js polyfills.node:http
.path
,fs
,http
andhttps
modules. It also referencesprocess.cwd
.Solution
For open-api-utils.ts, inlining the
STATUS_CODE
variable is easy enough.For @apidevtools/json-schema-ref-parser, since it is the ubiquitous library used for JSON Schema dereferencing in Node, it may not make sense to replace it in Node. We could create a separate package entrypoint for the browser that prebundles the Node.js modules or replaces the library with web-compatible alternative (that may not support all features of JSON Schema dereferencing, but works for the web.)
Alternatives
@apidevtools
folks. Make the change there.