How to use the typesystem.Object function in typesystem

To help you get started, we’ve selected a few typesystem examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github encode / apistar / apistar / schemas / config.py View on Github external
import typesystem

APISTAR_CONFIG = typesystem.Object(
    properties={
        "schema": typesystem.Object(
            properties={
                "path": typesystem.String(),
                "format": typesystem.Choice(choices=["openapi", "swagger"]),
                "base_format": typesystem.Choice(choices=["json", "yaml"]),
            },
            additional_properties=False,
            required=["path", "format"],
        ),
        "docs": typesystem.Object(
            properties={
                "output_dir": typesystem.String(),
                "theme": typesystem.Choice(choices=["apistar", "redoc", "swaggerui"]),
            },
            additional_properties=False,
github encode / apistar / apistar / schemas / swagger.py View on Github external
"description": typesystem.Text(allow_blank=True),
        "name": typesystem.String(),
        "in": typesystem.Choice(choices=["query", "header"]),
        "flow": typesystem.Choice(
            choices=["implicit", "password", "application", "accessCode"]
        ),
        "authorizationUrl": typesystem.String(format="url"),
        "tokenUrl": typesystem.String(format="url"),
        "scopes": typesystem.Reference("Scopes", definitions=definitions),
    },
    pattern_properties={"^x-": typesystem.Any()},
    additional_properties=False,
    required=["type"],
)

definitions["Scopes"] = typesystem.Object(
    pattern_properties={"^x-": typesystem.Any()},
    additional_properties=typesystem.String(),
)


METHODS = ["get", "put", "post", "delete", "options", "head", "patch", "trace"]


def lookup(value, keys, default=None):
    for key in keys:
        try:
            value = value[key]
        except (KeyError, IndexError, TypeError):
            return default
    return value
github encode / apistar / apistar / schemas / swagger.py View on Github external
parameters += operation_info.get("parameters", [])

        fields = [
            self.get_field(parameter, schema_definitions) for parameter in parameters
        ]

        default_encoding = None
        if any([field.location == "body" for field in fields]):
            default_encoding = "application/json"
        elif any([field.location == "formData" for field in fields]):
            default_encoding = "application/x-www-form-urlencoded"
            form_fields = [field for field in fields if field.location == "formData"]
            body_field = Field(
                name="body",
                location="body",
                schema=typesystem.Object(
                    properties={
                        field.name: typesystem.Any()
                        if field.schema is None
                        else field.schema
                        for field in form_fields
                    },
                    required=[field.name for field in form_fields if field.required],
                ),
            )
            fields = [field for field in fields if field.location != "formData"]
            fields.append(body_field)

        encoding = lookup(operation_info, ["consumes", 0], default_encoding)

        return Link(
            name=name,
github encode / apistar / apistar / schemas / openapi.py View on Github external
"MediaType", definitions=definitions
            )
        ),
        "headers": typesystem.Object(
            additional_properties=typesystem.Reference(
                "Header", definitions=definitions
            )
        ),
        # TODO: Header | ReferenceObject
        # TODO: links
    },
    pattern_properties={"^x-": typesystem.Any()},
    additional_properties=False,
)

definitions["MediaType"] = typesystem.Object(
    properties={
        "schema": JSON_SCHEMA | SCHEMA_REF,
        "example": typesystem.Any(),
        # TODO 'examples', 'encoding'
    },
    pattern_properties={"^x-": typesystem.Any()},
    additional_properties=False,
)

definitions["Header"] = typesystem.Object(
    properties={
        "description": typesystem.Text(),
        "required": typesystem.Boolean(),
        "deprecated": typesystem.Boolean(),
        "allowEmptyValue": typesystem.Boolean(),
        "style": typesystem.Choice(choices=["matrix", "label", "form", "simple", "spaceDelimited", "pipeDelimited", "deepObject"]),
github kdebowski / starlette-jsonrpc / starlette_jsonrpc / schemas.py View on Github external
class ErrorSchema(typesystem.Schema):
    code = typesystem.Integer()
    message = typesystem.String()
    data = typesystem.Object(additional_properties=True)


class JSONRPCRequest(typesystem.Schema):
    jsonrpc = typesystem.String(pattern="2.0", trim_whitespace=False)
    id = typesystem.Union(
        any_of=[
            typesystem.String(allow_null=True, min_length=1, trim_whitespace=False),
            typesystem.Integer(allow_null=True),
        ]
    )
    params = typesystem.Union(
        any_of=[typesystem.Object(additional_properties=True), typesystem.Array()]
    )
    method = typesystem.String()


class JSONRPCResponse(typesystem.Schema):
    jsonrpc = typesystem.String(pattern="2.0", trim_whitespace=False)
    id = typesystem.Union(
        any_of=[
            typesystem.String(allow_null=True, min_length=1, trim_whitespace=False),
            typesystem.Integer(allow_null=True),
        ]
    )
    result = typesystem.Any()


class JSONRPCNotificationResponse(typesystem.Schema):
github encode / apistar / apistar / schemas / openapi.py View on Github external
import re
from urllib.parse import urljoin

import typesystem
from apistar.document import Document, Field, Link, Section
from apistar.schemas.jsonschema import JSON_SCHEMA

SCHEMA_REF = typesystem.Object(
    properties={"$ref": typesystem.String(pattern="^#/components/schemas/")}
)
REQUESTBODY_REF = typesystem.Object(
    properties={"$ref": typesystem.String(pattern="^#/components/requestBodies/")}
)
RESPONSE_REF = typesystem.Object(
    properties={"$ref": typesystem.String(pattern="^#/components/responses/")}
)

definitions = typesystem.SchemaDefinitions()

OPEN_API = typesystem.Object(
    title="OpenAPI",
    properties={
        "openapi": typesystem.String(),
        "info": typesystem.Reference("Info", definitions=definitions),
github encode / apistar / apistar / schemas / config.py View on Github external
import typesystem

APISTAR_CONFIG = typesystem.Object(
    properties={
        "schema": typesystem.Object(
            properties={
                "path": typesystem.String(),
                "format": typesystem.Choice(choices=["openapi", "swagger"]),
                "base_format": typesystem.Choice(choices=["json", "yaml"]),
            },
            additional_properties=False,
            required=["path", "format"],
        ),
        "docs": typesystem.Object(
            properties={
                "output_dir": typesystem.String(),
                "theme": typesystem.Choice(choices=["apistar", "redoc", "swaggerui"]),
            },
            additional_properties=False,
        ),
    },
    additional_properties=False,
    required=["schema"],
)
github encode / apistar / apistar / schemas / openapi.py View on Github external
"security": typesystem.Array(
            items=typesystem.Reference("SecurityRequirement", definitions=definitions)
        ),
        "tags": typesystem.Array(
            items=typesystem.Reference("Tag", definitions=definitions)
        ),
        "externalDocs": typesystem.Reference(
            "ExternalDocumentation", definitions=definitions
        ),
    },
    pattern_properties={"^x-": typesystem.Any()},
    additional_properties=False,
    required=["openapi", "info", "paths"],
)

definitions["Info"] = typesystem.Object(
    properties={
        "title": typesystem.String(allow_blank=True),
        "description": typesystem.Text(allow_blank=True),
        "termsOfService": typesystem.String(format="url"),
        "contact": typesystem.Reference("Contact", definitions=definitions),
        "license": typesystem.Reference("License", definitions=definitions),
        "version": typesystem.String(allow_blank=True),
    },
    pattern_properties={"^x-": typesystem.Any()},
    additional_properties=False,
    required=["title", "version"],
)

definitions["Contact"] = typesystem.Object(
    properties={
        "name": typesystem.String(allow_blank=True),
github encode / apistar / apistar / schemas / swagger.py View on Github external
definitions["Responses"] = typesystem.Object(
    properties={
        "default": typesystem.Reference("Response", definitions=definitions)
        | RESPONSE_REF
    },
    pattern_properties={
        "^([1-5][0-9][0-9]|[1-5]XX)$": typesystem.Reference(
            "Response", definitions=definitions
        )
        | RESPONSE_REF,
        "^x-": typesystem.Any(),
    },
    additional_properties=False,
)

definitions["Response"] = typesystem.Object(
    properties={
        "description": typesystem.String(allow_blank=True),
        "content": typesystem.Object(
            additional_properties=typesystem.Reference(
                "MediaType", definitions=definitions
            )
        ),
        "headers": typesystem.Object(
            additional_properties=typesystem.Reference(
                "Header", definitions=definitions
            )
        ),
        # TODO: Header | ReferenceObject
        # TODO: links
    },
    pattern_properties={"^x-": typesystem.Any()},