Skip to content

feat: support ORD document perspective configuration#392

Open
zongqichen wants to merge 1 commit intomainfrom
feat/perspective-support
Open

feat: support ORD document perspective configuration#392
zongqichen wants to merge 1 commit intomainfrom
feat/perspective-support

Conversation

@zongqichen
Copy link
Copy Markdown
Contributor

Summary

  • Add perspective field to ORD config endpoint and ORD document
  • Support describedSystemVersion, describedSystemInstance, describedSystemType passthrough from .cdsrc.json
  • Invalid perspective values are dropped with a warning log
  • Backward compatible: no changes when perspective is not configured

Configuration example (.cdsrc.json)

{
  "ord": {
    "perspective": "system-version",
    "describedSystemVersion": { "version": "1.2.0" }
  }
}

Closes #272
Closes #185

Users can now configure the ORD document perspective and described system
metadata via .cdsrc.json:

  { "ord": {
    "perspective": "system-version",
    "describedSystemVersion": { "version": "1.2.0" },
    "describedSystemInstance": { "baseUrl": "https://..." },
    "describedSystemType": { "systemNamespace": "customer.myapp" }
  }}

- perspective field added to both config endpoint and ORD document
- Invalid perspective values are dropped with a warning
- describedSystemVersion/Instance/Type passthrough to ORD document
- Backward compatible: no changes when perspective is not configured

Closes #272
Closes #185
@hyperspace-insights
Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


feat: Support ORD Document Perspective Configuration

New Feature

✨ Adds support for configuring the perspective field in the ORD document and ORD config endpoint. Users can now specify perspective, describedSystemVersion, describedSystemInstance, and describedSystemType via .cdsrc.json. Invalid perspective values are gracefully dropped with a warning log. The change is fully backward compatible — no behavior changes when perspective is not configured.

Configuration example (.cdsrc.json):

{
  "ord": {
    "perspective": "system-version",
    "describedSystemVersion": { "version": "1.2.0" }
  }
}

Changes

  • lib/constants.js: Added ORD_PERSPECTIVE enum with all allowed values (system-type, system-version, system-instance, system-independent) and exported ALLOWED_PERSPECTIVES array for validation.
  • lib/ord.js: Introduced _getPerspectiveFields() helper that reads perspective, describedSystemVersion, describedSystemInstance, and describedSystemType from appConfig.env, validates the perspective value against allowed values (warns and drops if invalid), and spreads results into the ORD document.
  • lib/defaults.js: Updated baseTemplate() to accept an optional ordConfig parameter and conditionally include perspective in the document entry of the ORD config response.
  • lib/ord-service.js: Reads cds.env["ord"] and passes it as ordConfig to defaults.baseTemplate() so the config endpoint reflects the configured perspective.
  • __tests__/unit/defaults.test.js: Added unit tests verifying perspective is included when configured, omitted when not configured, and omitted when ordConfig is empty.
  • __tests__/unit/ord.e2e.test.js: Added e2e tests covering perspective inclusion, describedSystemInstance passthrough, omission when unconfigured, and invalid value handling.

GitHub Issues

  • #272: [FEATURE] customize ORD Perspectives
  • #185: Support ORD 1.12 - static perspective

  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.18.5 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback


💌 Have ideas or want to contribute? Create an issue and share your thoughts with us!
📑 Check out the documentation for more information.
📬 Subscribe to the Hyperspace PR Bot DL to get the latest announcements and pilot features!

Made with ❤️ by Hyperspace.

Copy link
Copy Markdown
Contributor

@hyperspace-insights hyperspace-insights bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR introduces perspective support in a clean, backward-compatible way, but has three substantive issues: the config endpoint emits unvalidated perspective strings while the ORD document silently drops them (inconsistency); the afterEach teardown will crash if cds.env.ord is undefined; and the described-system companion fields (describedSystemVersion, describedSystemInstance, describedSystemType) are emitted even when no valid perspective is present, which would produce a spec-violating document.

PR Bot Information

Version: 1.18.5 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • LLM: anthropic--claude-4.6-sonnet
  • Event Trigger: pull_request.opened
  • Correlation ID: 14868b80-1e43-11f1-867d-cbc0069693e1
  • Agent Instructions:

Comment on lines +147 to +148
if (ordConfig?.perspective) {
documentEntry.perspective = ordConfig.perspective;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: perspective in the config endpoint document entry is not validated against ALLOWED_PERSPECTIVES

In lib/ord.js, _getPerspectiveFields validates the perspective value against ALLOWED_PERSPECTIVES before writing it into the ORD document. However, defaults.baseTemplate blindly copies whatever ordConfig.perspective contains into the config endpoint response — including invalid values. An operator who misconfigures .cdsrc.json with perspective: "invalid-value" will get the invalid string silently emitted at the config endpoint while being dropped (with a warning) from the document, creating an inconsistency.

Consider importing and checking ALLOWED_PERSPECTIVES here, mirroring the validation in _getPerspectiveFields:

Suggested change
if (ordConfig?.perspective) {
documentEntry.perspective = ordConfig.perspective;
if (ordConfig?.perspective && ALLOWED_PERSPECTIVES.includes(ordConfig.perspective)) {
documentEntry.perspective = ordConfig.perspective;
}

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

Comment on lines +569 to +574
afterEach(() => {
delete cds.env.ord.perspective;
delete cds.env.ord.describedSystemVersion;
delete cds.env.ord.describedSystemInstance;
delete cds.env.ord.describedSystemType;
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: afterEach will throw if cds.env.ord is undefined or null

If cds.env.ord happens to be undefined (e.g. the test environment initialises without a .cdsrc.json that sets the ord key), then delete cds.env.ord.perspective throws a TypeError: Cannot read properties of undefined. The existing pattern in the rest of the test file uses cds.env.ord = {} as a reset guard.

Consider guarding the deletions:

Suggested change
afterEach(() => {
delete cds.env.ord.perspective;
delete cds.env.ord.describedSystemVersion;
delete cds.env.ord.describedSystemInstance;
delete cds.env.ord.describedSystemType;
});
afterEach(() => {
if (cds.env.ord) {
delete cds.env.ord.perspective;
delete cds.env.ord.describedSystemVersion;
delete cds.env.ord.describedSystemInstance;
delete cds.env.ord.describedSystemType;
}
});

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

Comment on lines +278 to +300
const _getPerspectiveFields = (appConfig) => {
const result = {};
const perspective = appConfig.env?.perspective;

if (perspective) {
if (ALLOWED_PERSPECTIVES.includes(perspective)) {
result.perspective = perspective;
} else {
Logger.warn(`Invalid perspective "${perspective}". Allowed: ${ALLOWED_PERSPECTIVES.join(", ")}`);
}
}

if (appConfig.env?.describedSystemVersion) {
result.describedSystemVersion = appConfig.env.describedSystemVersion;
}
if (appConfig.env?.describedSystemInstance) {
result.describedSystemInstance = appConfig.env.describedSystemInstance;
}
if (appConfig.env?.describedSystemType) {
result.describedSystemType = appConfig.env.describedSystemType;
}

return result;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic Error: describedSystemVersion, describedSystemInstance, and describedSystemType are passed through unconditionally regardless of whether perspective is valid or even set

The ORD spec requires these fields to be paired with a valid perspective value (e.g. describedSystemVersion is only meaningful with perspective: "system-version"). As currently written, a caller can omit perspective (or provide an invalid one) and still have describedSystemVersion / describedSystemInstance / describedSystemType emitted in the document, producing a malformed ORD document.

Consider only emitting the companion fields when a valid perspective is present:

Suggested change
const _getPerspectiveFields = (appConfig) => {
const result = {};
const perspective = appConfig.env?.perspective;
if (perspective) {
if (ALLOWED_PERSPECTIVES.includes(perspective)) {
result.perspective = perspective;
} else {
Logger.warn(`Invalid perspective "${perspective}". Allowed: ${ALLOWED_PERSPECTIVES.join(", ")}`);
}
}
if (appConfig.env?.describedSystemVersion) {
result.describedSystemVersion = appConfig.env.describedSystemVersion;
}
if (appConfig.env?.describedSystemInstance) {
result.describedSystemInstance = appConfig.env.describedSystemInstance;
}
if (appConfig.env?.describedSystemType) {
result.describedSystemType = appConfig.env.describedSystemType;
}
return result;
const _getPerspectiveFields = (appConfig) => {
const result = {};
const perspective = appConfig.env?.perspective;
if (!perspective) {
return result;
}
if (!ALLOWED_PERSPECTIVES.includes(perspective)) {
Logger.warn(`Invalid perspective "${perspective}". Allowed: ${ALLOWED_PERSPECTIVES.join(", ")}`);
return result;
}
result.perspective = perspective;
if (appConfig.env?.describedSystemVersion) {
result.describedSystemVersion = appConfig.env.describedSystemVersion;
}
if (appConfig.env?.describedSystemInstance) {
result.describedSystemInstance = appConfig.env.describedSystemInstance;
}
if (appConfig.env?.describedSystemType) {
result.describedSystemType = appConfig.env.describedSystemType;
}
return result;
};

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] customize ORD Perspectives Support ORD 1.12 - static perspective

1 participant