Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support spectree[offline] #399

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@ If all you need is a framework-agnostic library that can generate OpenAPI docume

## Quick Start

Install with pip: `pip install spectree`. If you'd like for email fields to be validated, use `pip install spectree[email]`.
Install with pip:

```bash
pip install spectree
```

If you want to install with offline OpenAPI web pages support:

> Offline mode doesn't support SwaggerUI OAuth2 redirection.

```bash
pip install spectree[offline]
```

### Examples

Expand Down
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[project]
name = "spectree"
version = "1.4.3"
version = "1.4.4"
dynamic = []
description = "generate OpenAPI document and validate request&response with Python annotations."
readme = "README.md"
license = {text = "Apache-2.0"}
requires-python = ">=3.8"
requires-python = ">=3.9"
authors = [
{ name = "Keming Yang", email = "kemingy94@gmail.com" },
]
Expand All @@ -14,7 +14,6 @@ classifiers = [
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand All @@ -28,6 +27,9 @@ dependencies = [
]

[project.optional-dependencies]
offline = [
"offapi>=0.1.0",
]
dev = [
"ruff>=0.1.3",
"mypy>=0.971",
Expand Down
4 changes: 2 additions & 2 deletions spectree/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ._pydantic import AnyUrl, InternalBaseModel, root_validator
from .models import SecurityScheme, Server
from .page import DEFAULT_PAGE_TEMPLATES
from .page import PAGE_TEMPLATES


class ModeEnum(str, Enum):
Expand Down Expand Up @@ -69,7 +69,7 @@ class Configuration(InternalBaseModel):
#: to render the documentation page content. (Each page template should contain a
#: `{spec_url}` placeholder, that'll be replaced by the actual OpenAPI spec URL in
#: the rendered documentation page
page_templates: Dict[str, str] = DEFAULT_PAGE_TEMPLATES
page_templates: Dict[str, str] = PAGE_TEMPLATES
#: opt-in type annotation feature, see the README examples
annotations: bool = True
#: servers section of OAS :py:class:`spectree.models.Server`
Expand Down
13 changes: 12 additions & 1 deletion spectree/page.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict

DEFAULT_PAGE_TEMPLATES: Dict[str, str] = {
ONLINE_PAGE_TEMPLATES: Dict[str, str] = {
# https://github.com/Redocly/redoc
"redoc": """
<!DOCTYPE html>
Expand Down Expand Up @@ -189,3 +189,14 @@
</body>
</html>""",
}

try:
from offapi import OpenAPITemplate

PAGE_TEMPLATES = {
"redoc": OpenAPITemplate.REDOC.value,
"swagger": OpenAPITemplate.SWAGGER.value,
"scalar": OpenAPITemplate.SCALAR.value,
}
except ImportError:
PAGE_TEMPLATES = ONLINE_PAGE_TEMPLATES
Loading