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

SAP OData missing __metadata property #60

Open
snebjorn opened this issue Feb 6, 2020 · 6 comments
Open

SAP OData missing __metadata property #60

snebjorn opened this issue Feb 6, 2020 · 6 comments

Comments

@snebjorn
Copy link
Contributor

snebjorn commented Feb 6, 2020

I'm working with an ODATA endpoint in SAP and I noticed that SAP sends a __metadata property which isn't described in the $metadata unfortunately. Not sure if it can be "turned on" via a query parameter. However it's there.

I looked though the XSLT scripts and couldn't find a "handler" for the __metadata property. Is it possible to add this to the generated OAS when converting a metadata from SAP OData?

The reason why the __metadata property is relevant is because it contains the etag value for an entity.

The SAP ODATA response looks like this:

{
  "d": {
    "results": [
      {
        "__metadata": {
          "id": "https://.../{dataservice}/{resource}('id')",
          "uri": "https://.../{dataservice}/{resource}('id')",
          "type": "{dataservice}.{resource}",
          "etag": "..."
        },
        "...": "..." // omitted
      }
    ]
  }
}
@ralfhandl
Copy link
Contributor

That's standard OData V2, you can also see it in the public Northwind V2 service.

It is not reflected in $metadata because it is there by default in all V2 "Verbose JSON" responses.

It is currently also not reflected in the generated OAS because it always has the same structure, see OData V2 Specification, 2.2.6.3.3 Entity Type (as a JSON Object)

@snebjorn
Copy link
Contributor Author

snebjorn commented Feb 6, 2020

I see. It's good that it's not a special case, makes things a bit easier :)

It is currently also not reflected in the generated OAS because it always has the same structure

I'm using the OAS to generate a client (https://github.com/OpenAPITools/openapi-generator). When the property is missing I have to alter the generated model to include __metadata.
So in that scenario adding it has some value :)

I guess the counter argument is that the openapi-generator should know it's an OAS for an ODATA data source and include these default properties.

Not sure which is the better option.

@ralfhandl
Copy link
Contributor

One could argue that the purpose of the generated OAS is that clients don't need to know about OData. (Did I actually write this? In my opinion everyone should know about OData 😃)

I'd be willing to test and merge a pull request if you would want to add that feature. The __metadata property would only be needed for the "read" structure of an entity type, so to be added in template properties, and only if test="$odata-version='2.0' and not($suffix) and local-name($structuredType)='EntityType'".

@snebjorn
Copy link
Contributor Author

snebjorn commented Feb 6, 2020

I'll have a look

@ralfhandl
Copy link
Contributor

Added simple test script https://github.com/oasis-tcs/odata-openapi/blob/master/tools/test.cmd

Runs XSLTs for a bunch of test input files and uses git diff to show what has changed.

@snebjorn
Copy link
Contributor Author

snebjorn commented Mar 28, 2020

I need some help with this one. I'm bad at XSLT :(
Just needed to sleep on it

snebjorn added a commit to snebjorn/odata-openapi that referenced this issue Mar 29, 2020
snebjorn added a commit to snebjorn/odata-openapi that referenced this issue Mar 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants