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

Import JSON Schema as File Not Over HTTP Request #246

Closed
sam3k opened this issue Mar 23, 2023 · 2 comments
Closed

Import JSON Schema as File Not Over HTTP Request #246

sam3k opened this issue Mar 23, 2023 · 2 comments

Comments

@sam3k
Copy link

sam3k commented Mar 23, 2023

I'm trying to use the Swagger parser in the browser and need to import a JSON schema file in a relative path instead of a HTTP get request. It will be served next to the app.js file to begin with and later i'll be loading from a NPM package that generates the JSON schema via some CI/CD build. (e.g. node_modules/some_package/schema.json);

App structure (Typical React app):

src/
  - app.js
  - schema.json

Here is what I've tried so far:

  const api = await SwaggerParser.bundle(path.join('schema.json', ''), {
    resolve: {
      file: true,
      http: false,
    }
  });

Per the docs:

Swagger Parser comes with built-in support for HTTP and HTTPS, as well as support for local files (when running in Node.js). You can configure or disable either of these built-in resolvers.

Is this not possible in browser mode?

@sam3k
Copy link
Author

sam3k commented Mar 24, 2023

I may have overthought this.

import schema from './apiv3.json';

const api = await SwaggerParser.bundle(schema);

console.log(api); // works!! 

I will keep this issue open till I have the functionality I have in mind implemented.

@sam3k
Copy link
Author

sam3k commented Mar 27, 2023

Closing this issue as my previous comment is the way to solve it.

@sam3k sam3k closed this as completed Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant