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 123 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 with git clone https://github.com/apple/swift-openapi-generator
  • run locally cd swift-openapi-generator && 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.

timbms added 30 commits March 14, 2025 17:50
… Mapping to openapi is anyway a manual process

Signed-off-by: Tim Bert <[email protected]>
OpenAPIServiceDelegate had a race condition that was addressed with the new actor AuthAttemptTracker

Signed-off-by: Tim Bert <[email protected]>
Make use of AuthAttemptTracker in HTTPClient / simplified interface for resetAttempt

Signed-off-by: Tim Bert <[email protected]>
…isationMiddleware, HTTPClient

In OpenHABRootViewController  transfer of password.

Signed-off-by: Tim Bert <[email protected]>
…rrespondingly remove it from NetworkTracker.

Signed-off-by: Tim Bert <[email protected]>
Changed path for getRoot  to '/'

Signed-off-by: Tim Bert <[email protected]>
…saving url in a codable, ensure the string is well formatted

Signed-off-by: Tim Bert <[email protected]>
… likely due to navigation

Continue adaptation of ConnectionConfiguration also in OpenHABSitemapViewController

Signed-off-by: Tim Bert <[email protected]>
Reworked DrawerView to remove appData / the environmentobject networktracker is injected now.

Signed-off-by: Tim Bert <[email protected]>
…enHABRootViewController, OpenHABSitemapViewController

Signed-off-by: Tim Bert <[email protected]>
…ted. Apple renamed webView(_, didReceive:, completionHandler:) to webView(_, respondTo:)

Signed-off-by: Tim Bert <[email protected]>
…to pass them down the throw handling / Enable ignore in the case of a cancellation.

Nicer connection testing button and feedback

Signed-off-by: Tim Bert <[email protected]>
Signed-off-by: Tim Bert <[email protected]>
Migration of HTTPClient's initializer to init(configuration: )
Migrating watchApp to ConnectionConfiguration

Signed-off-by: Tim Bert <[email protected]>
…d the decoding to HTTPClient convenience function

Signed-off-by: Tim Bert <[email protected]>
…oad and longpolling): Easier to cancel and debug, No more recursion or chaining needed.

Signed-off-by: Tim Bert <[email protected]>
Decluttering OpenHABSitemapViewController: moved helpers to separate files, moved extract icon logic to helper WidgetIconRenderer, preparing for using a widget cell provider

Signed-off-by: Tim Bert <[email protected]>
… widget types, abstract common behavior into protocols/extensions to reduce the giant cellForRowAt

Signed-off-by: Tim Bert <[email protected]>
Signed-off-by: Tim Bert <[email protected]>
…ration

Setting .requestModifier  in NetworkTracker

Signed-off-by: Tim Bert <[email protected]>
Signed-off-by: Tim Bert <[email protected]>
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