How do I use swagger-codegen cli with custom template? - swagger-codegen

I would like to add a few tweaks to the typescript-fetch template.
I have downloaded the typescript-fetch folder linked above and stored it in .\template folder in my project. I assumed that all I would have to do is pass --template-dir .\template to the CLI as follows:
>Java -jar .\bin\swagger-codegen-cli.jar generate -l typescript-fetch -i https://localhost:7113/swagger/v1/swagger.json -o output -Dio.swagger.v3.parser.util.RemoteUrl.trustAll=true --template-dir .\template
but getting the following exception:
07:55:44.212 [Thread-1] INFO i.s.codegen.v3.AbstractGenerator - writing file c:\projects\trustwell-api-client-ts\output\index.ts
Exception in thread "Thread-1" java.lang.RuntimeException: Could not generate supporting file 'SupportingFile:
templateFile: api.mustache
folder:
destinationFilename: api.ts
'
at io.swagger.codegen.v3.DefaultGenerator.generateSupportingFiles(DefaultGenerator.java:666)
at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:789)
at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:388)
at java.lang.Thread.run(Unknown Source)
Caused by: com.github.jknack.handlebars.HandlebarsException: c:\projects\trustwell-api-client-ts\.\template\api.mustache:142:73: found: '-last', expected: 'no viable alternative at input '{{^-last''
? configuration.accessToken("{{name}}", [{{#scopes}}"{{{scope}}}"{{^-last}}, {{/-last}}{{/scopes}}])
^
at com.github.jknack.handlebars.internal.HbsErrorReporter.syntaxError(HbsErrorReporter.java:93)
at com.github.jknack.handlebars.internal.antlr.ProxyErrorListener.syntaxError(ProxyErrorListener.java:41)
at com.github.jknack.handlebars.internal.antlr.Parser.notifyErrorListeners(Parser.java:544)
...
It seems that CLI is picking up my folder, but I'm not sure if there is anything else I need to do to make this work.
Question: how can I run swagger-codegen CLI with local mustache templates?

The solution was to use templates from here:
https://github.com/swagger-api/swagger-codegen-generators/tree/master/src/main/resources/handlebars/typescript-fetch
I don't understand the distinction, and I suspect the two might get out of sync at some point, but it works.

Related

Cake Running Nunit 3 using DotNetCoreTest Is Failing

Task("Nunit")
.Does(() => {
DotNetCoreTest("D:\Workspace\Proj14\test\test\WebAutomation\NUnit\UserManageLMTWS.cs", );
});
Currently have by build.cake defining the task as such as listed in the https://cakebuild.net/api/Cake.Common.Tools.DotNetCore/DotNetCoreAliases/8191BBC4 example. I don't have any settings, as I guess I'm building into Debug instead of Release, but I am getting the following errors when running the task:
Error: Bootstrapping failed for 'D:/Workspace/Proj14/test/test/Nunit'.
Nunit, line #0: Could not find script 'D:/Workspace/Proj14/test/test/Nunit'.
Do I need to pass NUnit into the DotNetCoreTest method somehow?
DotNetCoreTest is meant to test projects and not individual files.
So you specify either the <PROJECT> | <SOLUTION> | <DIRECTORY> file i.e.
DotNetCoreTest("./test/Project.Tests/", settings);
DotNetCoreTest("./test/My.sln", settings);
DotNetCoreTest("./test/Project.Tests/Project.Tests.csproj", settings);
DotNetCoreTest calls to the .NET SDK CLI command dotnet test.
The error you're receiving though is because the path to the specified script is wrong / doesn't exist. There's no file called D:/Workspace/Proj14/test/test/Nunit which is why error message says Could not find script 'D:/Workspace/Proj14/test/test/Nunit'

How do I customize the location of index.js with Sentry in React Native?

Our bundle entry point is at src/index.tsx, which appears not to match the Sentry default of ./index.js.
Sentry is failing on sentry-cli react-native-xcode with the error EOF while parsing a value at line 1 column 0.
Using debug log level, I see:
+ ENTRY_FILE=index.js
...
Error: The resource `/Users/lukecwilliams/Projects/mobile2mr/index.js` was not found.
And in the actual CLI command, this is being run: --entry-file index.js
We need instead --entry-file src/index.tsx. How can we customize this? I can't find an answer in the docs or source code.
I've found this solution (custom build script) but it's still not working.
I have a script in the project root:
sentry-cli-xcode-build.sh:
./node_modules/react-native/packager/react-native-xcode.sh ./src/index.tsx
And in the build command in project.pbxproj:
shellScript = "export SENTRY_PROPERTIES=sentry.properties\nexport EXTRA_PACKAGER_ARGS=\"--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/#sentry/cli/bin/sentry-cli react-native xcode ../sentry-cli-xcode-build.sh";
But the result is a fairly ambiguous: error: Permission denied (os error 13)
Do I need to change the directory setup somehow? I don't see a concrete example in Sentry docs or the GH answer above regarding where to put the script and how to reference it exactly.
It turns out that this build step should simply be disabled in iOS projects using Bitcode (which is the default). So, we have no more need to run a custom build script.
We'll use Fastlane afterward to upload debug symbols.
Docs for reference:: https://docs.sentry.io/platforms/react-native/#ios-specifics
The answer is
export ENTRY_FILE=index.ios.js
in the script

"Unrecognized plugin: org.jetbrains.plugins.cucumber.java.run.CucumberJvm2SMFormatter" error every time I run test in intellij idea

I am getting the following error every time I try to cucumber test using the cucumber plugin in Intellij Idea. I am using the following version deaIC-2017.3.5. I even tried installing the latest version - ideaIC-2018.2.4 - but the issue still persists. Anybody has any idea why this could be happening?
Exception in thread "main" cucumber.runtime.CucumberException: Unrecognized plugin: org.jetbrains.plugins.cucumber.java.run.CucumberJvm2SMFormatter
at cucumber.runtime.RuntimeOptions.addPluginName(RuntimeOptions.java:171)
at cucumber.runtime.RuntimeOptions.parse(RuntimeOptions.java:122)
at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:84)
at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:77)
at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:69)
at cucumber.api.cli.Main.run(Main.java:31)
at cucumber.api.cli.Main.main(Main.java:18)
In the "Run/Debug Configuration", update "Program arguments" replacing --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvm2SMFormatter by --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvmSMFormatter
Let me illustrate how I encountered and found a way about to solve this problem.
I used to run my feature file by right clicking and run in intelliJ. Then I modified the program arguments in the edit configuration for that Run XYZ.feature file configuration.
In that process, I deleted the argument that passed " org.jetbrains.plugins.cucumber.java.run.CucumberJvm4SMFormatter" and added "--thread 5" something like that.
And then when I was done with wanted to revert to the old config. It wouldn't run and throw this error. My hunch is that maybe the arguments are not being passed properly?.
Anyway the solution (kinda hack) is to choose another feature file ABC.feature and edit the configuration for Run ABC.feature and change the location path of the feature file to XYZ.feature and change nothing else. Maybe could rename the configuration to Run XYZ2.feature something like that.This works for me.
This has worked for me: (intelliJ)
In the Program Arguments I have kept below line and it worked for me.
--plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvmSMFormatter --monochrome --name "^Login with valid credentials$"

Configuring Erlang plugin for Intellij

I am trying to set-up an Erlang project in IntelliJ 15. I am running windows.
I have built Rebar. trying escript.exe "//rebar_path//" --version returns the version number. Erlang also works on command line. In Settings->Other-settings->Erlang External tools I have the address of rebar file and IntelliJ detects the version number alright.
For my hello-world Erlang App, I have added an Erlang console application which runs fine and gives me
D:/Program Files/erl7.2.1\bin\erl" -pa E:/Documents/Projects/Erlang_test/out/production/Erlang_test -pa E:/Documents/Projects/Erlang_test
at the top. However attempting to call the functions gives me:
exception error: undefined function hello:hello2/0
It's as if compilation does not happen. I also tried setting up an "Erlang Rebar" Run configuration with compile as the command. It outputs:
*"D:\Program Files\erl7.2.1\bin\escript.exe"
E:\Documents\Projects\rebar_source\rebar c*
at the top, followed by the error:
escript: Error executing 'D:\Program': 193
What am I doing wrong?
update: I tried adding the rebar.cmd as an external tool to run it before the run configuration. After doing some research, I tried adding a rebar.config file with:
{sub_dirs, ["src" ] }.
to match the project structure.
Running the tool with compile on its own outputs: (configuration page screenshot)
==>src (compile)
==> Erlang_test (compile)
I was expecting to get: Compiled src/hello.erl but I neither get that, nor do I see any bean files created anywhere; and if I try running hello:hello() in the "Erlang console" run configuration gives me:
exception error: undefined function hello:hello2/0

Why is sys.stdin.encoding under PyDev / Jython different from standalone Jython console?

I am trying to get python-gnupg to work in Jython under PyDev under Eclipse. There is a problem which seems to be caused by the sys.stdin.encoding, which is tested by python-gnupg at it's initialisation.
I found that the following script
import sys
print sys.stdin.encoding
outptus cp850 when I run it from Python standalone in a console and from Jython standalone in a console. When I run it in Python under PyDev, it outputs Cp1252, and when I run it in Jython under PyDev, I get None.
Looking at python-gnupg, both encodings cp850 and Cp1252 seem to be ok, but if it's None, it raises an exception:
File "C:\Python27\lib\site-packages\gnupg.py", line 487, in __init__
self._collect_output(p, result, stdin=p.stdin)
File "C:\Python27\lib\site-packages\gnupg.py", line 561, in _collect_output
stderr = codecs.getreader(self.encoding)(process.stderr)
File "C:\jython2.5.2\Lib\codecs.py", line 920, in getreader
return lookup(encoding).streamreader
at org.python.core.codecs.normalizestring(codecs.java:101)
at org.python.core.codecs.lookup(codecs.java:75)
at org.python.modules._codecs.lookup(_codecs.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
java.lang.NullPointerException: java.lang.NullPointerException
Looks like there are differences between PyDev and standalone encodings, as well as no (?) encoding for PyDev/Jython? I'd really like to use the convenient PyDev development environment, but how can I get the sys.stdin.encoding to be something sensible when developing a Jython program?
Update 1
Maybe the problem is related to one of the following Jython bug reports:
http://bugs.jython.org/issue1839
http://bugs.jython.org/issue1807 (see msg6717)
But then again, these seem to be independent from PyDev/Eclipse..?
It's actually a Jython issue:
In PySystemState.java, when setting up the encodings, Jython will skip setting any encoding if it's not a tty console:
private void initEncoding() {
String encoding = registry.getProperty(PYTHON_CONSOLE_ENCODING);
if (encoding == null) {
return;
}
for (PyFile stdStream : new PyFile[] {(PyFile)this.stdin, (PyFile)this.stdout,
(PyFile)this.stderr}) {
if (stdStream.isatty()) {
stdStream.encoding = encoding;
}
}
}
So, a workaround could be creating a java module to set that (as encoding is a public field of PyFile, but does not have a setter from the Jython side -- or you could use java reflection to set it)...
Maybe you could ask the Jython guys why this is made in the first place (I think the encoding could be set even if it was not a tty device, but I'm not sure which implications could it have and why it's done that way).
EDIT to summarise the results of the many comments below, between the developers of Jython and PyDev as well as the author of the original question (Philip Jenvey, Fabio Zadrozny and Christian Gelinek, resp.):
During the progress, a couple of test scripts were discussed and developed:
A Python unit test written by Philip to test different encodings set by minimal custom created sitecusomize.py scripts. Fabio thinks that the reason for it not actually setting the encoding is because sys.stdin.encoding is inherited from the parent process instead configured by the unit test script.
A Java test program written by Christian which sets up custom I/O streams for creating a Python subprocess, which was found by Fabio to be more similar to how PyDev sets up the subprocess.
As this didn't work as expected by Fabio, he remembered that PyDev also uses the PYTHONIOENCODING environment variable.
As was pointed out by Philip, the current (2.5) version of Jython doesn't support the PYTHONIOENCODING environment variable, which is used by PyDev (in combination with sitecusomize.py) to set the encoding:
You can log a bug for it, although PYTHONIOENCODING was only added in CPython 2.6, so Jython probably wouldn't support it until 2.7 (Jython's skipping 2.6).
I believe you should be able to explicitly encoding on the launch properties.
Run configurations -> Python run -> Xxx -> Common tab -> Encoding.
PyDev inherits some settings from global Eclipse settings. On Linux the encoding is sane UTF-8 everywhere, but some cranky operating systems cause their own issues..
Also you can probably detect encoding in your .py main module and have PyDev specific hack to fix problems related to your configuration.