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

Generator updates #10924

Merged
merged 45 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fab28b0
[csharp] masked EnumMember names in modelEnum
jages May 3, 2018
deb1d58
[csharp] masked EnumMember names in modelEnum
jages May 3, 2018
03aadf8
fixd TOS for aspnetcore generator and update samples
HugoMario Feb 12, 2021
5d6e370
Merge branch 'master' of https://github.com/jages/swagger-codegen int…
HugoMario Feb 12, 2021
db5a82b
fixed body parameter datatype issue on csharp
HugoMario Feb 16, 2021
7f4641b
updated csharp samples
HugoMario Feb 16, 2021
50528e4
Revert "fixed calls in templates"
HugoMario Feb 18, 2021
0142468
replaced wget for curl call
HugoMario Feb 18, 2021
ec30fe7
updated csharp dotnet 2 sample
HugoMario Feb 18, 2021
3afe17b
fixed enums for number type
HugoMario Feb 19, 2021
164d45f
updated go client model template to get enums value right and updated…
HugoMario Feb 19, 2021
06491a4
update html samples
HugoMario Feb 19, 2021
17176a1
updated api client and enum templates for java generator
HugoMario Feb 21, 2021
e6c501d
updated java samples
HugoMario Feb 21, 2021
79b9b4d
updated typescript fetch samples
HugoMario Feb 21, 2021
a59fa58
changed petstore version 2 sample http scheme and update typescript f…
HugoMario Feb 23, 2021
a4fb3fd
disabled typescript fetch module temporary.
HugoMario Feb 23, 2021
0acfa03
disabled typescript fetch sample modules on main pom
HugoMario Feb 23, 2021
79336c7
Revert "disabled typescript fetch module temporary."
HugoMario Feb 23, 2021
1434ad9
added missed annotation to jaxrs cxf-cdi model template
HugoMario Feb 24, 2021
629d89e
updated java jax rs cxf-cdi pom template and sample
HugoMario Feb 24, 2021
3860c3f
updated jaxrs-cxf samples
HugoMario Feb 24, 2021
969cded
fixed jackson imports on models with enums and updated dependency to …
HugoMario Feb 26, 2021
a9d28d7
updated jaxrs-spec samples
HugoMario Feb 26, 2021
57e4de1
updated jaxrs jersey samples
HugoMario Feb 26, 2021
35595bf
updated jaxrs-resteasy-eap samples
HugoMario Feb 26, 2021
4627d3b
updated resteasy dependency version
HugoMario Feb 27, 2021
265e269
updated jaxrs resteasy samples.
HugoMario Feb 27, 2021
a3cb2d2
added docker file for jaxrs resteasy
HugoMario Feb 27, 2021
ea64861
tweaked tabs on import for spring pojo template
HugoMario Feb 27, 2021
cc07172
updated spring samples
HugoMario Feb 27, 2021
361b1fd
updated node-js sample
HugoMario Feb 27, 2021
97b4767
updated kotlin samples
HugoMario Feb 27, 2021
a56e0b7
updated swift5 samples
HugoMario Feb 28, 2021
c7905d6
updated typescript angular sample
HugoMario Feb 28, 2021
acd2d4b
updated javascript samples
HugoMario Feb 28, 2021
69e50bb
Merge remote-tracking branch 'origin/master' into generator-updates
HugoMario Mar 2, 2021
8813794
change http schema on java feign sample tests
HugoMario Mar 2, 2021
8a99df8
fixed test apli client test
HugoMario Mar 2, 2021
d6172a9
changed https schema on spring cloud
HugoMario Mar 2, 2021
30799fe
disabled spring cloud tests temporary
HugoMario Mar 2, 2021
43d78ac
ignoring spring cloud tests.
HugoMario Mar 2, 2021
1aa1f3f
fixed spring cloud tests
HugoMario Mar 2, 2021
b78de69
reverted scheme to http and update client samples
HugoMario Mar 2, 2021
bc9691e
disabled jetty start plugin on jax-cxf sample
HugoMario Mar 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.regex.Pattern;

import io.swagger.models.properties.UntypedProperty;
import io.swagger.util.Yaml;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -401,6 +400,15 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj

// override to post-process any model properties
@SuppressWarnings("unused")
public void postProcessModelProperties(CodegenModel model){
if (model.vars == null || model.vars.isEmpty()) {
return;
}
for(CodegenProperty codegenProperty : model.vars) {
postProcessModelProperty(model, codegenProperty);
}
}

public void postProcessModelProperty(CodegenModel model, CodegenProperty property){
}

Expand Down Expand Up @@ -1546,11 +1554,7 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
addVars(m, impl.getProperties(), impl.getRequired(), allDefinitions);
}

if (m.vars != null) {
for(CodegenProperty prop : m.vars) {
postProcessModelProperty(m, prop);
}
}
postProcessModelProperties(m);
return m;
}

Expand Down Expand Up @@ -2784,26 +2788,7 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
} else {
Model sub = bp.getSchema();
if (sub instanceof RefModel) {
String name = ((RefModel) sub).getSimpleRef();
try {
name = URLDecoder.decode(name, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
LOGGER.error("Could not decoded string: " + name, e);
}
name = getAlias(name);
if (typeMapping.containsKey(name)) {
name = typeMapping.get(name);
p.baseType = name;
} else {
name = toModelName(name);
p.baseType = name;
if (defaultIncludes.contains(name)) {
imports.add(name);
}
imports.add(name);
name = getTypeDeclaration(name);
}
p.dataType = name;
readRefModelParameter((RefModel) model, p, imports);
} else {
if (sub instanceof ComposedModel) {
p.dataType = "object";
Expand Down Expand Up @@ -2913,6 +2898,29 @@ public boolean isDataTypeFile(String dataType) {
}
}

protected void readRefModelParameter(RefModel refModel, CodegenParameter codegenParameter, Set<String> imports) {
String name = refModel.getSimpleRef();
try {
name = URLDecoder.decode(name, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
LOGGER.error("Could not decoded string: " + name, e);
}
name = getAlias(name);
if (typeMapping.containsKey(name)) {
name = typeMapping.get(name);
codegenParameter.baseType = name;
} else {
name = toModelName(name);
codegenParameter.baseType = name;
if (defaultIncludes.contains(name)) {
imports.add(name);
}
imports.add(name);
name = getTypeDeclaration(name);
}
codegenParameter.dataType = name;
}

/**
* Convert map of Swagger SecuritySchemeDefinition objects to a list of Codegen Security objects
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,13 @@ public Map<String, String> createMapping(String key, String value) {

@Override
public String toEnumValue(String value, String datatype) {
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
if ("int".equals(datatype) || "int32".equals(datatype) || "int64".equals(datatype)
|| "uint".equals(datatype) || "uint32".equals(datatype) || "uint64".equals(datatype)
|| "float".equals(datatype) || "float32".equals(datatype) || "float64".equals(datatype)
|| "boolean".equals(datatype) || "double".equals(datatype)) {
return value;
} else if ("string".equals(datatype)) {
return String.format("\"%s\"", value);
} else {
return escapeText(value);
}
Expand All @@ -477,11 +482,16 @@ public String toEnumVarName(String name, String datatype) {
}

// number
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
if ("int".equals(datatype) || "int32".equals(datatype) || "int64".equals(datatype)
|| "uint".equals(datatype) || "uint32".equals(datatype) || "uint64".equals(datatype)
|| "float".equals(datatype) || "float32".equals(datatype) || "float64".equals(datatype)) {
String varName = name;
varName = varName.replaceAll("-", "MINUS_");
varName = varName.replaceAll("\\+", "PLUS_");
varName = varName.replaceAll("\\.", "_DOT_");
if (varName.matches("\\d.*")) {
return "_" + varName;
}
return varName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.swagger.codegen.*;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.RefModel;
import io.swagger.models.Swagger;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.Property;
Expand All @@ -15,6 +16,9 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.*;

import static org.apache.commons.lang3.StringUtils.isEmpty;
Expand Down Expand Up @@ -583,6 +587,28 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
return codegenModel;
}

@Override
protected void readRefModelParameter(RefModel refModel, CodegenParameter codegenParameter, Set<String> imports) {
String name = getSwaggerType(new RefProperty(refModel.get$ref()));

try {
name = URLDecoder.decode(name, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
LOGGER.error("Could not decoded string: " + name, e);
}
name = getAlias(name);
if (typeMapping.containsKey(name)) {
name = typeMapping.get(name);
} else {
if (defaultIncludes.contains(name)) {
imports.add(name);
}
}
codegenParameter.baseType = name;
codegenParameter.dataType = name;
}


public void setOptionalProjectFileFlag(boolean flag) {
this.optionalProjectFileFlag = flag;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package io.swagger.codegen.languages;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;

import io.swagger.codegen.CliOption;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.CodegenParameter;
import io.swagger.codegen.CodegenProperty;
import io.swagger.codegen.SupportingFile;
import io.swagger.models.Operation;
import io.swagger.models.Swagger;
import io.swagger.models.parameters.Parameter;
import io.swagger.util.Json;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen
{
Expand Down Expand Up @@ -57,6 +59,7 @@ public JavaJAXRSSpecServerCodegen()
typeMapping.put("date", "LocalDate");

importMapping.put("LocalDate", "org.joda.time.LocalDate");
importMapping.put("InputStream", "java.io.InputStream");

super.embeddedTemplateDir = templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "spec";

Expand Down Expand Up @@ -162,6 +165,33 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
model.imports.remove("JsonProperty");
}

@Override
public void postProcessModelProperties(CodegenModel model){
if (model.vars == null || model.vars.isEmpty()) {
return;
}
final boolean useJackson = Boolean.valueOf(String.valueOf(additionalProperties.get("jackson")));
boolean hasEnumProperty = false;
for(CodegenProperty codegenProperty : model.vars) {
postProcessModelProperty(model, codegenProperty);
if (codegenProperty.isEnum) {
hasEnumProperty = true;
}
}
if (useJackson && hasEnumProperty) {
model.imports.add("JsonValue");
model.imports.add("JsonCreator");
}
}

public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
final CodegenParameter parameter = super.fromParameter(param, imports);
if (parameter.isFile) {
imports.add("InputStream");
}
return parameter;
}

@Override
public void preprocessSwagger(Swagger swagger) {
//copy input swagger to output folder
Expand All @@ -175,8 +205,7 @@ public void preprocessSwagger(Swagger swagger) {

}
@Override
public String getHelp()
{
public String getHelp() {
return "Generates a Java JAXRS Server according to JAXRS 2.0 specification.";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("LocalDateProvider.mustache",
(sourceFolder + '/' + apiPackage).replace(".", "/"), "LocalDateProvider.java"));
}
writeOptional(outputFolder, new SupportingFile("Dockerfile.mustache", "", "Dockerfile"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,12 +646,12 @@ public class ApiClient {
builder = httpClient.resource(url).accept(accept);
}

for (Entry<String, String> keyValue : headerParams.entrySet()) {
builder = builder.header(keyValue.getKey(), keyValue.getValue());
for (String key : headerParams.keySet()) {
builder = builder.header(key, headerParams.get(key));
}
for (Map.Entry<String,String> keyValue : defaultHeaderMap.entrySet()) {
if (!headerParams.containsKey(keyValue.getKey())) {
builder = builder.header(keyValue.getKey(), keyValue.getValue());
for (String key : defaultHeaderMap.keySet()) {
if (!headerParams.containsKey(key)) {
builder = builder.header(key, defaultHeaderMap.get(key));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum

@Override
public {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} read(final JsonReader jsonReader) throws IOException {
{{{dataType}}} value = {{#isNumber}}new BigDecimal(jsonReader.nextDouble()){{/isNumber}}{{^isNumber}}jsonReader.{{#isInteger}}nextInt(){{/isInteger}}{{^isInteger}}next{{{dataType}}}(){{/isInteger}}{{/isNumber}};
{{#isNumber}}BigDecimal value = new BigDecimal(jsonReader.nextDouble()){{/isNumber}}{{^isNumber}}{{#isInteger}}Integer value {{/isInteger}}{{^isInteger}}String value {{/isInteger}}= jsonReader.{{#isInteger}}nextInt(){{/isInteger}}{{^isInteger}}nextString(){{/isInteger}}{{/isNumber}};
return {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.fromValue(String.valueOf(value));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@

@Override
public {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} read(final JsonReader jsonReader) throws IOException {
{{{dataType}}} value = {{#isNumber}}new BigDecimal(jsonReader.nextDouble()){{/isNumber}}{{^isNumber}}jsonReader.{{#isInteger}}nextInt(){{/isInteger}}{{^isInteger}}next{{{dataType}}}(){{/isInteger}}{{/isNumber}};
return {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.fromValue(String.valueOf(value));
{{#isNumber}}Object value = new BigDecimal(jsonReader.nextDouble()){{/isNumber}}{{^isNumber}}{{#isInteger}}int value {{/isInteger}}{{^isInteger}}String value {{/isInteger}}= jsonReader.{{#isInteger}}nextInt(){{/isInteger}}{{^isInteger}}nextString(){{/isInteger}}{{/isNumber}};
return {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.fromValue(String.valueOf(value));
}
}
{{/gson}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package {{package}};
{{/imports}}
{{#useBeanValidation}}
import javax.validation.constraints.*;
import javax.validation.Valid;
{{/useBeanValidation}}
{{#models}}
{{#model}}{{#description}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<!-- Version is just a guess -->
<!-- IBM WebSphere Application Server Liberty Core v8.5.5.6 uses v3.0.2, source https://www.ibm.com/support/knowledgecenter/SSD28V_8.5.5/com.ibm.websphere.wlp.core.doc/ae/rwlp_jaxrs_secure.html -->
<version>3.0.2</version>
<!-- TOMCAT EE JaxRS v8.0.6 uses v3.0.2, https://www.apache.org/dyn/closer.cgi/tomee/tomee-8.0.6/ -->
<version>3.3.8</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM jboss/wildfly:21.0.2.Final

ADD target/{{artifactId}}-{{artifactVersion}}.war /opt/jboss/wildfly/standalone/deployments/

EXPOSE 8080 9990 8009

CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0", "-c", "standalone.xml"]
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ is an example of building a swagger-enabled JAX-RS server.

This example uses the [JAX-RS](https://jax-rs-spec.java.net/) framework.

To run the server, please execute the following:
To run with docker, please execute the following:

```
mvn clean package jetty:run
mvn package

docker build -q --rm --tag=swagger-codegen-resteasy .

docker run -d -p 8080:8080 -p 9990:9990 -p 8009:8009 --name swagger-resteasy -it swagger-codegen-resteasy
```

You can then view the swagger listing here:

```
http://localhost:{{serverPort}}{{contextPath}}/swagger.json
```

Note that if you have configured the `host` to be something other than localhost, the calls through
swagger-ui will be directed to that host and not localhost!
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@
<version>${resteasy-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<version>${resteasy-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-validator-provider-11</artifactId>
<version>${resteasy-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
Expand Down Expand Up @@ -192,7 +180,7 @@
<properties>
<swagger-core-version>1.5.24</swagger-core-version>
<jetty-version>9.3.27.v20190418</jetty-version>
<resteasy-version>3.0.11.Final</resteasy-version>
<resteasy-version>3.13.2.Final</resteasy-version>
<slf4j-version>1.6.3</slf4j-version>
<junit-version>4.13.1</junit-version>
<servlet-api-version>2.5</servlet-api-version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public enum {{datatypeWithEnum}} {
value = v;
}

public String value() {
public {{datatype}} value() {
return value;
}

Expand Down
Loading