Hi All,
I'm writing an API module that I'd like to take 'complex' data for one of the parameters, e.g.
{ "action": "example", "token": "<some csrf token>", "data": [ {"key": "value1", "otherkey": "othervalue1"}, {"key": "value2", "otherkey": "othervalue2", "optionalkey": "optionalvalue"}, {"key": "value3", "otherkey": "othervalue3"} ] }
The list in data can grow to several hundred elements all of which contain the same 2 keys with an optional third. For reference, I'm developing on mw1.31, but I can swap to something more recent if that's where new possibilities become available.
This module takes POST requests, so I'd just send it as part of the request body, but when it comes to deserialising it, I'm not really sure what to deserialise it to as everything seems to assume primitive values, e.g. strings, integers, etc. when it comes to setting the parameter type. I'm not averse to claiming it's a string and deserialising it myself, but my attempts so far haven't proved successful. I also tried writing a phpunit test which displayed different behaviour (it seems to have quietly lost the value) and using the mwapi python library for an integration/end-to-end test which caused a third behaviour by quietly joining the elements in the list into a string. I get the feeling what I'm trying to do is at the very least non-standard for mediawiki.
Does anyone have experience in trying to do this or know of prior art that does something similar?
Cheers, Matt
Wikibase has several API modules which take JSON blobs of varying sizes as text parameters, e. g. wbsetclaimvalue [1] or wbeditentity [2].
Cheers, Lucas
[1]: https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/Wikibase... [2]: https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/Wikibase...
On 25.02.20 00:00, Matthew Dowdell wrote:
Hi All,
I'm writing an API module that I'd like to take 'complex' data for one of the parameters, e.g.
{ "action": "example", "token": "<some csrf token>", "data": [ {"key": "value1", "otherkey": "othervalue1"}, {"key": "value2", "otherkey": "othervalue2", "optionalkey": "optionalvalue"}, {"key": "value3", "otherkey": "othervalue3"} ] }
The list in data can grow to several hundred elements all of which contain the same 2 keys with an optional third. For reference, I'm developing on mw1.31, but I can swap to something more recent if that's where new possibilities become available.
This module takes POST requests, so I'd just send it as part of the request body, but when it comes to deserialising it, I'm not really sure what to deserialise it to as everything seems to assume primitive values, e.g. strings, integers, etc. when it comes to setting the parameter type. I'm not averse to claiming it's a string and deserialising it myself, but my attempts so far haven't proved successful. I also tried writing a phpunit test which displayed different behaviour (it seems to have quietly lost the value) and using the mwapi python library for an integration/end-to-end test which caused a third behaviour by quietly joining the elements in the list into a string. I get the feeling what I'm trying to do is at the very least non-standard for mediawiki.
Does anyone have experience in trying to do this or know of prior art that does something similar?
Cheers, Matt
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
https://phabricator.wikimedia.org/T182475 has some related discussion. These days though, you are probably better off implementing it as a REST API (requires 1.34).
Hi Mathew,
With java api I generated the json object, and edit item with a python script. Yo can do the same procedure with the many available apis in java, python, js.
Regards
Luis
Matthew Dowdell mdowdell244@gmail.com hat am 25. Februar 2020 um 00:00 geschrieben:
Hi All, I'm writing an API module that I'd like to take 'complex' data for one of the parameters, e.g. { "action": "example", "token": "<some csrf token>", "data": [ {"key": "value1", "otherkey": "othervalue1"}, {"key": "value2", "otherkey": "othervalue2", "optionalkey": "optionalvalue"}, {"key": "value3", "otherkey": "othervalue3"} ] } The list in data can grow to several hundred elements all of which contain the same 2 keys with an optional third. For reference, I'm developing on mw1.31, but I can swap to something more recent if that's where new possibilities become available. This module takes POST requests, so I'd just send it as part of the request body, but when it comes to deserialising it, I'm not really sure what to deserialise it to as everything seems to assume primitive values, e.g. strings, integers, etc. when it comes to setting the parameter type. I'm not averse to claiming it's a string and deserialising it myself, but my attempts so far haven't proved successful. I also tried writing a phpunit test which displayed different behaviour (it seems to have quietly lost the value) and using the mwapi python library for an integration/end-to-end test which caused a third behaviour by quietly joining the elements in the list into a string. I get the feeling what I'm trying to do is at the very least non-standard for mediawiki. Does anyone have experience in trying to do this or know of prior art that does something similar? Cheers, Matt _______________________________________________ Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Luis Ramos
Senior Java Developer
(Semantic Web Developer)
PST.AG
Jena, Germany.
On Mon, Feb 24, 2020 at 6:01 PM Matthew Dowdell mdowdell244@gmail.com wrote:
This module takes POST requests, so I'd just send it as part of the request body, but when it comes to deserialising it, I'm not really sure what to deserialise it to as everything seems to assume primitive values, e.g. strings, integers, etc. when it comes to setting the parameter type.
The Action API is generally based around a "form" model, and submission of complex data structures is generally discouraged. If you really need to do so anyway, you might accept data as a JSON string, or possibly you might use the "templated parameters" added in 1.32.
MediaWiki now (since 1.34) also has a REST API. There the convention is to accept JSON data structures via POST or PUT, ideally validated against a JSON Schema of some sort.
On Tue, 25 Feb 2020, 19:04 Brad Jorsch (Anomie), bjorsch@wikimedia.org wrote:
On Mon, Feb 24, 2020 at 6:01 PM Matthew Dowdell mdowdell244@gmail.com wrote:
This module takes POST requests, so I'd just send it as part of the request body, but when it comes to deserialising it, I'm not really sure what to deserialise it to as everything seems to assume primitive values, e.g. strings, integers, etc. when it comes to setting the parameter type.
The Action API is generally based around a "form" model, and submission of complex data structures is generally discouraged. If you really need to do so anyway, you might accept data as a JSON string, or possibly you might use the "templated parameters" added in 1.32.
MediaWiki now (since 1.34) also has a REST API. There the convention is to accept JSON data structures via POST or PUT, ideally validated against a JSON Schema of some sort.
-- Brad Jorsch (Anomie) Senior Software Engineer Wikimedia Foundation _______________________________________________ Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Thanks for the advice all. I think the REST API is the most promising avenue of investigation and the interface I was hoping to discover, so thanks to those who directed me towards it. The existing history implementation looks particularly helpful as I've got something similar to implement. For now I'll likely use the approach used by Wikibase with JSON strings but aim to migrate over to coincide with the release of 1.35 (which will be the next proper upgrade for my target wiki).
I haven't seen it mentioned in the docs so far, but is there support for defining the interface using swagger/openapi? Given how tied into MediaWiki the server will be it seems unlikely, but I figured it was worth asking in case it was on a roadmap somewhere.
Cheers, Matt
On Tue, Feb 25, 2020 at 3:17 PM Matthew Dowdell mdowdell244@gmail.com wrote:
I haven't seen it mentioned in the docs so far, but is there support for defining the interface using swagger/openapi? Given how tied into MediaWiki the server will be it seems unlikely, but I figured it was worth asking in case it was on a roadmap somewhere.
Not for the Action API or the MediaWiki REST API. The closest current plan I'm aware of is a suggestion to generate a swagger/openapi spec *from* the MediaWiki REST API (for use by clients that can do something useful with such a spec), but that's kind of the opposite of what you asked about.
RestBase/RestRouter does use swagger, I think.
mediawiki-api@lists.wikimedia.org