Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Extending JSON-API compatibility #5

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

signal-intrusion
Copy link

@signal-intrusion signal-intrusion commented Jan 31, 2017

I'm experimenting with added support for compound documents and resource identifier objects based on work started by @joshuamiller.

Example map returned from request handler:

{
  :data {...
         :resource-identifiers [{:type "heroes" :id 1}]
         ...}
  :included {:heroes [{:id 1 :name "Jason"}]
                   :ally {:id 2 :name "Medea"}}
}

@stephenmuss
Copy link
Owner

By all means please feel free to continue. Thanks for your interest.

@signal-intrusion signal-intrusion changed the title [WIP] Extending JSON-API compatibility Extending JSON-API compatibility Feb 12, 2017
@signal-intrusion
Copy link
Author

@stephenmuss I finished up work on extending argo to handle included resources. I have on place that may need a review.

Thanks again.

@stephenmuss
Copy link
Owner

Thank you very much. When I get some spare time over the course of the week I will review it.

@stephenmuss
Copy link
Owner

I'm getting an exception when running the example app and requesting /v1/achievments/1

java.lang.ClassCastException: clojure.lang.MapEntry cannot be cast to clojure.lang.IPersistentMap
                                  RT.java:758 clojure.lang.RT.dissoc
                                core.clj:1434 clojure.core/dissoc
                                 core.clj:119 argo.core/x-to-api
                              RestFn.java:445 clojure.lang.RestFn.invoke
                                 core.clj:133 argo.core/build-included[fn]
                                core.clj:2559 clojure.core/map[fn]
                              LazySeq.java:40 clojure.lang.LazySeq.sval
                              LazySeq.java:49 clojure.lang.LazySeq.seq
                                  RT.java:484 clojure.lang.RT.seq
                                 core.clj:133 clojure.core/seq
                             generate.clj:127 cheshire.generate/generate
                             generate.clj:119 cheshire.generate/generate
                                  core.clj:32 cheshire.core/generate-string
                                 AFn.java:156 clojure.lang.AFn.applyToHelper
                                 AFn.java:144 clojure.lang.AFn.applyTo
                                 core.clj:626 clojure.core/apply
                                core.clj:5698 clojure.core/update-in
                              RestFn.java:467 clojure.lang.RestFn.invoke
                                  json.clj:67 ring.middleware.json/wrap-json-response[fn]
                                 Var.java:379 clojure.lang.Var.invoke
                                reload.clj:22 ring.middleware.reload/wrap-reload[fn]
                            stacktrace.clj:23 ring.middleware.stacktrace/wrap-stacktrace-log[fn]
                            stacktrace.clj:86 ring.middleware.stacktrace/wrap-stacktrace-web[fn]
                                 jetty.clj:20 ring.adapter.jetty/proxy-handler[fn]
                             (Unknown Source) ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle
                      HandlerWrapper.java:116 org.eclipse.jetty.server.handler.HandlerWrapper.handle
                              Server.java:369 org.eclipse.jetty.server.Server.handle
              AbstractHttpConnection.java:486 org.eclipse.jetty.server.AbstractHttpConnection.handleRequest
              AbstractHttpConnection.java:933 org.eclipse.jetty.server.AbstractHttpConnection.headerComplete
              AbstractHttpConnection.java:995 org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete
                          HttpParser.java:644 org.eclipse.jetty.http.HttpParser.parseNext
                          HttpParser.java:235 org.eclipse.jetty.http.HttpParser.parseAvailable
                  AsyncHttpConnection.java:82 org.eclipse.jetty.server.AsyncHttpConnection.handle
               SelectChannelEndPoint.java:668 org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle
                SelectChannelEndPoint.java:52 org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run
                    QueuedThreadPool.java:608 org.eclipse.jetty.util.thread.QueuedThreadPool.runJob
                    QueuedThreadPool.java:543 org.eclipse.jetty.util.thread.QueuedThreadPool$3.run
                              Thread.java:745 java.lang.Thread.run

@signal-intrusion
Copy link
Author

@stephenmuss Fixed the bug which also makes the feature more tolerant of different data structures being passed as :included resources.

I also added birthplace to the attributes returned for /achievements/:id/hero.

@stephenmuss
Copy link
Owner

Thanks. I'll check it out.

@stephenmuss
Copy link
Owner

I think when we have included resources we will also need to include the data member in the relationships object.

e.g.

"relationships": {
  "hero": {
    "links": {
      "related": "/v1/achievements/1/hero"
    },
    "data": {
      "type": "heroes",
      "id": "1"
    }
  }
}

http://jsonapi.org/format/#document-resource-object-relationships

@signal-intrusion
Copy link
Author

Looks like you're right about that: Compound documents require “full linkage”, meaning that every included resource MUST be identified by at least one resource identifier object in the same document.

I'll work on that this week.

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

Successfully merging this pull request may close these issues.

3 participants