Skip to content

feat(java): support transforming modular models#615

Draft
SoulPancake wants to merge 1 commit into
mainfrom
feat/java-module-transform
Draft

feat(java): support transforming modular models#615
SoulPancake wants to merge 1 commit into
mainfrom
feat/java-module-transform

Conversation

@SoulPancake

Copy link
Copy Markdown
Member

Adds modular-model support to the Java package, matching the Go implementation:

  • ModulesToModelTransformer merges a set of module files into a single AuthorizationModel, tagging type/relation/condition metadata with module and source-info, handling extend type, and reporting transformation and syntax errors (duplicate type/condition, extending a missing type, redefining a relation, non-module files).
  • The DSL listener now records the module name and stamps module metadata on types, conditions, and extension relations; the modular parse result exposes type-definition extensions.
  • JsonToDslTransformer gains an includeSourceInformation option that emits # module: x, file: y comments (and # extended by: for extension relations) with module-ordered output, plus getModulesFromJSON returning the sorted module list.
  • ModelUtils.isModelModular mirrors the JS helper.

Test runners drive the shared tests/data/transformer-module fixtures. As in the Go runner, model-validation errors are filtered out and validation-only cases are skipped, since the transformer surfaces transformation/syntax errors only.

Also documents the modules-to-model transform in the Java README and applies Spotless formatting.

Description

What problem is being solved?

How is it being solved?

What changes are made to solve it?

References

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Adds modular-model support to the Java package, matching the Go
implementation:

- ModulesToModelTransformer merges a set of module files into a single
  AuthorizationModel, tagging type/relation/condition metadata with
  module and source-info, handling `extend type`, and reporting
  transformation and syntax errors (duplicate type/condition, extending
  a missing type, redefining a relation, non-module files).
- The DSL listener now records the module name and stamps module
  metadata on types, conditions, and extension relations; the modular
  parse result exposes type-definition extensions.
- JsonToDslTransformer gains an includeSourceInformation option that
  emits `# module: x, file: y` comments (and `# extended by:` for
  extension relations) with module-ordered output, plus
  getModulesFromJSON returning the sorted module list.
- ModelUtils.isModelModular mirrors the JS helper.

Test runners drive the shared tests/data/transformer-module fixtures.
As in the Go runner, model-validation errors are filtered out and
validation-only cases are skipped, since the transformer surfaces
transformation/syntax errors only.

Also documents the modules-to-model transform in the Java README and
applies Spotless formatting.
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7903e24f-94e0-4dda-9f9f-b7c41701526f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/java-module-transform

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@SoulPancake SoulPancake linked an issue Jun 22, 2026 that may be closed by this pull request
@SoulPancake SoulPancake requested a review from Copilot June 23, 2026 05:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds modular-model support to the Java package of OpenFGA Language, aligning Java’s DSL↔JSON tooling and tests with the existing modular DSL behavior and shared fixtures.

Changes:

  • Introduces ModulesToModelTransformer plus supporting ModuleFile / ModuleDsl to merge multiple module DSL files into a single AuthorizationModel with source-info.
  • Extends parsing + transformation to carry module metadata (types/conditions/extension relations) and to optionally emit module/file source comments when rendering DSL from JSON.
  • Adds Java test harness for tests/data/transformer-module fixtures and updates documentation.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/java/src/test/java/dev/openfga/language/utils/ModelUtilsTest.java Adds unit tests for ModelUtils.isModelModular.
pkg/java/src/test/java/dev/openfga/language/util/TestsData.java Loads shared transformer-module fixtures and module files for parameterized tests.
pkg/java/src/test/java/dev/openfga/language/util/ModuleTransformerTestCase.java Test case holder for module transformer fixtures.
pkg/java/src/test/java/dev/openfga/language/util/ModuleExpectedError.java Fixture error DTO + filtering helper for validation-only errors.
pkg/java/src/test/java/dev/openfga/language/ModuleToModelShould.java Runs module→model transform tests over shared fixtures.
pkg/java/src/test/java/dev/openfga/language/JsonToDslShould.java Adds modular JSON→DSL + module extraction tests over shared fixtures.
pkg/java/src/main/java/dev/openfga/language/utils/ModelUtils.java Adds isModelModular helper for detecting modular models.
pkg/java/src/main/java/dev/openfga/language/OpenFgaDslListener.java Captures module name and stamps module metadata; exposes type extensions.
pkg/java/src/main/java/dev/openfga/language/ModulesToModelTransformer.java New transformer to merge module files and report transformation/syntax errors.
pkg/java/src/main/java/dev/openfga/language/ModuleFile.java New module-file value object (name + DSL contents).
pkg/java/src/main/java/dev/openfga/language/ModuleDsl.java New helper for resolving line/column for module error reporting.
pkg/java/src/main/java/dev/openfga/language/JsonToDslTransformer.java Adds includeSourceInformation, modular ordering, and module list extraction.
pkg/java/src/main/java/dev/openfga/language/errors/UnsupportedModularModulesException.java New exception for module operations on unsupported schema versions.
pkg/java/src/main/java/dev/openfga/language/errors/ParsingError.java Adds optional file field for error serialization/deserialization.
pkg/java/src/main/java/dev/openfga/language/errors/ModuleTransformationSingleError.java New per-error wrapper for module transformation errors.
pkg/java/src/main/java/dev/openfga/language/errors/ModuleTransformationError.java New aggregate exception for module transformation errors.
pkg/java/src/main/java/dev/openfga/language/DslToJsonTransformer.java Exposes modular parse result (extensions) and reuses a shared walk helper.
pkg/java/README.md Documents Java “Modules To Model” transformation usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +67 to +68
var extensions = result.getTypeDefExtensions();
for (var typeDef : result.getAuthorizationModel().getTypeDefinitions()) {
Comment on lines +433 to +438
private static boolean isModularModel(AuthorizationModel model) {
if (model == null || model.getTypeDefinitions() == null) {
return false;
}
return model.getTypeDefinitions().stream().anyMatch(typeDef -> !isBlank(module(typeDef.getMetadata())));
}
Comment on lines +85 to 89
for (var relationName : relationNames) {
var formattedRelationString = formatRelation(
typeName, relationName, relations.get(relationName), metadataRelations.get(relationName));
formatedTypeBuilder.append(EOL).append(formattedRelationString);
}
Comment on lines +85 to +99
public static boolean isModelModular(AuthorizationModel model) {
var schemaVersion = model != null && model.getSchemaVersion() != null ? model.getSchemaVersion() : "1.1";
switch (schemaVersion) {
case "1.0":
case "1.1":
return false;
case "1.2":
break;
default:
throw new IllegalArgumentException("Unsupported schema version: " + schemaVersion);
}

if (model.getTypeDefinitions() == null) {
return false;
}
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.

Better support for modules in java

2 participants