cap-js / ord

Open Resource Discovery (ORD) is a protocol that allows applications and services to self-describe their exposed resources and capabilities. This plugin enables generation of ORD document for CAP based applications.
Apache License 2.0
3 stars 4 forks source link

fix: event resources generation #55

Closed ductaily closed 1 month ago

ductaily commented 2 months ago

Address issues from https://github.com/cap-js/ord/issues/38

eventResources

ductaily commented 2 months ago

I extended service definitions of bookshop in the test:

using { sap.capire.bookshop as my } from '../db/schema';
service AdminService @(requires:'authenticated-user') { 
  entity Books as projection on my.Books;
  entity Authors as projection on my.Authors;

  event BookCreated : {
    ID    : Integer;
    title : String @title: 'Title';
  };

  event BookDeleted : {
    ID    : Integer;
  };

  event BookUpdated : {
    ID    : Integer;
    title : String @title: 'Title';
  }
}
using { sap.capire.bookshop as my } from '../db/schema';
service CatalogService @(path:'/browse') { 

  @readonly entity Books as select from my.Books {*,
    author.name as author
  } excluding { createdBy, modifiedBy };

  @requires: 'authenticated-user'
  action submitOrder (book: Books:ID, quantity: Integer);

  event BookCreated : {
      ID    : Integer;
    title : String @title: 'Title';
  };

  event BookDeleted : {
    ID    : Integer;
  };

  event BookUpdated : {
    ID    : Integer;
    title : String @title: 'Title';
  }
}

Resulting ORD Document:

{
  "$schema": "https://sap.github.io/open-resource-discovery/spec-v1/interfaces/Document.schema.json",
  "apiResources": [
     //...
  ],
  "description": "this is an application description",
  "eventResources": [
    {
      "description": "This is an example event catalog that contains only a partial ODM cap-js-ord V1 event",
      "extensible": {
        "supported": "no",
      },
      "ordId": "capjs.ord:eventResource:undefined.AdminService:v1",
      "partOfGroups": [
        "sap.cds:service:capjs.ord:undefined.AdminService",
      ],
      "partOfPackage": "capjsord:package:undefined:v1",
      "releaseStatus": "beta",
      "resourceDefinitions": [
        {
          "accessStrategies": [
            {
              "type": "open",
            },
          ],
          "mediaType": "application/json",
          "type": "asyncapi-v2",
          "url": "/.well-known/open-resource-discovery/v1/api-metadata/AdminService.asyncapi2.json",
        },
      ],
      "shortDescription": "Example ODM Event",
      "title": "ODM capjsord Events",
      "version": "1.0.0",
      "visibility": "public",
    },
    {
      "description": "This is an example event catalog that contains only a partial ODM cap-js-ord V1 event",
      "extensible": {
        "supported": "no",
      },
      "ordId": "capjs.ord:eventResource:undefined.CatalogService:v1",
      "partOfGroups": [
        "sap.cds:service:capjs.ord:undefined.CatalogService",
      ],
      "partOfPackage": "capjsord:package:undefined:v1",
      "releaseStatus": "beta",
      "resourceDefinitions": [
        {
          "accessStrategies": [
            {
              "type": "open",
            },
          ],
          "mediaType": "application/json",
          "type": "asyncapi-v2",
          "url": "/.well-known/open-resource-discovery/v1/api-metadata/CatalogService.asyncapi2.json",
        },
      ],
      "shortDescription": "Example ODM Event",
      "title": "ODM capjsord Events",
      "version": "1.0.0",
      "visibility": "public",
    },
  ],
  "groups": [
    {
      "groupId": "sap.cds:service:capjs.ord:undefined.AdminService",
      "groupTypeId": "sap.cds:service",
      "title": "Admin Service Title",
    },
    {
      "groupId": "sap.cds:service:capjs.ord:undefined.CatalogService",
      "groupTypeId": "sap.cds:service",
      "title": "Catalog Service Title",
    },
  ],
  "openResourceDiscovery": "1.9",
  "packages": [
    {
      "description": "Description for capjs ord",
      "ordId": "capjsord:package:undefined:v1",
      "partOfProducts": [
        "customer:product:capjs.ord:",
      ],
      "shortDescription": "Short description for capjs ord",
      "title": "capjs ord",
      "vendor": "customer:vendor:Customer:",
      "version": "1.0.0",
    },
  ],
  "policyLevel": "none",
  "products": [
    {
      "ordId": "customer:product:cap.js.ord:",
      "shortDescription": "Description for cap js ord",
      "title": "cap js ord",
      "vendor": "customer:vendor:customer:",
    },
  ],
}

@Fannon

ductaily commented 2 months ago

Result with our example: document.json

ductaily commented 2 months ago

The tests are failing and I can't reproduce the error on @zongqichen and my machine.

@RoshniNaveenaS Do you have an idea what could be the cause and how we could resolve it?

ductaily commented 2 months ago

The tests are failing and I can't reproduce the error on @zongqichen and my machine.

@RoshniNaveenaS Do you have an idea what could be the cause and how we could resolve it?

I see now that the failure is caused by the new CDS Version: https://github.tools.sap/cap/cds/releases/tag/rel%2F8.2.0 The LinkedDefinitions were changed and do not contain map, forEach, ... anymore.

zongqichen commented 2 months ago

The tests are failing and I can't reproduce the error on @zongqichen and my machine. @RoshniNaveenaS Do you have an idea what could be the cause and how we could resolve it?

I see now that the failure is caused by the new CDS Version: https://github.tools.sap/cap/cds/releases/tag/rel%2F8.2.0 The LinkedDefinitions were changed and do not contain map, forEach, ... anymore.

Cool, your commit has fixed it. I have one more question, it seems github action will always install the latest version of cds, and brings the issue like it. We should control peerDepdencies upper limits as well?

ductaily commented 1 month ago

The tests are failing and I can't reproduce the error on @zongqichen and my machine. @RoshniNaveenaS Do you have an idea what could be the cause and how we could resolve it?

I see now that the failure is caused by the new CDS Version: https://github.tools.sap/cap/cds/releases/tag/rel%2F8.2.0 The LinkedDefinitions were changed and do not contain map, forEach, ... anymore.

Cool, your commit has fixed it. I have one more question, it seems github action will always install the latest version of cds, and brings the issue like it. We should control peerDepdencies upper limits as well?

@zongqichen Yes, we should specify the exact version.

aramovic79 commented 1 month ago

@ductaily: There are a few merge conflicts to be resolved...

@zongqichen @Fannon

ductaily commented 1 month ago

@ductaily: There are a few merge conflicts to be resolved...

@zongqichen @Fannon

Done.

aramovic79 commented 1 month ago

@RoshniNaveenaS @RamIndia : Can we merge this PR? cc: @ductaily @zongqichen @Fannon

aramovic79 commented 1 month ago

@ductaily : I guess the following one is solved as well, correct? The groups for events shall be services, not the individual events → but then the last two entries in the bookstore sample are duplicate

ductaily commented 1 month ago

@ductaily : I guess the following one is solved as well, correct? The groups for events shall be services, not the individual events → but then the last two entries in the bookstore sample are duplicate

Correct. This PR would also solve that issue.