interagent / interagent/committee

How can I use a hyperschema that references external schemas?

Open
#60 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
955
Forks
145
Avg merge
5d 4h
Merged PRs (30d)
6

Description

Hello, I started this question as a comment at brandur/json_schema#22, but it's perhaps more appropriate here.

I'd like to break my API hyperschema into a separate files for better modularity and easier management; and in fact I may want to refer to schemas that are defined externally, but I'm not certain how to do that with Committee:Middleware::RequestValidation.

For example, the hyperschema might include something like:

"links": [
    {
      "description": "Create a widget",
      "href": "/widgets",
      "method": "POST",
      "rel": "create",
      "title": "Create Widget",
      "schema": { "$ref": "file://schemas/widget-create-request.schema.json" },
      "targetSchema": { "$ref": "file://schemas/widget-create-response.schema.json" }
    },
    ...
  ]

The request and response schemas might themselves refer to a URI for an externally-defined widget schema, e.g. something like:

{
    "type": "object",
    "properties": {
         "metadata": { "type": "object" }
         "widget": { "$ref": "http://widget-host.com/schemas/widget.schema.json" }
    },
    "required": ["widget"]
}

In the discussion at brandur/json_schema#22 it seems that one must set things up to use "id" rather than $ref, and must pre-load the external schemas into a JsonSchema::DocumentStore which is then used to expand references on a JsonSchema object.

I can probably figure out the use of "id" in my schemas, but how can I use JsonSchema::DocumentStore when configuring the middleware -- there's no documented parameter for it at:

 use Committee::Middleware::RequestValidation, schema: JSON.parse(File.read(...))

Thanks for any advice!

PS. Lacking anything else, I'll probably do a preprocessing step on my own to load the schema and recursively expand $ref's, before passing it to use Committee::Middleware::RequestValidation. Not the most elegant thing in the world, but should work.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Committee::Middleware::RequestValidation and the documented schema configuration, then trace how JsonSchema::DocumentStore is expected to relate to external references. No file or test is named; done would be documentation that explains whether and how external schemas can be configured, including the role of id and $ref.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, backend
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.