oasis-open / odata-rapid

Rapid - Specification, tools and libraries to support the development and adoption of simple REST-based APIs.
https://rapid.rocks
Apache License 2.0
16 stars 8 forks source link

odata-openapi injects invalid "$ContainsTarget" into entity sets and singletons #415

Closed mikepizzo closed 1 year ago

mikepizzo commented 1 year ago

Steps to Repro:

  1. Go to https://rapid.rocks/api-designer/index.html
  2. Click on "CSDL" tab

Result: competitors entity set and company singleton both contain the "$ContainsTarget=true" properties:

{
  ...
    "Service": {
      "$Kind": "EntityContainer",
      "competitors": {
        "$Collection": true,
        "$Type": "Model.Company",
        "$ContainsTarget": true
      },
      "company": {
        "$Type": "Model.Company",
        "$ContainsTarget": true
      }
}

Expected: $ContainsTarget should only be valid on a navigation property.

More Information: $ContainsTarget is set on line 407 of parser.js. According to line 399 this line should only be encountered if $Kind is EntityType or ComplexType, but it seems the line is being hit for entity sets and singletons, which have no $Kind.

ralfhandl commented 1 year ago

Strange, we even have a test case for Jetsons that checks the entity container:

https://github.com/oasis-open/odata-rapid/blob/2a0457798a6be31217c7f5c9949a28f851a3f8a7/tools/rsdl/rsdl-js/test/cli.test.js#L31-L38

The test passes, and running the tool from the command line also produces correct CSDL JSON.

mikepizzo commented 1 year ago

Weird.

It looks like api-designer pulls rsdl-js from nuget, not from our project. Perhaps it was a bug in the nuget package that doesn't exist in the latest source.

I'll check to see if referencing the latest source fixes the issue in the designer.

mikepizzo commented 1 year ago

Updated packages to point to rsdl-js project, but still getting $ContainsTarget in the entity sets/singletons in CSDL tab of api-designer. This is definitely coming from directly from the parse() method (not inserted from elsewhere); curiously, the urlEditor also individually calls parse() to parse the same rsdl just prior to parsing for the csdl tab, and the urlEditor gets the correct result (no $ContainsTarget for the entityset/singleton).

ralfhandl commented 1 year ago

The problem is in odata-openapi: it modifies its JSON input and injects $ContainsTarget into container children because from an OpenAPI perspective they behave like containment navigation properties.

ralfhandl commented 1 year ago

Fixed with https://github.com/oasis-tcs/odata-openapi/pull/222