Ich beginne ein winziges kleines Python -Projekt, um mich mit Fastapi zu befriedigen, und ich stehe auf ein Problem mit dem Zugriff auf die Swagger UI -Dokumente. Der Endpunkt selbst, den ich bis zum heiklen möglichen, funktioniert einwandfrei. Wenn ich versuche, /docs < /code> zu klicken, schlägt der nachfolgende Anruf unter /openapi.json < /code> fehl. Ich schwöre, ich muss einen unglaublich dummen Fehler fehlen und würde mich über jede Hilfe freuen.
import uvicorn
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def root():
return {"message": "This is the root of the project"}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
< /code>
Wenn ich versuche, < /code> zu klicken, das sich selbst aufruft, ist 200, aber wenn es versucht, /openapi.json < /code> zu erhalten, gibt es einen 500 und den folgenden Fehler in der Konsole zurück. Offensichtlich werden die Dokumente also nicht im Browser angezeigt. < /P>
INFO: 127.0.0.1:51857 - "GET /openapi.json HTTP/1.1" 500 Internal Server Error
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 403, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
return await self.app(scope, receive, send)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/fastapi/applications.py", line 1054, in __call__
await super().__call__(scope, receive, send)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/applications.py", line 112, in __call__
await self.middleware_stack(scope, receive, send)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 187, in __call__
raise exc
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 165, in __call__
await self.app(scope, receive, _send)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
raise exc
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/routing.py", line 714, in __call__
await self.middleware_stack(scope, receive, send)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/routing.py", line 734, in app
await route.handle(scope, receive, send)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/routing.py", line 288, in handle
await self.app(scope, receive, send)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/routing.py", line 76, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
raise exc
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/routing.py", line 73, in app
response = await f(request)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/fastapi/applications.py", line 1009, in openapi
return JSONResponse(self.openapi())
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/fastapi/applications.py", line 981, in openapi
self.openapi_schema = get_openapi(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/fastapi/openapi/utils.py", line 513, in get_openapi
schema_generator = GenerateJsonSchema(ref_template=REF_TEMPLATE)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pydantic/json_schema.py", line 278, in __init__
self._schema_type_to_method = self.build_schema_type_to_method()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pydantic/json_schema.py", line 317, in build_schema_type_to_method
method_name = f'{key.replace("-", "_")}_schema'
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 647, in __getattr__
return getattr(self.__origin__, attr)
AttributeError: '_SpecialForm' object has no attribute 'replace'
Ich beginne ein winziges kleines Python -Projekt, um mich mit Fastapi zu befriedigen, und ich stehe auf ein [url=viewtopic.php?t=20324]Problem[/url] mit dem Zugriff auf die Swagger UI -Dokumente. Der Endpunkt selbst, den ich bis zum heiklen möglichen, funktioniert einwandfrei. Wenn ich versuche, /docs < /code> zu klicken, schlägt der nachfolgende Anruf unter /openapi.json < /code> fehl. Ich schwöre, ich muss einen unglaublich dummen Fehler fehlen und würde mich über jede Hilfe freuen.[code]import uvicorn from fastapi import FastAPI
app = FastAPI()
@app.get("/") def root(): return {"message": "This is the root of the project"}
if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=8000) < /code> Wenn ich versuche, < /code> zu klicken, das sich selbst aufruft, ist 200, aber wenn es versucht, /openapi.json < /code> zu erhalten, gibt es einen 500 und den folgenden Fehler in der Konsole zurück. Offensichtlich werden die Dokumente also nicht im Browser angezeigt. < /P> INFO: 127.0.0.1:51857 - "GET /openapi.json HTTP/1.1" 500 Internal Server Error ERROR: Exception in ASGI application Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 403, in run_asgi result = await app( # type: ignore[func-returns-value] File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__ return await self.app(scope, receive, send) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/fastapi/applications.py", line 1054, in __call__ await super().__call__(scope, receive, send) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/applications.py", line 112, in __call__ await self.middleware_stack(scope, receive, send) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 187, in __call__ raise exc File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 165, in __call__ await self.app(scope, receive, _send) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 62, in __call__ await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app raise exc File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app await app(scope, receive, sender) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/routing.py", line 714, in __call__ await self.middleware_stack(scope, receive, send) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/routing.py", line 734, in app await route.handle(scope, receive, send) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/routing.py", line 288, in handle await self.app(scope, receive, send) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/routing.py", line 76, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app raise exc File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app await app(scope, receive, sender) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/starlette/routing.py", line 73, in app response = await f(request) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/fastapi/applications.py", line 1009, in openapi return JSONResponse(self.openapi()) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/fastapi/applications.py", line 981, in openapi self.openapi_schema = get_openapi( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/fastapi/openapi/utils.py", line 513, in get_openapi schema_generator = GenerateJsonSchema(ref_template=REF_TEMPLATE) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pydantic/json_schema.py", line 278, in __init__ self._schema_type_to_method = self.build_schema_type_to_method() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pydantic/json_schema.py", line 317, in build_schema_type_to_method method_name = f'{key.replace("-", "_")}_schema' File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 647, in __getattr__ return getattr(self.__origin__, attr) AttributeError: '_SpecialForm' object has no attribute 'replace' [/code]
Swagger OpenAPI 3.0 arbeitet mit Springdoc-OpenAPI-UI und einer benutzerdefinierten OpenAPI-Bean.
org.springframework.cloud
spring-cloud-starter-parent
Hoxton.SR10
Ich verwende Springdoc OpenAPI 3.0.3 mit Spring Boot, um die Swagger -Benutzeroberfläche in meiner Anwendung aufzudecken. Es funktioniert in Entwicklungs- und Integrationsumgebungen vollkommen in...
Ich habe nach dem Upgrade auf Spring Boot 3 ein Problem mit der Swagger-Benutzeroberfläche. Die Swagger-Benutzeroberfläche funktioniert nicht mehr und ich habe als Antwort eine 404- und „White...
Ich implementiere eine OpenAPI -Dokumentation in einem Frühlings -Cloud -Gateway -Dienst, der zu mehreren Microservices weiterleitet. Ich habe das Gateway mithilfe von GruppedOpenAPI -Dokumentation...