-
Notifications
You must be signed in to change notification settings - Fork 115
Add support for DateTime field for Go, JS, Python #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6d62e79
Add support for DateTime field for Go, JS, Python and keep the origin…
MOmarMiraj 66bfad1
fmt fix
MOmarMiraj 916ef7b
remove diff for kotlin
MOmarMiraj 05ea27e
remove unused error and add TODOs for the languages that we don't add…
MOmarMiraj def0131
add todo
MOmarMiraj 4e9246f
change to OffSetDateTime
MOmarMiraj f9f3ca4
add test cases for datetime and add errors for Datetime for unsupport…
MOmarMiraj eddbf9a
fix python serialization logic
MOmarMiraj 4ee40f5
Merge branch 'main' into omar/34/add-date-time-support
MOmarMiraj a7accd9
update typescript update
MOmarMiraj 5b474d6
add key as a match for TS
MOmarMiraj fc673a8
clean up code a bit
MOmarMiraj 529be9c
add capability to add imports in go as well as address nits in python…
MOmarMiraj b4d5d3f
fix go imports and typescript spacing
MOmarMiraj e1a2b92
update imports to be tabs and sort them
MOmarMiraj ad45688
update expected tests
MOmarMiraj 8371b66
ensure the custom translations are determnistic by sorting them
MOmarMiraj 7a74614
fmt fix
MOmarMiraj 9e39854
update typescript regex to include optional seconds as well as fix go…
MOmarMiraj 82b5ece
add new line after single imports
MOmarMiraj 2ef4d4a
change write import to add import
MOmarMiraj 646f8f2
fix chaining and check if value is string instead of type casting it
MOmarMiraj 2c7717e
ensure custom serialization/deserialzation is determinstic
MOmarMiraj 5056f25
make go imports deterministic and add all numbers for python serializ…
MOmarMiraj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type ItemDetailsFieldValue struct { | ||
Hello string `json:"hello"` | ||
} | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
// Struct comment | ||
type ItemDetailsFieldValue struct { | ||
} | ||
|
1 change: 0 additions & 1 deletion
1
core/data/tests/can_generate_algebraic_enum_with_skipped_variants/output.go
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type SomeEnumTypes string | ||
const ( | ||
SomeEnumTypeVariantA SomeEnumTypes = "A" | ||
|
1 change: 0 additions & 1 deletion
1
core/data/tests/can_generate_anonymous_struct_with_skipped_fields/output.go
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
// This is a comment. | ||
type Colors string | ||
const ( | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
const MyVar uint32 = 12 |
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type AddressDetails struct { | ||
} | ||
type AddressTypes string | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
// This is a comment. | ||
// Continued lovingly here | ||
type Colors string | ||
|
1 change: 0 additions & 1 deletion
1
core/data/tests/can_generate_simple_struct_with_a_comment/output.go
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type Location struct { | ||
} | ||
// This is a comment. | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type Video struct { | ||
Tags []Tag `json:"tags"` | ||
} |
1 change: 0 additions & 1 deletion
1
core/data/tests/can_generate_struct_with_skipped_fields/output.go
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type MyStruct struct { | ||
A int `json:"a"` | ||
C int `json:"c"` | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type UnitStruct struct { | ||
} |
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
// This is a comment. | ||
type Colors string | ||
const ( | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type OtherType struct { | ||
} | ||
// This is a comment. | ||
|
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type OtherType struct { | ||
} | ||
// This is a comment. | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type A struct { | ||
Field uint32 `json:"field"` | ||
} | ||
|
1 change: 0 additions & 1 deletion
1
core/data/tests/enum_is_properly_named_with_serde_overrides/output.go
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
// This is a comment. | ||
// Continued lovingly here | ||
type Colors string | ||
|
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type CustomType struct { | ||
} | ||
type Types struct { | ||
|
1 change: 0 additions & 1 deletion
1
core/data/tests/generates_empty_structs_and_initializers/output.go
This file contains hidden or 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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type MyEmptyStruct struct { | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
// This is a comment. | ||
type Things struct { | ||
Bla string `json:"bla"` | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type A struct { | ||
Field uint32 `json:"field"` | ||
} | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type AliasTest []SomethingFoo | ||
|
||
type Test struct { | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type Uuid string | ||
|
||
// Unique identifier for an Account | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
// This is a comment. | ||
type ArcyColors struct { | ||
Red int `json:"red"` | ||
|
1 change: 0 additions & 1 deletion
1
core/data/tests/test_algebraic_enum_case_name_support/output.go
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
type ItemDetailsFieldValue struct { | ||
} | ||
type AdvancedColorsTypes string | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
core/data/tests/test_custom_serialize_deserialize_functions/input.rs
This file contains hidden or 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,9 @@ | ||
#[typeshare] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Foo { | ||
pub time: time::OffsetDateTime, | ||
pub time2: time::OffsetDateTime, | ||
pub time3: time::OffsetDateTime, | ||
pub bytes: Vec<u8>, | ||
pub bytes2: Vec<u8> | ||
} |
14 changes: 14 additions & 0 deletions
14
core/data/tests/test_custom_serialize_deserialize_functions/output.go
This file contains hidden or 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,14 @@ | ||
package proto | ||
|
||
import ( | ||
"encoding/json" | ||
"time" | ||
) | ||
|
||
type Foo struct { | ||
Time time.Time `json:"time"` | ||
Time2 time.Time `json:"time2"` | ||
Time3 time.Time `json:"time3"` | ||
Bytes []byte `json:"bytes"` | ||
Bytes2 []byte `json:"bytes2"` | ||
} |
45 changes: 45 additions & 0 deletions
45
core/data/tests/test_custom_serialize_deserialize_functions/output.py
This file contains hidden or 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,45 @@ | ||
from __future__ import annotations | ||
|
||
from datetime import datetime | ||
from pydantic import BaseModel, BeforeValidator, ConfigDict, Field, PlainSerializer | ||
from typing import Annotated | ||
|
||
|
||
def serialize_binary_data(value: bytes) -> list[int]: | ||
return list(value) | ||
|
||
def deserialize_binary_data(value): | ||
if isinstance(value, list): | ||
if all(isinstance(x, int) and 0 <= x <= 255 for x in value): | ||
return bytes(value) | ||
raise ValueError("All elements must be integers in the range 0-255 (u8).") | ||
elif isinstance(value, bytes): | ||
return value | ||
raise TypeError("Content must be a list of integers (0-255) or bytes.") | ||
|
||
def serialize_datetime_data(utc_time: datetime) -> str: | ||
return utc_time.strftime("%Y-%m-%dT%H:%M:%SZ") | ||
|
||
def parse_rfc3339(date_str: str) -> datetime: | ||
date_formats = [ | ||
"%Y-%m-%dT%H:%M:%SZ", | ||
"%Y-%m-%dT%H:%M:%S.%fZ" | ||
] | ||
|
||
for fmt in date_formats: | ||
try: | ||
return datetime.strptime(date_str, fmt) | ||
except ValueError: | ||
continue | ||
|
||
raise ValueError(f"Invalid RFC 3339 date format: {date_str}") | ||
|
||
class Foo(BaseModel): | ||
model_config = ConfigDict(populate_by_name=True) | ||
|
||
time: Annotated[datetime, BeforeValidator(parse_rfc3339), PlainSerializer(serialize_datetime_data)] | ||
time_2: Annotated[datetime, BeforeValidator(parse_rfc3339), PlainSerializer(serialize_datetime_data)] = Field(alias="time2") | ||
time_3: Annotated[datetime, BeforeValidator(parse_rfc3339), PlainSerializer(serialize_datetime_data)] = Field(alias="time3") | ||
bytes: Annotated[bytes, BeforeValidator(deserialize_binary_data), PlainSerializer(serialize_binary_data)] | ||
bytes_2: Annotated[bytes, BeforeValidator(deserialize_binary_data), PlainSerializer(serialize_binary_data)] = Field(alias="bytes2") | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.