Skip to content

Commit

Permalink
Forbiddenapis check and fix (#672)
Browse files Browse the repository at this point in the history
* Added forbiddenapis check and fixed the findings in the normal code
* Fixed forbiddenapi findings in java templates and samples.
* Generated all samples for Java.
  • Loading branch information
burberius authored and jmini committed Aug 22, 2018
1 parent 227f277 commit 9bc335b
Show file tree
Hide file tree
Showing 126 changed files with 709 additions and 546 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void testParseAndFormatDate() {
assertEquals(dateStr, apiClient.formatDate(apiClient.parseDate("2015-11-07T02:49:09.356-01:00")));

// custom date format: without milli-seconds, custom time zone
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.ROOT);
format.setTimeZone(TimeZone.getTimeZone("GMT+10"));
apiClient.setDateFormat(format);
dateStr = "2015-11-07T13:49:09+10:00";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void testParseAndFormatDate() {
assertEquals(dateStr, apiClient.formatDate(apiClient.parseDate("2015-11-07T02:49:09.356-01:00")));

// custom date format: without milli-seconds, custom time zone
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.ROOT);
format.setTimeZone(TimeZone.getTimeZone("GMT+10"));
apiClient.setDateFormat(format);
dateStr = "2015-11-07T13:49:09+10:00";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;

import okio.ByteString;
Expand Down Expand Up @@ -46,7 +47,7 @@ public void testSqlDateTypeAdapter() {
assertEquals(json.deserialize("\"2015-11-07T03:49:09.356" + getCurrentTimezoneOffset() + "\"", java.sql.Date.class).toString(), date.toString());

// custom date format: without day
DateFormat format = new SimpleDateFormat("yyyy-MM");
DateFormat format = new SimpleDateFormat("yyyy-MM", Locale.ROOT);
apiClient.setSqlDateFormat(format);
String dateStr = "\"2015-11\"";
assertEquals(dateStr, json.serialize(json.deserialize("\"2015-11-07T03:49:09Z\"", java.sql.Date.class)));
Expand Down Expand Up @@ -79,7 +80,7 @@ public void testDateTypeAdapter() {
assertEquals(utcDate, json.serialize(date));

// custom datetime format: without milli-seconds, custom time zone
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.ROOT);
format.setTimeZone(TimeZone.getTimeZone("GMT+10"));
apiClient.setDateFormat(format);

Expand Down Expand Up @@ -190,10 +191,10 @@ public void testByteArrayTypeAdapterDeserialization() {
public static String getCurrentTimezoneOffset() {

TimeZone tz = TimeZone.getDefault();
Calendar cal = GregorianCalendar.getInstance(tz);
Calendar cal = GregorianCalendar.getInstance(tz, Locale.ROOT);
int offsetInMillis = tz.getOffset(cal.getTimeInMillis());

String offset = String.format("%02d:%02d", Math.abs(offsetInMillis / 3600000), Math.abs((offsetInMillis / 60000) % 60));
String offset = String.format(Locale.ROOT,"%02d:%02d", Math.abs(offsetInMillis / 3600000), Math.abs((offsetInMillis / 60000) % 60));
offset = (offsetInMillis >= 0 ? "+" : "-") + offset;

return offset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testParseAndFormatDate() {
assertEquals(dateStr, apiClient.formatDate(apiClient.parseDate("2015-11-07T02:49:09.356-01:00")));

// custom date format: without milli-seconds, custom time zone
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.ROOT);
format.setTimeZone(TimeZone.getTimeZone("GMT+10"));
apiClient.setDateFormat(format);
dateStr = "2015-11-07T13:49:09+10:00";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import io.airlift.airline.ParseOptionMissingValueException;
import org.openapitools.codegen.cmd.*;

import java.util.Locale;

/**
* User: lanwen Date: 24.03.15 Time: 17:56
* <p>
Expand All @@ -40,6 +42,7 @@ public static void main(String[] args) {
Cli.<Runnable>builder("openapi-generator-cli")
.withDescription(
String.format(
Locale.ROOT,
"OpenAPI generator CLI (version %s).",
version))
.withDefaultCommand(ListGenerators.class)
Expand Down Expand Up @@ -69,10 +72,10 @@ public static void main(String[] args) {
System.exit(1);
}
} catch (ParseArgumentsUnexpectedException e) {
System.err.printf("[error] %s%n%nSee 'openapi-generator-cli help' for usage.%n", e.getMessage());
System.err.printf(Locale.ROOT,"[error] %s%n%nSee 'openapi-generator-cli help' for usage.%n", e.getMessage());
System.exit(1);
} catch (ParseOptionMissingException | ParseOptionMissingValueException e) {
System.err.printf("[error] %s%n", e.getMessage());
System.err.printf(Locale.ROOT,"[error] %s%n", e.getMessage());
System.exit(1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import io.airlift.airline.Command;
import org.openapitools.codegen.CodegenConfig;

import java.util.Locale;

import static ch.lambdaj.Lambda.on;
import static ch.lambdaj.collection.LambdaCollections.with;
import static java.util.ServiceLoader.load;
Expand All @@ -34,6 +36,6 @@ public class Langs implements Runnable {
public void run() {
LambdaIterable<String> langs =
with(load(CodegenConfig.class)).extract(on(CodegenConfig.class).getName());
System.out.printf("Available languages (generators): %s%n", langs);
System.out.printf(Locale.ROOT, "Available languages (generators): %s%n", langs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

// 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 @@ -53,6 +54,6 @@ public void run() {
}
}

System.out.printf("%s%n", sb.toString());
System.out.printf(Locale.ROOT,"%s%n", sb.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@

import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.core.models.ParseOptions;
import org.openapitools.codegen.*;
import io.swagger.v3.parser.core.models.AuthorizationValue;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.parser.core.models.ParseOptions;
import org.openapitools.codegen.CliOption;
import org.openapitools.codegen.ClientOptInput;
import org.openapitools.codegen.ClientOpts;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenConfigLoader;
import org.openapitools.codegen.DefaultGenerator;
import org.openapitools.codegen.online.model.GeneratorInput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -34,6 +39,7 @@
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class Generator {
Expand All @@ -44,7 +50,7 @@ public static Map<String, CliOption> getOptions(String language) {
try {
config = CodegenConfigLoader.forName(language);
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format("Unsupported target %s supplied. %s",
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format(Locale.ROOT,"Unsupported target %s supplied. %s",
language, e));
}
Map<String, CliOption> map = new LinkedHashMap<>();
Expand Down Expand Up @@ -77,7 +83,7 @@ public static String generateServer(String language, GeneratorInput opts) {
}

private static String generate(String language, GeneratorInput opts, Type type) {
LOGGER.debug(String.format("generate %s for %s", type.getTypeName(), language));
LOGGER.debug(String.format(Locale.ROOT,"generate %s for %s", type.getTypeName(), language));
if (opts == null) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "No options were supplied");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -76,7 +77,7 @@ public class CodegenModel {

@Override
public String toString() {
return String.format("%s(%s)", name, classname);
return String.format(Locale.ROOT, "%s(%s)", name, classname);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -196,7 +197,7 @@ public boolean isRestfulCreate() {
* @return true if act as Restful update method, false otherwise
*/
public boolean isRestfulUpdate() {
return Arrays.asList("PUT", "PATCH").contains(httpMethod.toUpperCase()) && isMemberPath();
return Arrays.asList("PUT", "PATCH").contains(httpMethod.toUpperCase(Locale.ROOT)) && isMemberPath();
}

/**
Expand All @@ -205,7 +206,7 @@ public boolean isRestfulUpdate() {
* @return true request method is PUT, PATCH or POST; false otherwise
*/
public boolean isBodyAllowed() {
return Arrays.asList("PUT", "PATCH", "POST").contains(httpMethod.toUpperCase());
return Arrays.asList("PUT", "PATCH", "POST").contains(httpMethod.toUpperCase(Locale.ROOT));
}

/**
Expand All @@ -232,7 +233,7 @@ public boolean isRestful() {
* @return the substring
*/
private String pathWithoutBaseName() {
return baseName != null ? path.replace("/" + baseName.toLowerCase(), "") : path;
return baseName != null ? path.replace("/" + baseName.toLowerCase(Locale.ROOT), "") : path;
}

/**
Expand All @@ -248,7 +249,7 @@ private boolean isMemberPath() {

@Override
public String toString() {
return String.format("%s(%s)", baseName, path);
return String.format(Locale.ROOT, "%s(%s)", baseName, path);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class CodegenResponse {
Expand Down Expand Up @@ -47,7 +48,7 @@ public boolean isWildcard() {

@Override
public String toString() {
return String.format("%s(%s)", code, containerType);
return String.format(Locale.ROOT, "%s(%s)", code, containerType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class CodegenSecurity {
Expand All @@ -38,7 +39,7 @@ public class CodegenSecurity {

@Override
public String toString() {
return String.format("%s(%s)", name, type);
return String.format(Locale.ROOT, "%s(%s)", name, type);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public enum CodegenType {
Expand All @@ -30,7 +31,7 @@ public enum CodegenType {

@JsonCreator
public static CodegenType forValue(String value) {
return names.get(value.toLowerCase());
return names.get(value.toLowerCase(Locale.ROOT));
}

@JsonValue
Expand All @@ -50,4 +51,4 @@ public String toValue() {
names.put("documentation", DOCUMENTATION);
names.put("other", OTHER);
}
}
}
Loading

0 comments on commit 9bc335b

Please sign in to comment.