Using OpenAPI from outside world

Hello everyone

It is obvious that OpenAPI was created to be used from inside of MPS. Then you have to use base language to operate it.

However I would like to use openapi from another application. I assume that importing a couple of jar-s and knowing how to bootstrap (i.e. how to create a new SRepository instance) would allow me to operate on MPS model programmatically, in particular I could get access to an existing MPS project.

Well, however this way of using openapi is not documented. Mainly I need to know:
1. Which jars I need ?
2. How to create a new SRepository instace having a given location of the project in the filesystem.
3. Am I not missing something important that makes the whole idea impossible ?

It probably should be said that I consider this question actually important for the whole future of MPS project. The scenario is: when my DSL built with MPS is not about EXECUTION, but about MODELLING, then the final result of what I want is the model expressed as data structures in target programming language. This language not necessarily being java. Well, I know I can possibly expost jar encapsulation of target structures and use this jar from inside MPS, so the transformation will happen via "generators" framework.

In practice it is less then optimal, for the first reason coming from the fact that I am using another programming language (yes, JVM based). And while I see MPS as a nice way to build my DSL, I want to limit my MPS base-lang code only to building the DSL. Once I get the resulting model, I want to process is on my custom platform.

From my perspective MPS being "open" is only via "openapi" usable from everywhere, not only from inside of MPS runtime.

Thanks for any help !
Wojtek
4 comments
We are in a similar situation. Within our code generation platform, which executes generators on a server, we would want to be able to programmatically access models that get created by means of MPS. Theoretically, I see at least four different options to accomplish this:

1) Using Open API outside of MPS, as outlined by Wojtek.
2) Implementing an MPS generator that serializes a model using Java serialization and use the serialized model (binary) within our platform to deserialize the model. I doubt that this will work at all. At least it is very likely that it doesn't work _properly_.
3) Send the whole MPS model repository to the server and parse the xml files there. I think this is only a theoretical solution since this would mean to duplicate the logic that is already there within MPS to handle projects, solutions, models, etc., which is a complex task to be implemented (and also not stable over time).
4) Implementing an MPS generator that creates a textual representation of a model. Send that textual representation to the server and parse it there in order to be able to use the result as the input for code generators.

I personally would prefer option 1). If this is not possible, I guess I will have to go for option 4), right?

Maybe there is already a way how MPS can support the above usage scenario?

Thanks for any help in relation to this issue,
Marcus
0
Hello Marcus

It is maybe worth saying that - mainly because my question remained unanswered - I applied the more ugly and more verbose (and honestly ... pretty desperate) approach: I implemented an "export feature" feature for my DSL by using MPS "generator" framework. The output language is XML (MPS representation of XML is fortunately bundled with MPS).

So effectively the development cycle I established looks like:
1. I implement/correct something using the DSL I crafted in MPS.
2. I export this as (MPS-based) XML model.
3. I generate XML model as text (getting a set of XML files).
4. I load XML files into my Scala app.
5. I work with this loaded model, discover problems.
6. goto (1)

Of course I am pretty unhappy with this solution because:
1. I had to spend effort making generator (FYI - generator tutorial is 12 hours of work, not mentioning surrounding docs, just to understand how this sophisticated generator feature works)
2. The export feature (=generator definition) has to be changed every time I introduce some changes into my DSL.

But at least it works :-)
Wojtek
0
I have further investigated this issue and found a solution that should work for me. Maybe this is something for you, too, Wojtek?

1. Develop an MPS plugin as being outlined here: https://confluence.jetbrains.com/display/MPSD32/Plugin
2. Adding an action - in my case I am adding the action "Export to XML"
3. Writing XML (or maybe a different format, whatever suites best) in an action handler. The output of this action handler will be typed according to the MPS meta meta model, which means there will be types like "model", "concept", "node" and the like, along the lines of the MPS OpenAPI types SModel, SConcept, SNode, etc.
4. To further process the XML, you can read it by means of JAXB. We will provide ready-to-use Java classes with JAXB annotations.
5. Convert the XML model to a strongly typed model. For example, if in my language I have the concept "Service", the result of this conversion will have objects of type "Service". I plan to provide a general facility to automatically generate the meta model for such a strongly typed model.

Once we will have completed this MPS plugin, we will make it available as open source. Please note that the very first version of it might not include step 5.
0
The solution with the action for the model export into generic XML format is what I wanted to suggest. It can use open API. No generator. But Marcus has already found it.
We also plan to create an additional feature for our build language that will execute arbitrary MPS code after build script execution. This will allow to start export routine (or other code) not from MPS. Just by running generated ant script.

Right now there is no simple way to use open API not from inside MPS.
0

Please sign in to leave a comment.