From 150b60fccdb1662713f2d758162fd95d23837ab0 Mon Sep 17 00:00:00 2001 From: dsinghvi Date: Fri, 7 Feb 2025 21:02:47 +0000 Subject: [PATCH] chore(java): update java-spring seed --- .../accept-header/.mock/definition/api.yml | 4 ++ .../.mock/definition/service.yml | 16 ++++++ .../accept-header/.mock/fern.config.json | 1 + .../accept-header/.mock/generators.yml | 1 + .../accept-header/core/APIException.java | 10 ++++ .../accept-header/core/BearerAuth.java | 30 ++++++++++ .../core/DateTimeDeserializer.java | 56 +++++++++++++++++++ .../accept-header/core/ObjectMappers.java | 41 ++++++++++++++ .../resources/service/ServiceService.java | 24 ++++++++ .../service/exceptions/NotFoundError.java | 24 ++++++++ .../NotFoundErrorExceptionHandler.java | 19 +++++++ .../accept-header/snippet-templates.json | 0 seed/java-spring/accept-header/snippet.json | 0 13 files changed, 226 insertions(+) create mode 100644 seed/java-spring/accept-header/.mock/definition/api.yml create mode 100644 seed/java-spring/accept-header/.mock/definition/service.yml create mode 100644 seed/java-spring/accept-header/.mock/fern.config.json create mode 100644 seed/java-spring/accept-header/.mock/generators.yml create mode 100644 seed/java-spring/accept-header/core/APIException.java create mode 100644 seed/java-spring/accept-header/core/BearerAuth.java create mode 100644 seed/java-spring/accept-header/core/DateTimeDeserializer.java create mode 100644 seed/java-spring/accept-header/core/ObjectMappers.java create mode 100644 seed/java-spring/accept-header/resources/service/ServiceService.java create mode 100644 seed/java-spring/accept-header/resources/service/exceptions/NotFoundError.java create mode 100644 seed/java-spring/accept-header/resources/service/handlers/NotFoundErrorExceptionHandler.java create mode 100644 seed/java-spring/accept-header/snippet-templates.json create mode 100644 seed/java-spring/accept-header/snippet.json diff --git a/seed/java-spring/accept-header/.mock/definition/api.yml b/seed/java-spring/accept-header/.mock/definition/api.yml new file mode 100644 index 00000000000..4c370c1686d --- /dev/null +++ b/seed/java-spring/accept-header/.mock/definition/api.yml @@ -0,0 +1,4 @@ +name: accept +auth: bearer +error-discrimination: + strategy: status-code diff --git a/seed/java-spring/accept-header/.mock/definition/service.yml b/seed/java-spring/accept-header/.mock/definition/service.yml new file mode 100644 index 00000000000..1ea148bbf00 --- /dev/null +++ b/seed/java-spring/accept-header/.mock/definition/service.yml @@ -0,0 +1,16 @@ +errors: + NotFoundError: + docs: Admin not found + status-code: 404 + type: unknown + +service: + auth: true + base-path: /container + endpoints: + endpoint: + errors: + - NotFoundError + method: DELETE + path: / + diff --git a/seed/java-spring/accept-header/.mock/fern.config.json b/seed/java-spring/accept-header/.mock/fern.config.json new file mode 100644 index 00000000000..4c8e54ac313 --- /dev/null +++ b/seed/java-spring/accept-header/.mock/fern.config.json @@ -0,0 +1 @@ +{"organization": "fern-test", "version": "*"} \ No newline at end of file diff --git a/seed/java-spring/accept-header/.mock/generators.yml b/seed/java-spring/accept-header/.mock/generators.yml new file mode 100644 index 00000000000..0967ef424bc --- /dev/null +++ b/seed/java-spring/accept-header/.mock/generators.yml @@ -0,0 +1 @@ +{} diff --git a/seed/java-spring/accept-header/core/APIException.java b/seed/java-spring/accept-header/core/APIException.java new file mode 100644 index 00000000000..27289cf9b2e --- /dev/null +++ b/seed/java-spring/accept-header/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/accept-header/core/BearerAuth.java b/seed/java-spring/accept-header/core/BearerAuth.java new file mode 100644 index 00000000000..58a05842c2f --- /dev/null +++ b/seed/java-spring/accept-header/core/BearerAuth.java @@ -0,0 +1,30 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package core; + +import com.fasterxml.jackson.annotation.JsonValue; +import java.lang.String; + +public final class BearerAuth { + private final String token; + + private BearerAuth(String token) { + this.token = token; + } + + @JsonValue + public String getToken() { + return token; + } + + @java.lang.Override + public String toString() { + return "Bearer " + getToken(); + } + + public static BearerAuth of(String token) { + return new BearerAuth(token.startsWith("Bearer ") ? token.substring(7) : token); + } +} diff --git a/seed/java-spring/accept-header/core/DateTimeDeserializer.java b/seed/java-spring/accept-header/core/DateTimeDeserializer.java new file mode 100644 index 00000000000..3d3174aec00 --- /dev/null +++ b/seed/java-spring/accept-header/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/accept-header/core/ObjectMappers.java b/seed/java-spring/accept-header/core/ObjectMappers.java new file mode 100644 index 00000000000..e02822614a8 --- /dev/null +++ b/seed/java-spring/accept-header/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/accept-header/resources/service/ServiceService.java b/seed/java-spring/accept-header/resources/service/ServiceService.java new file mode 100644 index 00000000000..70cfcc6ff56 --- /dev/null +++ b/seed/java-spring/accept-header/resources/service/ServiceService.java @@ -0,0 +1,24 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package resources.service; + +import core.BearerAuth; +import java.security.Principal; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import resources.service.exceptions.NotFoundError; + +@RequestMapping( + path = "/container" +) +public interface ServiceService { + @DeleteMapping( + value = "/", + produces = "application/json" + ) + void endpoint(@RequestHeader("Authorization") BearerAuth auth, Principal principal) throws + NotFoundError; +} diff --git a/seed/java-spring/accept-header/resources/service/exceptions/NotFoundError.java b/seed/java-spring/accept-header/resources/service/exceptions/NotFoundError.java new file mode 100644 index 00000000000..4dd194eabc9 --- /dev/null +++ b/seed/java-spring/accept-header/resources/service/exceptions/NotFoundError.java @@ -0,0 +1,24 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package resources.service.exceptions; + +import com.fasterxml.jackson.annotation.JsonValue; +import core.APIException; +import java.lang.Object; + +public final class NotFoundError extends APIException { + public static final int STATUS_CODE = 404; + + private final Object body; + + public NotFoundError(Object body) { + this.body = body; + } + + @JsonValue + public Object getBody() { + return this.body; + } +} diff --git a/seed/java-spring/accept-header/resources/service/handlers/NotFoundErrorExceptionHandler.java b/seed/java-spring/accept-header/resources/service/handlers/NotFoundErrorExceptionHandler.java new file mode 100644 index 00000000000..0a3fa9af6d3 --- /dev/null +++ b/seed/java-spring/accept-header/resources/service/handlers/NotFoundErrorExceptionHandler.java @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package resources.service.handlers; + +import java.lang.Object; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import resources.service.exceptions.NotFoundError; + +@RestControllerAdvice +public final class NotFoundErrorExceptionHandler { + @ExceptionHandler(NotFoundError.class) + ResponseEntity handle(NotFoundError notFoundError) { + return new ResponseEntity<>(notFoundError.getBody(), null, NotFoundError.STATUS_CODE); + } +} diff --git a/seed/java-spring/accept-header/snippet-templates.json b/seed/java-spring/accept-header/snippet-templates.json new file mode 100644 index 00000000000..e69de29bb2d diff --git a/seed/java-spring/accept-header/snippet.json b/seed/java-spring/accept-header/snippet.json new file mode 100644 index 00000000000..e69de29bb2d