Skip to content

Conversation

@Swolebrain
Copy link
Contributor

Description of changes

Refactored the ffi functionality a little bit to move some of it to cedar-policy so it can be reused by both the ffi module and the cli. Added cli functionality to convert cedar schemas to json with resolved types.

Issue #, if available

n/a

Checklist for requesting a review

The change in this PR is (choose one, and delete the other options):

  • A breaking change requiring a major version bump to cedar-policy (e.g., changes to the signature of an existing API).
  • A backwards-compatible change requiring a minor version bump to cedar-policy (e.g., addition of a new API).
  • A bug fix or other functionality change requiring a patch to cedar-policy.
  • A change "invisible" to users (e.g., documentation, changes to "internal" crates like cedar-policy-core, cedar-validator, etc.)
  • A change (breaking or otherwise) that only impacts unreleased or experimental code.

I confirm that this PR (choose one, and delete the other options):

  • Updates the "Unreleased" section of the CHANGELOG with a description of my change (required for major/minor version bumps).
  • Does not update the CHANGELOG because my change does not significantly impact released code.

I confirm that cedar-spec (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar formal model or DRT infrastructure.
  • Requires updates, and I have made / will make these updates myself. (Please include in your description a timeline or link to the relevant PR in cedar-spec, and how you have tested that your updates are correct.)
  • Requires updates, but I do not plan to make them in the near future. (Make sure that your changes are hidden behind a feature flag to mark them as experimental.)
  • I'm not sure how my change impacts cedar-spec. (Post your PR anyways, and we'll discuss in the comments.)

I confirm that docs.cedarpolicy.com (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar language specification.
  • Requires updates, and I have made / will make these updates myself. (Please include in your description a timeline or link to the relevant PR in cedar-docs. PRs should be targeted at a staging-X.Y branch, not main.)
  • I'm not sure how my change impacts the documentation. (Post your PR anyways, and we'll discuss in the comments.)

@Swolebrain Swolebrain force-pushed the json-schema-with-resolved-types-cli branch from a7ae8d9 to fa9b56b Compare January 8, 2026 22:53
@Swolebrain Swolebrain force-pushed the json-schema-with-resolved-types-cli branch from fa9b56b to e2d596b Compare January 8, 2026 22:54
@github-actions
Copy link

github-actions bot commented Jan 8, 2026

Coverage Report

Head Commit: e2d596b974846e90eeaba01209d2f86868741901

Base Commit: 2d6b09538777f874cc3c8d8eb1c1ad622afe37bc

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 86.76%

Status: PASSED ✅

Details
File Status Covered Coverage Missed Lines
cedar-policy-cli/src/lib.rs 🟢 25/25 100.00%
cedar-policy-core/src/validator/json_schema.rs 🟢 3/3 100.00%
cedar-policy/src/api.rs 🟢 24/24 100.00%
cedar-policy/src/ffi/convert.rs 🔴 7/16 43.75% 199-204, 207, 209-210

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 86.18%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-language-server 🟢 4724/5106 92.52% --
cedar-policy 🟡 3784/5161 73.32% --
cedar-policy-cli 🔴 798/1218 65.52% --
cedar-policy-core 🟢 22002/25294 86.99% --
cedar-policy-formatter 🟢 906/1080 83.89% --
cedar-policy-symcc 🟢 6341/6853 92.53% --
cedar-wasm 🔴 0/28 0.00% --

Comment on lines 2149 to 2157
pub fn schema_str_to_resolved_fragment(
schema_str: &str,
) -> Result<
(
json_schema::Fragment<cedar_policy_core::ast::InternalName>,
Vec<miette::Report>,
),
Vec<miette::Report>,
> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of returning warnings and errors as miette::Report, in this cedar-policy function can we return them as SchemaError and SchemaWarning, which are already public types? (Or whatever other specific error types are appropriate here.) This will also allow us to get rid of the code in CLI that detects parse errors just by looking for specific strings like "parse" in the error message. And the code for converting into miette::Reports can live in the ffi module

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wrap SchemaError and SchemaWarning in an enum for the Err type?

Copy link
Contributor

Choose a reason for hiding this comment

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

isn't it only SchemaError in the Err case? the warnings being in the Ok pair?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah my bad, there's two errors in the Err case though, which was why I didn't do it this way. There's CedarSchemaParseErrors from converting the&str to Fragment<RawName> and SchemaError from converting from raw to internal. Should I wrap those two in an enum for this function? Didn't love the idea of creating a new public enum just for this

Copy link
Contributor

Choose a reason for hiding this comment

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

CedarSchemaError is an existing public enum covering this

Copy link
Contributor

Choose a reason for hiding this comment

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

(I think)

schema_str: &str,
) -> Result<
(
json_schema::Fragment<cedar_policy_core::ast::InternalName>,
Copy link
Contributor Author

@Swolebrain Swolebrain Jan 9, 2026

Choose a reason for hiding this comment

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

is it ok that this function in cedar_policy::api is leaking cedar_policy_core::ast::InternalName? Should i make it return something else, like maybe serde_json::Value?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's also leaking json_schema::Fragment, if I'm not mistaken.

serde_json::Value sounds good to me -- I think both the CLI and FFI don't need anything more detailed than that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah it's definitely leaking that too

@github-actions
Copy link

github-actions bot commented Jan 9, 2026

Coverage Report

Head Commit: 0dad8737f137e6e20d2682fbe7727021d8366a1e

Base Commit: 2d6b09538777f874cc3c8d8eb1c1ad622afe37bc

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 81.25%

Status: PASSED ✅

Details
File Status Covered Coverage Missed Lines
cedar-policy-cli/src/lib.rs 🟢 13/13 100.00%
cedar-policy-core/src/validator/json_schema.rs 🟢 3/3 100.00%
cedar-policy/src/api.rs 🟡 19/24 79.17% 2175-2179
cedar-policy/src/ffi/convert.rs 🔴 4/8 50.00% 196, 198-200

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 86.17%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-language-server 🟢 4724/5106 92.52% 92.52%
cedar-policy 🟡 3777/5153 73.30% 73.16%
cedar-policy-cli 🔴 786/1206 65.17% 64.29%
cedar-policy-core 🟢 22002/25294 86.99% 86.96%
cedar-policy-formatter 🟢 906/1080 83.89% 83.89%
cedar-policy-symcc 🟢 6341/6853 92.53% 92.53%
cedar-wasm 🔴 0/28 0.00% 0.00%

Copy link
Contributor

@john-h-kastner-aws john-h-kastner-aws left a comment

Choose a reason for hiding this comment

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

looks good. just two comment tweaks

JsonToCedar,
/// Cedar schema syntax -> JSON
CedarToJson,
/// Cedar schema syntax -> JSON with all types resolved to entity or common
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Cedar schema syntax -> JSON with all types resolved to entity or common
/// Cedar schema syntax -> JSON with all types resolved to entity or common
///
/// In contrast to `cedar-to-json`, this option requires that every type
/// referenced in the schema is also defined.

/// This is primarily meant to be used when working with schemas programmatically,
/// for example when creating a schema building UI.
///
/// Returns `Ok((json_value`, warnings)) on success, or Err(error) on failure.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Returns `Ok((json_value`, warnings)) on success, or Err(error) on failure.
/// Returns `Ok((json_value, warnings))` on success, or `Err(error)` on failure.

@github-actions
Copy link

Coverage Report

Head Commit: 27c7eae32fb03b3501bc0b06408226ff74e06fa5

Base Commit: 2d6b09538777f874cc3c8d8eb1c1ad622afe37bc

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 81.25%

Status: PASSED ✅

Details
File Status Covered Coverage Missed Lines
cedar-policy-cli/src/lib.rs 🟢 13/13 100.00%
cedar-policy-core/src/validator/json_schema.rs 🟢 3/3 100.00%
cedar-policy/src/api.rs 🟡 19/24 79.17% 2175-2179
cedar-policy/src/ffi/convert.rs 🔴 4/8 50.00% 196, 198-200

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 86.17%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-language-server 🟢 4724/5106 92.52% 92.52%
cedar-policy 🟡 3777/5153 73.30% 73.16%
cedar-policy-cli 🔴 786/1206 65.17% 64.29%
cedar-policy-core 🟢 22002/25294 86.99% 86.96%
cedar-policy-formatter 🟢 906/1080 83.89% 83.89%
cedar-policy-symcc 🟢 6341/6853 92.53% 92.53%
cedar-wasm 🔴 0/28 0.00% 0.00%

@Swolebrain Swolebrain merged commit 28614e1 into cedar-policy:main Jan 12, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants