Skip to content

Commit

Permalink
Merge pull request #20 from community-of-python/vrslev-patch-1
Browse files Browse the repository at this point in the history
Disable debug and reload & enable offline docs by default
  • Loading branch information
insani7y authored Oct 10, 2024
2 parents 0a5693a + cda71a8 commit 15e91e5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ from microbootstrap import LitestarSettings

class YourSettings(LitestarSettings):
# General settings
service_debug: bool = False
service_name: str = "my-awesome-service"

# Sentry settings
Expand Down Expand Up @@ -140,7 +139,6 @@ Example:

```python
class YourSettings(BaseServiceSettings):
service_debug: bool = True
service_name: str = "micro-service"

your_awesome_parameter: str = "really awesome"
Expand Down Expand Up @@ -171,7 +169,6 @@ from microbootstrap.settings import BaseServiceSettings


class ServiceSettings(BaseServiceSettings):
service_debug: bool = True
service_environment: str | None = None
service_name: str = "micro-service"
service_description: str = "Micro service description"
Expand Down Expand Up @@ -325,7 +322,7 @@ These settings are subsequently passed to [opentelemetry](https://opentelemetry.
<b>microbootstrap</b> provides in-memory JSON logging through the use of [structlog](https://pypi.org/project/structlog/).
For more information on in-memory logging, refer to [MemoryHandler](https://docs.python.org/3/library/logging.handlers.html#memoryhandler).

To utilize this feature, your application must be in non-debug mode, meaning `service_debug` should be set to `False`.
To utilize this feature, your application must be in non-debug mode, meaning `service_debug` should be set to `False`, which is the default.

```python
import logging
Expand Down
2 changes: 1 addition & 1 deletion microbootstrap/instruments/swagger_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SwaggerConfig(BaseInstrumentConfig):
service_static_path: str = "/static"

swagger_path: str = "/docs"
swagger_offline_docs: bool = False
swagger_offline_docs: bool = True
swagger_extra_params: dict[str, typing.Any] = pydantic.Field(default_factory=dict)


Expand Down
4 changes: 2 additions & 2 deletions microbootstrap/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class BaseServiceSettings(
pydantic_settings.BaseSettings,
):
service_debug: bool = True
service_debug: bool = False
service_environment: str | None = None
service_name: str = pydantic.Field(
"micro-service", validation_alias=pydantic.AliasChoices("SERVICE_NAME", f"{ENV_PREFIX}SERVICE_NAME")
Expand All @@ -38,7 +38,7 @@ class BaseServiceSettings(

server_host: str = "0.0.0.0" # noqa: S104
server_port: int = 8000
server_reload: bool = True
server_reload: bool = False
server_workers_count: int = 1

model_config = pydantic_settings.SettingsConfigDict(
Expand Down
6 changes: 3 additions & 3 deletions tests/instruments/test_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_swagger_teardown(


def test_litestar_swagger_bootstrap_online_docs(minimal_swagger_config: SwaggerConfig) -> None:
minimal_swagger_config.swagger_offline_docs = False
swagger_instrument: typing.Final = LitestarSwaggerInstrument(minimal_swagger_config)

swagger_instrument.bootstrap()
Expand All @@ -52,7 +53,6 @@ def test_litestar_swagger_bootstrap_online_docs(minimal_swagger_config: SwaggerC


def test_litestar_swagger_bootstrap_offline_docs(minimal_swagger_config: SwaggerConfig) -> None:
minimal_swagger_config.swagger_offline_docs = True
swagger_instrument: typing.Final = LitestarSwaggerInstrument(minimal_swagger_config)

swagger_instrument.bootstrap()
Expand All @@ -72,6 +72,7 @@ async def test_litestar_swagger_bootstrap_working_online_docs(
minimal_swagger_config: SwaggerConfig,
) -> None:
minimal_swagger_config.swagger_path = "/my-docs-path"
minimal_swagger_config.swagger_offline_docs = False
swagger_instrument: typing.Final = LitestarSwaggerInstrument(minimal_swagger_config)

swagger_instrument.bootstrap()
Expand All @@ -88,7 +89,6 @@ async def test_litestar_swagger_bootstrap_working_offline_docs(
minimal_swagger_config: SwaggerConfig,
) -> None:
minimal_swagger_config.service_static_path = "/my-static-path"
minimal_swagger_config.swagger_offline_docs = True
swagger_instrument: typing.Final = LitestarSwaggerInstrument(minimal_swagger_config)

swagger_instrument.bootstrap()
Expand Down Expand Up @@ -116,6 +116,7 @@ async def test_fastapi_swagger_bootstrap_working_online_docs(
minimal_swagger_config: SwaggerConfig,
) -> None:
minimal_swagger_config.swagger_path = "/my-docs-path"
minimal_swagger_config.swagger_offline_docs = False
swagger_instrument: typing.Final = FastApiSwaggerInstrument(minimal_swagger_config)

swagger_instrument.bootstrap()
Expand All @@ -132,7 +133,6 @@ async def test_fastapi_swagger_bootstrap_working_offline_docs(
minimal_swagger_config: SwaggerConfig,
) -> None:
minimal_swagger_config.service_static_path = "/my-static-path"
minimal_swagger_config.swagger_offline_docs = True
swagger_instrument: typing.Final = FastApiSwaggerInstrument(minimal_swagger_config)
fastapi_application = fastapi.FastAPI(
**swagger_instrument.bootstrap_before(),
Expand Down

0 comments on commit 15e91e5

Please sign in to comment.