From e066230f4483db54419f7d003ae89e4860cb5953 Mon Sep 17 00:00:00 2001 From: dsinghvi Date: Sat, 25 Jan 2025 19:02:40 +0000 Subject: [PATCH] chore(java): update java-spring seed --- .../.mock/definition/api.yml | 2 + .../.mock/definition/single-property.yml | 15 +++++ .../.mock/fern.config.json | 1 + .../.mock/generators.yml | 2 + .../core/APIException.java | 10 ++++ .../core/DateTimeDeserializer.java | 56 +++++++++++++++++++ .../core/ObjectMappers.java | 41 ++++++++++++++ .../singleproperty/SinglePropertyService.java | 25 +++++++++ .../snippet-templates.json | 0 .../snippet.json | 0 .../pagination/.mock/definition/users.yml | 27 ++++++++- .../resources/users/UsersService.java | 11 ++++ 12 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 seed/java-spring/java-single-property-endpoint/.mock/definition/api.yml create mode 100644 seed/java-spring/java-single-property-endpoint/.mock/definition/single-property.yml create mode 100644 seed/java-spring/java-single-property-endpoint/.mock/fern.config.json create mode 100644 seed/java-spring/java-single-property-endpoint/.mock/generators.yml create mode 100644 seed/java-spring/java-single-property-endpoint/core/APIException.java create mode 100644 seed/java-spring/java-single-property-endpoint/core/DateTimeDeserializer.java create mode 100644 seed/java-spring/java-single-property-endpoint/core/ObjectMappers.java create mode 100644 seed/java-spring/java-single-property-endpoint/resources/singleproperty/SinglePropertyService.java create mode 100644 seed/java-spring/java-single-property-endpoint/snippet-templates.json create mode 100644 seed/java-spring/java-single-property-endpoint/snippet.json diff --git a/seed/java-spring/java-single-property-endpoint/.mock/definition/api.yml b/seed/java-spring/java-single-property-endpoint/.mock/definition/api.yml new file mode 100644 index 00000000000..c787598c7e7 --- /dev/null +++ b/seed/java-spring/java-single-property-endpoint/.mock/definition/api.yml @@ -0,0 +1,2 @@ +name: single-property + diff --git a/seed/java-spring/java-single-property-endpoint/.mock/definition/single-property.yml b/seed/java-spring/java-single-property-endpoint/.mock/definition/single-property.yml new file mode 100644 index 00000000000..f53b95ff518 --- /dev/null +++ b/seed/java-spring/java-single-property-endpoint/.mock/definition/single-property.yml @@ -0,0 +1,15 @@ +service: + auth: false + base-path: / + endpoints: + doThing: + path: /{id} + method: GET + request: + name: GetThingRequest + path-parameters: + id: string + query-parameters: + include-remote-data: optional + response: + type: string diff --git a/seed/java-spring/java-single-property-endpoint/.mock/fern.config.json b/seed/java-spring/java-single-property-endpoint/.mock/fern.config.json new file mode 100644 index 00000000000..4c8e54ac313 --- /dev/null +++ b/seed/java-spring/java-single-property-endpoint/.mock/fern.config.json @@ -0,0 +1 @@ +{"organization": "fern-test", "version": "*"} \ No newline at end of file diff --git a/seed/java-spring/java-single-property-endpoint/.mock/generators.yml b/seed/java-spring/java-single-property-endpoint/.mock/generators.yml new file mode 100644 index 00000000000..311847daa5a --- /dev/null +++ b/seed/java-spring/java-single-property-endpoint/.mock/generators.yml @@ -0,0 +1,2 @@ +{} + diff --git a/seed/java-spring/java-single-property-endpoint/core/APIException.java b/seed/java-spring/java-single-property-endpoint/core/APIException.java new file mode 100644 index 00000000000..27289cf9b2e --- /dev/null +++ b/seed/java-spring/java-single-property-endpoint/core/APIException.java @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package core; + +import java.lang.Exception; + +public class APIException extends Exception { +} diff --git a/seed/java-spring/java-single-property-endpoint/core/DateTimeDeserializer.java b/seed/java-spring/java-single-property-endpoint/core/DateTimeDeserializer.java new file mode 100644 index 00000000000..3d3174aec00 --- /dev/null +++ b/seed/java-spring/java-single-property-endpoint/core/DateTimeDeserializer.java @@ -0,0 +1,56 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package core; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.module.SimpleModule; +import java.io.IOException; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalQueries; + +/** + * Custom deserializer that handles converting ISO8601 dates into {@link OffsetDateTime} objects. + */ +class DateTimeDeserializer extends JsonDeserializer { + private static final SimpleModule MODULE; + + static { + MODULE = new SimpleModule().addDeserializer(OffsetDateTime.class, new DateTimeDeserializer()); + } + + /** + * Gets a module wrapping this deserializer as an adapter for the Jackson ObjectMapper. + * + * @return A {@link SimpleModule} to be plugged onto Jackson ObjectMapper. + */ + public static SimpleModule getModule() { + return MODULE; + } + + @Override + public OffsetDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException { + JsonToken token = parser.currentToken(); + if (token == JsonToken.VALUE_NUMBER_INT) { + return OffsetDateTime.ofInstant(Instant.ofEpochSecond(parser.getValueAsLong()), ZoneOffset.UTC); + } else { + TemporalAccessor temporal = DateTimeFormatter.ISO_DATE_TIME.parseBest( + parser.getValueAsString(), OffsetDateTime::from, LocalDateTime::from); + + if (temporal.query(TemporalQueries.offset()) == null) { + return LocalDateTime.from(temporal).atOffset(ZoneOffset.UTC); + } else { + return OffsetDateTime.from(temporal); + } + } + } +} \ No newline at end of file diff --git a/seed/java-spring/java-single-property-endpoint/core/ObjectMappers.java b/seed/java-spring/java-single-property-endpoint/core/ObjectMappers.java new file mode 100644 index 00000000000..e02822614a8 --- /dev/null +++ b/seed/java-spring/java-single-property-endpoint/core/ObjectMappers.java @@ -0,0 +1,41 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package core; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import java.io.IOException; +import java.lang.Integer; +import java.lang.Object; +import java.lang.String; + +public final class ObjectMappers { + public static final ObjectMapper JSON_MAPPER = JsonMapper.builder() + .addModule(new Jdk8Module()) + .addModule(new JavaTimeModule()) + .addModule(DateTimeDeserializer.getModule()) + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .build(); + + private ObjectMappers() { + } + + public static String stringify(Object o) { + try { + return JSON_MAPPER.setSerializationInclusion(JsonInclude.Include.ALWAYS) + .writerWithDefaultPrettyPrinter() + .writeValueAsString(o); + } + catch (IOException e) { + return o.getClass().getName() + "@" + Integer.toHexString(o.hashCode()); + } + } + } diff --git a/seed/java-spring/java-single-property-endpoint/resources/singleproperty/SinglePropertyService.java b/seed/java-spring/java-single-property-endpoint/resources/singleproperty/SinglePropertyService.java new file mode 100644 index 00000000000..ce4bf369dce --- /dev/null +++ b/seed/java-spring/java-single-property-endpoint/resources/singleproperty/SinglePropertyService.java @@ -0,0 +1,25 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package resources.singleproperty; + +import java.lang.Boolean; +import java.lang.String; +import java.util.Optional; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@RequestMapping( + path = "/" +) +public interface SinglePropertyService { + @GetMapping( + value = "/{id}", + produces = "application/json" + ) + String doThing(@PathVariable("id") String id, + @RequestParam("include-remote-data") Optional includeRemoteData); +} diff --git a/seed/java-spring/java-single-property-endpoint/snippet-templates.json b/seed/java-spring/java-single-property-endpoint/snippet-templates.json new file mode 100644 index 00000000000..e69de29bb2d diff --git a/seed/java-spring/java-single-property-endpoint/snippet.json b/seed/java-spring/java-single-property-endpoint/snippet.json new file mode 100644 index 00000000000..e69de29bb2d diff --git a/seed/java-spring/pagination/.mock/definition/users.yml b/seed/java-spring/pagination/.mock/definition/users.yml index b8a1df01ccc..a135137954d 100644 --- a/seed/java-spring/pagination/.mock/definition/users.yml +++ b/seed/java-spring/pagination/.mock/definition/users.yml @@ -152,6 +152,31 @@ service: the next page of results. response: ListUsersPaginationResponse + listWithDoubleOffsetPagination: + pagination: + offset: $request.page + results: $response.data + method: GET + path: "" + request: + name: ListUsersDoubleOffsetPaginationRequest + query-parameters: + page: + type: optional + docs: Defaults to first page + default: 0 + per_page: + type: optional + docs: Defaults to per page + order: + type: optional + starting_after: + type: optional + docs: | + The cursor used for pagination in order to fetch + the next page of results. + response: ListUsersPaginationResponse + listWithBodyOffsetPagination: pagination: offset: $request.pagination.page @@ -267,4 +292,4 @@ service: query-parameters: offset: type: optional - response: UsernameContainer \ No newline at end of file + response: UsernameContainer diff --git a/seed/java-spring/pagination/resources/users/UsersService.java b/seed/java-spring/pagination/resources/users/UsersService.java index ade6bc72f34..55fc0f5288b 100644 --- a/seed/java-spring/pagination/resources/users/UsersService.java +++ b/seed/java-spring/pagination/resources/users/UsersService.java @@ -4,6 +4,7 @@ package resources.users; +import java.lang.Double; import java.lang.Integer; import java.lang.String; import java.util.Optional; @@ -52,6 +53,16 @@ ListUsersPaginationResponse listWithOffsetPagination(@RequestParam("page") Optio @RequestParam("order") Optional order, @RequestParam("starting_after") Optional startingAfter); + @GetMapping( + value = "", + produces = "application/json" + ) + ListUsersPaginationResponse listWithDoubleOffsetPagination( + @RequestParam("page") Optional page, + @RequestParam("per_page") Optional perPage, + @RequestParam("order") Optional order, + @RequestParam("starting_after") Optional startingAfter); + @PostMapping( value = "", produces = "application/json",