Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python-flask] Can't specify more than one value in -Dmodels #811

Closed
csimmons0 opened this issue Aug 14, 2018 · 6 comments
Closed

[python-flask] Can't specify more than one value in -Dmodels #811

csimmons0 opened this issue Aug 14, 2018 · 6 comments

Comments

@csimmons0
Copy link

Description

If I use the -Dmodels argument to specify which models to generate and I specify more than one model, only the first is generated. Wrapping the list of model names in quotes does not fix the problem. I experience the same problem with -DsupportingFiles.

I took a look at the code in modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java, but I couldn't see an issue with it.

openapi-generator version

3.2.0

OpenAPI declaration file content or url

https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml

Command line used for generation
$ openapi-generator generate -i ./petstore.yaml -g python-flask -o ./server -Dmodels=Pet,Tag
Steps to reproduce
~/openapi_issue
$ openapi-generator generate -i ./petstore.yaml -g python-flask -o ./server -Dmodels=Pet,Tag
[main] WARN  o.o.c.ignore.CodegenIgnoreProcessor - Output directory does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] INFO  o.o.codegen.AbstractGenerator - writing file /Users/csimmons/openapi_issue/./server/openapi_server/models/pet.py
~/openapi_issue
$ rm -rf ./server/
~/openapi_issue
$ openapi-generator generate -i ./petstore.yaml -g python-flask -o ./server -Dmodels=Tag,Pet
[main] WARN  o.o.c.ignore.CodegenIgnoreProcessor - Output directory does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] INFO  o.o.codegen.AbstractGenerator - writing file /Users/csimmons/openapi_issue/./server/openapi_server/models/tag.py
Related issues/PRs
Suggest a fix/enhancement
@wing328
Copy link
Member

wing328 commented Aug 21, 2018

@csimmons0 can you try the following by putting the -Dmodels at the beginning of the command line argument?

$ openapi-generator -Dmodels=Tag,Pet generate -i ./petstore.yaml -g python-flask -o ./server

@csimmons0
Copy link
Author

$ openapi-generator -Dmodels=Tag,Pet generate -i ./petstore.yaml -g python-flask -o ./server
[error] Found unexpected parameters: [-Dmodels=Tag,Pet, generate, -i, ./petstore.yaml, -g, python-flask, -o, ./server]

See 'openapi-generator-cli help' for usage.

I also tried making "-Dmodels" the first argument after "generate", but that resulted in the same behavior as what I originally reported.

@jmini
Copy link
Member

jmini commented Aug 23, 2018

I am at the root of this repo (cloned locally)
I have run mvn verify once

Then I enter:

java -Dmodels=Order,Pet -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g python-flask -o ./out

And I get:

[main] INFO  o.o.c.ignore.CodegenIgnoreProcessor - No .openapi-generator-ignore file found.
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] WARN  o.o.codegen.utils.ModelUtils - Multiple schemas found, returning only the first one
[main] INFO  o.o.codegen.AbstractGenerator - writing file /Users/jbr/Git/openapi-generator/./out/openapi_server/models/order.py
[main] INFO  o.o.codegen.AbstractGenerator - writing file /Users/jbr/Git/openapi-generator/./out/openapi_server/models/pet.py

This is the expected result.


Note:
Proper usage of Java -D command-line parameters


I have the feeling you are using Homebrew. Is that correct? If not, what is the openapi-generator command you enter?

@jmini
Copy link
Member

jmini commented Aug 23, 2018

Ok I took an other look at the problem.

In our code we do a System.getProperty("models"):

generateModels = System.getProperty(CodegenConstants.MODELS) != null ? Boolean.TRUE : getGeneratorPropertyDefaultSwitch(CodegenConstants.MODELS, null);

But if you put -Dmodels=Order,Pet after the -jar line, the app is responsible to parse it.

So this is what we are doing in the Generate command:

@Option(
name = {"-D"},
title = "system properties",
description = "sets specified system properties in "
+ "the format of name=value,name=value (or multiple options, each with name=value)")
private List<String> systemProperties = new ArrayList<>();

But then line 332:

applySystemPropertiesKvpList(systemProperties, configurator);

tries to pass the content of systemProperties to the configurator.
At this point systemProperties is a List<String> containing a single value "models=Order,Pet" (correct).
The result in configurator is wrong:
configurator.getSystemProperties() is returning a Map with 2 entries:

  1. key "models" value "Order"
  2. key "Pet", value "" (empty string)

This is wrong because later in toClientOptInput(), CodegenConfigurator.setSystemProperties() is called here:

public ClientOptInput toClientOptInput() {
Validate.notEmpty(generatorName, "language/generatorName must be specified");
Validate.notEmpty(inputSpec, "input spec must be specified");
setVerboseFlags();
setSystemProperties();
CodegenConfig config = CodegenConfigLoader.forName(generatorName);

And the implementation distributes the content of the map as system property:

private void setSystemProperties() {
for (Map.Entry<String, String> entry : systemProperties.entrySet()) {
System.setProperty(entry.getKey(), entry.getValue());
}
}

@keeed
Copy link

keeed commented Aug 18, 2022

Since this issue is still open and in case anyone is using an Ant based task and is using java ant task to run the codegen, here's how to pass it.

Example:

    <java .... >
        ...
        <jvmarg value="-Dmodels=Order,Pet"/>
        <jvmarg value="-DsupportingFiles=JSON.java,ApiException.java,ApiResponse.java"/>
        <arg value="generate" />
         ...
    </java>

@wing328
Copy link
Member

wing328 commented Aug 18, 2022

@keeed thanks for sharing the tips.

@wing328 wing328 closed this as completed Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants