Fix NullPointerException in MarkdownRender when schema is null
- Understand the issue: NullPointerException in MarkdownRender when schema is null (similar to issue #865 which was fixed for HtmlRender)
- Identify the root cause:
itemContentmethod in MarkdownRender.java at line 276-278 passes potentially null schema toschema()method which doesn't handle null - Add null check in
MarkdownRender.itemContent()method to handle null schema - Identify and fix the same issue in
AsciidocRenderandConsoleRender - Add test cases for null schema scenario in MarkdownRenderTest, AsciidocRenderTest, and ConsoleRenderTest
- Use issue ID prefix in test method names (e.g.,
issue870_renderDoesNotFailWhenSchemaIsNullButExampleChanged) - Run tests to verify the fixes work correctly
- Run code review - only nitpick found (StringBuilder vs string concatenation), kept current implementation for consistency with codebase
- Run security scan - no vulnerabilities found
Original prompt
This section details on the original issue you should resolve
<issue_title>NullPointerException in Markdown Renderer</issue_title>
<issue_description>Description
The
--markdownoutput option fails with aNullPointerExceptionwhen generating markdown reports, while the console output and--jsonoutput work correctly.Steps to Reproduce
- Run openapi-diff with markdown output:
docker run --rm -v $(pwd):/specs openapitools/openapi-diff:latest \ /specs/swagger.json /specs/main.json --markdown /specs/report.md
- The command fails with the error below, despite the console output showing the comparison completed successfully.
Expected Behavior
The markdown file should be generated successfully, similar to how the console output and JSON output work.
Actual Behavior
The command throws a
NullPointerException:java.lang.NullPointerException: Cannot invoke "org.openapitools.openapidiff.core.model.ChangedSchema.isDiscriminatorPropertyChanged()" because "schema" is null at org.openapitools.openapidiff.core.output.MarkdownRender.schema(MarkdownRender.java:289) at org.openapitools.openapidiff.core.output.MarkdownRender.itemContent(MarkdownRender.java:248) at org.openapitools.openapidiff.core.output.MarkdownRender.lambda$bodyContent$7(MarkdownRender.java:222)Environment
- Docker Image:
openapitools/openapi-diff:latest- OpenAPI Version: 3.0.1
- Date Tested: November 27, 2025
Console Output (Successful)
When running without
--markdown, the tool works correctly:========================================================================== == API CHANGE LOG == ========================================================================== Targeting.DayPartingApi -------------------------------------------------------------------------- -- What's Changed -- -------------------------------------------------------------------------- - PUT /targeting Request: - Changed application/json Schema: Backward compatible - Changed text/json Schema: Backward compatible - Changed application/*+json Schema: Backward compatible -------------------------------------------------------------------------- -- Result -- -------------------------------------------------------------------------- API changes are backward compatible --------------------------------------------------------------------------Root Cause Analysis
The error occurs in
MarkdownRender.javaat line 289, where it attempts to callisDiscriminatorPropertyChanged()on a nullChangedSchemaobject. The markdown renderer appears to be less tolerant of null schemas compared to the console renderer.The issue specifically arises when:
- The API has schema changes in request/response bodies
- The
ChangedSchemaobject is null for certain content types- The markdown renderer tries to check all schema properties without null-checking
Workarounds
- Use JSON output instead:
docker run --rm -v $(pwd):/specs openapitools/openapi-diff:latest \ /specs/swagger.json /specs/main.json --json /specs/report.json
- Use console output and parse manually:
docker run --rm -v $(pwd):/specs openapitools/openapi-diff:latest \ /specs/swagger.json /specs/main.json --info > output.txtImpact
- Severity: Medium
- Affected Feature: Markdown output generation (
--markdownflag)- Impact: Users cannot generate markdown reports but can use JSON or console output as alternatives
Additional Context
This issue was discovered when comparing two OpenAPI 3.0.1 specifications where the request body examples changed but the schemas remained the same. The tool correctly identifies the changes as backward compatible but fails during markdown generation.
</issue_description><agent_instructions>Looks like the same problem https://github.com/OpenAPITools/openapi-diff/issues/865</agent_instructions>
Comments on the Issue (you are @copilot in this section)
@DrSatyr Looks similar to https://github.com/OpenAPITools/openapi-diff/issues/865
š¬ We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.