Page MenuHomePhabricator

Proposal: introduce RESTEntityFormatter
Closed, DuplicatePublic

Description

As we're working on the common schemas for common entities in MW REST API responses, we could introduce an MW service, RESTEntityFormatter (name TBD). The service would have methods for serializing common MW entities (RevisionRecord, UserIdentity etc) into defined schemas.

The service could be injected into handlers when needed and would contain the collection of formatter functions, like formatRevision( RevisionRecord $rev), returning an JSON-strigifyable array according to the specified schema.

Complications to consider:

  • Formatters for some of the entities might depend on more services. For example, to format a revision and calculate a 'delta' we might need RevisionLookup to fetch the parent revision. Perhaps splitting formatters into separate classes would allow us to have less dependencies.
  • Sometimes formatters can be optimized by the context that's already known in a handler. Example: revision 'delta' property can be calculated with less queries if the whole list of revisions is being processed. We could make the formatters have formatRevisionList method, but it's quite ugly..

What do you think? The output of this task would be a decision of whether we want to do something like this or not, and how do we want to do it.

Event Timeline

we could introduce an MW service

I wonder whether this should be done via composition or traits rather than as a global service.

The advantage to that would be avoiding the addition of a public global service for internal functionality. Disadvantages include having to inject into the handler any dependencies of the composed class (although for example something needing formatting of revisions probably already needs RevisionStore to fetch the revisions in the first place).

kchapman added subscribers: daniel, santhosh, kchapman.

@Pchelolo this is also something that the FAWG is talking about as well. @santhosh and @daniel this might be of interest to you.

I'm closing this as a duplicate of T252145 - that approach would be better since not all the representations exist as core MW concepts.