def from_asgi( schema_path: str, app: Any, base_url: Optional[str] = None, method: Optional[Filter] = None, endpoint: Optional[Filter] = None, tag: Optional[Filter] = None, validate_schema: bool = True, skip_deprecated_endpoints: bool = False, data_generation_methods: Iterable[DataGenerationMethod] = DEFAULT_DATA_GENERATION_METHODS, force_schema_version: Optional[str] = None, **kwargs: Any, ) -> BaseOpenAPISchema: _setup_headers(kwargs) client = ASGIClient(app) response = client.get(schema_path, **kwargs) check_response(response, schema_path) return from_file( response.text, location=schema_path, base_url=base_url, method=method, endpoint=endpoint, tag=tag, app=app, validate_schema=validate_schema, skip_deprecated_endpoints=skip_deprecated_endpoints, data_generation_methods=data_generation_methods, force_schema_version=force_schema_version, )
def from_asgi( schema_path: str, app: Any, *, base_url: Optional[str] = None, data_generation_methods: DataGenerationMethodInput = DEFAULT_DATA_GENERATION_METHODS, code_sample_style: str = CodeSampleStyle.default().name, **kwargs: Any, ) -> GraphQLSchema: """Load GraphQL schema from an ASGI app. :param str schema_path: An in-app relative URL to the schema. :param app: An ASGI app instance. :param Optional[str] base_url: Base URL to send requests to. """ require_relative_url(schema_path) setup_headers(kwargs) kwargs.setdefault("json", {"query": INTROSPECTION_QUERY}) client = ASGIClient(app) response = client.post(schema_path, **kwargs) HTTPError.check_response(response, schema_path) return from_dict( response.json()["data"], location=schema_path, base_url=base_url, app=app, data_generation_methods=data_generation_methods, code_sample_style=code_sample_style, )
def from_asgi( schema_path: str, app: Any, base_url: Optional[str] = None, method: Optional[Filter] = None, endpoint: Optional[Filter] = None, tag: Optional[Filter] = None, validate_schema: bool = True, **kwargs: Any, ) -> BaseOpenAPISchema: kwargs.setdefault("headers", {}).setdefault("User-Agent", USER_AGENT) client = ASGIClient(app) response = client.get(schema_path, **kwargs) # Raising exception to provide unified behavior # E.g. it will be handled in CLI - a proper error message will be shown if 400 <= response.status_code < 600: raise HTTPError(response=response, url=schema_path) return from_file( response.text, location=schema_path, base_url=base_url, method=method, endpoint=endpoint, tag=tag, app=app, validate_schema=validate_schema, )
def from_asgi( schema_path: str, app: Any, base_url: Optional[str] = None, method: Optional[Filter] = None, endpoint: Optional[Filter] = None, tag: Optional[Filter] = None, validate_schema: bool = True, skip_deprecated_endpoints: bool = False, data_generation_methods: Iterable[DataGenerationMethod] = DEFAULT_DATA_GENERATION_METHODS, force_schema_version: Optional[str] = None, **kwargs: Any, ) -> BaseOpenAPISchema: headers = kwargs.setdefault("headers", {}) if "user-agent" not in {header.lower() for header in headers}: kwargs["headers"]["User-Agent"] = USER_AGENT client = ASGIClient(app) response = client.get(schema_path, **kwargs) # Raising exception to provide unified behavior # E.g. it will be handled in CLI - a proper error message will be shown if 400 <= response.status_code < 600: raise HTTPError(response=response, url=schema_path) return from_file( response.text, location=schema_path, base_url=base_url, method=method, endpoint=endpoint, tag=tag, app=app, validate_schema=validate_schema, skip_deprecated_endpoints=skip_deprecated_endpoints, data_generation_methods=data_generation_methods, force_schema_version=force_schema_version, )
def call_asgi( self, app: Any = None, base_url: Optional[str] = "http://testserver", headers: Optional[Dict[str, str]] = None, **kwargs: Any, ) -> requests.Response: application = app or self.app if application is None: raise RuntimeError( "ASGI application instance is required. " "Please, set `app` argument in the schema constructor or pass it to `call_asgi`" ) client = ASGIClient(application) return self.call(base_url=base_url, session=client, headers=headers, **kwargs)
def from_asgi( schema_path: str, app: Any, *, base_url: Optional[str] = None, method: Optional[Filter] = None, endpoint: Optional[Filter] = None, tag: Optional[Filter] = None, operation_id: Optional[Filter] = None, skip_deprecated_operations: bool = False, validate_schema: bool = True, force_schema_version: Optional[str] = None, data_generation_methods: DataGenerationMethodInput = DEFAULT_DATA_GENERATION_METHODS, code_sample_style: str = CodeSampleStyle.default().name, **kwargs: Any, ) -> BaseOpenAPISchema: """Load Open API schema from an ASGI app. :param str schema_path: An in-app relative URL to the schema. :param app: An ASGI app instance. """ require_relative_url(schema_path) setup_headers(kwargs) client = ASGIClient(app) response = client.get(schema_path, **kwargs) HTTPError.check_response(response, schema_path) return from_file( response.text, app=app, base_url=base_url, method=method, endpoint=endpoint, tag=tag, operation_id=operation_id, skip_deprecated_operations=skip_deprecated_operations, validate_schema=validate_schema, force_schema_version=force_schema_version, data_generation_methods=data_generation_methods, code_sample_style=code_sample_style, location=schema_path, )