Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Implements v2 #178

Merged
merged 27 commits into from
Jun 18, 2019
Merged

Implements v2 #178

merged 27 commits into from
Jun 18, 2019

Conversation

artem-zakharchenko
Copy link
Contributor

@artem-zakharchenko artem-zakharchenko commented May 28, 2019

These changes implement the next major version of Gavel per defined spec. They must be merged once the spec lands.

Refs

Changelog

  • See Gavel spec v2 to know the breaking and non-breaking changes

Roadmap

  • Remove unused code (utils, tests, feature tests setups)
  • Decide on uri feature, implement if decided

@artem-zakharchenko
Copy link
Contributor Author

CI requires next gavel-spec release to pass successfully.

@honzajavorek
Copy link
Contributor

CI requires next gavel-spec release to pass successfully.

I'm wondering whether it wouldn't help if we had those two in one repo 🤔

@artem-zakharchenko
Copy link
Contributor Author

artem-zakharchenko commented May 30, 2019

@honzajavorek it's troublesome that spec lives its own life, yet wasn't that the original intent? So that there could be multiple implementations of gavel?

I would say we need to assess if that's useful, and how many Gavel implementations in other languages we have. If the effort is not worth a trouble, I would vote for moving gavel-spec into gavel package (or vice versa), and treating its test suites as behavior tests.

@honzajavorek
Copy link
Contributor

yet wasn't that the original intent? So that there could be multiple implementations of gavel?

Yes, it was. I guess we could solve it for once when we have Dredd monorepo where all these things can live, together and separated at the same time.

how many Gavel implementations in other languages we have

After 6 years of gavel.js existence we still have just gavel.js. The strategy did work out for dredd hooks, but not for gavel. It seems there is no audience to it, people want to use gavel as a core of other tools, not to use it separately. You can see the hopes were different - there's gavel-spec, and there's gavel CLI. I'm not sure how many people use the CLI, TBH, gavel as an end product has never took off.

@artem-zakharchenko
Copy link
Contributor Author

artem-zakharchenko commented Jun 4, 2019

As of 71a02bc, gavel.js is compliant with the next version of gavel-spec (https://github.com/apiaryio/gavel-spec/tree/dcda152fb0f404d25aa90cf656be323502b57640).

Roadmap

  • Ensure method field is validated as per spec (b575e93)
  • Ensure uri field is validated as per spec

bin/gavel Outdated Show resolved Hide resolved
@artem-zakharchenko
Copy link
Contributor Author

artem-zakharchenko commented Jun 11, 2019

Updated data_model steps in 7e48433.

Previously, code snippets described in features were compared to the parsed HTTP message (parsing done as a part of world.js cucumber setup, not a part of the library's API). Parsed HTTP message was wrapped in one of the following classes from the library's API:

  • HttpRequest
  • ExpectedHttpRequet
  • HttpResponse
  • ExpectedHttpResponse

On their own those classes did absolutely nothing to perform the parsing, or affect a provided HTTP message (I omit partial normalization during the validation because this is not what data_model feature asserts).

Since aforementioned classes have been removed from the library's public API, test setup cannot rely on dynamic class instantiation anymore:

const foo = gavel[klass](data)

Also, since gavel[klass] doesn't affect the given payload, there is no need to use it during the assertion. I've removed dynamic class instantiation and compare feature code snippet and parsed HTTP message.

I do, however, find this test useless, as it doesn't involve testing actual library's API, and looks like test for the sake of test. I would vote for removing it, which means removing data_model.feature from gavel-spec as well (not the library's feature and doesn't have to be in the spec).

@artem-zakharchenko
Copy link
Contributor Author

Updated to the latest release of gavel-spec, build passes. Need to ensure clean-up is done, and re-request a code review on this pull request.

@honzajavorek
Copy link
Contributor

Regarding #178 (comment), I think the only benefit left is documenting how over-the-wire HTTP messages map to Gavel input. If we have proper docs about how to run Gavel and how to structure its inputs, I think it is okay to remove the feature.

Copy link
Contributor

@honzajavorek honzajavorek left a comment

Choose a reason for hiding this comment

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

if (string === 'true') return true;
if (string === 'false') return false;
return !!string;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think JSON.parse('false') produces false and JSON.parse('true') produces true. Perhaps we could use it instead, for a simplicity?

Copy link
Contributor Author

@artem-zakharchenko artem-zakharchenko Jun 18, 2019

Choose a reason for hiding this comment

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

How would this work if the string is "abc"?
Calling JSON.parse('abc') will throw, and if the JSON.parse(string) is positioned below the !!string it's rendered useless. Maybe I'm not fully understanding what you meant...

Copy link
Contributor

Choose a reason for hiding this comment

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

I wanted to reply with more context, but then I got stuck not being able to find toBoolean() used. Where is it being called? I couldn't find toCamelCase() or toPascalCase() either.

lib/units/validateURI.js Outdated Show resolved Hide resolved
@artem-zakharchenko
Copy link
Contributor Author

I agree. Data models bear informative value, but they weren't asserting anything in the public's API. As discussed with @kylef, I also voted to include this models in the documentation for general knowledge, but remove from tests.

@artem-zakharchenko
Copy link
Contributor Author

I wonder, would require('url') resolve in the browser? As any dependency, I would expect url to be bundled in order to be executed, yet being a native nodejs dependency I'm not sure what would happen.

@honzajavorek what do you think about this?

query: parseQueryString(queryString)
pathname,
port,
hash,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accounting for previously missing hash in the URI.

BREAKING CHANGE: Gavel no longer exposes "isValidatable" method in its public API
BREAKING CHANGE: Gavel no longer exports "isValid" method from public API. Pleae use "gavel.validate" instead.
BREAKING CHANGE: Calling "gavel.validate" no longer requires the "type" parameter.
BREAKING CHANGE: Gavel no longer exports "HttpRequest" and "HttpResponse" classes. Use "validate" instead.
BREAKING CHANGE: Gavel's call signature of the "validate" function is now the following:
validate(expected, real)
BREAKING CHANGE: "gavel.validate()" no longer accepts a callback as an argument.
Please use the "validate()" function as follows:

const result = gavel.validate(expected, real)
@ApiaryBot
Copy link
Collaborator

🎉 This PR is included in version 6.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@honzajavorek
Copy link
Contributor

I think #178 (comment) is a good point. I'm not sure about the consequences. If relative URLs are an issue my idea was to work around it with prefixing it with example.com just for the sake of parsing, but I see you found solutions already in fcd0ccf

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants