Brian
Brian

Reputation: 3334

How can I extract a JSON schema from Open API file for specific interface?

I am working with an Open API file that has multiple interfaces described in it. What I would like to do is extract programmatically the JSON schema for a particular interface and publish that schema externally so that it can be used to do message verification remotely.

Seems like this is the kind of thing that would be needed very often but I'm not finding a solution and I would hate to have to build my own.

In my wildest dreams, I would find a library that did something like this:

import magicOASLibrary

helloWorldSchema = magicOASLibary.getSchema("OASFile.json", "/helloworld", "get")

Upvotes: 2

Views: 1070

Answers (1)

Ether
Ether

Reputation: 53996

What you're looking for is an implementation of the JSON Pointer syntax.

  1. read the file from disk
  2. decode the JSON into a data structure
  3. use JSON Pointer syntax to find the right position in the data structure.

In Perl, I'd use Mojo::JSON::Pointer (or JSON::Pointer, which is older but seems to work just fine), but I can't give any advice for Python.

Upvotes: 1

Related Questions