Okay I found the first problem with a step debugger. The schema validation successfully validates with the first schema; validation is passed for entirely every single key-value pair, including the nested parts. That even with type="object". The problem seems to be that, in the file wp-includes/rest-api.php, in the method rest_find_one_matching_schema(), the validation continues with the second schema, although the retrieved value has been fully validated.
And this because $stop_after_first_match in the method mentioned above has a value of false. Then, after proceeding with the validation, it of course fails, as the validation fails with the second schema, which no longer matches. Now I just gotta find out by what that $stop_after_first_match value is controlled..
Turns out it cannot be controlled. The core file wp-includes/rest-api.php/` via the method rest_validate_value_from_schema(), calls rest_find_one_matching_schema()with the default value of false for $stop_after_first_match. Ergo, the validation will actually never stop after the first matching schema; leading to the resulting validation always to be null.
@bosco If I do this, "meta" : []is present in the response, so this does not solve the problem.
I guess I'll open a new question about this one; it seems to be a tricky one..
It doesn't for me, but I think I'm figuring it out slowly why..
Currently, it's looking like you must completely omit the type key in the array where you specify the oneOf key. Otherwise core scans for a properties key within your array where the oneOfkey lies, resulting in a complete chain of messes
Omitting the type key did not work for me - only explicitly setting it to null. I certainly haven't dug into the issue as far as you have, but I can provide the specifics of my test in any scenario. The schema I used was identical to the one you provided above, with only that modification: hastebin.com/imohutosif.php
(and registering the meta to post)
Oh hmm
I might have to eat my words - it's not presently reproducing
On a side note, on reviewing my test case, I see now that I omitted the 'type'=>'object' argument for the meta registration. However, after adding it both requests continue to operate as before
Due to exactly that type => object mapping, core scans your $args array as an object with your matched schema! This is the last problem I have, actually
You mean you omitted the type => object mapping within $args ? Or within schema?
Works: Checks for the first schema and validates Works: Checks for the second schema and fails Works: Verifies that exactly one schema is matched, and store that schema successfully under $matching_schema.
The problem now seems to be that, due to the 'type' => 'object' present within the $args array provided to your schema, it relaunches a new validation with $matching_schema against your $args array, which of course fails, then returns `null` for your meta. That's the current point of failure.
I mean I took so much of your time already, so I feel bad for asking for more. If you still have the nerves to register a custom post type and do it for that one, let me know. But I completely understand if you don't want to..
Yes there's actually little difference in between register_post_meta() and register_meta(), I can't imagine that it returns something different. If the result is the same, I'll do just do two different meta fields and relate the retrieval to the value of a custom taxonomy to know which one to retrieve.
That'd be authorization rather than authentication
Easiest way to authenticate for dev is to create an "App Password" for your user Dashboard > Users > {User profile} > scroll to the bottom, add a new one titled whatever
> A lot of the GET requests are completely public, but most every request which can modify data will require authentication
That is, for the core routes, anyway. The core routes' authorization is handled automatically based on user roles/capabilities - if a piece of content would usually be publicly available on the front-end of the site, so too is it on the REST API. If a WordPress user has the capabilities to manage users or plugins on the dashboard - so too will they be able to over the REST API.
You can use the automatic roles & capabilities checks for your own routes - or customize them however you see fit with those auth_callbacks
I've also coupled that stuff to the session management, and related an additional nonce I generate (as you must set the REST's nonce value to wp_rest) to something related to the session ID, retrieved post-authentication
@DevelJoe I feel that - totally my last few days on a project
@DevelJoe Cookie auth/app password auth are separate mechanisms. You can use one or the other. If you've got cookie auth already working, you shouldn't need to go the app password route - I just find it a lot easier for dev and testing
Maybe also worth a mention that some security plugins disable app passwords by default - but if you were able to see/create one from your user profile, then it should be enabled
Just about - I think I might have modified some required keywords when I was converting to JSON to test some things in a JSON Schema validator. But otherwise I think it's 1:1 - hastebin.com/imohutosif.php
(well, apart from the type => null, and the type => object arg that's missing from that hastebin)
You have any idea about how long such bugs take to be fixed? Where can I report that thing?
And you know what. Can I maybe send you a new somewhat more complex schema-couple? Again, I understand if you don't want, but it's literally the last idea I have
WordPress core issues are tracked in Trac using your wordpress.org profile, and for everything Gutenberg it's just the wordpress/gutenberg GitHub repo. This would go to Trac!
Core issues can take from weeks to... many years in some cases. Given the prominence of the REST API I'd reckon within a release or two, at least so far as to eliminate the current work-around for the strange behavior.
If you manage to get things working by submitting a new purchase_details meta via add_post_meta() and then retrieve that with the value not being null, I officially give up. If you could exactly use my callback hastebin.com/xanafuteba.php; and not change anything in the schema, that would be really helpful!