@@ -280,33 +280,122 @@ def test_get_data_formats_jsonschema() -> None:
280280 from datamodel_code_generator .parser .schema_version import get_data_formats
281281 from datamodel_code_generator .types import Types
282282
283- formats = get_data_formats (is_openapi = False )
284- assert "binary" not in formats ["string" ]
285- assert "password" not in formats ["string" ]
286- assert formats ["string" ]["byte" ] == snapshot (Types .byte )
287- assert formats ["string" ]["date-time" ] == snapshot (Types .date_time )
283+ assert get_data_formats (is_openapi = False ) == snapshot ({
284+ "integer" : {
285+ "int32" : Types .int32 ,
286+ "int64" : Types .int64 ,
287+ "default" : Types .integer ,
288+ "date-time" : Types .date_time ,
289+ "unix-time" : Types .int64 ,
290+ "unixtime" : Types .int64 ,
291+ },
292+ "number" : {
293+ "float" : Types .float ,
294+ "double" : Types .double ,
295+ "decimal" : Types .decimal ,
296+ "date-time" : Types .date_time ,
297+ "time" : Types .time ,
298+ "time-delta" : Types .timedelta ,
299+ "default" : Types .number ,
300+ "unixtime" : Types .int64 ,
301+ },
302+ "string" : {
303+ "default" : Types .string ,
304+ "byte" : Types .byte ,
305+ "date" : Types .date ,
306+ "date-time" : Types .date_time ,
307+ "timestamp with time zone" : Types .date_time ,
308+ "date-time-local" : Types .date_time_local ,
309+ "duration" : Types .timedelta ,
310+ "time" : Types .time ,
311+ "time-local" : Types .time_local ,
312+ "path" : Types .path ,
313+ "email" : Types .email ,
314+ "idn-email" : Types .email ,
315+ "uuid" : Types .uuid ,
316+ "uuid1" : Types .uuid1 ,
317+ "uuid2" : Types .uuid2 ,
318+ "uuid3" : Types .uuid3 ,
319+ "uuid4" : Types .uuid4 ,
320+ "uuid5" : Types .uuid5 ,
321+ "uri" : Types .uri ,
322+ "uri-reference" : Types .string ,
323+ "hostname" : Types .hostname ,
324+ "ipv4" : Types .ipv4 ,
325+ "ipv4-network" : Types .ipv4_network ,
326+ "ipv6" : Types .ipv6 ,
327+ "ipv6-network" : Types .ipv6_network ,
328+ "decimal" : Types .decimal ,
329+ "integer" : Types .integer ,
330+ "unixtime" : Types .int64 ,
331+ "ulid" : Types .ulid ,
332+ },
333+ "boolean" : {"default" : Types .boolean },
334+ "object" : {"default" : Types .object },
335+ "null" : {"default" : Types .null },
336+ "array" : {"default" : Types .array },
337+ })
288338
289339
290340def test_get_data_formats_openapi () -> None :
291341 """Test that OpenAPI formats include OpenAPI-specific formats."""
292342 from datamodel_code_generator .parser .schema_version import get_data_formats
293343 from datamodel_code_generator .types import Types
294344
295- formats = get_data_formats (is_openapi = True )
296- assert formats ["string" ]["binary" ] == snapshot (Types .binary )
297- assert formats ["string" ]["password" ] == snapshot (Types .password )
298- assert formats ["string" ]["byte" ] == snapshot (Types .byte )
299-
300-
301- def test_get_data_formats_common_types () -> None :
302- """Test that common types are present in both modes."""
303- from datamodel_code_generator .parser .schema_version import get_data_formats
304- from datamodel_code_generator .types import Types
305-
306- jsonschema_formats = get_data_formats (is_openapi = False )
307- openapi_formats = get_data_formats (is_openapi = True )
308-
309- assert jsonschema_formats ["integer" ]["default" ] == snapshot (Types .integer )
310- assert openapi_formats ["integer" ]["default" ] == snapshot (Types .integer )
311- assert jsonschema_formats ["boolean" ]["default" ] == snapshot (Types .boolean )
312- assert openapi_formats ["boolean" ]["default" ] == snapshot (Types .boolean )
345+ assert get_data_formats (is_openapi = True ) == snapshot ({
346+ "integer" : {
347+ "int32" : Types .int32 ,
348+ "int64" : Types .int64 ,
349+ "default" : Types .integer ,
350+ "date-time" : Types .date_time ,
351+ "unix-time" : Types .int64 ,
352+ "unixtime" : Types .int64 ,
353+ },
354+ "number" : {
355+ "float" : Types .float ,
356+ "double" : Types .double ,
357+ "decimal" : Types .decimal ,
358+ "date-time" : Types .date_time ,
359+ "time" : Types .time ,
360+ "time-delta" : Types .timedelta ,
361+ "default" : Types .number ,
362+ "unixtime" : Types .int64 ,
363+ },
364+ "string" : {
365+ "default" : Types .string ,
366+ "byte" : Types .byte ,
367+ "date" : Types .date ,
368+ "date-time" : Types .date_time ,
369+ "timestamp with time zone" : Types .date_time ,
370+ "date-time-local" : Types .date_time_local ,
371+ "duration" : Types .timedelta ,
372+ "time" : Types .time ,
373+ "time-local" : Types .time_local ,
374+ "path" : Types .path ,
375+ "email" : Types .email ,
376+ "idn-email" : Types .email ,
377+ "uuid" : Types .uuid ,
378+ "uuid1" : Types .uuid1 ,
379+ "uuid2" : Types .uuid2 ,
380+ "uuid3" : Types .uuid3 ,
381+ "uuid4" : Types .uuid4 ,
382+ "uuid5" : Types .uuid5 ,
383+ "uri" : Types .uri ,
384+ "uri-reference" : Types .string ,
385+ "hostname" : Types .hostname ,
386+ "ipv4" : Types .ipv4 ,
387+ "ipv4-network" : Types .ipv4_network ,
388+ "ipv6" : Types .ipv6 ,
389+ "ipv6-network" : Types .ipv6_network ,
390+ "decimal" : Types .decimal ,
391+ "integer" : Types .integer ,
392+ "unixtime" : Types .int64 ,
393+ "ulid" : Types .ulid ,
394+ "binary" : Types .binary ,
395+ "password" : Types .password ,
396+ },
397+ "boolean" : {"default" : Types .boolean },
398+ "object" : {"default" : Types .object },
399+ "null" : {"default" : Types .null },
400+ "array" : {"default" : Types .array },
401+ })
0 commit comments