Scille / parsec-cloud

Open source Dropbox-like file sharing with full client encryption !
https://parsec.cloud
Other
268 stars 40 forks source link

Fix fastAPI's API documentation auto-generation #6345

Open touilleMan opened 8 months ago

touilleMan commented 8 months ago
INFO:     127.0.0.1:37506 - "GET /openapi.json HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/fastapi/applications.py", line 1106, in __call__
    await super().__call__(scope, receive, send)
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/starlette/middleware/cors.py", line 83, in __call__
    await self.app(scope, receive, send)
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in __call__
    raise e
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in __call__
    await self.app(scope, receive, send)
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/fastapi/applications.py", line 1061, in openapi
    return JSONResponse(self.openapi())
                        ^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/fastapi/applications.py", line 1033, in openapi
    self.openapi_schema = get_openapi(
                          ^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/fastapi/openapi/utils.py", line 475, in get_openapi
    field_mapping, definitions = get_definitions(
                                 ^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/fastapi/_compat.py", line 227, in get_definitions
    field_mapping, definitions = schema_generator.generate_definitions(
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 374, in generate_definitions
    self.generate_inner(schema)
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 549, in generate_inner
    json_schema = current_handler(schema)
                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/_internal/_schema_generation_shared.py", line 36, in __call__
    return self.handler(__core_schema)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 523, in new_handler_func
    json_schema = js_modify_function(schema_or_field, current_handler)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/main.py", line 601, in __get_pydantic_json_schema__
    return __handler(__core_schema)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/_internal/_schema_generation_shared.py", line 36, in __call__
    return self.handler(__core_schema)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 523, in new_handler_func
    json_schema = js_modify_function(schema_or_field, current_handler)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 212, in modify_model_json_schema
    json_schema = handler(schema_or_field)
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/_internal/_schema_generation_shared.py", line 36, in __call__
    return self.handler(__core_schema)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 506, in handler_func
    json_schema = generate_for_schema_type(schema_or_field)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 1318, in model_schema
    json_schema = self.generate_inner(schema['schema'])
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 549, in generate_inner
    json_schema = current_handler(schema)
                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/_internal/_schema_generation_shared.py", line 36, in __call__
    return self.handler(__core_schema)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 506, in handler_func
    json_schema = generate_for_schema_type(schema_or_field)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 1410, in model_fields_schema
    json_schema = self._named_required_fields_schema(named_required_fields)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 1221, in _named_required_fields_schema
    field_json_schema = self.generate_inner(field).copy()
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 549, in generate_inner
    json_schema = current_handler(schema)
                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/_internal/_schema_generation_shared.py", line 36, in __call__
    return self.handler(__core_schema)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 541, in new_handler_func
    json_schema = js_modify_function(schema_or_field, current_handler)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 963, in json_schema_update_func
    json_schema = {**handler(schema), **json_schema_updates}
                     ^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/_internal/_schema_generation_shared.py", line 36, in __call__
    return self.handler(__core_schema)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 506, in handler_func
    json_schema = generate_for_schema_type(schema_or_field)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 1289, in model_field_schema
    return self.generate_inner(schema['schema'])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 549, in generate_inner
    json_schema = current_handler(schema)
                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/_internal/_schema_generation_shared.py", line 36, in __call__
    return self.handler(__core_schema)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 506, in handler_func
    json_schema = generate_for_schema_type(schema_or_field)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 953, in function_plain_schema
    return self._function_schema(schema)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 918, in _function_schema
    return self.handle_invalid_for_json_schema(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emmanuel/.cache/pypoetry/virtualenvs/parsec-cloud-fUS9rJbY-py3.12/lib/python3.12/site-packages/pydantic/json_schema.py", line 2069, in handle_invalid_for_json_schema
    raise PydanticInvalidForJsonSchema(f'Cannot generate a JsonSchema for {error_info}')
pydantic.errors.PydanticInvalidForJsonSchema: Cannot generate a JsonSchema for core_schema.PlainValidatorFunctionSchema ({'type': 'no-info', 'function': <function <lambda> at 0x7adae29b3ba0>})

For further information visit https://errors.pydantic.dev/2.4/u/invalid-for-json-schema

Reproduce steps:

  1. Comment https://github.com/Scille/parsec-cloud/blob/ae006046be448dde40183c7e19b0b8b20365207c/server/parsec/asgi/__init__.py#L31-L33

  2. run ./make.py rts

  3. curl http://127.0.0.1:6770/openapi.json

Should be fixed by #6344

mmmarcos commented 8 months ago

This is not a priority for 3.0, back to backlog.

mmmarcos commented 4 months ago

Related to #6047