Skip to main content

Local filesystem based JSON catalogue, usable e.g. with package `jsonschema`

Project description

Package jsoncatalogue allows reading set of JSON files from directory structure resembling urls.

Files are loaded and provided as simple url: jsoncontent dictionary.

Such a dictionary can be used as catalogue of JSON schemas for JSON Schema validation.

Installation

$ pip install jsoncatalogue

Structure of directory with JSON files

If you want to have catalogue for Swagger v1.2 validation:

./catalogue/http/wordnik.github.io/schemas/v1.2/apiDeclaration.json
./catalogue/http/wordnik.github.io/schemas/v1.2/infoObject.json
./catalogue/http/wordnik.github.io/schemas/v1.2/authorizationObject.json
./catalogue/http/wordnik.github.io/schemas/v1.2/modelsObject.json
./catalogue/http/wordnik.github.io/schemas/v1.2/operationObject.json
./catalogue/http/wordnik.github.io/schemas/v1.2/parameterObject.json
./catalogue/http/wordnik.github.io/schemas/v1.2/dataTypeBase.json
./catalogue/http/wordnik.github.io/schemas/v1.2/oauth2GrantType.json
./catalogue/http/wordnik.github.io/schemas/v1.2/resourceObject.json
./catalogue/http/wordnik.github.io/schemas/v1.2/dataType.json
./catalogue/http/wordnik.github.io/schemas/v1.2/resourceListing.json

where

  • catalogue - is catalogue “home” directory (can be deeper)

  • http- is protocol name. Can be any other, like ftp

  • wordnik.github.io - domain name

  • schemas/v1.2 - local path to JSON files

  • apiDeclaration.json - actual JSON file - must be valid JSON file (no other requirement exist)

As you see, there are no complex rules to follow, just have uri leading to valid JSON file (which is not even required to have an extension “.json”)

Loading JSON Catalogue from directory

>>> from jsoncatalogue import Catalogue
>>> catalogue = Catalogue()
>>> catalogue.add_directory("catalog")
>>> catalogue.add_directory("../other/catalog")
>>> catalogue.store
{"http://exam.ple/schema/one.json": {...},
 "http://exam.ple/schema/two.json": {...},
 "http://wordnik.github.io/schema/v1.2/apiAuthentication.json": {...}
 "http://no.extensi.on/schema/pets": {...}
 }

And this is all. You now have a dictionary with uris and related JSON content. The JSON content is already loaded and is represented as dictionary.

Using catalogue for JSON Schema validator

This catalogue.store can be assigned e.g. to jsonschema validator:

>>> from jsonschema import Draft4Validator
>>> validator = Draft4Validator()
>>> validator.resolver.store = catalogue.store

From now on, validator will know about schemas from catalogue

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsoncatalogue-0.1.1.tar.gz (9.0 kB view details)

Uploaded Source

File details

Details for the file jsoncatalogue-0.1.1.tar.gz.

File metadata

File hashes

Hashes for jsoncatalogue-0.1.1.tar.gz
Algorithm Hash digest
SHA256 35b8514f25a6fb1771220334e45049a65a50125d2d727a4471d8c01e86b478d6
MD5 f351e935df00812a2dde9f88fd00473e
BLAKE2b-256 011fefea3ac5b0e02bd629ae0ab3c5a76eb1eafedab26edcf62ba59e3631bd5c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page