-
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.
- Loading branch information
1 parent
fbbb6d6
commit ddc70aa
Showing
6 changed files
with
127 additions
and
1 deletion.
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
42 changes: 42 additions & 0 deletions
42
...ncapi-processor/src/main/java/lu/greenhalos/j2asyncapi/core/fields/DateTimeFieldType.java
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,42 @@ | ||
package lu.greenhalos.j2asyncapi.core.fields; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
|
||
import java.util.List; | ||
|
||
|
||
/** | ||
* @author Ben Antony - [email protected] | ||
*/ | ||
class DateTimeFieldType implements FieldType { | ||
|
||
@Override | ||
public List<Class<?>> getAllowedClasses() { | ||
|
||
return List.of(LocalDateTime.class, Instant.class); | ||
} | ||
|
||
|
||
@Override | ||
public List<Object> getExamples(Field field) { | ||
|
||
return List.of("2022-01-31T23:20:50.52Z", "1985-04-12T15:59:55-08:00"); | ||
} | ||
|
||
|
||
@Override | ||
public String getType(Field field) { | ||
|
||
return "string"; | ||
} | ||
|
||
|
||
@Override | ||
public String getFormat(Field field) { | ||
|
||
return "date-time"; | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
j2asyncapi-processor/src/test/java/lu/greenhalos/j2asyncapi/core/InstantTest.java
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,33 @@ | ||
package lu.greenhalos.j2asyncapi.core; | ||
|
||
import com.asyncapi.v2.model.schema.Schema; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Instant; | ||
|
||
import java.util.List; | ||
|
||
|
||
/** | ||
* @author Ben Antony - [email protected] | ||
*/ | ||
class InstantTest { | ||
|
||
@Test | ||
void testField() { | ||
|
||
var fieldSchema = new Schema(); | ||
fieldSchema.setTitle("field"); | ||
fieldSchema.setType("string"); | ||
fieldSchema.setFormat("date-time"); | ||
fieldSchema.setExamples(List.of("2022-01-31T23:20:50.52Z", "1985-04-12T15:59:55-08:00")); | ||
|
||
FieldTestUtil.assertSchemaOnClass(Example.class, fieldSchema); | ||
} | ||
|
||
private static class Example { | ||
|
||
private Instant field; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
j2asyncapi-processor/src/test/java/lu/greenhalos/j2asyncapi/core/LocalDateTimeTest.java
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,33 @@ | ||
package lu.greenhalos.j2asyncapi.core; | ||
|
||
import com.asyncapi.v2.model.schema.Schema; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import java.util.List; | ||
|
||
|
||
/** | ||
* @author Ben Antony - [email protected] | ||
*/ | ||
class LocalDateTimeTest { | ||
|
||
@Test | ||
void testField() { | ||
|
||
var fieldSchema = new Schema(); | ||
fieldSchema.setTitle("field"); | ||
fieldSchema.setType("string"); | ||
fieldSchema.setFormat("date-time"); | ||
fieldSchema.setExamples(List.of("2022-01-31T23:20:50.52Z", "1985-04-12T15:59:55-08:00")); | ||
|
||
FieldTestUtil.assertSchemaOnClass(Example.class, fieldSchema); | ||
} | ||
|
||
private static class Example { | ||
|
||
private LocalDateTime field; | ||
} | ||
} |
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