Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,47 @@ import java.time.format.DateTimeParseException;
*/
{{>generatedAnnotation}}
public class JavaTimeFormatter {
private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;

private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
/**
* Get the date format used to parse/format {@code OffsetDateTime} parameters.
*
* @return DateTimeFormatter
*/
public DateTimeFormatter getOffsetDateTimeFormatter() {
return offsetDateTimeFormatter;
}

/**
* Get the date format used to parse/format {@code OffsetDateTime} parameters.
* @return DateTimeFormatter
*/
public DateTimeFormatter getOffsetDateTimeFormatter() {
return offsetDateTimeFormatter;
}
/**
* Set the date format used to parse/format {@code OffsetDateTime} parameters.
*
* @param offsetDateTimeFormatter {@code DateTimeFormatter}
*/
public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) {
this.offsetDateTimeFormatter = offsetDateTimeFormatter;
}

/**
* Set the date format used to parse/format {@code OffsetDateTime} parameters.
* @param offsetDateTimeFormatter {@code DateTimeFormatter}
*/
public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) {
this.offsetDateTimeFormatter = offsetDateTimeFormatter;
/**
* Parse the given string into {@code OffsetDateTime} object.
*
* @param str String
* @return {@code OffsetDateTime}
*/
public OffsetDateTime parseOffsetDateTime(String str) {
try {
return OffsetDateTime.parse(str, offsetDateTimeFormatter);
} catch (DateTimeParseException e) {
throw new RuntimeException(e);
}
}

/**
* Parse the given string into {@code OffsetDateTime} object.
* @param str String
* @return {@code OffsetDateTime}
*/
public OffsetDateTime parseOffsetDateTime(String str) {
try {
return OffsetDateTime.parse(str, offsetDateTimeFormatter);
} catch (DateTimeParseException e) {
throw new RuntimeException(e);
}
}
/**
* Format the given {@code OffsetDateTime} object into string.
* @param offsetDateTime {@code OffsetDateTime}
* @return {@code OffsetDateTime} in string format
*/
public String formatOffsetDateTime(OffsetDateTime offsetDateTime) {
return offsetDateTimeFormatter.format(offsetDateTime);
}
}
/**
* Format the given {@code OffsetDateTime} object into string.
*
* @param offsetDateTime {@code OffsetDateTime}
* @return {@code OffsetDateTime} in string format
*/
public String formatOffsetDateTime(OffsetDateTime offsetDateTime) {
return offsetDateTimeFormatter.format(offsetDateTime);
}
}
50 changes: 15 additions & 35 deletions modules/openapi-generator/src/main/resources/Java/Pair.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,23 @@ package {{invokerPackage}};

{{>generatedAnnotation}}
public class Pair {
private String name = "";
private String value = "";
private final String name;
private final String value;

public Pair (String name, String value) {
setName(name);
setValue(value);
}
public Pair(String name, String value) {
this.name = isValidString(name) ? name : "";
this.value = isValidString(value) ? value : "";
}

private void setName(String name) {
if (!isValidString(name)) {
return;
}
public String getName() {
return this.name;
}

this.name = name;
}
public String getValue() {
return this.value;
}

private void setValue(String value) {
if (!isValidString(value)) {
return;
}

this.value = value;
}

public String getName() {
return this.name;
}

public String getValue() {
return this.value;
}

private boolean isValidString(String arg) {
if (arg == null) {
return false;
}

return true;
}
private static boolean isValidString(String arg) {
return arg != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import java.util.Map;
import java.util.List;

public interface Authentication {
/**
* Apply authentication settings to header and query params.
*
* @param queryParams List of query parameters
* @param headerParams Map of header parameters
* @param cookieParams Map of cookie parameters
*/
void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams);
/**
* Apply authentication settings to header and query params.
*
* @param queryParams List of query parameters
* @param headerParams Map of header parameters
* @param cookieParams Map of cookie parameters
*/
void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {{invokerPackage}}.Pair;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;

{{>generatedAnnotation}}
Expand All @@ -15,7 +14,7 @@ public class HttpBearerAuth implements Authentication {
private Supplier<String> tokenSupplier;

public HttpBearerAuth(String scheme) {
this.scheme = scheme;
this.scheme = upperCaseBearer(scheme);
}

/**
Expand Down Expand Up @@ -47,15 +46,14 @@ public class HttpBearerAuth implements Authentication {

@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams) {
String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null);
String bearerToken = tokenSupplier != null ? tokenSupplier.get() : null;
if (bearerToken == null) {
return;
}

headerParams.put("Authorization", (scheme != null ? upperCaseBearer(scheme) + " " : "") + bearerToken);
headerParams.put("Authorization", (scheme != null ? scheme + " " : "") + bearerToken);
}

private static String upperCaseBearer(String scheme) {
return ("bearer".equalsIgnoreCase(scheme)) ? "Bearer" : scheme;
return "bearer".equalsIgnoreCase(scheme) ? "Bearer" : scheme;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,47 @@
*/
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.13.0-SNAPSHOT")
public class JavaTimeFormatter {
private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;

private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
/**
* Get the date format used to parse/format {@code OffsetDateTime} parameters.
*
* @return DateTimeFormatter
*/
public DateTimeFormatter getOffsetDateTimeFormatter() {
return offsetDateTimeFormatter;
}

/**
* Get the date format used to parse/format {@code OffsetDateTime} parameters.
* @return DateTimeFormatter
*/
public DateTimeFormatter getOffsetDateTimeFormatter() {
return offsetDateTimeFormatter;
}
/**
* Set the date format used to parse/format {@code OffsetDateTime} parameters.
*
* @param offsetDateTimeFormatter {@code DateTimeFormatter}
*/
public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) {
this.offsetDateTimeFormatter = offsetDateTimeFormatter;
}

/**
* Set the date format used to parse/format {@code OffsetDateTime} parameters.
* @param offsetDateTimeFormatter {@code DateTimeFormatter}
*/
public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) {
this.offsetDateTimeFormatter = offsetDateTimeFormatter;
/**
* Parse the given string into {@code OffsetDateTime} object.
*
* @param str String
* @return {@code OffsetDateTime}
*/
public OffsetDateTime parseOffsetDateTime(String str) {
try {
return OffsetDateTime.parse(str, offsetDateTimeFormatter);
} catch (DateTimeParseException e) {
throw new RuntimeException(e);
}
}

/**
* Parse the given string into {@code OffsetDateTime} object.
* @param str String
* @return {@code OffsetDateTime}
*/
public OffsetDateTime parseOffsetDateTime(String str) {
try {
return OffsetDateTime.parse(str, offsetDateTimeFormatter);
} catch (DateTimeParseException e) {
throw new RuntimeException(e);
}
}
/**
* Format the given {@code OffsetDateTime} object into string.
* @param offsetDateTime {@code OffsetDateTime}
* @return {@code OffsetDateTime} in string format
*/
public String formatOffsetDateTime(OffsetDateTime offsetDateTime) {
return offsetDateTimeFormatter.format(offsetDateTime);
}
}
/**
* Format the given {@code OffsetDateTime} object into string.
*
* @param offsetDateTime {@code OffsetDateTime}
* @return {@code OffsetDateTime} in string format
*/
public String formatOffsetDateTime(OffsetDateTime offsetDateTime) {
return offsetDateTimeFormatter.format(offsetDateTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,23 @@

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.13.0-SNAPSHOT")
public class Pair {
private String name = "";
private String value = "";
private final String name;
private final String value;

public Pair (String name, String value) {
setName(name);
setValue(value);
}
public Pair(String name, String value) {
this.name = isValidString(name) ? name : "";
this.value = isValidString(value) ? value : "";
}

private void setName(String name) {
if (!isValidString(name)) {
return;
}
public String getName() {
return this.name;
}

this.name = name;
}
public String getValue() {
return this.value;
}

private void setValue(String value) {
if (!isValidString(value)) {
return;
}

this.value = value;
}

public String getName() {
return this.name;
}

public String getValue() {
return this.value;
}

private boolean isValidString(String arg) {
if (arg == null) {
return false;
}

return true;
}
private static boolean isValidString(String arg) {
return arg != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import java.util.List;

public interface Authentication {
/**
* Apply authentication settings to header and query params.
*
* @param queryParams List of query parameters
* @param headerParams Map of header parameters
* @param cookieParams Map of cookie parameters
*/
void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams);
/**
* Apply authentication settings to header and query params.
*
* @param queryParams List of query parameters
* @param headerParams Map of header parameters
* @param cookieParams Map of cookie parameters
*/
void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.13.0-SNAPSHOT")
Expand All @@ -26,7 +25,7 @@ public class HttpBearerAuth implements Authentication {
private Supplier<String> tokenSupplier;

public HttpBearerAuth(String scheme) {
this.scheme = scheme;
this.scheme = upperCaseBearer(scheme);
}

/**
Expand Down Expand Up @@ -58,15 +57,14 @@ public void setBearerToken(Supplier<String> tokenSupplier) {

@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams) {
String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null);
String bearerToken = tokenSupplier != null ? tokenSupplier.get() : null;
if (bearerToken == null) {
return;
}

headerParams.put("Authorization", (scheme != null ? upperCaseBearer(scheme) + " " : "") + bearerToken);
headerParams.put("Authorization", (scheme != null ? scheme + " " : "") + bearerToken);
}

private static String upperCaseBearer(String scheme) {
return ("bearer".equalsIgnoreCase(scheme)) ? "Bearer" : scheme;
return "bearer".equalsIgnoreCase(scheme) ? "Bearer" : scheme;
}
}
Loading
Loading