Repository navigation
Read the public API into a rich model and write it as a .api file - #94
Merged
Merged
Conversation
Nullean.PublicApi now reads what a C# declaration says: base types and interfaces, type parameters with variance and constraints, nullability, tuple element names, dynamic, ref kinds, params, scoped, default and constant values, required and init, and the attributes that are about the API. ApiWriter writes it as an indented tree of namespaces, types and members, one declaration per line, with a header that names the types from other assemblies so the declarations can use short names. The JustAssembly model the existing reports are built on moves into Nullean.PublicApi.Diff as an internal detail; neither library has been released, and the reports are unchanged. RoslynOracleTests checks every visible signature of CoreLib and five other framework assemblies against Roslyn's reading of the same metadata. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Mpdreamz
added a commit
that referenced
this pull request
Nov 14, 2026
Step 4 of the public API files: the CLI and the action, on top of the reader, parser and comparison from #94 to #96. ## `assembly-differ api` ```sh dotnet build -c Release && assembly-differ api -o api # api/MyLib.api for every library in the solution assembly-differ api --verify api # exit 5 when the build no longer matches them assembly-differ api MyLib.1.2.0.nupkg # print a package's API assembly-differ api bin/Release/net8.0 -t MyLib -f json # every part of each declaration as a field ``` - **Sources:** a `.dll`, a directory, a `.nupkg`, or nothing. With nothing, it reads the solution's libraries for every target framework, skipping test and unpackable projects the way `projects` does. It doesn't build. - **Frameworks:** an assembly gets one file when all its frameworks have the same API, and one per framework otherwise, such as `MyLib.net8.0.api`. - **Splitting:** `--split namespace` or `--split top-level-namespace` writes `MyLib/<namespace>.api`. Each file's header names the types it uses from the other files, so every file parses on its own. - **Writing:** `-o` removes `.api` files the API no longer has. It only touches files that start with `assembly `. - **Verifying:** `--verify` lists each change by path, `file:line`, who it breaks and how, and the bump, then prints the command that updates the files: ``` [api] Lib: 2 changes since the committed files, suggested version change: Major {fixture}/api/Lib.api:7 Lib › Widget › Name(int, bool) added public string Name(int index, bool upper) [minor] {fixture}/api/Lib.api:11 Lib › Widget › Name(int) removed public string Name(int index) [major: breaks callers, compiled code and source] [api] {fixture}/api does not match the build. Suggested version change: Major [api] Update the files with: assembly-differ api {fixture}/new -o {fixture}/api ``` ## `nullean/assembly-differ/verify-api@v1` A composite action that installs the tool and runs `api --verify`. Checkout and the build are the caller's own steps, as the README documents. - **Permissions:** it needs only `contents: read`. - **Comment:** with `comment: true` and `pull-requests: write`, it keeps one comment on the pull request through `gh api`, holding the report and the update command. When the files match again it updates that comment, and it never posts one for a pull request that always matched. - **Outputs:** `matches` and `suggested-change`. ## Library - `ApiWriter.Write(assembly, split)` returns the chunks. - `ApiParser.Parse(files)` reads them back into one API. - `ApiDocument.LocationOf(node)` gives each declaration's file and line. - `ApiChange.OldScope` locates an addition in the old file. ## Tests - **CLI** (`ApiFileTests`, `ProjectsTests`): print, JSON, write then verify, five kinds of change under `--verify`, a split write/verify/rewrite cycle, a missing directory, solution mode and the help text. - **Library:** CoreLib and System.Text.Json split both ways parse back to the same model, field by field. - **Mutation:** a `--verify` that never reports a match makes two tests fail. - **The action:** I ran its shell steps locally, with the built tool and a stub `gh`. The outputs, exit code 5 and the comment body came out right. It has **not** run on GitHub. It installs the released tool, which doesn't have `api` yet, so it can only work after the next release. ## Not in this PR `.api` files as a baseline for `files`, `release` and `pull-request`. Those commands report through the JustAssembly-compatible engine, which compares assemblies. Taking `.api` files means moving them to the new comparison, which is the deliberate switch we agreed on: behind a flag first, the default in 2.0. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The reader and writer behind the
.apifiles, step 1 of the plan agreed for public API files. It needs no CLI changes yet: theapicommand,--splitand--verifycome later, as does the comparison on this model.What
Nullean.PublicApireads nowApiReader.Readreturns what a C# declaration says:notnull,unmanagedandallows ref struct;dynamic;ref,out,in,ref readonly,paramsandscoped;requiredandinit;It also records whether code outside the assembly can derive from or implement a type, which the semver classification will use.
ApiWriter.Writewrites the tree, one declaration per line:The header names the types from other assemblies, namespace by namespace, so the lines can use short names. A name two namespaces share is written in full.
The JustAssembly model
The model the existing reports are built on moves into
Nullean.PublicApi.Diffas an internal detail, with only its visibility and namespace changed. Neither library has been released, so nothing breaks, and the tool's reports are unchanged: all 617 tests pass.Tests
WriterTestssnapshots the.apitext of C# samples covering types, signatures and name clashes.RoslynOracleTestscompares every visible signature, base list and member of six assemblies (CoreLib, System.Collections.Immutable, System.Text.Json, System.Linq, System.Net.Http, System.Memory) and the samples against Roslyn's reading of the same metadata. It covers types and their nullability, tuple names, ref kinds, modifiers, accessibility, constraints,params, optional andscoped. It found these bugs, all fixed:modreq(In)wrapsref readonlyproperty returns;ValueTuple\8` is only a tuple when its eighth argument is one;uintDecimalConstantoverflowed;notnullnext toallows ref structwas missed.ref readonly, virtual detection and protected visibility.🤖 Generated with Claude Code