Repository: victools/jsonschema-generator
Pull request #317 (2023-03-01 09:16:20)

Use format "time" instead of "date-time" for LocalTime and OffsetTime
In Draft 7, the format `"time"` is introduced for time values ([Reference](https://json-schema.org/understanding-json-schema/reference/string.html#dates-and-times)). In Java, `java.time.LocalTime` and `java.time.OffsetTime` classes preserve time values without a date. In this merge request, the format value has been changed from `"date-time"` to `"time"` for the aforementioned classes.

<img width="687" alt="image" src="https://user-images.githubusercontent.com/20307301/222095297-f258e717-4220-4ff2-ba1e-57301ebfb4fa.png">


sonatype-lift[bot]: ## 🛠 Lift Auto-fix
Some of the Lift findings in this PR can be automatically fixed. You can download and apply these changes in your local project directory of your branch to review the suggestions before committing.[^1]
```bash
# Download the patch
curl https://lift.sonatype.com/api/patch/github.com/victools/jsonschema-generator/317.diff -o lift-autofixes.diff

# Apply the patch with git
git apply lift-autofixes.diff

# Review the changes
git diff
```
Want it all in a single command? Open a terminal in your project's directory and copy and paste the following command:
```bash
curl https://lift.sonatype.com/api/patch/github.com/victools/jsonschema-generator/317.diff | git apply
```
Once you're satisfied, commit and push your changes in your project.
[^1]: You can preview the patch by opening the [patch URL](https://lift.sonatype.com/api/patch/github.com/victools/jsonschema-generator/317.diff) in the browser.
eimanip: > Thank you @eimanip for raising this.
> 
> Just two minor points, but otherwise looks good to go. 👍

Thank you for pointing out these problems. I applied both suggestions.

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6cbfd74..fe65f5f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 #### Changed
 - treat `java.time.Period` as `{ "type": "string" }` when `Option.ADDITIONAL_FIXED_TYPES` is enabled
+- treat `java.time.LocalTime` and `java.time.OffsetTime` as `{ "format": "time" }` when `Option.ADDITIONAL_FIXED_TYPES` is enabled (instead of "date-time")
 
 ### `jsonschema-maven-plugin`
 #### Fixed
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/module/SimpleTypeModule.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/module/SimpleTypeModule.java
index aa9b190..9d6a7de 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/module/SimpleTypeModule.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/module/SimpleTypeModule.java
@@ -82,10 +82,12 @@ public class SimpleTypeModule implements Module {
         SimpleTypeModule module = SimpleTypeModule.forPrimitiveTypes();
 
         module.withStringType(java.time.LocalDate.class, "date");
-        Stream.of(java.time.LocalDateTime.class, java.time.LocalTime.class, java.time.ZonedDateTime.class,
-                java.time.OffsetDateTime.class, java.time.OffsetTime.class, java.time.Instant.class,
+        Stream.of(java.time.LocalDateTime.class, java.time.ZonedDateTime.class,
+                java.time.OffsetDateTime.class, java.time.Instant.class,
                 java.util.Date.class, java.util.Calendar.class)
                 .forEach(javaType -> module.withStringType(javaType, "date-time"));
+        Stream.of(java.time.LocalTime.class, java.time.OffsetTime.class)
+                .forEach(javaType -> module.withStringType(javaType, "time"));
         module.withStringType(java.util.UUID.class, "uuid");
         module.withStringType(java.net.URI.class, "uri");
         module.withStringType(java.time.ZoneId.class);


Test patch:
diff --git a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorSimpleTypesTest.java b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorSimpleTypesTest.java
index 2b58721..02ae9dd 100644
--- a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorSimpleTypesTest.java
+++ b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorSimpleTypesTest.java
@@ -54,10 +54,10 @@ public class SchemaGeneratorSimpleTypesTest {
             Arguments.of(float.class, SchemaKeyword.TAG_TYPE_NUMBER, "float"),
             Arguments.of(java.time.LocalDate.class, SchemaKeyword.TAG_TYPE_STRING, "date"),
             Arguments.of(java.time.LocalDateTime.class, SchemaKeyword.TAG_TYPE_STRING, "date-time"),
-            Arguments.of(java.time.LocalTime.class, SchemaKeyword.TAG_TYPE_STRING, "date-time"),
+            Arguments.of(java.time.LocalTime.class, SchemaKeyword.TAG_TYPE_STRING, "time"),
             Arguments.of(java.time.ZonedDateTime.class, SchemaKeyword.TAG_TYPE_STRING, "date-time"),
             Arguments.of(java.time.OffsetDateTime.class, SchemaKeyword.TAG_TYPE_STRING, "date-time"),
-            Arguments.of(java.time.OffsetTime.class, SchemaKeyword.TAG_TYPE_STRING, "date-time"),
+            Arguments.of(java.time.OffsetTime.class, SchemaKeyword.TAG_TYPE_STRING, "time"),
             Arguments.of(java.time.Instant.class, SchemaKeyword.TAG_TYPE_STRING, "date-time"),
             Arguments.of(java.util.Date.class, SchemaKeyword.TAG_TYPE_STRING, "date-time"),
             Arguments.of(java.util.Calendar.class, SchemaKeyword.TAG_TYPE_STRING, "date-time"),