Exemple #1
0
def get_type_info(spec: Spec, schema: Dict[str, Any], config: Config
                  ) -> TypeInfo:
    """
    Get the type of a schema within a Swagger spec.
    :param spec: Bravado-core spec object
    :param schema: Schema dict
    :return: A TypeInfo for the schema.
    """
    schema = spec.deref(schema)
    schema_type = get_type_from_schema(spec, schema)
    if schema_type == "array":
        type_info = _get_array_type_info(spec, schema, config)
    elif schema_type == "object":
        type_info = _get_object_type_info(spec, schema, config)
    elif schema_type in SWAGGER_PRIMITIVE_TYPES:
        type_info = _get_primitive_type_info(spec, schema, config)
    elif schema_type == "file":
        type_info = TypeInfo("typing.Any")
    elif schema_type is None:
        type_info = TypeInfo("typing.Any")
    else:
        warnings.warn(f"Unknown schema type: {schema_type!r}")
        type_info = TypeInfo("typing.Any")

    if schema.get("x-nullable", False):
        type_info = _wrap(type_info, "typing.Optional[{}]")

    return type_info
Exemple #2
0
def get_response_type_info(spec: Spec, rschema: Dict[str, Any], config: Config
                           ) -> TypeInfo:
    """Extract type information for a given response schema."""
    rschema = spec.deref(rschema)
    if "schema" in rschema:
        return get_type_info(spec, rschema["schema"], config)
    return TypeInfo("None")
def assert_validate_call_count(expected_call_count, config, petstore_dict):
    spec = Spec(petstore_dict, config=config)
    with patch('bravado_core.spec.validator20.validate_spec') as m_validate:
        spec.deref = Mock(return_value={})
        spec.build()
    assert expected_call_count == m_validate.call_count