Skip to content

Commit 23cef0e

Browse files
authored
Merge branch '3.0.0' into patch-1
2 parents 562a311 + 9f809ab commit 23cef0e

File tree

325 files changed

+37603
-421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

325 files changed

+37603
-421
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,9 @@ Other languages have petstore samples, too:
441441
It's just as easy--just use the `-i` flag to point to either a server or file.
442442

443443
### Modifying the client library format
444-
Don't like the default swagger client syntax? Want a different language supported? No problem! Swagger Codegen processes mustache templates with the [jmustache](https://github.com/samskivert/jmustache) engine. You can modify our templates or make your own.
444+
Don't like the default swagger client syntax? Want a different language supported? No problem! Swagger Codegen processes handlebar templates with the [Handlebars.java](https://github.com/jknack/handlebars.java) engine. You can modify our templates or make your own.
445445

446-
You can look at `modules/swagger-codegen/src/main/resources/${your-language}` for examples. To make your own templates, create your own files and use the `-t` flag to specify your template folder. It actually is that easy.
446+
You can look at [swagger-codegen-generators](https://github.com/swagger-api/swagger-codegen-generators/tree/master/src/main/resources/handlebars) for examples. To make your own templates, create your own files and use the `-t` flag to specify your template folder. It actually is that easy.
447447

448448
### Making your own codegen modules
449449
If you're starting a project with a new language and don't see what you need, Swagger Codegen can help you create a project to generate your own libraries:

bin/go-petstore-mixed.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
5+
while [ -h "$SCRIPT" ] ; do
6+
ls=`ls -ld "$SCRIPT"`
7+
link=`expr "$ls" : '.*-> \(.*\)$'`
8+
if expr "$link" : '/.*' > /dev/null; then
9+
SCRIPT="$link"
10+
else
11+
SCRIPT=`dirname "$SCRIPT"`/"$link"
12+
fi
13+
done
14+
15+
if [ ! -d "${APP_DIR}" ]; then
16+
APP_DIR=`dirname "$SCRIPT"`/..
17+
APP_DIR=`cd "${APP_DIR}"; pwd`
18+
fi
19+
20+
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
21+
22+
if [ ! -f "$executable" ]
23+
then
24+
mvn clean package
25+
fi
26+
27+
# if you've executed sbt assembly previously it will use that instead.
28+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -Dlogback.configurationFile=bin/logback.xml"
29+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/3_0_0/petstore-mixed.yaml -l go -o samples/client/petstore/go/go-petstore-mixed/swagger --flatten-inline-schema"
30+
31+
java $JAVA_OPTS -jar $executable $ags
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
5+
while [ -h "$SCRIPT" ] ; do
6+
ls=`ls -ld "$SCRIPT"`
7+
link=`expr "$ls" : '.*-> \(.*\)$'`
8+
if expr "$link" : '/.*' > /dev/null; then
9+
SCRIPT="$link"
10+
else
11+
SCRIPT=`dirname "$SCRIPT"`/"$link"
12+
fi
13+
done
14+
15+
if [ ! -d "${APP_DIR}" ]; then
16+
APP_DIR=`dirname "$SCRIPT"`/..
17+
APP_DIR=`cd "${APP_DIR}"; pwd`
18+
fi
19+
20+
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
21+
22+
if [ ! -f "$executable" ]
23+
then
24+
mvn clean package
25+
fi
26+
27+
# if you've executed sbt assembly previously it will use that instead.
28+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -Dlogback.configurationFile=bin/logback.xml"
29+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/3_0_0/petstore-mixed.yaml -l nodejs-server -o samples/server/petstore/nodejs-petstore-mixed -Dservice"
30+
31+
java $JAVA_OPTS -jar $executable $ags
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
5+
while [ -h "$SCRIPT" ] ; do
6+
ls=`ls -ld "$SCRIPT"`
7+
link=`expr "$ls" : '.*-> \(.*\)$'`
8+
if expr "$link" : '/.*' > /dev/null; then
9+
SCRIPT="$link"
10+
else
11+
SCRIPT=`dirname "$SCRIPT"`/"$link"
12+
fi
13+
done
14+
15+
if [ ! -d "${APP_DIR}" ]; then
16+
APP_DIR=`dirname "$SCRIPT"`/..
17+
APP_DIR=`cd "${APP_DIR}"; pwd`
18+
fi
19+
20+
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
21+
22+
if [ ! -f "$executable" ]
23+
then
24+
mvn clean package
25+
fi
26+
27+
# if you've executed sbt assembly previously it will use that instead.
28+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -Dlogback.configurationFile=bin/logback.xml"
29+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/3_0_0/petstore-mixed.yaml -l typescript-fetch -c bin/typescript-fetch-petstore-with-npm-version.json -o samples/client/petstore/typescript-fetch/builds/mixed-with-npm-version"
30+
31+
java $JAVA_OPTS -jar $executable $ags

bin/typescript-fetch-petstore-with-npm-version.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ fi
2626

2727
# if you've executed sbt assembly previously it will use that instead.
2828
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -Dlogback.configurationFile=bin/logback.xml"
29-
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l typescript-fetch -c bin/typescript-fetch-petstore-with-npm-version.json -o samples/client/petstore/typescript-fetch/builds/with-npm-version"
29+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/3_0_0/petstore.yaml -l typescript-fetch -c bin/typescript-fetch-petstore-with-npm-version.json -o samples/client/petstore/typescript-fetch/builds/with-npm-version"
3030

31-
# java $JAVA_OPTS -jar $executable $ags
31+
java $JAVA_OPTS -jar $executable $ags

modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/v3/cli/cmd/Generate.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public class Generate implements Runnable {
7777
protected Boolean disableExamples;
7878
protected Boolean resolveFully;
7979
protected Boolean ignoreImportMappings;
80+
protected Boolean flattenInlineSchema;
8081
private String url;
8182
private List<CodegenArgument> codegenArguments;
8283

@@ -224,6 +225,10 @@ public void setResolveFully(Boolean resolveFully) {
224225
this.resolveFully = resolveFully;
225226
}
226227

228+
public void setFlattenInlineSchema(Boolean flattenInlineSchema) {
229+
this.flattenInlineSchema = flattenInlineSchema;
230+
}
231+
227232
public void setIgnoreImportMappings(Boolean ignoreImportMappings) {
228233
this.ignoreImportMappings = ignoreImportMappings;
229234
}
@@ -331,6 +336,10 @@ public void run() {
331336
configurator.setIgnoreFileOverride(ignoreFileOverride);
332337
}
333338

339+
if (flattenInlineSchema != null) {
340+
configurator.setFlattenInlineSchema(flattenInlineSchema);
341+
}
342+
334343
if (removeOperationIdPrefix != null) {
335344
configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix);
336345
}

modules/swagger-codegen-cli/src/main/resources/oas3.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,12 @@ components:
210210
type: "boolean"
211211
title: "fully resolve schemas"
212212
description: "fully resolves json schemas when loading definitions."
213-
x-option: "--resolve-fully"
213+
x-option: "--resolve-fully"
214+
flattenInlineSchema:
215+
type: "boolean"
216+
title: "flatten inline schemas"
217+
description: "flattens inline composed schemas."
218+
x-option: "--flatten-inline-schema"
214219
ConfigHelp:
215220
x-command: "config-help"
216221
x-command-description: "Config help for chosen lang"

modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/v3/maven/plugin/CodeGenMojo.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
/*
44
* Copyright 2001-2005 The Apache Software Foundation.
5-
*
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
77
* in compliance with the License. You may obtain a copy of the License at
8-
*
8+
*
99
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
10+
*
1111
* Unless required by applicable law or agreed to in writing, software distributed under the License
1212
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
1313
* or implied. See the License for the specific language governing permissions and limitations under
@@ -52,7 +52,7 @@
5252
/**
5353
* Goal which generates client/server code from a swagger json/yaml definition.
5454
*/
55-
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
55+
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
5656
public class CodeGenMojo extends AbstractMojo {
5757

5858
@Parameter(name = "verbose", required = false, defaultValue = "false")
@@ -220,7 +220,7 @@ public class CodeGenMojo extends AbstractMojo {
220220
* A map of reserved names and how they should be escaped
221221
*/
222222
@Parameter(name = "reservedWordsMappings")
223-
private List<String> reservedWordsMappings;
223+
private List<String> reservedWordsMappings;
224224

225225
/**
226226
* Generate the apis
@@ -314,6 +314,13 @@ public class CodeGenMojo extends AbstractMojo {
314314

315315
@Override
316316
public void execute() throws MojoExecutionException {
317+
// Using the naive approach for achieving thread safety
318+
synchronized (CodeGenMojo.class) {
319+
execute_();
320+
}
321+
}
322+
323+
protected void execute_() throws MojoExecutionException {
317324

318325
if (skip) {
319326
getLog().info("Code generation is skipped.");

modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/AbstractGenerator.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,25 @@ public String getFullTemplateFile(CodegenConfig config, String templateFile) {
8686
final String library = config.getLibrary();
8787
if (StringUtils.isNotEmpty(library)) {
8888
//look for the file in the library subfolder of the supplied template
89+
if (StringUtils.isNotBlank(config.customTemplateDir())) {
90+
final String libTemplateFile = buildLibraryFilePath(config.customTemplateDir(), library, templateFile);
91+
if (new File(libTemplateFile).exists()) {
92+
return libTemplateFile;
93+
}
94+
}
8995
final String libTemplateFile = buildLibraryFilePath(config.templateDir(), library, templateFile);
9096
if (new File(libTemplateFile).exists()) {
9197
return libTemplateFile;
9298
}
9399
}
94100

95101
//check the supplied template main folder for the file
102+
if (StringUtils.isNotBlank(config.customTemplateDir())) {
103+
final String template = config.customTemplateDir() + File.separator + templateFile;
104+
if (new File(template).exists()) {
105+
return template;
106+
}
107+
}
96108
final String template = config.templateDir() + File.separator + templateFile;
97109
if (new File(template).exists()) {
98110
return template;

modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/CodegenConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public interface CodegenConfig {
4141

4242
String embeddedTemplateDir();
4343

44+
String customTemplateDir();
45+
4446
String getTemplateVersion();
4547

4648
String modelFileFolder();

0 commit comments

Comments
 (0)