scalar / openapi-parser

Modern OpenAPI parser written in TypeScript
MIT License
34 stars 1 forks source link

`load()` function supports string url #136

Closed huypham50 closed 3 months ago

huypham50 commented 3 months ago

What happens?

Right now it is unclear based on the docs if the library supports fetching the spec from an URL. Since the helper fetchUrls already exists, it would be great to be able to just load(url) and we can get a validated spec ready.https://www.npmjs.com/package/oas-normalize

What did you expect to happen?

https://www.npmjs.com/package/oas-normalize

import OASNormalize from 'oas-normalize';

const oas = new OASNormalize(
  'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml',
  // ...or a string, path, JSON blob, whatever you've got.
);

oas
  .validate()
  .then(definition => {
    // Definition will always be JSON, and valid.
    console.log(definition);
  })
  .catch(err => {
    console.log(err);
  });

How can we reproduce the issue?

load()

Swagger/OpenAPI Example

No response

hanspagel commented 3 months ago

Not documented, but you can pass just an URL if you use the fetchUrl plugin as documented. :)

hanspagel commented 3 months ago

Documented :)