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

[CLI] Improvements for meta and list command #799

Merged
merged 16 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/meta-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ags="meta -n myClientCodegen -p com.my.company.codegen -o samples/meta-codegen/l

java $JAVA_OPTS -jar $executable $ags

mvn verify -f samples/meta-codegen/lib/pom.xml
mvn clean package -f samples/meta-codegen/pom.xml

ags2="generate -g myClientCodegen -i modules/openapi-generator/src/test/resources/2_0/petstore.json -o samples/meta-codegen/usage $@"

Expand Down
1 change: 1 addition & 0 deletions bin/utils/ensure-up-to-date
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sleep 5
./bin/rust-server-petstore.sh > /dev/null 2>&1
./bin/openapi3/haskell-http-client-petstore.sh > /dev/null 2>&1
./bin/csharp-petstore.sh > /dev/null 2>&1
./bin/meta-codegen.sh > /dev/null 2>&1

# Check:
if [ -n "$(git status --porcelain)" ]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package org.openapitools.codegen.cmd;

import com.google.common.base.Objects;

import io.airlift.airline.Command;
import io.airlift.airline.Option;

import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenConfigLoader;
import org.openapitools.codegen.CodegenType;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

// NOTE: List can later have subcommands such as list languages, list types, list frameworks, etc.
@Command(name = "list", description = "Lists the available generators")
Expand Down Expand Up @@ -40,19 +44,29 @@ public void run() {
sb.append(System.lineSeparator());

for (CodegenType type : types) {
sb.append(type.name()).append(" generators:");
sb.append(System.lineSeparator());

generators.stream()
.filter(g -> g.getTag().equals(type))
.sorted(Comparator.comparing(CodegenConfig::getName))
.forEach(generator -> sb.append(" - ").append(generator.getName()).append(System.lineSeparator()));

sb.append(System.lineSeparator());
sb.append(System.lineSeparator());
appendForType(sb, type, type.name(), generators);
}
appendForType(sb, null, "UNSPECIFIED", generators);
}

System.out.printf("%s%n", sb.toString());
}

private void appendForType(StringBuilder sb, CodegenType type, String typeName, List<CodegenConfig> generators) {
List<CodegenConfig> list = generators.stream()
.filter(g -> Objects.equal(type, g.getTag()))
.sorted(Comparator.comparing(CodegenConfig::getName))
.collect(Collectors.toList());

if(list.size() > 0) {
sb.append(typeName).append(" generators:");
sb.append(System.lineSeparator());

list.stream()
.forEach(generator -> sb.append(" - ").append(generator.getName()).append(System.lineSeparator()));

sb.append(System.lineSeparator());
sb.append(System.lineSeparator());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class {{generatorClass}} extends DefaultCodegen implements CodegenConfig
* @see org.openapitools.codegen.CodegenType
*/
public CodegenType getTag() {
return CodegenType.CLIENT;
return CodegenType.OTHER;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Expand Down
2 changes: 1 addition & 1 deletion samples/meta-codegen/lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ the object you have available during client generation:

```
# The following additional debug options are available for all codegen targets:
# -DdebugSwagger prints the OpenAPI Specification as interpreted by the codegen
# -DdebugOpenAPI prints the OpenAPI Specification as interpreted by the codegen
# -DdebugModels prints models passed to the template engine
# -DdebugOperations prints operations passed to the template engine
# -DdebugSupportingFiles prints additional data passed to the template engine
Expand Down
6 changes: 3 additions & 3 deletions samples/meta-codegen/lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Expand All @@ -116,7 +116,7 @@
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<openapi-generator-version>3.0.0-SNAPSHOT</openapi-generator-version>
<openapi-generator-version>3.2.2-SNAPSHOT</openapi-generator-version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take note of this during the release process.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lib/ is generated (output of the meta command of the CLI). It is updated with ensure-up-to-date.

<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.8.1</junit-version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class MyclientcodegenGenerator extends DefaultCodegen implements CodegenC
* @see org.openapitools.codegen.CodegenType
*/
public CodegenType getTag() {
return CodegenType.CLIENT;
return CodegenType.OTHER;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions samples/meta-codegen/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.openapitools</groupId>
<artifactId>meta-codegen</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>lib/</module>
<module>../../modules/openapi-generator</module>
</modules>
</project>
2 changes: 1 addition & 1 deletion samples/meta-codegen/usage/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0-SNAPSHOT
3.2.2-SNAPSHOT