Comments (1)
Reason this doesn't work today is due to the rules defined in the test-cases yml file: https://github.com/palantir/conjure-verification/blob/85ec2c15cde616415e79d6b3b03c34559e287ab0/master-test-cases.yml#L390
- type: KebabCaseObjectExample
positive:
- '{"kebab-cased-field":1}'
negative:
- '{"kebabCasedField":1}'
- '{"kebab_cased_field":1}'
For example:
Given a generated conjure bean like so:
class CreateDatasetRequest(ConjureBeanType):
@classmethod
def _fields(cls) -> Dict[str, ConjureFieldDefinition]:
return {
"file_system_id": ConjureFieldDefinition("fileSystemId", str),
"path": ConjureFieldDefinition("path", str),
}
_file_system_id: str = None
_path: str = None
def __init__(self, file_system_id: str, path: str) -> None:
self._file_system_id = file_system_id
self._path = path
@property
def file_system_id(self) -> str:
return self._file_system_id
@property
def path(self) -> str:
return self._path
Called like this:
def test_object_with_hyphen():
decoded = ConjureDecoder().decode({"file-system-id": "foo", "path": "bar"}, CreateDatasetRequest)
assert decoded == CreateDatasetRequest("foo", "bar")
And this implementation:
@classmethod
def decode_conjure_bean_type(cls, obj, conjure_type):
"""Decodes json into a conjure bean type (a plain bean, not enum
or union).
Args:
obj: the json object to decode <----------------------------------- # {"file-system-id": "foo", "path": "bar"}
conjure_type: a class object which is the bean type
we're decoding into
Returns:
A instance of a bean of type conjure_type.
"""
deserialized: Dict[str, Any] = {}
for (
python_arg_name, <----------------------------------- # ends up being "'file_system_id'"
field_definition,
) in conjure_type._fields().items():
field_identifier = field_definition.identifier <----------------------------------- # ends up being "'fileSystemId'
# only checking the field_identifier means incorrectly flagging the valid hyphenated case here
if field_identifier not in obj or obj[field_identifier] is None:
# Logic passes here
cls.check_null_field(
obj, deserialized, python_arg_name, field_definition
)
else:
value = obj[field_identifier]
field_type = field_definition.field_type
deserialized[python_arg_name] = cls.do_decode(
value, field_type
)
return conjure_type(**deserialized)
which passes through to
@classmethod
def check_null_field(
cls, obj, deserialized, python_arg_name, field_definition
):
type_origin = get_origin(field_definition.field_type)
if isinstance(field_definition.field_type, ListType):
deserialized[python_arg_name] = []
elif isinstance(field_definition.field_type, DictType):
deserialized[python_arg_name] = {}
elif isinstance(field_definition.field_type, OptionalType):
deserialized[python_arg_name] = None
elif type_origin is OptionalTypeWrapper:
deserialized[python_arg_name] = None
elif type_origin is list:
deserialized[python_arg_name] = []
elif type_origin is dict:
deserialized[python_arg_name] = {}
else:
raise Exception( <----------------------------------- this is where we are throwing the exception
"field {} not found in object {}".format(
field_definition.identifier, obj
)
)
This fails with the above exception:
Exception: field fileSystemId not found in object {'file-system-id': 'foo', 'path': 'bar'}
When it shouldn't given the conjure client generator separates it out with underscores already and is fairly straightforward to at least look for it.
"file_system_id": ConjureFieldDefinition("fileSystemId", str),
from conjure-python-client.
Related Issues (17)
- Dependency on enum34 breaks python 3.7 (and proabably 3.6) - is it possible to make it a conditional dependency HOT 2
- Support deserializing unknown union variants
- Service initialization should be easier
- :bug: Failure with missing conjure_type.__code__
- Support URIs with a 'mesh-' prefix
- ConjureDecoder does not throw when array passed as object
- ConjureType should include __hash__ implementation
- URL parameters are not encoded automatically
- Catch non-JSON error message
- Convert to using new style classes
- Using "property" as a parameter breaks the generated code HOT 1
- Implement adaptive rate limits
- Add license to MANIFEST.in
- Service exceptions from Java are not properly decoded in Python client
- datetime is not encoded properly
- Deserializer does not throw exceptions if fields are missing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from conjure-python-client.