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

Proposal to make use of swift-openapi-generator #799

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open

Conversation

timbms
Copy link
Contributor

@timbms timbms commented Aug 12, 2024

This is a proposal to make use of swift-openapi-generator presented at WWDC 23.

This proof-of-concept is working on openHAB iOS app:
-Properly polls data and handles updates
-Able to send commands
-Making use of structured concurrency, ie async/await, actors -Still a lot to do

Renamed OpenHABSitemapPage into OpenHABPage to avoid confusion Reworked OpenHABSitemap to properly handle embedded OpenHABPage
Created convenience initializers for OpenHAB models to map from openAPI generated models

Properly decoding required some manual changes on openAPI schema. They are reported as bugs to openHABcore #openhab/openhab-core#4340:
Widgets within a widget
Manually adding X-Atmosphere-Transport in header parameters for pollDataPage

Making use of openAPI in a package requires workaround to invoke the CLI manually: https://swiftpackageindex.com/apple/swift-openapi-generator/1.2.1/documentation/swift-openapi-generator/manually-invoking-the-generator-cli :

  • clone the generator package locally
  • run locally cd swift-openapi-generator generate && swift run swift-openapi-generator generate --config ../Sources/OpenHABCore/openapi/openapi-generator-config.yml --output-directory ../Sources/OpenHABCore/GeneratedSources/openapi ../Sources/OpenHABCore/openapi/openapi.json

Exclude the package and the generated code from swiftlint

Upgrade target to iOS 16
Making use of os logger new API

Support for basic authorization

timbms added 8 commits July 30, 2024 21:09
-Properly gets data every 30s
-Able to send commands
-Making use of structured concurrency, ie async/await, actors
-Still a lot to do

Renamed OpenHABSitemapPage into OpenHABPage to avoid confusion
Reworked OpenHABSitemap to properly handle embedded OpenHABPage
Created convenience initializers for OpenHAB models to map from openAPI generated models

Properly decoding widgets within a widget
Manually modifying the OpenHAB's openAPI schema
Manually adding X-Atmosphere-Transport in header parameters for pollDataPage

Transferred code to package - requires workaround to invoke the CLI manually: https://swiftpackageindex.com/apple/swift-openapi-generator/1.2.1/documentation/swift-openapi-generator/manually-invoking-the-generator-cli
:
- clone the generator package locally
- run locally  swift run swift-openapi-generator generate --config ../Sources/OpenHABCore/openapi/openapi-generator-config.yml --output-directory ../GeneratedSources/openapi ../Sources/OpenHABCore/openapi/openapi.json

Exclude the package and the generated code from swiftlint

Async update for actor APIActor and initialiser with URL about:blank
Using APIActor throughout the app
Upgrade target to iOS 16

Helper function openHABpollPage(sitemapname: String, longPolling: Bool) for access without

Making use internal accesModifier to properly isolate the internals in OpenHABCore
Using openAPI generated interface to send command
Support for basic authorization
Making use of os logger
… create event subscription, Allowing for X-Atmosphere-Transport for long-polling, SitemapWidgetEvent for server side events

Experimenting with SSE consumption
Include Client and Types to make it compile on github
Shifted logging to dedicated ClientMiddleware
Created class OpenHABSitemapWidgetEvent
Modified openapi to include sitemapName and pageId in SitemapWidgetEvent
Getting server sent events working - establishing a subscription and receiving events , not yet consuming  / Commented out in OpenHABSitemapViewController
update OpenHABWidget with OpenHABSitemapWidgetEvent
Update to swift-tools-version 5.10
In order not to expose decode OpenHABSitemapWidgetEvents manually. Some relaxations required on OpenHABItem
@digitaldan
Copy link
Contributor

this looks pretty cool, i know absolutely nothing about swift-openapi-generator in swift ;-)

@digitaldan
Copy link
Contributor

Would it make sense for me to add an openAPI schema to the myopenhab cloud service? So we can use the generator for calls for registering notifications, listing notifications, etc.... ?

@timbms
Copy link
Contributor Author

timbms commented Sep 15, 2024

Would it make sense for me to add an openAPI schema to the myopenhab cloud service? So we can use the generator for calls for registering notifications, listing notifications, etc.... ?

That would be cool. I just noticed that OpenHAB does not have an openAPI for notifications yet.
Also, if you could correct the openAPI scheme. I had to manually adjust to make it valid and correct.

@digitaldan
Copy link
Contributor

so i just created a PR for the cloud service, i have not tested this, let me know if this looks about right. I can always deploy this for us to test since it should not hurt anything.

openhab/openhab-cloud#474

Regarding Core, thats going to be a little more difficult, so i would plan to work around it if you can, i think it may take more time then we would want to wait for.

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.

2 participants