def from_dict(cls, spec_dict, origin_url=None, http_client=None, config=None): """ Build a :class:`Spec` from Swagger API Specificiation :param spec_dict: swagger spec in json-like dict form. :param origin_url: the url used to retrieve the spec, if any :type origin_url: str :param config: Configuration dict. See CONFIG_DEFAULTS. """ fix_malformed_model_refs(spec_dict) spec_dict = jsonref.JsonRef.replace_refs(spec_dict, base_uri=origin_url or '') # Populated by post-processing callbacks below models = {} post_process_spec(spec_dict, on_container_callbacks=( annotate_with_xmodel_callback, fix_models_with_no_type_callback, functools.partial(create_reffed_models_callback, models), functools.partial( create_dereffed_models_callback, models), replace_jsonref_proxies_callback, )) spec = cls(spec_dict, origin_url, http_client, config) spec.definitions = models spec.build() return spec
def from_dict(cls, spec_dict, origin_url=None, http_client=None, config=None): """ Build a :class:`Spec` from Swagger API Specificiation :param spec_dict: swagger spec in json-like dict form. :param origin_url: the url used to retrieve the spec, if any :type origin_url: str :param config: Configuration dict. See CONFIG_DEFAULTS. """ fix_malformed_model_refs(spec_dict) spec_dict = jsonref.JsonRef.replace_refs( spec_dict, base_uri=origin_url or '') # Populated by post-processing callbacks below models = {} post_process_spec( spec_dict, on_container_callbacks=( annotate_with_xmodel_callback, fix_models_with_no_type_callback, functools.partial(create_reffed_models_callback, models), functools.partial(create_dereffed_models_callback, models), replace_jsonref_proxies_callback, )) spec = cls(spec_dict, origin_url, http_client, config) spec.definitions = models spec.build() return spec
def jsonref_petstore_dict(): my_dir = os.path.abspath(os.path.dirname(__file__)) fpath = os.path.join(my_dir, '../../test-data/2.0/petstore/swagger.json') with open(fpath) as f: petstore = json.loads(f.read()) fix_malformed_model_refs(petstore) unrefed_petstore = jsonref.JsonRef.replace_refs(petstore) validator20.validate_spec(unrefed_petstore) return unrefed_petstore
def from_dict(cls, spec_dict, origin_url=None, http_client=None, config=None): """ Build a :class:`Spec` from Swagger API Specificiation :param spec_dict: swagger spec in json-like dict form. :param origin_url: the url used to retrieve the spec, if any :type origin_url: str :param config: Configuration dict. See CONFIG_DEFAULTS. """ tag_models(spec_dict) fix_malformed_model_refs(spec_dict) spec_dict = jsonref.JsonRef.replace_refs(spec_dict) replace_jsonref_proxies(spec_dict) spec = cls(spec_dict, origin_url, http_client, config) spec.build() return spec