APIDevTools / swagger-parser

Swagger 2.0 and OpenAPI 3.0 parser/validator
https://apitools.dev/swagger-parser
MIT License
1.09k stars 154 forks source link

Compatibility with rollup (Svelte) #143

Open wilcoschoneveld opened 4 years ago

wilcoschoneveld commented 4 years ago

Hey guys!

How would I go about adding this package to a svelte rollup project?

I'm working from this template: https://github.com/sveltejs/template

Even when I add @rollup/plugin-json I can't seem to get it to work, rollup is complaining about missing util package..

It looks like the browser:true is ignored in the resolve plugin?

A quick explanation of steps needed to get it to work in the template would be awesome!

Thanks a lot for the help!

rubenfiszel commented 3 years ago

I have the same issue

DanielMPries commented 3 years ago

I did resolve those and its specific to rollup used by Svelte with Typescript

I added import nodePolyfills from 'rollup-plugin-polyfill-node'; followed by

plugins: [
    nodePolyfills([
    'url',
    'util',
    'http',
    'https'
    ]),

from there I ran into a complaint with require('child_process') in writeBundle(). To fix that I added an import for child_process and then change the reference to use the imported type

import child_process from 'child_process';
...
server = child_process.spawn('npm', ['run', 'start', '--', '--dev'], {

Consequently, no good deed goes unpunished and now if I try to leverage the following, I get a complaint about Zschema using require and I'm back at square one

import SwaggerParser from "@apidevtools/swagger-parser";
...
onMount(() => {
   SwaggerParser.parse(myAwesomeUri).then( (document: OpenApi.Document ) => {...});
});