Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions core/src/language/python.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::language::SupportedLanguage;
use crate::parser::ParsedData;
use crate::rust_types::{RustEnumShared, RustItem, RustType, RustTypeFormatError, SpecialRustType};
use crate::topsort::topsort;
Expand Down Expand Up @@ -448,9 +449,12 @@ impl Python {
let is_optional = field.ty.is_optional() || field.has_default;
// currently, if a field has a serde default value, it must be an Option
let not_optional_but_default = !field.ty.is_optional() && field.has_default;
let python_type = self
.format_type(&field.ty, generic_types)
.map_err(std::io::Error::other)?;
let python_type: String = match field.type_override(SupportedLanguage::Python) {
Some(type_override) => type_override.to_owned(),
None => self
.format_type(&field.ty, generic_types)
.map_err(std::io::Error::other)?,
};
let python_field_name = python_property_aware_rename(&field.id.original);
let is_aliased = python_field_name != field.id.renamed;
let custom_translations = json_translation_for_type(&python_type);
Expand Down
10 changes: 10 additions & 0 deletions docs/src/usage/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,17 @@ This would generate the following Kotlin code:
typealias Options = String
```

This decorator can also be applied to fields. If you want to precisely specify
the serialized type in the foreign language, you can use the `(type = "...")` decorator:

```rust
#[typeshare]
struct MyStruct {
#[typeshare(typescript(type = "Record<string, any>"))]
#[typeshare(python(type = "dict"))]
my_field: MyCustomType,
}
```

## The `#[serde]` Attribute

Expand Down
Loading