fastapi-docshield 0.2.0__tar.gz → 0.2.1__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.
@@ -71,3 +71,6 @@ dmypy.json
71
71
  # OS specific files
72
72
  .DS_Store
73
73
  **/.claude/settings.local.json
74
+
75
+ # Claude Code memory file
76
+ CLAUDE.md
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastapi-docshield
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: A simple FastAPI integration to protect documentation endpoints with authentication
5
5
  Project-URL: Homepage, https://github.com/georgekhananaev/fastapi-docshield
6
6
  Project-URL: Bug Tracker, https://github.com/georgekhananaev/fastapi-docshield/issues
@@ -52,6 +52,7 @@ Provides-Extra: dev
52
52
  Requires-Dist: httpx>=0.23.0; extra == 'dev'
53
53
  Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
54
54
  Requires-Dist: pytest>=7.0.0; extra == 'dev'
55
+ Requires-Dist: python-multipart>=0.0.5; extra == 'dev'
55
56
  Requires-Dist: requests>=2.28.0; extra == 'dev'
56
57
  Requires-Dist: uvicorn>=0.18.0; extra == 'dev'
57
58
  Description-Content-Type: text/markdown
@@ -281,6 +282,20 @@ pytest --cov=fastapi_docshield
281
282
 
282
283
  ## Changelog
283
284
 
285
+ ### Version 0.2.1 (2025-08-17)
286
+ - **Fixed**: Blank page issue after authentication for some users
287
+ - Improved handling of custom URL parameters by storing them as instance variables
288
+ - Simplified `_setup_routes()` method for better maintainability
289
+ - Applied fix from PR #2 for more robust URL parameter handling
290
+ - **Fixed**: Route removal logic now correctly removes all default documentation routes
291
+ - Properly removes `/docs`, `/redoc`, and `/openapi.json` endpoints
292
+ - Prevents 500 errors when accessing old endpoints
293
+ - **Improved**: Example files and documentation
294
+ - Fixed `custom_styling.py` to work with uvicorn by adding default app variable
295
+ - Standardized credentials across all custom styling examples
296
+ - Added `python-multipart` to dev dependencies for form data handling
297
+ - Added clear run instructions in example files
298
+
284
299
  ### Version 0.2.0 (2025-08-17)
285
300
  - **Added**: Custom CSS and JavaScript injection support
286
301
  - New `custom_css` parameter to inject custom styles into documentation pages
@@ -223,6 +223,20 @@ pytest --cov=fastapi_docshield
223
223
 
224
224
  ## Changelog
225
225
 
226
+ ### Version 0.2.1 (2025-08-17)
227
+ - **Fixed**: Blank page issue after authentication for some users
228
+ - Improved handling of custom URL parameters by storing them as instance variables
229
+ - Simplified `_setup_routes()` method for better maintainability
230
+ - Applied fix from PR #2 for more robust URL parameter handling
231
+ - **Fixed**: Route removal logic now correctly removes all default documentation routes
232
+ - Properly removes `/docs`, `/redoc`, and `/openapi.json` endpoints
233
+ - Prevents 500 errors when accessing old endpoints
234
+ - **Improved**: Example files and documentation
235
+ - Fixed `custom_styling.py` to work with uvicorn by adding default app variable
236
+ - Standardized credentials across all custom styling examples
237
+ - Added `python-multipart` to dev dependencies for form data handling
238
+ - Added clear run instructions in example files
239
+
226
240
  ### Version 0.2.0 (2025-08-17)
227
241
  - **Added**: Custom CSS and JavaScript injection support
228
242
  - New `custom_css` parameter to inject custom styles into documentation pages
@@ -9,9 +9,9 @@ License: MIT License
9
9
  Copyright (c) 2025 George Khananaev
10
10
  """
11
11
 
12
- from .docshield import DocShield
12
+ from .docshield import DocShield, __version__
13
13
 
14
- __version__ = "0.2.0"
14
+ __version__ = __version__
15
15
  __author__ = "George Khananaev"
16
16
  __license__ = "MIT"
17
17
  __copyright__ = "Copyright (c) 2025 George Khananaev"
@@ -6,14 +6,14 @@ License: MIT
6
6
  Copyright (c) 2025 George Khananaev
7
7
  """
8
8
 
9
- from typing import Dict, Optional, Tuple
10
- from fastapi import FastAPI, HTTPException, status, Request, Depends
11
- from fastapi.security.utils import get_authorization_scheme_param
9
+ __version__ = "0.2.1"
10
+
11
+ from typing import Dict, Optional
12
+ from fastapi import FastAPI, HTTPException, status, Depends
12
13
  from fastapi.openapi.docs import get_swagger_ui_html, get_redoc_html
13
14
  from fastapi.security import HTTPBasic, HTTPBasicCredentials
14
15
  from fastapi.responses import HTMLResponse
15
16
  import secrets
16
- import base64
17
17
  from .static_handler import StaticHandler
18
18
 
19
19
 
@@ -67,6 +67,9 @@ class DocShield:
67
67
  self.docs_url = docs_url
68
68
  self.redoc_url = redoc_url
69
69
  self.openapi_url = openapi_url
70
+ self.swagger_js_url = swagger_js_url
71
+ self.swagger_css_url = swagger_css_url
72
+ self.redoc_js_url = redoc_js_url
70
73
  self.use_cdn_fallback = use_cdn_fallback
71
74
  self.prefer_local = prefer_local
72
75
  self.custom_css = custom_css
@@ -89,11 +92,7 @@ class DocShield:
89
92
  app.openapi_url = None
90
93
 
91
94
  # Set up protected documentation routes
92
- self._setup_routes(
93
- swagger_js_url=swagger_js_url,
94
- swagger_css_url=swagger_css_url,
95
- redoc_js_url=redoc_js_url
96
- )
95
+ self._setup_routes()
97
96
 
98
97
  def _remove_existing_docs_routes(self) -> None:
99
98
  """
@@ -108,12 +107,18 @@ class DocShield:
108
107
  for route in self.app.routes:
109
108
  path = getattr(route, "path", "")
110
109
 
111
- # Skip documentation routes
112
- if (path == self.docs_url or
110
+ # Skip both original and new documentation routes
111
+ if (path == self.original_docs_url or
112
+ path == self.original_redoc_url or
113
+ path == self.original_openapi_url or
114
+ path == self.docs_url or
113
115
  path == self.redoc_url or
114
116
  path == self.openapi_url or
115
- path.startswith(f"{self.docs_url}/") or # Docs static files
116
- path == "/openapi.json"):
117
+ path == "/docs" or # Default docs
118
+ path == "/redoc" or # Default redoc
119
+ path == "/openapi.json" or # Default openapi
120
+ path.startswith("/docs/") or # Docs static files
121
+ path.startswith(f"{self.docs_url}/")): # New docs static files
117
122
  continue
118
123
 
119
124
  routes_to_keep.append(route)
@@ -154,19 +159,11 @@ class DocShield:
154
159
  headers={"WWW-Authenticate": "Basic"},
155
160
  )
156
161
 
157
- def _setup_routes(
158
- self,
159
- swagger_js_url: Optional[str],
160
- swagger_css_url: Optional[str],
161
- redoc_js_url: Optional[str],
162
- ) -> None:
162
+ def _setup_routes(self) -> None:
163
163
  """
164
164
  Set up all protected documentation endpoints.
165
165
 
166
- Args:
167
- swagger_js_url: Custom Swagger UI JavaScript URL
168
- swagger_css_url: Custom Swagger UI CSS URL
169
- redoc_js_url: Custom ReDoc JavaScript URL
166
+ Uses the stored swagger_js_url, swagger_css_url, and redoc_js_url.
170
167
  """
171
168
  # Set up OpenAPI JSON endpoint
172
169
  @self.app.get(self.openapi_url, include_in_schema=False)
@@ -186,16 +183,16 @@ class DocShield:
186
183
  self._verify_credentials(credentials)
187
184
 
188
185
  # Determine which URLs to use
189
- if swagger_js_url is not None or swagger_css_url is not None:
186
+ if self.swagger_js_url is not None or self.swagger_css_url is not None:
190
187
  # User provided custom URLs, use them
191
188
  kwargs = {
192
189
  "openapi_url": self.openapi_url,
193
190
  "title": self.app.title + " - Swagger UI",
194
191
  }
195
- if swagger_js_url is not None:
196
- kwargs["swagger_js_url"] = swagger_js_url
197
- if swagger_css_url is not None:
198
- kwargs["swagger_css_url"] = swagger_css_url
192
+ if self.swagger_js_url is not None:
193
+ kwargs["swagger_js_url"] = self.swagger_js_url
194
+ if self.swagger_css_url is not None:
195
+ kwargs["swagger_css_url"] = self.swagger_css_url
199
196
  elif self.static_handler and self.prefer_local:
200
197
  # Prefer local files
201
198
  js_url, css_url = self.static_handler.get_swagger_urls(prefer_local=True)
@@ -229,12 +226,12 @@ class DocShield:
229
226
  self._verify_credentials(credentials)
230
227
 
231
228
  # Determine which URL to use
232
- if redoc_js_url is not None:
229
+ if self.redoc_js_url is not None:
233
230
  # User provided custom URL, use it
234
231
  kwargs = {
235
232
  "openapi_url": self.openapi_url,
236
233
  "title": self.app.title + " - ReDoc",
237
- "redoc_js_url": redoc_js_url,
234
+ "redoc_js_url": self.redoc_js_url,
238
235
  }
239
236
  elif self.static_handler and self.prefer_local:
240
237
  # Prefer local files
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "fastapi-docshield"
7
- version = "0.2.0"
7
+ version = "0.2.1"
8
8
  description = "A simple FastAPI integration to protect documentation endpoints with authentication"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.7"
@@ -42,6 +42,7 @@ dev = [
42
42
  "httpx>=0.23.0",
43
43
  "uvicorn>=0.18.0",
44
44
  "requests>=2.28.0",
45
+ "python-multipart>=0.0.5",
45
46
  ]
46
47
 
47
48
  [project.urls]