How to use the typesystem.from_json_schema 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 / openapi.py View on Github external
"""
        Return a single field in a link.
        """
        name = parameter.get("name")
        location = parameter.get("in")
        description = parameter.get("description")
        required = parameter.get("required", False)
        schema = parameter.get("schema")
        example = parameter.get("example")

        if schema is not None:
            if "$ref" in schema:
                ref = schema["$ref"]
                schema = schema_definitions.get(ref)
            else:
                schema = typesystem.from_json_schema(
                    schema, definitions=schema_definitions
                )

        return Field(
            name=name,
            location=location,
            description=description,
            required=required,
            schema=schema,
            example=example,
        )
github encode / apistar / apistar / schemas / openapi.py View on Github external
def get_schema_definitions(self, data):
        definitions = typesystem.SchemaDefinitions()
        schemas = lookup(data, ["components", "schemas"], {})
        for key, value in schemas.items():
            ref = f"#/components/schemas/{key}"
            definitions[ref] = typesystem.from_json_schema(
                value, definitions=definitions
            )
        return definitions
github encode / apistar / apistar / schemas / openapi.py View on Github external
]

        # TODO: Handle media type generically here...
        body_schema = lookup(
            operation_info, ["requestBody", "content", "application/json", "schema"]
        )

        encoding = None
        if body_schema:
            encoding = "application/json"
            if "$ref" in body_schema:
                ref = body_schema["$ref"]
                schema = schema_definitions.get(ref)
                field_name = ref[len("#/components/schemas/") :].lower()
            else:
                schema = typesystem.from_json_schema(
                    body_schema, definitions=schema_definitions
                )
                field_name = "body"
            field_name = lookup(
                operation_info, ["requestBody", "x-name"], default=field_name
            )
            fields += [Field(name=field_name, location="body", schema=schema)]

        return Link(
            name=name,
            url=urljoin(base_url, path),
            method=operation,
            title=title,
            description=description,
            fields=fields,
            encoding=encoding,
github encode / apistar / apistar / schemas / swagger.py View on Github external
"""
        Return a single field in a link.
        """
        name = parameter.get("name")
        location = parameter.get("in")
        description = parameter.get("description")
        required = parameter.get("required", False)
        schema = parameter.get("schema")
        example = parameter.get("example")

        if schema is not None:
            if "$ref" in schema:
                ref = schema["$ref"]
                schema = schema_definitions.get(ref)
            else:
                schema = typesystem.from_json_schema(
                    schema, definitions=schema_definitions
                )

        return Field(
            name=name,
            location=location,
            description=description,
            required=required,
            schema=schema,
            example=example,
        )