Problem/Motivation
Currently the UI is using mock http requests
We would like to build Drupal controllers to support these
In order to do so we should document the required endpoints with Open API
See https://git.drupalcode.org/project/decoupled_lb_api/-/blob/1.x/openapi.s... for an example
Proposed resolution
- ✅
Document API requirements with Open API. - ✅
Test that the OpenAPI spec is valid. - ✅
Test that the fixtures inui/src/mocks/fixturesmatch the OpenAPI spec, which proves the client (XB React UI) conforms to the OpenAPI spec - ✅
Test that requests generated by the OpenAPI spec result in successful responses from the server, proving that the server (Drupal XB module) conforms to the OpenAPI spec
User interface changes
- Before

- (Also currently live at https://project.pages.drupalcode.org/experience_builder/)
- After

(but since making these screenshots, #3460952: Implement add button for top level item (section) landed, which changed the mock fixtures, so it'll look different now)
| Comment | File | Size | Author |
|---|---|---|---|
| #22 | Screenshot 2024-08-06 at 4.56.48 PM.png | 224.39 KB | wim leers |
| #22 | Screenshot 2024-08-06 at 4.56.28 PM.png | 193.85 KB | wim leers |
| #5 | 3450308-openapi-spec.yml | 2.25 KB | pfrilling |
Issue fork experience_builder-3450308
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
larowlanComment #3
wim leersFYI: the
FieldForComponentSuggesterservice added in https://git.drupalcode.org/project/experience_builder/-/merge_requests/2... should provide a solid foundation one of the API responses we'll need ()Comment #4
wim leersAny takers? Capturing the current mock requests + responses in this way sure would be beneficial, because we'd be able to evolve the OpenAPI schema, which would auto-document the evolution of the communication between client & server!
Comment #5
pfrillingLooking through the handlers mock, I started the attached OpenAPI spec. It's still a work in progress, but I think it is a good starting point. Let me know what I missed and I can continue updating the spec.
Comment #6
wim leersThanks, @pfrilling! 🤩
Could you convert that to an MR? 🙏 And could you add the
SchemaValidationTestthat verifies this Open API spec is itself valid? You can pretty much copy/paste it from @larowlan's work at https://git.drupalcode.org/project/decoupled_lb_api/-/commit/84bf1e54153... 😄How do we validate this, and how do we keep it in sync with the reality? 🤔
Comment #7
larowlanWe can also write a test that loads the fixtures from UI and validates them AND uses drupalGet to load the controllers and validate them.
Compliance all round 💪
Comment #8
wim leersThat'd be amazing and what I'd hope for — because in a heterogeneous project like this (geographically, timezone-wise, employment-wise, availability-wise), that's really valuable!
Comment #10
syeda-farheen commentedHi @pfrilling,
Can you brief me about the above merge request and how this issue needs further work?
Comment #11
wim leers@syeda-farheen:
Clarified issue summary.
Comment #12
wim leersGiven @syeda-farheen is not responding, assuming they're no longer working on this. Asking @TravisCarden to push this to completion, after he's done with #3458369: DDEV support for Cypress tests 😊
Comment #13
wim leersImportance/impactfulness of this confirmed one more at #3458683: Mock fixtures missing `field_data`.
Bumping to .
Comment #14
pfrillingThis has been resolved and the API Spec test should be passing now.
> # 1 The new test is failing:
Do you have any examples for testing the fixtures against the spec? If not, I'll start researching how to make that happen.
Comment #15
wim leersI don't — I have zero experience with Open API 😅
But a quick search in @larowlan's
decoupled_lb_apimodule reveals https://git.drupalcode.org/project/decoupled_lb_api/-/blob/1.x/tests/src..., whoseassertDataCompliesWithApiSpecification()achieves exactly that :)Comment #16
wim leersThe tests that we add here should fail, because they should automatically identify #3458683: Mock fixtures missing `field_data`.
Comment #17
pfrillingTests have been added to confirm that the UI fixtures are validating against the Open API Spec. This should resolve #3.
Comment #18
wim leersOMG that's exciting! 🤩 And it's passing tests, too! 🚀
Comment #19
wim leersComment #20
wim leers#3460952: Implement add button for top level item (section) conflicted with this, merged in upstream and accepted upstream changes to the mocks.
Comment #21
wim leersThis was causing increasing frustration for @jessebaker, @bnjmnm and @hooroomoo, and was slowing down @tedbow while working on #3446722: Introduce an example set of representative SDC components; transition from "component list" to "component tree", so I took this on.
This is now ready for final review.
Comment #22
wim leers@jessebaker & @bnjmnm FYI, based on the discussion y’all had yesterday, I prioritized this issue today. Result:
Result:
npm run devworks again:(but since making these screenshots, #3460952: Implement add button for top level item (section) landed, which changed the mock fixtures, so it'll look different now)
Assigning to @bnjmnm for review, since it's close to @jessebaker's workday.
Comment #23
wim leersBut it still might make sense to delete the mocks+MSW functionality, if @bnjmnm and @jessebaker decide it's not relevant anymore.
However, if we do that, we should also get rid of the GitLab Pages CI job, which would remove the static UI demo.
If that's the case, then we should IMHO still land this first and then delete the mocks in a different issue. Because that'll make it easier to someday restore it if that'll ever make sense. I propose to repurpose #3458683: Mock fixtures missing `field_data` in that case.
Comment #24
larowlanIt's a pity we can't have MSW wire up to cy.intercept and have the best of both worlds
Comment #25
wim leers@bnjmnm didn't get to this yesterday; so re-assigning to @jessebaker at his start of day 🤞
Comment #26
wim leers@jessebaker approved this 🥳 Hence reflecting that here by marking .
Note that the
phpunit (next major)CI job is failing though:For those 45 deprecations, I already opened #3466534: Fix PHPUnit 11 deprecations when tested with Drupal 11 (it's happening on HEAD too). That 1 error I'll need to figure out here prior to merging.
Comment #27
wim leersAlso, @jessebaker did point out that
is not quite accurate. It's currently required. I did that because I want developers of XB to be aware of violations of the OpenAPI spec. But … actually doing that conditionally (if those deps are installed) would be better.
Did that in https://git.drupalcode.org/project/experience_builder/-/merge_requests/5... 👍
Comment #28
wim leersRE the error described in #26:
cebe/php-openapiis getting installed: https://git.drupalcode.org/project/experience_builder/-/jobs/2359889WTAF?!
Well … AFAICT the reason is Drupal 11 requires Symfony 7, and that is not yet allowed by
cebe/php-openapi: https://github.com/cebe/php-openapi/pull/203 + https://github.com/cebe/php-openapi/pull/202.That last link points to https://github.com/DEVizzent/cebe-php-openapi, which … is a fork because the original is no longer maintained 🤷♂️
So obviously the ecosystem is switching over. Did the same here.
Bonus: upgrade to OpenAPI 3.1 (released in Feb 2021), which was a major motivator for people forking that library! 🎉
Comment #30
wim leersSo I just read https://lornajane.net/posts/2020/whats-new-in-openapi-3-1 and found several things that I could not get to work to be fixed now! So refined the OpenAPI spec some more.
I noticed that the examples visible in GitLab's OpenAPI visualization at https://git.drupalcode.org/issue/experience_builder-3450308/-/blob/34503... were off … so I tried improving that using https://editor.swagger.io/, but that does not support OpenAPI 3.0.
Then found https://editor-next.swagger.io/ and … that works perfectly. With live updating, even!
I did not make material changes since @jessebaker approved this, I only made it not get in the way (see #27) and pass tests against Drupal 11/Symfony 7 (see #26 and #28). And then I added finishing touches (see this comment.)
So: merging 🚢
Comment #31
wim leersActually, the title has been inaccurate all along 😅 Fixed that, and created a follow-up for doing that other part: #3466555: Also validate request bodies against the OpenAPI spec.
Comment #33
wim leers