Skip to content

Comments

feat: new scalar UI provider to provide beautiful UI to blacksheep de…#531

Merged
RobertoPrevato merged 1 commit intoNeoteroi:mainfrom
arthurbrenno:main
Apr 27, 2025
Merged

feat: new scalar UI provider to provide beautiful UI to blacksheep de…#531
RobertoPrevato merged 1 commit intoNeoteroi:mainfrom
arthurbrenno:main

Conversation

@arthurbrenno
Copy link
Contributor

I've added a new integration for Scalar. Scalar is one of the UI providers that provide the most beautiful UIs. I think it would be a great add to BlackSheep default UI providers. I've only changed ui.py file.

@RobertoPrevato
Copy link
Member

Thanks for the PR, @arthurbrenno. It looks interesting and I am willing to merge, but I wish to review Scalar before merging.

@arthurbrenno
Copy link
Contributor Author

Np. Thanks!

@bymoye
Copy link
Contributor

bymoye commented Apr 11, 2025

hi, I think creating a separate file named scalar_ui.html and putting it in blacksheep.server.res will make the code style more unified.

<!DOCTYPE html>
<html>

<head>
    <title>##PAGE_TITLE##</title>
    <link rel="icon" href="##FAVICON_URL##" />
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link href="##CSS_URL##" rel="stylesheet">
</head>

<body>
    <div id="app"></div>
    <script src="##JS_URL##"></script>
    <script>
        Scalar.createApiReference('#app', {
            url: '##SPEC_URL##',
        })
    </script>
</body>

</html>

Then change the function get_openapi_ui_html:

    def get_openapi_ui_html(self, options: UIOptions) -> str:
        """
        Returns the HTML response to serve the Scalar API Reference UI.
        Parameters:
        options (UIOptions): Configuration options for the UI
        Returns:
        str: HTML content for the Scalar UI
        """
        return (
            get_resource_file_content("scalar_ui.html")
            .replace("##PAGE_TITLE##", options.page_title)
            .replace("##FAVICON_URL##", options.favicon_url)
            .replace("##CSS_URL##", self.ui_files.css_url or "")
            .replace("##SPEC_URL##", options.spec_url)
            .replace("##JS_URL##", self.ui_files.js_url or "")
        )

@RobertoPrevato RobertoPrevato merged commit 9c77aa8 into Neoteroi:main Apr 27, 2025
2 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants