Skip to content
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

OData v2 support #143

Open
kriegfrj opened this issue May 31, 2021 · 8 comments
Open

OData v2 support #143

kriegfrj opened this issue May 31, 2021 · 8 comments
Labels
question Further information is requested

Comments

@kriegfrj
Copy link
Contributor

This looks like a great generator, I particularly like the type safety. But unfortunately the server I need to connect to is OData v2. How hard would it be to modify the generator to generate v2 compatible clients?

@davidmoten
Copy link
Owner

I don't know. I'm not familiar with v2. I'll have a short look at what's changed. What product are you connecting to?

@davidmoten
Copy link
Owner

Can you give me your v2 metadata to see what the differences are?

@kriegfrj
Copy link
Contributor Author

kriegfrj commented Jun 1, 2021

Thanks for the response @davidmoten. Unfortunately, I'm not sure that I can give you the metadata for my specific service due to its licensing, but I found another sample OData v2 service online here:

https://services.odata.org/V2/OData/OData.svc/$metadata

The main difference between it and mine seems to be the version of the schema XML namespace used for the <Schema> element (the sample service reports http://schemas.microsoft.com/ado/2007/05/edm and my service is using http://schemas.microsoft.com/ado/2008/09/edm). I'm not sure how much of a difference that makes. There are also some extra proprietary attributes on the <Property> elements of the 'EntityType' declarations.

@kriegfrj
Copy link
Contributor Author

kriegfrj commented Jun 1, 2021

Upon investigation:

I was getting an NPE here:

when I was trying to run this on the v2 metadata. I had assumed that this was because it was v2. When I downloaded and tried out the odata-client project itself on my system, I was getting the same error when trying to build

This could be a bug or a misconfiguration error on my part (even if it's a misconfiguration error, I'd consider it a bug that the diagnostics aren't more useful). I'll continue to investigate.

@davidmoten
Copy link
Owner

V2 does look very similar. You might be able to modify the metadata file to make it comply with V4 and then use the generated client.

The xml namespace will be important. You will want to modify the namespaces to look like this simple example in V4:

https://github.com/davidmoten/odata-client/blob/master/odata-client-test-unit/src/main/odata/metadata1.xml

The null pointer is probably because you are loading a file with a root element of a completely different namespace and the t in your code extract ends up being null because there is no match at all.

@kriegfrj
Copy link
Contributor Author

kriegfrj commented Jun 1, 2021

Thanks for the response David. I've come to a similar conclusion. I'm having a bit of a play with it at the moment.

There were two causes of the NPE. One of them I reported in #145. The other is I think due to the reason that you specified.

I managed to track down XSD files for OData v2; I'll see if these can be incorporated. Otherwise, munging my xml to make it look like OData v4 might work.

@davidmoten davidmoten added the question Further information is requested label Jun 1, 2021
@kriegfrj
Copy link
Contributor Author

kriegfrj commented Jun 2, 2021

Here is the definitive reference for the differences between OData 2 and 4: http://docs.oasis-open.org/odata/new-in-odata/v4.0/cn01/new-in-odata-v4.0-cn01.html
There are also a couple of summaries of the difference between OData v2 and v4:

I've gone with the munging approach as a bit of an exploration. For my particular service, these are the sticking points that I have found so far:

  1. The xml namespace schema declarations have to be updated to the OData v4 ones (http://schemas.microsoft.com/ado/2008/09/edm -> http://docs.oasis-open.org/odata/ns/edm, http://schemas.microsoft.com/ado/2007/06/edmx -> http://docs.oasis-open.org/odata/ns/edmx).
  2. <NavigationProperty> syntax is different. v2 does not have a Type property (from what I can tell, type is inferred by referring to the type of the values that are linked to), v4 requires it to be set explicitly on the property declaration itself. To get my schema to compile, I had to comment out the <NavigationProperty> elements for now.
  3. Some of the primitive data types have changed, in particular Edm.DateTime has been deprecated. It seems that the client generator at the moment doesn't handle the deprecated type and skips it. Had to change these to make it work.

It would be nice if this was more seamless, but I now have a schema that compiles and is hitting remote servers. Ready for the next hurdle! 😄 Thanks for your help @davidmoten .

@davidmoten
Copy link
Owner

Nice work @kriegfrj !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants