Replies: 1 comment 4 replies
-
You can try using the following piece of code. import { Document, isOpenApiv2, isOpenApiv3, Parsers, Spectral } from '@stoplight/spectral';
import { html } from '@stoplight/spectral/dist/cli/formatters';
import { DiagnosticSeverity } from '@stoplight/types';
fetch(myURL)
.then(res => {
if (!res.ok) {
throw new Error('some error occurred'); // can be replaced with any other error handling you need
}
return res;
})
.then(res => res.text())
.then(text => {
const doc = new Document(text, Parsers.Json, myURL); // or Parsers.Yaml if you deal with Yaml
const spectral = new Spectral();
spectral.registerFormat('oas2', isOpenApiv2);
spectral.registerFormat('oas3', isOpenApiv3);
return spectral.loadRuleset('spectral:oas').then(() => spectral.run(doc));
})
.then(results => {
return html(results, {
failSeverity: DiagnosticSeverity.Warning, // or you can use some other setting, depending on the severity you like
});
}); |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to use Spectral Javascript API, and I want to ask on how:
URL
instead ofOpenApiDocument
, for example to do thisspectral.run(myURL).then(console.log);
--format html
).Thank you!
Beta Was this translation helpful? Give feedback.
All reactions