Skip to content

feat: add scalar configuration#4162

Merged
provinzkraut merged 7 commits intolitestar-org:mainfrom
skv0zsneg:scalar-configuration
May 4, 2025
Merged

feat: add scalar configuration#4162
provinzkraut merged 7 commits intolitestar-org:mainfrom
skv0zsneg:scalar-configuration

Conversation

@skv0zsneg
Copy link
Copy Markdown
Contributor

Description

Hello! I'm currently work on adding scalar configuration and during work got some questions:

  • I start adding config params from here, but not sure about including every param. What should we add?
  • Here is MRE for how to work with configuration:
from litestar import Litestar, get
from litestar.openapi.config import OpenAPIConfig
from litestar.openapi.datastructures import ScalarConfig
from litestar.openapi.plugins import ScalarRenderPlugin

scalar_plugin = ScalarRenderPlugin(version="1.19.5", config=ScalarConfig(show_sidebar=False))

@get("/")
async def hello_world() -> dict[str, str]:
    """Keeping the tradition alive with hello world."""
    return {"hello": "world"}

app = Litestar(
    route_handlers=[hello_world],
    openapi_config=OpenAPIConfig(
        title="Litestar Example",
        description="Example of Litestar with Scalar OpenAPI docs",
        version="0.0.1",
        render_plugins=[scalar_plugin],
        path="/docs",
    ),
)

I'm not sure about config dataclass object location. Maybe it must be somewhere else?

  • The config could change with changing Scalar version and we have version arg in ScalarRenderPlugin. So should we somehow detect difference?

Closes

#3951

@codecov
Copy link
Copy Markdown

codecov bot commented May 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.38%. Comparing base (7f8d1d4) to head (21dac5b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4162   +/-   ##
=======================================
  Coverage   98.38%   98.38%           
=======================================
  Files         348      348           
  Lines       15884    15889    +5     
  Branches     1754     1755    +1     
=======================================
+ Hits        15627    15632    +5     
  Misses        121      121           
  Partials      136      136           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@provinzkraut
Copy link
Copy Markdown
Member

Generally a good approach, but I'm not sure we need the config object at all. You could just add the options as arguments to the plugin directly, as it's already specialised for scalar.

The config could change with changing Scalar version and we have version arg in ScalarRenderPlugin. So should we somehow detect difference?

One option to do this would be to just accept a scalar_options: dict[str, Any]. Then the user is responsible for providing the correct options corresponding to the version.

Actually, I think this is the right approach, because otherwise we'd always have to make Litestar release before a new scalar option could be used.

@provinzkraut
Copy link
Copy Markdown
Member

Looks good! If you address the missing coverage, this can go in!

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 3, 2025

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/4162

@provinzkraut provinzkraut merged commit 94e1a48 into litestar-org:main May 4, 2025
29 checks passed
@provinzkraut provinzkraut linked an issue May 4, 2025 that may be closed by this pull request
@a-wip0
Copy link
Copy Markdown

a-wip0 commented Sep 2, 2025

i see this PR already merged to main, is the documentation not exist? https://docs.litestar.dev/2/search.html?q=ScalarConfig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: Support Scalar configuration

3 participants