datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

Consider replacing httpx with requests for pyodide support

Open simontaurus opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. Even with https://github.com/wolverdude/GenSON/issues/73 fixed, datamodel-code-generator still depends on httpx, which is not yet supported in pyodide (see https://github.com/koenvo/pyodide-http/issues/37)

Describe the solution you'd like Replacing httpx with requests would solve this issue. Beside some mockup patches in the tests, this is merly about two lines: https://github.com/koxudaxi/datamodel-code-generator/blob/fcab9a4d555d4b96d64bb277f974bb7507982fb2/datamodel_code_generator/http.py#L19 which can be replaced with

requests.get(url, headers=headers, verify=verify, allow_redirects=follow_redirects, params=params)

and https://github.com/koxudaxi/datamodel-code-generator/blob/fcab9a4d555d4b96d64bb277f974bb7507982fb2/datamodel_code_generator/http.py#L29 which should be replaceable with

urllib.parse.urlparse

wrapped here: https://github.com/encode/httpx/blob/88a81c5d31a4a8b4bd0a860dedd3bb12dc09ff86/httpx/_urls.py#L370

see also https://github.com/search?q=repo%3Akoxudaxi%2Fdatamodel-code-generator%20httpx&type=code

Describe alternatives you've considered As a temporary workaround, a patch is also possible:

import requests
import httpx
def patch_get(url, headers, verify, follow_redirects, params
    ):
    return requests.get(
        url, headers=headers, verify=verify, allow_redirects=follow_redirects, params=params
    )
httpx.get = patch_get

Additional context Patch solution is used here: https://oo-ld.github.io/playground-python-yaml/

simontaurus avatar May 12 '24 12:05 simontaurus