I am currently trying to develop a REST API using Erlang. I used OpenAPI (Swagger) to define the API and wanted to use their openapi-generator to create the stubs and some helper code. This also works and some code is generated, but I cannot find any documentation on what I have to do from there.
For the explanation of my problem, I will refer to their sample output from code generation for erlang-server.
I have two main problems at the moment:
I cannot find an entry point into the code (e.g. a init/0 or start/0 function)
I am not sure which function I have to implement to execute my code on each endpoint. I think that I have to implement handle_request, but the execution path seems a bit weird to me.
Which function to implement
In openapi_router they define openapi_pet_handler to be the handler for 'AddPet'. In that module, there is a function called handle_request_json, which tries to populate the request and in case of OK executes openapi_logic_handler:handle_request(LogicHandler, ...).
openapi_logic_handler:handle_request(Handler, ...) takes that handler and executes Handler:handle_request(OperationID, Req, Context).. This leads me to the conclusion, that I probably have to implement openapi_pet_handler:handle_request with my custom code.
How to start the server
I checked the code and it seems to use cowboy as a web server. At least it includes dependencies to cowboy in the generated openapi.app.src. However, in rebar.config there is no reference to cowboy.
In the cowboy tutorial, they use erlang.mk to build their project. This allows them to run the code with make run. With rebar this does not seem to be possible. I did not find a specific command for rebar to start a program. You seem to have to know the entrypoint (init function) if you use rebar.
However, I am not able to find any function that looks like it could be an init function in the generated stub code.
Summary
Can somebody explain what has to be done to use the stub generated by openapi-generator for erlang-server? Do I have to setup my own cowboy project and then somehow link the stubs into it? If yes, how?
Related
I've just started looking into using NSwag to auto-generate typescript clients for a WebAPI project. I've naively started with this simple build step:
nswag webapi2swagger /assembly:bin\MyProject.WebAPI.dll /output:Swagger.json
nswag swagger2tsclient /input:Swagger.json /output:WebAPIs.ts
This works great... maybe too great. I've now got a 17000 line typescript file full of clients for every endpoint in the API.
I know I could specify individual classes or controllers for nswag to generate, but I'd like it to be automatic for new controllers as we continue to build the system. Ideally, I'd probably be best served with a set of typescript files where each file represented a single controller.
Does anyone know how I might use the command line tools to break up the output that way?
I don't think this is possible with the current CLI tools, so I wrote a small console application which uses reflection to gather controllers from the webapi assembly, then calls the WebApiToSwaggerGenerator and SwaggerToTypeScriptClientGenerator for each controller individually.
This is not possible yet but you can follow this feature's progress on: https://github.com/RicoSuter/NSwag/issues/1398
The page contains some suggested workarounds. One is to use this tool:
https://github.com/hemiaoio/nswag-ts-splitter
I'm developing a DSL using xText (version 2.10.0) and i would like to add also a code generator.
When running the plug-ins, as I understood, the code generator should be invoked automatically upon a change in a file.
This is not happening.
Using a debugger I've noticed that the doGenerate function is not invoked.
What can I do so the doGenerate function will be invoked automatically?
Thanks.
Your file needs the right file extension (case sensitive) the project needs xtext nature and build automatically needs to be enabled. Then the generator will be called upon save of error free models
I'm trying PHPStorm and have trouble with its code completion. I write project with Silex framework and faced PHPStorm's lack of code completion for Silex dependency injection container. For example, it doesnt codecomplete $app['twig']-> or $app['db']-> or any other service. The only way solution I've found is to do smth like this
$db = $app['db'];
/** #var $db \Doctrine\DBAL\Connection */
$db->....
And then PHPStorm will do code completion. Services are registered using ServiceProvider interface.
Is there a way to make PHPStorm do code completion in such cases without additional vars and comments?
As far as I'm aware, this is currently not possible, however, there is currently work going on to add support for generic factory patterns, see this issue on their issue-tracker:
http://youtrack.jetbrains.com/issue/WI-6027
The PhpStorm developers welcome new feature requests on their issue tracker and are quite responsive. So you may file a feature request
Also, this may be related to your question:
http://youtrack.jetbrains.com/issue/WI-5304
Here's a plugin for PHPStorm / Intellij IDEA:
https://plugins.jetbrains.com/plugin/7809?pr=
Didn't tried it yet, but looks promising...
Edit: Just gave it a quick shot, and it looks really cool and simple to set up:
Install the plugin via the IDE plugin manager
Add the following dependency:
"require": {
"sorien/silex-pimple-dumper": "~1.0"
}
Register the provider:
$app->register(new Sorien\Provider\PimpleDumpProvider());
And you are done.
Folks, i'm trying to execute a jar file inside RoR. Thanks to SO, I figured using IO::popen calls to execute a jar file.
Requirements:
- To login to site: To let our company employees login. Its a Java library which does some magic and figures if the username/password is valid. Which I did using,
result = IO::popen("java -cp auth.jar com.name.auth.LDAPLookup " + params[:username] + " " + params[:password]).read
p result
output: ["Authorized", "email", "id"]
No input sanitizing done. This is risky. Anyone could type something up in username/password and that will be executed in the server.
I'm not sure how to do this. One option I want to try is to use fork() or Process APIs to launch "java" and pass arguments. Couldn't figure out however. Any other thoughts?
Aside from the issue you mention, this sounds pretty painful in terms of performance (you're waiting around for the JVM to start up on every request, after all).
Two solutions jump out at me:
Look what the library does, and see if you really need to call out to Java for this; in particular, if it's just a question of making a lookup in an LDAP directory with a set of canned parameters, there are plenty of gems for that
If you must make use of Java classes from Ruby, strongly consider using JRuby, which will let you call the Java class in question directly, with neither the overhead of restarting the JVM on each call, nor the risk which comes with trying to correctly escape your arguments from Ruby to the shell to the JVM, and back.
I am using someone else's library that provides its own scripting host instance, it appears.
This lib provides me with functions to define the type of scripting language such as "jscript" and "vbscript", and I can supply it with script code and have that executed, with passing arguments in and back. So, basically, it works.
However, when I try to access the "WScript" object, I get an exception saying that this keyword is undefined.
The developer, not knowing much about this either (he only made this lib for me because I do not want to deal with Windows SDKs right now), told me that he is using "IScriptControl" for this.
Oh, and the lib also provides flags to allow "only safe subset" and "allow UI", which I set to false and true, respectively.
Does that ring a bell with anyone? Do a user of IScriptControl have to take extra steps in order to make a WScript object available? Or, can he use IScriptControl in a way that this is supplied automatically, just as when running the same script from wscript.exe?
Basically, all I need is the WScript.CreateObject function in order to access another app's API via COM.
I don't know why WScript is not known, but I suspect it is because the script host doesn't provide it. Maybe only wscript.exe does this.
If you are using Javascript, to create an object you can use new ActiveXObject(). If you are using VBScript, you can just use CreateObject.
See this article for some background.