-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Provide example value for uuid and email
- Loading branch information
Showing
4 changed files
with
61 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,11 +35,17 @@ public class ExampleJsonGenerator implements ExampleGenerator { | |
private static final String DEFAULT_BINARY_EXAMPLE = | ||
"\"0111010001100101011100110111010000101101011000100110100101101110011000010110010001111001\""; | ||
private static final String DEFAULT_STRING_EXAMPLE = "\"string\""; | ||
public static final String DEFAULT_EMAIL_EXAMPLE = "\"[email protected]\""; | ||
public static final String DEFAULT_UUID_EXAMPLE = "\"3fa85f64-5717-4562-b3fc-2c963f66afa6\""; | ||
|
||
private static String DEFAULT_UNKNOWN_SCHAME_EXAMPLE(String type) { | ||
private static String DEFAULT_UNKNOWN_SCHEMA_EXAMPLE(String type) { | ||
return "\"unknown schema type: " + type + "\""; | ||
} | ||
|
||
private static String DEFAULT_UNKNOWN_SCHEMA_STRING_EXAMPLE(String format) { | ||
return "\"unknown string schema format: " + format + "\""; | ||
} | ||
|
||
@Override | ||
public Object fromSchema(Schema schema, Map<String, Schema> definitions) { | ||
try { | ||
|
@@ -79,7 +85,7 @@ private static String buildSchemaInternal(Schema schema, Map<String, Schema> def | |
case "number" -> DEFAULT_NUMBER_EXAMPLE; | ||
case "object" -> ExampleJsonGenerator.handleObject(schema, definitions, visited); | ||
case "string" -> ExampleJsonGenerator.handleStringSchema(schema); | ||
default -> DEFAULT_UNKNOWN_SCHAME_EXAMPLE(type); | ||
default -> DEFAULT_UNKNOWN_SCHEMA_EXAMPLE(type); | ||
}; | ||
} | ||
|
||
|
@@ -120,10 +126,12 @@ private static String handleStringSchema(Schema schema) { | |
return switch (format) { | ||
case "date" -> DEFUALT_DATE_EXAMPLE; | ||
case "date-time" -> DEFAULT_DATE_TIME_EXAMPLE; | ||
case "email" -> DEFAULT_EMAIL_EXAMPLE; | ||
case "password" -> DEFAULT_PASSWORD_EXAMPLE; | ||
case "byte" -> DEFAULT_BYTE_EXAMPLE; | ||
case "binary" -> DEFAULT_BINARY_EXAMPLE; | ||
default -> "unknown type format: " + format; | ||
case "uuid" -> DEFAULT_UUID_EXAMPLE; | ||
default -> DEFAULT_UNKNOWN_SCHEMA_STRING_EXAMPLE(format); | ||
}; | ||
} | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,14 @@ | |
import io.swagger.v3.oas.models.media.BooleanSchema; | ||
import io.swagger.v3.oas.models.media.DateSchema; | ||
import io.swagger.v3.oas.models.media.DateTimeSchema; | ||
import io.swagger.v3.oas.models.media.EmailSchema; | ||
import io.swagger.v3.oas.models.media.IntegerSchema; | ||
import io.swagger.v3.oas.models.media.NumberSchema; | ||
import io.swagger.v3.oas.models.media.ObjectSchema; | ||
import io.swagger.v3.oas.models.media.PasswordSchema; | ||
import io.swagger.v3.oas.models.media.Schema; | ||
import io.swagger.v3.oas.models.media.StringSchema; | ||
import io.swagger.v3.oas.models.media.UUIDSchema; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
@@ -197,6 +199,15 @@ void type_string_format_datetime() { | |
assertThat(actual).isEqualTo("\"2015-07-20T15:49:04-07:00\""); | ||
} | ||
|
||
@Test | ||
void type_string_format_email() { | ||
EmailSchema schema = new EmailSchema(); | ||
|
||
String actual = ExampleJsonGenerator.buildSchema(schema, emptyMap()); | ||
|
||
assertThat(actual).isEqualTo("\"[email protected]\""); | ||
} | ||
|
||
@Test | ||
void type_string_format_password() { | ||
PasswordSchema schema = new PasswordSchema(); | ||
|
@@ -206,6 +217,25 @@ void type_string_format_password() { | |
assertThat(actual).isEqualTo("\"string-password\""); | ||
} | ||
|
||
@Test | ||
void type_string_format_uuid() { | ||
UUIDSchema schema = new UUIDSchema(); | ||
|
||
String actual = ExampleJsonGenerator.buildSchema(schema, emptyMap()); | ||
|
||
assertThat(actual).isEqualTo("\"3fa85f64-5717-4562-b3fc-2c963f66afa6\""); | ||
} | ||
|
||
@Test | ||
void type_string_format_unknown() { | ||
StringSchema schema = new StringSchema(); | ||
schema.setType("unknown"); | ||
|
||
String actual = ExampleJsonGenerator.buildSchema(schema, emptyMap()); | ||
|
||
assertThat(actual).isEqualTo("\"unknown string schema type: unknown\""); | ||
} | ||
|
||
@Test | ||
void type_unknown_schema() { | ||
class TestSchema extends Schema<StringSchema> { | ||
|
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