-
Notifications
You must be signed in to change notification settings - Fork 221
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
How can we handle untyped JSON? #2319
Comments
Tying the generation result to any specific format would break one of our tenets. However we could use the a default entity class added to the abstractions with no properties so all the undocumented properties would go to the additional data. For the array it's a bit more complicated since it could be an array of objects or scalar values. And we need to think about writing back too. Overall I thought the last time we talked about the we decided not to facilitate those scenarios since that would make kiota wrap around the serialization librairies with little control over what's going on. Falling early encourages API producers to fix their description. |
I wonder if we could fallback to a memorystream/byte array for properties that we don't know how to deserialize? That would at least allow the consumer to manually deserialize the properties. This isn't just about "fixing" the API description. There are parts of APIs that are declared as "untyped" content. Microsoft Graph does this in a number of places where content is simply described as JSON. The problem with relying on AdditionalProperties is that it only supports primitives in a reasonable way. Where additional properties are complex types like objects and arrays, we expose it as JSON strings. At least that's how we used to do it. I'm assuming Kiota does it the same. |
At the moment the serialization library exposes these types as object representation of the json Object depending on the serialization library. As the json library uses I think in this scenario,
could project to generic object types like class SomeThing {
someObject: object;
someArray: object;
} And then the serialization libraries could still assign the appropriate type to the objects such as |
The value of supporting arbitrary JSON decreases a great deal when more advanced concepts like union/intersection types are supported. (our previous generation of SDKs didn't have support for that) I'm just worried that we're trying to enable scenarios that will produce terrible client code instead of adding incentive for client consumers to talk to the API producers into improving their design. Right now I believe most languages deserialize scalar properties into the additional data and anything else is stored as IParseNode instance. But we're probably not symmetric in the serialization. To Andrew's point: using a generic object that people have to cast will make for an error prone client code, I'd much rather just generate with an IParseNode type for those unknown properties. And we'd probably need to augment that interface with a kind (object/array/scalar) to enable symmetric serialization. |
This comment was marked as outdated.
This comment was marked as outdated.
Re-opening this as this is needed for API's using the |
This comment was marked as outdated.
This comment was marked as outdated.
1 similar comment
This comment was marked as outdated.
This comment was marked as outdated.
Is there any way how the community can help with this? I guess it requires changes in more repositories, at least some subtasks which don't require a deep knowledge of Kiota before the main implementation can be done. |
@MartinM85 thanks for offering your help.
Once we have a working prototype in dotnet, we can then think about replicating the efforts across other languages. Thoughts? don't hesitate if you have follow up questions |
Hi @baywet, it's quite clear. I will have probably have more questions later. |
@baywet I see that this has a milestone for v1.13. I'm using v1.12. If I use the latest version of all the related Nuget packages, we get issues with microsoft/kiota-dotnet#175. When we downgrade the following packages to the specific versions (almost latest) everything is working fine with v1.12.
So what will v1.13 change? What could be the reason? |
The generated code would change with untyped JSON @LockTar and 1.13 was shipped this morning. Can you validate this solves the issue now? |
Hi, If I update in the future and it doesn't work I will create a new issue. For now my comment can be discarded. |
Currently in the OpenAPI for Graph we have this which I'm fairly sure is wrong. I don't think the @odata.Type comes back with graph.JSON payloads
and uses of it look like this.
I tried something similar to this in a different API and was expecting to see other properties appearing in the AdditionalData collection but there was nothing.
I would expect
to project a type like
However, to do that, the serializer would have to expose via some kind of interface that would communicate what types to use for generic JSON content.
The text was updated successfully, but these errors were encountered: