forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request OpenAPITools#20 from tvallin/helidon-generators
Java Helidon Server MP Basic generator
- Loading branch information
Showing
46 changed files
with
1,338 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...-generator/src/main/resources/java-helidon/server/libraries/mp/JavaTimeFormatter.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{{>licenseInfo}} | ||
package {{invokerPackage}}; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
/** | ||
* Class that add parsing/formatting support for Java 8+ {@code OffsetDateTime} class. | ||
* It's generated for java clients when {@code AbstractJavaCodegen#dateLibrary} specified as {@code java8}. | ||
*/ | ||
{{>generatedAnnotation}} | ||
public class JavaTimeFormatter { | ||
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; | ||
} | ||
|
||
/** | ||
* 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); | ||
} | ||
} | ||
/** | ||
* 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); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...-generator/src/main/resources/java-helidon/server/libraries/mp/RFC3339DateFormat.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{{>licenseInfo}} | ||
package {{invokerPackage}}; | ||
|
||
import com.fasterxml.jackson.databind.util.StdDateFormat; | ||
|
||
import java.text.DateFormat; | ||
import java.text.FieldPosition; | ||
import java.text.ParsePosition; | ||
import java.util.Date; | ||
import java.util.GregorianCalendar; | ||
import java.util.TimeZone; | ||
|
||
public class RFC3339DateFormat extends DateFormat { | ||
private static final long serialVersionUID = 1L; | ||
private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC"); | ||
private final StdDateFormat fmt = new StdDateFormat() | ||
.withTimeZone(TIMEZONE_Z) | ||
.withColonInTimeZone(true); | ||
public RFC3339DateFormat() { | ||
this.calendar = new GregorianCalendar(); | ||
} | ||
|
||
@Override | ||
public Date parse(String source, ParsePosition pos) { | ||
return fmt.parse(source, pos); | ||
} | ||
|
||
@Override | ||
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { | ||
return fmt.format(date, toAppendTo, fieldPosition); | ||
} | ||
|
||
@Override | ||
public Object clone() { | ||
return this; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...pi-generator/src/main/resources/java-helidon/server/libraries/mp/RestApplication.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package {{invokerPackage}}; | ||
|
||
import {{rootJavaEEPackage}}.enterprise.context.ApplicationScoped; | ||
import {{rootJavaEEPackage}}.ws.rs.ApplicationPath; | ||
import {{rootJavaEEPackage}}.ws.rs.core.Application; | ||
|
||
@ApplicationScoped | ||
@ApplicationPath("{{{contextPath}}}") | ||
public class RestApplication extends Application { | ||
} |
72 changes: 72 additions & 0 deletions
72
...openapi-generator/src/main/resources/java-helidon/server/libraries/mp/StringUtil.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{{>licenseInfo}} | ||
|
||
package {{invokerPackage}}; | ||
|
||
import java.util.Collection; | ||
import java.util.Iterator; | ||
|
||
{{>generatedAnnotation}} | ||
public class StringUtil { | ||
/** | ||
* Check if the given array contains the given value (with case-insensitive comparison). | ||
* | ||
* @param array The array | ||
* @param value The value to search | ||
* @return true if the array contains the value | ||
*/ | ||
public static boolean containsIgnoreCase(String[] array, String value) { | ||
for (String str : array) { | ||
if (value == null && str == null) { | ||
return true; | ||
} | ||
if (value != null && value.equalsIgnoreCase(str)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Join an array of strings with the given separator. | ||
* <p> | ||
* Note: This might be replaced by utility method from commons-lang or guava someday | ||
* if one of those libraries is added as dependency. | ||
* </p> | ||
* | ||
* @param array The array of strings | ||
* @param separator The separator | ||
* @return the resulting string | ||
*/ | ||
public static String join(String[] array, String separator) { | ||
int len = array.length; | ||
if (len == 0) { | ||
return ""; | ||
} | ||
|
||
StringBuilder out = new StringBuilder(); | ||
out.append(array[0]); | ||
for (int i = 1; i < len; i++) { | ||
out.append(separator).append(array[i]); | ||
} | ||
return out.toString(); | ||
} | ||
|
||
/** | ||
* Join a list of strings with the given separator. | ||
* | ||
* @param list The list of strings | ||
* @param separator The separator | ||
* @return the resulting string | ||
*/ | ||
public static String join(Collection<String> list, String separator) { | ||
Iterator<String> iterator = list.iterator(); | ||
StringBuilder out = new StringBuilder(); | ||
if (iterator.hasNext()) { | ||
out.append(iterator.next()); | ||
} | ||
while (iterator.hasNext()) { | ||
out.append(separator).append(iterator.next()); | ||
} | ||
return out.toString(); | ||
} | ||
} |
Oops, something went wrong.