Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

schemax

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

schemax

district42 to JSON-Schema translator and vise versa

  • 1.0.0
  • PyPI
  • Socket score

Maintainers
1

SchemaMaximal

PyPI PyPI - Downloads Python Version

district42 schemas ⇆ JSON Schema

Installation

pip3 install schemax

Usage

Translation

>>> import schemax
>>> from d42 import schema
>>> ExampleSchema = schema.str.len(1, 10)
>>> schemax.to_json_schema(ExampleSchema)
{'type': 'string', 'minLength': 1, 'maxLength': 10}

Also, you could use schemax to translate from JSON-Schema to d42 and generate tests interfaces (in future releases) via command line:

$ schemax translate schema.json
Translation from JSON-Schema to d42-schema for schema.json:
schema.dict({
    'number': schema.int.min(1),
    optional('street_name'): schema.str,
    ...: ...
})

schema.json:

{
  "type": "object",
  "properties": {
    "number": { "type": "integer", "minimum": 1 },
    "street_name": { "type": "string" }
  },
  "required": ["number"],
  "additionalProperties": true
}

Generation

schemax generate my-schema.yml

This command will generate request and response schemas files, API interface and basic scenarios.

You could add basic url to your API as following: --base-url="http://api.example.com".

Making your schemas and interfaces more "friendly" could --humanize flag.

Using SchemaData object in code

import yaml
from schemax import collect_schema_data, SchemaData 

from typing import List

# Also could be JSON OpenAPI file
with open('my_openapi.yaml') as schema_file:
    raw_schema = yaml.load(schema_file, yaml.FullLoader)
    
    parsed_data: List[SchemaData] = collect_schema_data(raw_schema)
    for item in parsed_data:
        print(item.path)
        print(item.response_schema_d42)
        ...

All the data is stored in SchemaData object, which has the following fields:

  • http_method: HTTP method of the request.
  • path: URL path of the request.
  • converted_path: URL path converted to the camel-case for usage in schemax generation.
  • args: Arguments of the request.
  • queries: Query parameters of the request. Currently unsupported and always '[]'.
  • interface_method: Interface name for usage in schemax generation.
  • interface_method_humanized: Interface 'humanized' name for usage in schemax generation.
  • status: Status code for specified schemas.
  • schema_prefix: Schema prefix name for usage in schemax generation.
  • schema_prefix_humanized: Schema prefix 'humanized' name for user in schemax generation.
  • response_schema: Normalized response schema (without $ref).
  • response_schema_d42: Converted to d42 response_schema.
  • request_schema: Normalized request schema (without $ref).
  • request_schema_d42: Converted to d42 request_schema.
  • tags: Tags of the request from OpenAPI schema.

Supported d42 -> JSON Schema types and features

(✅ - done; 🔧 - planned support; ❌ - unsupportable)

Supported JSON Schema -> d42 types and features

(✅ - done; 🔧 - planned support; ❌ - unsupportable)

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc