Skip to content

Fixing resolve logic in serve and lint#19

Merged
philsturgeon merged 5 commits intomasterfrom
bug/serve-resolve
Mar 9, 2018
Merged

Fixing resolve logic in serve and lint#19
philsturgeon merged 5 commits intomasterfrom
bug/serve-resolve

Conversation

@philsturgeon
Copy link
Copy Markdown
Contributor

@philsturgeon philsturgeon commented Mar 7, 2018

When running serve on a $ref-filled schema it fails to load the target. Instead of shows the same index.html so we dont even get a 404, just a invalid response error.

It turns out that lint was also not resolving correctly, so expect to start seeing more linting errors after updating.

For that reason I'm thinking this will be v0.5.0 Don't wanna break things for people on a minor.

Todo

  • Need to add some tests

@philsturgeon philsturgeon changed the title Why cant i make this resolve Fixing resolve logic in serve and lint Mar 8, 2018
@philsturgeon philsturgeon force-pushed the bug/serve-resolve branch 6 times, most recently from 6a3410c to 65eae1a Compare March 8, 2018 22:05
@philsturgeon philsturgeon requested a review from Whitespace March 8, 2018 22:06
Comment thread lib/loader.js
class OpenError extends ExtendableError {}
class ReadError extends ExtendableError {}

function readFileAsync(filename, encoding) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from resolver, but resolver is going away in a future version as we ship the dependency to a new package. Let's just be ok with this for now.

@philsturgeon philsturgeon force-pushed the bug/serve-resolve branch 4 times, most recently from 10eb272 to 8812a3c Compare March 9, 2018 16:45
Comment thread lib/loader.js
source: source
};

options.openapi = openapi;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not ?

const options = {
    resolve: true,
    cache: [],
    externals: [],
    externalRefs: {},
    rewriteRefs: true,
    origin: source,
    source: source,
    openapi : openapi
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha yes. This was code that changed over time, thanks for catching it.

Comment thread lint.js
return loader.loadSpec(file, { resolve: true });
}
catch (error) {
if (error.name == 'OpenError') {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't use if(error instanceof OpenError)?
same for ReadError

Comment thread lint.js
if (err) {
console.log(colors.red + 'Specification schema is invalid.' + colors.reset);
formatSchemaError(err, options.context);
process.exit(1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it ok to exit here? shouldn't throw a validation error or something and be caught in the main func?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. There should be some error output for the exit IMO

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, this was confusing as the formatSchemaError was outputting content, so there is always content. I've made those functions return strings, and its a bit more clear now.

          const output = formatSchemaError(err, options.context);
          console.error(output);
          process.exit(1);

Copy link
Copy Markdown

@perico perico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrote some minor comments.
well done!

@dangoosby
Copy link
Copy Markdown
Contributor

Wrote a minor comment which agreed with perico. Looks great.

Copy link
Copy Markdown
Contributor

@dangoosby dangoosby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comment is based on opinion so I’m approving this PR.
👍

Copy link
Copy Markdown
Contributor

@dangoosby dangoosby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@philsturgeon philsturgeon merged commit e1ed396 into master Mar 9, 2018
@philsturgeon philsturgeon deleted the bug/serve-resolve branch March 9, 2018 18:51
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

Successfully merging this pull request may close these issues.

3 participants