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

OpenAPI Endpoint #3705

Open
makp0 opened this issue Nov 28, 2024 · 6 comments
Open

OpenAPI Endpoint #3705

makp0 opened this issue Nov 28, 2024 · 6 comments
Labels
enhancement New feature or request integration Command-line interface

Comments

@makp0
Copy link

makp0 commented Nov 28, 2024

As a user I would like to generate BetterDisplay HTTP clients in multiple languages from an OpenAPI endpoint exposed by BetterDisplay.

For example, it will allow to no-code integrate BetterDisplay with Node-Red using this package:
https://flows.nodered.org/node/openapi-red

@waydabber
Copy link
Owner

I am not very familiar with OpenAPI except that it's a descriptor of some kind. The app generates the current help from its internal structures so depending on how complicated OpenAPI is (need to look into it) it might be possible to create and maintain an OpenAPI specification. Will tag this as an enhancement.

@waydabber waydabber added enhancement New feature or request integration Command-line interface labels Nov 28, 2024
@makp0
Copy link
Author

makp0 commented Nov 28, 2024

What framework is BetterDisplay using for it's RESTful APIs?

My best guess would be Vapor.

Here's ChatGPT's guide on the least intrusive approach (of course, may as well be a complete BS):

To integrate OpenAPI into a Vapor project with no required changes to existing routes, use VaporToOpenAPI.

1. Add Dependency

Add the library to your Package.swift:

.package(url: "https://github.com/dankinsoid/VaporToOpenAPI.git", from: "1.0.0")

2. Expose OpenAPI Specification

Expose the OpenAPI specification without modifying existing routes:

app.get("openapi.json") { req in
    req.application.routes.openAPI(
        info: InfoObject(
            title: "My Vapor API",
            description: "API documentation for My Vapor App.",
            version: "1.0.0"
        )
    )
}

@waydabber
Copy link
Owner

It does not use any framework, as there is a common interpreter for HTTP, command line, macOS notification dispatch, the entire thing is totally custom-written.

@makp0
Copy link
Author

makp0 commented Nov 28, 2024

Screenshot 2024-11-28 at 11 34 48

It's interesting why API's response headers contain Server: Aoxiang. Usually, this header should be hidden not to give any clues to attackers

@waydabber
Copy link
Owner

It's because I reused a simple lightweight Swift implementation for HTTP:

https://github.com/isaced/Aoxiang

Screenshot 2024-11-28 at 14 13 31

I am not sure it is hardened in any way against any kind of attacks, this is meant for maybe for a home enthusiast integration thing only or some one-off projects - after all it's about controlling a display of one specific Mac. :)

But if it is any trouble, I can remove that. Felt like a nice touch not to though.

@waydabber
Copy link
Owner

Anyway, I removed the header for the sake of security through obscurity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request integration Command-line interface
Projects
None yet
Development

No branches or pull requests

2 participants