fastapi-voyager 0.5.3__tar.gz → 0.6.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/PKG-INFO +8 -8
  2. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/README.md +7 -7
  3. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/cli.py +8 -2
  4. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/server.py +26 -22
  5. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/type_helper.py +24 -2
  6. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/version.py +1 -1
  7. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/component/render-graph.js +1 -1
  8. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/component/schema-field-filter.js +1 -1
  9. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/index.html +10 -10
  10. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/vue-main.js +5 -5
  11. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/tests/demo.py +3 -1
  12. fastapi_voyager-0.6.2/tests/programatic.py +8 -0
  13. fastapi_voyager-0.6.2/tests/test_generic.py +20 -0
  14. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/.gitignore +0 -0
  15. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/.python-version +0 -0
  16. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/LICENSE +0 -0
  17. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/pyproject.toml +0 -0
  18. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/__init__.py +0 -0
  19. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/filter.py +0 -0
  20. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/module.py +0 -0
  21. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/render.py +0 -0
  22. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/type.py +0 -0
  23. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/voyager.py +0 -0
  24. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/component/route-code-display.js +0 -0
  25. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/component/schema-code-display.js +0 -0
  26. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/graph-ui.js +0 -0
  27. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/graphviz.svg.css +0 -0
  28. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/graphviz.svg.js +0 -0
  29. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/icon/android-chrome-192x192.png +0 -0
  30. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/icon/android-chrome-512x512.png +0 -0
  31. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/icon/apple-touch-icon.png +0 -0
  32. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/icon/favicon-16x16.png +0 -0
  33. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/icon/favicon-32x32.png +0 -0
  34. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/icon/favicon.ico +0 -0
  35. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/icon/site.webmanifest +0 -0
  36. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/quasar.min.css +0 -0
  37. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/src/fastapi_voyager/web/quasar.min.js +0 -0
  38. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/tests/__init__.py +0 -0
  39. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/tests/demo_anno.py +0 -0
  40. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/tests/service/__init__.py +0 -0
  41. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/tests/service/schema.py +0 -0
  42. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/tests/test_analysis.py +0 -0
  43. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/tests/test_import.py +0 -0
  44. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/tests/test_module.py +0 -0
  45. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/tests/test_type_helper.py +0 -0
  46. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/uv.lock +0 -0
  47. {fastapi_voyager-0.5.3 → fastapi_voyager-0.6.2}/voyager.jpg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastapi-voyager
3
- Version: 0.5.3
3
+ Version: 0.6.2
4
4
  Summary: Visualize FastAPI application's routing tree and dependencies
5
5
  Project-URL: Homepage, https://github.com/allmonday/fastapi-voyager
6
6
  Project-URL: Source, https://github.com/allmonday/fastapi-voyager
@@ -183,13 +183,7 @@ features
183
183
  - [ ] abstract render module
184
184
  - [ ] export voyager core data into json (for better debugging)
185
185
  - [ ] add api to rebuild core data from json, and render it
186
- - [ ] fix Generic case
187
-
188
- ```python
189
- class Paged(BaseModel, Generic[T]):
190
- total: int
191
- items: List[T]
192
- ```
186
+ - [x] fix Generic case `test_generic.py`
193
187
 
194
188
  bugs:
195
189
  - [ ] fix duplicated link from class and parent class, it also break clicking highlight
@@ -205,3 +199,9 @@ TODO: ...
205
199
 
206
200
  - https://apis.guru/graphql-voyager/, for inspiration.
207
201
  - https://github.com/tintinweb/vscode-interactive-graphviz, for web visualization.
202
+
203
+
204
+ ## Changelog
205
+
206
+ - 0.6.2:
207
+ - fix generic related issue
@@ -156,13 +156,7 @@ features
156
156
  - [ ] abstract render module
157
157
  - [ ] export voyager core data into json (for better debugging)
158
158
  - [ ] add api to rebuild core data from json, and render it
159
- - [ ] fix Generic case
160
-
161
- ```python
162
- class Paged(BaseModel, Generic[T]):
163
- total: int
164
- items: List[T]
165
- ```
159
+ - [x] fix Generic case `test_generic.py`
166
160
 
167
161
  bugs:
168
162
  - [ ] fix duplicated link from class and parent class, it also break clicking highlight
@@ -178,3 +172,9 @@ TODO: ...
178
172
 
179
173
  - https://apis.guru/graphql-voyager/, for inspiration.
180
174
  - https://github.com/tintinweb/vscode-interactive-graphviz, for web visualization.
175
+
176
+
177
+ ## Changelog
178
+
179
+ - 0.6.2:
180
+ - fix generic related issue
@@ -169,6 +169,12 @@ Examples:
169
169
  default=8000,
170
170
  help="Port for the preview server when --server is used (default: 8000)"
171
171
  )
172
+ parser.add_argument(
173
+ "--host",
174
+ type=str,
175
+ default="127.0.0.1",
176
+ help="Host/IP for the preview server when --server is used (default: 127.0.0.1). Use 0.0.0.0 to listen on all interfaces."
177
+ )
172
178
 
173
179
  parser.add_argument(
174
180
  "--version", "-v",
@@ -267,8 +273,8 @@ Examples:
267
273
  print("Error: uvicorn is required to run the server. Install via 'pip install uvicorn' or 'uv add uvicorn'.")
268
274
  sys.exit(1)
269
275
  app_server = viz_server.create_app_with_fastapi(app, module_color=module_color)
270
- print(f"Starting preview server at http://127.0.0.1:{args.port} ... (Ctrl+C to stop)")
271
- uvicorn.run(app_server, host="127.0.0.1", port=args.port)
276
+ print(f"Starting preview server at http://{args.host}:{args.port} ... (Ctrl+C to stop)")
277
+ uvicorn.run(app_server, host=args.host, port=args.port)
272
278
  else:
273
279
  # Generate and write dot file locally
274
280
  generate_visualization(
@@ -1,6 +1,6 @@
1
1
  from pathlib import Path
2
2
  from typing import Optional
3
- from fastapi import FastAPI
3
+ from fastapi import FastAPI, APIRouter
4
4
  from starlette.middleware.gzip import GZipMiddleware
5
5
  from pydantic import BaseModel
6
6
  from fastapi.responses import HTMLResponse, PlainTextResponse, JSONResponse
@@ -33,23 +33,13 @@ class Payload(BaseModel):
33
33
  show_fields: str = 'object'
34
34
  show_meta: bool = False
35
35
 
36
- def create_app_with_fastapi(
36
+ def create_route(
37
37
  target_app: FastAPI,
38
38
  module_color: dict[str, str] | None = None,
39
- gzip_minimum_size: int | None = 500,
40
- ) -> FastAPI:
41
- """Create a FastAPI server that serves DOT computed via Analytics.
42
-
43
- This avoids module-level globals by keeping state in closures.
44
- """
45
-
46
- app = FastAPI(title="fastapi-voyager demo server")
39
+ ):
40
+ router = APIRouter(tags=['fastapi-voyager'])
47
41
 
48
- # Enable gzip compression for larger responses (e.g. DOT / schemas payload)
49
- if gzip_minimum_size is not None and gzip_minimum_size >= 0:
50
- app.add_middleware(GZipMiddleware, minimum_size=gzip_minimum_size)
51
-
52
- @app.get("/dot", response_model=OptionParam)
42
+ @router.get("/dot", response_model=OptionParam)
53
43
  def get_dot() -> str:
54
44
  voyager = Voyager(module_color=module_color, load_meta=True)
55
45
  voyager.analysis(target_app)
@@ -71,7 +61,7 @@ def create_app_with_fastapi(
71
61
 
72
62
  return OptionParam(tags=tags, schemas=schemas, dot=dot)
73
63
 
74
- @app.post("/dot", response_class=PlainTextResponse)
64
+ @router.post("/dot", response_class=PlainTextResponse)
75
65
  def get_filtered_dot(payload: Payload) -> str:
76
66
  voyager = Voyager(
77
67
  include_tags=payload.tags,
@@ -85,7 +75,7 @@ def create_app_with_fastapi(
85
75
  voyager.analysis(target_app)
86
76
  return voyager.render_dot()
87
77
 
88
- @app.post("/dot-core-data", response_model=CoreData)
78
+ @router.post("/dot-core-data", response_model=CoreData)
89
79
  def get_filtered_dot_core_data(payload: Payload) -> str:
90
80
  voyager = Voyager(
91
81
  include_tags=payload.tags,
@@ -98,13 +88,13 @@ def create_app_with_fastapi(
98
88
  )
99
89
  voyager.analysis(target_app)
100
90
  return voyager.dump_core_data()
101
-
102
- @app.post('/dot-render-core-data', response_class=PlainTextResponse)
91
+
92
+ @router.post('/dot-render-core-data', response_class=PlainTextResponse)
103
93
  def render_dot_from_core_data(core_data: CoreData) -> str:
104
94
  renderer = Renderer(show_fields=core_data.show_fields, module_color=core_data.module_color, schema=core_data.schema)
105
95
  return renderer.render_dot(core_data.tags, core_data.routes, core_data.nodes, core_data.links)
106
96
 
107
- @app.get("/", response_class=HTMLResponse)
97
+ @router.get("/", response_class=HTMLResponse)
108
98
  def index():
109
99
  index_file = WEB_DIR / "index.html"
110
100
  if index_file.exists():
@@ -120,8 +110,22 @@ def create_app_with_fastapi(
120
110
  </html>
121
111
  """
122
112
 
123
- # Serve static files under /static
124
- app.mount("/static", StaticFiles(directory=str(WEB_DIR)), name="static")
113
+ return router
114
+
115
+
116
+ def create_app_with_fastapi(
117
+ target_app: FastAPI,
118
+ module_color: dict[str, str] | None = None,
119
+ gzip_minimum_size: int | None = 500,
120
+ ) -> FastAPI:
121
+ router = create_route(target_app, module_color=module_color)
122
+
123
+ app = FastAPI(title="fastapi-voyager demo server")
124
+ if gzip_minimum_size is not None and gzip_minimum_size >= 0:
125
+ app.add_middleware(GZipMiddleware, minimum_size=gzip_minimum_size)
126
+
127
+ app.mount("/fastapi-voyager-static", StaticFiles(directory=str(WEB_DIR)), name="static")
128
+ app.include_router(router)
125
129
 
126
130
  return app
127
131
 
@@ -1,7 +1,7 @@
1
1
  import inspect
2
2
  import os
3
3
  from pydantic import BaseModel
4
- from typing import get_origin, get_args, Union, Annotated, Any, Type
4
+ from typing import get_origin, get_args, Union, Annotated, Any, Type, Generic
5
5
  from fastapi_voyager.type import FieldInfo
6
6
  from types import UnionType
7
7
  import pydantic_resolve.constant as const
@@ -142,7 +142,7 @@ def get_type_name(anno):
142
142
 
143
143
 
144
144
  def is_inheritance_of_pydantic_base(cls):
145
- return issubclass(cls, BaseModel) and cls is not BaseModel
145
+ return safe_issubclass(cls, BaseModel) and cls is not BaseModel and not is_generic_container(cls)
146
146
 
147
147
 
148
148
  def get_bases_fields(schemas: list[type[BaseModel]]) -> set[str]:
@@ -228,6 +228,7 @@ def safe_issubclass(kls, classinfo):
228
228
  try:
229
229
  return issubclass(kls, classinfo)
230
230
  except TypeError:
231
+ print(kls.__name__, 'is not a class')
231
232
  return False
232
233
 
233
234
 
@@ -255,6 +256,27 @@ def update_forward_refs(kls):
255
256
  if safe_issubclass(shelled_type, BaseModel):
256
257
  update_pydantic_forward_refs(shelled_type)
257
258
 
259
+
260
+ def is_generic_container(cls):
261
+ """
262
+ T = TypeVar('T')
263
+ class DataModel(BaseModel, Generic[T]):
264
+ data: T
265
+ id: int
266
+
267
+ type DataModelPageStory = DataModel[PageStory]
268
+
269
+ is_generic_container(DataModel) -> True
270
+ is_generic_container(DataModel[PageStory]) -> False
271
+
272
+ DataModel.__parameters__ == (T,)
273
+ DataModelPageStory.__parameters__ == (,)
274
+ """
275
+ try:
276
+ return (hasattr(cls, '__bases__') and Generic in cls.__bases__ and (hasattr(cls, '__parameters__') and bool(cls.__parameters__)))
277
+ except (TypeError, AttributeError):
278
+ return False
279
+
258
280
  if __name__ == "__main__":
259
281
  from tests.demo_anno import PageSprint, PageOverall
260
282
 
@@ -1,2 +1,2 @@
1
1
  __all__ = ["__version__"]
2
- __version__ = "0.5.3"
2
+ __version__ = "0.6.2"
@@ -31,7 +31,7 @@ export default defineComponent({
31
31
  if (!props.coreData) return;
32
32
  loading.value = true;
33
33
  try {
34
- const res = await fetch("/dot-render-core-data", {
34
+ const res = await fetch("dot-render-core-data", {
35
35
  method: "POST",
36
36
  headers: { "Content-Type": "application/json" },
37
37
  body: JSON.stringify(props.coreData),
@@ -81,7 +81,7 @@ export default defineComponent({
81
81
  schema_field: state.fieldName || null,
82
82
  show_fields: state.showFields,
83
83
  };
84
- const res = await fetch("/dot", {
84
+ const res = await fetch("dot", {
85
85
  method: "POST",
86
86
  headers: { "Content-Type": "application/json" },
87
87
  body: JSON.stringify(payload),
@@ -2,14 +2,14 @@
2
2
  <head>
3
3
  <title>FastAPI Voyager</title>
4
4
  <meta name="theme-color" content="#ffffff" />
5
- <link rel="stylesheet" href="/static/graphviz.svg.css" />
6
- <link rel="stylesheet" href="/static/quasar.min.css" />
5
+ <link rel="stylesheet" href="fastapi-voyager-static/graphviz.svg.css" />
6
+ <link rel="stylesheet" href="fastapi-voyager-static/quasar.min.css" />
7
7
  <!-- App Icons / Favicons -->
8
- <link rel="apple-touch-icon" sizes="180x180" href="/static/icon/apple-touch-icon.png" />
9
- <link rel="icon" type="image/png" sizes="32x32" href="/static/icon/favicon-32x32.png" />
10
- <link rel="icon" type="image/png" sizes="16x16" href="/static/icon/favicon-16x16.png" />
11
- <link rel="icon" href="/static/icon/favicon.ico" sizes="any" />
12
- <link rel="manifest" href="/static/icon/site.webmanifest" />
8
+ <link rel="apple-touch-icon" sizes="180x180" href="fastapi-voyager-static/icon/apple-touch-icon.png" />
9
+ <link rel="icon" type="image/png" sizes="32x32" href="fastapi-voyager-static/icon/favicon-32x32.png" />
10
+ <link rel="icon" type="image/png" sizes="16x16" href="fastapi-voyager-static/icon/favicon-16x16.png" />
11
+ <link rel="icon" href="fastapi-voyager-static/icon/favicon.ico" sizes="any" />
12
+ <link rel="manifest" href="fastapi-voyager-static/icon/site.webmanifest" />
13
13
  <link
14
14
  href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons"
15
15
  rel="stylesheet"
@@ -265,8 +265,8 @@
265
265
 
266
266
  <!-- Add the following at the end of your body tag -->
267
267
  <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/3.5.22/vue.global.prod.min.js" integrity="sha512-Y9sKU0AwzWRxKSLd2i35LuDpUdHY/E9tJrKG0mxw0qYQ75VVgGYazIUQPwKhFK9vGO3jIgAtxLiSq8GQ7PDfUg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
268
- <script src="/static/quasar.min.js"></script>
269
- <script src="/static/graphviz.svg.js"></script>
268
+ <script src="fastapi-voyager-static/quasar.min.js"></script>
269
+ <script src="fastapi-voyager-static/graphviz.svg.js"></script>
270
270
  <!-- highlight.js minimal ES module load (python only) -->
271
271
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css" />
272
272
  <script type="module">
@@ -275,6 +275,6 @@
275
275
  hljs.registerLanguage('python', python);
276
276
  window.hljs = hljs;
277
277
  </script>
278
- <script type="module" src="/static/vue-main.js"></script>
278
+ <script type="module" src="fastapi-voyager-static/vue-main.js"></script>
279
279
  </body>
280
280
  </html>
@@ -37,8 +37,8 @@ const app = createApp({
37
37
  const dumpJson = ref("");
38
38
  const showImportDialog = ref(false);
39
39
  const importJsonText = ref("");
40
- const showRenderGraph = ref(false);
41
- const renderCoreData = ref(null);
40
+ const showRenderGraph = ref(false);
41
+ const renderCoreData = ref(null);
42
42
  const schemaName = ref(""); // used by detail dialog
43
43
  const schemaFieldFilterSchema = ref(null); // external schemaName for schema-field-filter
44
44
  const schemaCodeName = ref("");
@@ -94,7 +94,7 @@ const app = createApp({
94
94
  async function loadInitial() {
95
95
  state.initializing = true;
96
96
  try {
97
- const res = await fetch("/dot");
97
+ const res = await fetch("dot");
98
98
  const data = await res.json();
99
99
  state.rawTags = Array.isArray(data.tags) ? data.tags : [];
100
100
  state.rawSchemasFull = Array.isArray(data.schemas) ? data.schemas : [];
@@ -134,7 +134,7 @@ const app = createApp({
134
134
  show_fields: state.showFields,
135
135
  };
136
136
 
137
- const res = await fetch("/dot", {
137
+ const res = await fetch("dot", {
138
138
  method: "POST",
139
139
  headers: { "Content-Type": "application/json" },
140
140
  body: JSON.stringify(payload),
@@ -180,7 +180,7 @@ const app = createApp({
180
180
  route_name: state.routeId || null,
181
181
  show_fields: state.showFields,
182
182
  };
183
- const res = await fetch("/dot-core-data", {
183
+ const res = await fetch("dot-core-data", {
184
184
  method: "POST",
185
185
  headers: { "Content-Type": "application/json" },
186
186
  body: JSON.stringify(payload),
@@ -69,6 +69,8 @@ class DataModel(BaseModel, Generic[T]):
69
69
  data: T
70
70
  id: int
71
71
 
72
- @app.get("/page_test_1/", tags=['for-page'], response_model=DataModel[PageStory])
72
+ type DataModelPageStory = DataModel[PageStory]
73
+
74
+ @app.get("/page_test_1/", tags=['for-page'], response_model=DataModelPageStory)
73
75
  def get_page_test_1():
74
76
  return {} # no implementation
@@ -0,0 +1,8 @@
1
+ from fastapi import FastAPI
2
+ from fastapi_voyager.server import create_app_with_fastapi
3
+ from tests.demo import app as demo_app
4
+
5
+ subapp = create_app_with_fastapi(demo_app)
6
+
7
+ app = FastAPI()
8
+ app.mount("/xxx", subapp)
@@ -0,0 +1,20 @@
1
+ from pydantic import BaseModel
2
+ from typing import Generic, TypeVar
3
+ from fastapi_voyager.type_helper import is_generic_container
4
+
5
+ class PageStory(BaseModel):
6
+ id: int
7
+ title: str
8
+
9
+ T = TypeVar('T')
10
+ class DataModel(BaseModel, Generic[T]):
11
+ data: T
12
+ id: int
13
+
14
+ type DataModelPageStory = DataModel[PageStory]
15
+
16
+ def test_is_generic_container():
17
+ print(DataModelPageStory.__value__.__bases__)
18
+ print(DataModelPageStory.__value__.model_fields.items())
19
+ assert is_generic_container(DataModel) is True
20
+ assert is_generic_container(DataModelPageStory) is False
File without changes
File without changes