(I don't know if this is the right wot repository to ask my question. Sorry if I picked the wrong one).
We would like to support thing descriptions in our applications. However, there is a large stack of applications that provide OpenAPI specifications. In order to have a migration path, we would like to support both ways - TDs and OpenAPI files. However, to keep things consistent and reduce headache, we asked ourselves if there are any libraries or tools that can convert TDs into OpenAPI specs and back. Googling returned nothing, therefore I am asking here. Is anyone working on this?
As far as I know, there's no such a converter. TD to Open API conversion should be pretty easy, however, the opposite might be a lossy transformation, since OpenAPI is more expressive in some points (i.e. you can express different responses for one resource, but in TD you can't right now).
I guess if your company aims to be "Thing Description complaint", they have to use a subset of features of OpenAPI to be able to migrate easily in the future.
There is one since a couple of weeks, to be introduced in the W3C TPAC. It is a submodule of the TD playground for now and will be deployed on the hosted instance as well
https://github.com/thingweb/thingweb-playground/tree/master/playground-td_to_openAPI
By the way, this is only TD -> Open API and soon there will be TD -> Async API but the other way around has serious limitations, one you have already pointed out. One big difference is that TD abstracts resources into affordances where an affordance can have multiple resource representations or if the affordance is using an REST protocol like most industrial protocols and MQTT to some extend, the affordance will not have a resource but a URI-like string that represents one way to interaction with the affordance.
For doing the OpenAPI -> TD we need to figure out some things:
/myapi/properties/weather then we can wing it and say that this is a property called weather but what about other cases? We can simply name the property the URI of the resource and it would work.Since the above converter implementation was done by @adriankast, do you have something to add?
I think you mentioned all major points, but I can share some additional thoughts:
psk equivalent in openAPI, the http authentication has to happen in the Header, ...And you can always check the current state of TD -> OpenAPI conversion here:
https://github.com/adriankast/thingweb-playground/tree/openAPI
You can now easily test it out on the deployed version: http://plugfest.thingweb.io/playground/ :)
Now available as a standalone npm package: https://www.npmjs.com/package/@thing-description-playground/td_to_openapi :)
I propose closing this issue, @FilipBrinkmann are you ok?
I am sorry for answering late. Thanks to everyone for your quick and insightful answers. It definitely helped me a lot!
We will definitely have a look at the converter you pointed out. On a side note, I guess that it will be sufficient for our use cases - namely providing a fallback strategy for developers which are new to WoT, as well as for legacy applications using OpenAPI.
So this issue can be closed from my point of view. And thank you again - great community here!
Most helpful comment
And you can always check the current state of TD -> OpenAPI conversion here:
https://github.com/adriankast/thingweb-playground/tree/openAPI