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: make ord document url endpoint configurable and extendable #70

Closed zongqichen closed 1 month ago

zongqichen commented 1 month ago

At the moment, there is only one fixed url endpoint set in https://github.com/cap-js/ord/blob/main/lib/defaults.js#L81:

    baseTemplate: {
        openResourceDiscoveryV1: {
            documents: [
                {
                    url: "/open-resource-discovery/v1/documents/1",
                    accessStrategies: [
                        {
                            type: "open",
                        },
                    ],
                },
            ],
        },
    },

and call it in https://github.com/cap-js/ord/blob/main/lib/plugin.js#L20:

  app.get("/open-resource-discovery/v1/documents/1", async (req, res) => {
    try {
      const csn = await cds.load(cds.env.folders.srv);
      const data = ord(csn);
      return res.status(200).send(data);
    } catch (error) {
      console.log(error);
      console.log('Error while creating ORD document');
      return res.status(500).send(error.message);
    }
  });
});

We need to consider two more cases:

  1. if user has more than ord documents: e.g they have their own ord document
  2. we should make url endpoint configurable when user wants to adjust
swennemers commented 1 month ago

the ORD endpoint configuration is a quite optional feature. the endpoints used in the plugin should be the recommended ones from the specification. Having multiple services, does not mean, we need own ORD documents for each of them. A single ORD document is fine to contain multiple APIs (derived from the multiple services).