Possible to change the package name when generating client code - scala

I am generating the client scala code for an API using the Swagger Edtior. I pasted the json then did a Generate Client/Scala. It gives me a default root package of
io.swagger.client
I can't see any obvious way of specifying something different. Can this be done?

Step (1): Create a file config.json and add following lines and define package names:
{
"modelPackage" : "com.xyz.model",
"apiPackage" : "com.xyz.api"
}
Step (2): Now, pass the above file name along with codegen command with -c option:
$ java -jar swagger-codegen-cli.jar generate -i path/swagger.json -l java -o Code -c path/config.json
Now, it will generate your java packages like com.xyz… instead of default one io.swagger.client…

Run the following command to get information about the supported configuration options
java -jar swagger-codegen-cli.jar config-help -l scala
This will give you information about supported by this generator (Scala in this example):
CONFIG OPTIONS
sortParamsByRequiredFlag
Sort method arguments to place required parameters before optional parameters. (Default: true)
ensureUniqueParams
Whether to ensure parameter names are unique in an operation (rename parameters that are not). (Default: true)
modelPackage
package for generated models
apiPackage
package for generated api classes
Next, define a config.json file with the above parameters:
{
"modelPackage": "your package name",
"apiPackage": "your package name"
}
And supply config.json as input to swagger-codegen using the -c flag.

Related

How to use OneOf with OpenAPI generator for Dart?

I'm trying to use the OpenAPI generator for Dart (in particular dart-dio-next). First, some code and tooling invocation snippets:
API specification: https://raw.githubusercontent.com/aptos-labs/aptos-core/main/api/doc/openapi.yaml. In particular I'm focusing on TransactionPayload right now.
OpenAPI generator version:
$ openapi-generator --version
openapi-generator-cli 5.4.0
CLI invocation:
openapi-generator generate \
-i https://raw.githubusercontent.com/aptos-labs/aptos-core/main/api/doc/openapi.yaml \
-g dart-dio-next \
-c openapi-generator.yaml \
--enable-post-process-file \
Full script: https://gist.github.com/banool/e22d94025ecd713f1596285bc6661449.
openapi-generator.yaml:
# Unrelated fields like author omitted
pubName: aptos_api_dart
pubLibrary: "aptos_api_dart"
legacyDiscriminatorBehavior: true
# disallowAdditionalPropertiesIfNotPresent: false
useEnumExtension: true
Here are some potentially relevant docs / issues I've found:
https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/dart.md
https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/dart-dio.md
https://github.com/OpenAPITools/openapi-generator/issues/9507
Now, when I'm trying to use the client I'm doing this:
// Build a transaction request.
TransactionPayloadBuilder transactionPayloadBuilder =
TransactionPayloadBuilder()
..writeSet = (WriteSetBuilder())
..type = "script_function_payload"
..function_ = "0x1::Coin::transfer"
..typeArguments = ListBuilder(["0x1::TestCoin::TestCoin"])
..arguments = ListBuilder(
[otherAddress.withPrefix(), "100"].map((e) => JsonObject(e)));
SubmitTransactionRequest submitTransactionRequest =
(SubmitTransactionRequestBuilder()
..sender = account.address.withPrefix()
..payload = transactionPayloadBuilder)
.build();
// Submit the transaction.
await client
.getTransactionsApi()
.submitTransaction(submitTransactionRequest: submitTransactionRequest);
});
But I get an error like this:
$ flutter test
00:02 +4 -1: /Users/dport/github/aptos_sdk_dart/test/full_library_test.dart: client account e2e test [E]
Tried to build class "SubmitTransactionRequest" but nested builder for field "payload" threw: Tried to build class "TransactionPayload" but nested builder for field "code" threw: Tried to construct class "MoveScript" with null field "bytecode". This is forbidden; to allow it, mark "bytecode" with #nullable.
package:aptos_api_dart/src/model/submit_transaction_request.g.dart 221:9 SubmitTransactionRequestBuilder.build
test/full_library_test.dart 51:14 main.<fn>
The field it's talking about is not a required member of the variant of TransactionPayloadBuilder that I'm trying to use, ScriptFunctionPayload, and the server would know this based on type being the discriminator I believe. Naturally instead I should just build ScriptFunctionPayload, since that correctly requires only the necessary fields, except I can't pass this in to submitTransaction, because it expects a TransactionPayloadBuilder. Is there some way to make it generate a version of signTransaction that accepts any of the variants?
You can see what it generates here: https://github.com/banool/aptos_api_dart.
Assume I don't have control over the openapi spec and can't change it in any way.
Any help with how to use this correctly would be very much appreciated.
Thanks!

Is there any way to define own options in *.pc files except standard options

I am trying to make a .pc file and want to define a flag ldflags and use it something like this
pkg-config package --ldflags
but it's showing unknown option ldflags.
Is there a way to define my own option in pc file.
.pc file has special format, check here:
The file format contains predefined metadata keywords and freeform
variables.
keywords are fixed, e.g. Cflags and most of them correspond to pkg-config tool options e.g. --cflags. But variables:
... can be used by the keyword definitions for flexibility or to store
data not covered by pkg-config
So, it possible to add own, for example I created minimum possible one (Name, Version, Description are mandatory keywords):
$ cat test.pc
Name: test
Version: 1
Description: test
aaa=bbb
$ pkg-config --variable=aaa
bbb
It's possible to list all with --print-variables option (interestingly though that pcfiledir variable is added automatically):
$ pkg-config --print-variables test.pc
aaa
pcfiledir
$ pkg-config --variable=pcfiledir
.
It can even (re)define one variable using another:
$ cat test.pc
Name: test
Version: 1
Description: test
aaa=bbb${ccc}
$ pkg-config test.pc --variable=aaa --define-variable=ccc=xxx
bbbxxx
Wonder about your use case? since contents of this file is just for keeping metadata about dependencies some package has. Maybe you should add instead these flags to Libs or Libs.private keywords?

Open api generator : change Client name

I am using the "OpenApi generator" to create the client library for an api.
openapi-generator generate -i https://xxxx.cloudfront.net/openapi/en-us/product/2-0/openapi.yaml -g ruby -o tmp/test/custom_name
This generate a class "OpenapiClient" but I need to change this name to "CustomApiClient". How can I pass this value?
This seems to me a standard thing to do, why is not so immediate? Am I following the best practice?
# Load the gem
require 'openapi_client'
# Setup authorization
OpenapiClient.configure do |config|
# Configure Bearer authorization: bearer
config.access_token = 'YOUR_BEARER_TOKEN'
end
This seemed way harder to find than it should have been, but if you run openapi-generator config-help -g ruby, it will show you all the options for ruby client configurations. Specifically, gemName. So you can simply create a config file like:
# config.yaml
gemName: custom_api_client
and provide -c /path/to/your/config.yaml when running the generate command.

How to use plugin commands in bcftools?

My goal is to use bcftools to check that the reference alleles in my dataset (vcf file) match with a reference genome (fasta file) using the fixref plugin.
Working on command line, I first set the following environment:
export BCFTOOLS_PLUGINS=/path/to/bcftools/plugins
The following code is recommended for test datasets with mismatches:
bcftools +fixref test.bcf -Ob -o output.bcf -- -f ref.fa -m top
When I run this code using my own files (please note that my data is .vcf, not .bcf) I get the following error:
[main] Unrecognized command
If I simply enter:
bcftools
I get a list of the only 5 commands (view, index, cat, ld, ldpair) that I can use. So although I've set the environment, does it somehow need to be activated? Do I need to run my command through a bash script?
bcftools
was pointing to a deprecated version of bcftools (0.1.19) in ../bin/, while
BCFTOOLS_PLUGINS=/path/to/bcftools/plugins
was pointing to the plugins for bcftools version 1.10.2 outside /bin/
Replacing ../bin/bcftools (0.1.19 with 1.10.2) was the fix.

How to pass command-line arguments in CTest at runtime

I'm using CTest and want to pass command-line arguments to the underlying tests at runtime. I know there are ways to hard code command-line arguments into the CMake/CTest script, but I want to specify the command-line arguments at runtime and have those arguments passed through CTest to the underlying test.
Is this even possible?
I've figured out a way to do it (using the Fundamental theorem of software engineering). It's not as simple as I'd like, but here it is.
First, create a file ${CMAKE_SOURCE_DIR}/cmake/RunTests.cmake with the content
if(NOT DEFINED ENV{TESTS_ARGUMENTS})
set(ENV{TESTS_ARGUMENTS} "--default-arguments")
endif()
execute_process(COMMAND ${TEST_EXECUTABLE} $ENV{TESTS_ARGUMENTS} RESULT_VARIABLE result)
if(NOT "${result}" STREQUAL "0")
message(FATAL_ERROR "Test failed with return value '${result}'")
endif()
Then, when you add the test, use
add_test(
NAME MyTest
COMMAND ${CMAKE_COMMAND} -DTEST_EXECUTABLE=$<TARGET_FILE:MyTest> -P ${CMAKE_SOURCE_DIR}/cmake/RunTests.cmake
)
Finally, you can run the test with custom arguments using
cmake -E env TESTS_ARGUMENTS="--custom-arguments" ctest
Note that if you use bash, you can simplify this to
TESTS_ARGUMENTS="--custom-arguments" ctest
There are some problems with this approach, e.g. it ignores the WILL_FAIL property of the tests. Of course I wish it could be as simple as calling ctest -- --custom-arguments, but, as the Stones said, You can't always get what you want.
I'm not sure I fully understand what you want, but I still can give you a way to pass arguments to tests in CTest, at runtime.
I'll give you an example, with CTK (the Common Toolkit, https://github.com/commontk/CTK):
In the build dir (ex: CTK-build/CTK-build, it's a superbuild), if I run: ('-V' for Verbose, and '-N' for View Mode only)
ctest -R ctkVTKDataSetArrayComboBoxTest1 -V -N
I get:
UpdateCTestConfiguration from : /CTK-build/CTK-build/DartConfiguration.tcl
Parse Config file:/CTK-build/CTK-build/DartConfiguration.tcl
Add coverage exclude regular expressions.
Add coverage exclude: /CMakeFiles/CMakeTmp/
Add coverage exclude: .*/moc_.*
Add coverage exclude: .*/ui_.*
Add coverage exclude: .*/Testing/.*
Add coverage exclude: .*/CMakeExternals/.*
Add coverage exclude: ./ctkPixmapIconEngine.*
Add coverage exclude: ./ctkIconEngine.*
UpdateCTestConfiguration from :/CTK-build/CTK-build/DartConfiguration.tcl
Parse Config file:/CTK-build/CTK-build/DartConfiguration.tcl
Test project /CTK-build/CTK-build
Constructing a list of tests
Done constructing a list of tests
178: Test command: /CTK-build/CTK-build/bin/CTKVisualizationVTKWidgetsCppTests "ctkVTKDataSetArrayComboBoxTest1"
Labels: CTKVisualizationVTKWidgets
Test #178: ctkVTKDataSetArrayComboBoxTest1
Total Tests: 1
You can copy-paste the "Test command" in your terminal:
/CTK-build/CTK-build/bin/CTKVisualizationVTKWidgetsCppTests "ctkVTKDataSetArrayComboBoxTest1"
And add the arguments, for example "-I" for interactive testing:
/CTK-build/CTK-build/bin/CTKVisualizationVTKWidgetsCppTests "ctkVTKDataSetArrayComboBoxTest1" "-I"
Tell me if it helps.
matthieu's answer gave me the clue to get it to work for me.
For my code I did the following:
Type the command ctest -V -R TestMembraneCellCrypt -N to get the output:
...
488: Test command: path/to/ctest/executable/TestMembraneCellCrypt
Labels: Continuous_project_ChasteMembrane
Test #488: TestMembraneCellCrypt
...
Then I copied the Test command and provided the arguments there:
path/to/ctest/executable/TestMembraneCellCrypt -e 2 -em 5 -ct 10
I'll note that the package I'm using (Chaste), is pretty large so there might be things going on that I don't know about.