Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 28, 2025

  • Understand the issue: NullPointerException in MarkdownRender when schema is null (similar to issue BUG: An unhandled exception after printing the result #865 which was fixed for HtmlRender)
  • Identify the root cause: itemContent method in MarkdownRender.java at line 276-278 passes potentially null schema to schema() method which doesn't handle null
  • Add null check in MarkdownRender.itemContent() method to handle null schema
  • Identify and fix the same issue in AsciidocRender and ConsoleRender
  • 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 --markdown output option fails with a NullPointerException when generating markdown reports, while the console output and --json output work correctly.

Steps to Reproduce

  1. 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
  1. 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.java at line 289, where it attempts to call isDiscriminatorPropertyChanged() on a null ChangedSchema object. 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 ChangedSchema object is null for certain content types
  • The markdown renderer tries to check all schema properties without null-checking

Workarounds

  1. Use JSON output instead:
docker run --rm -v $(pwd):/specs openapitools/openapi-diff:latest \
  /specs/swagger.json /specs/main.json --json /specs/report.json
  1. Use console output and parse manually:
docker run --rm -v $(pwd):/specs openapitools/openapi-diff:latest \
  /specs/swagger.json /specs/main.json --info > output.txt

Impact

  • Severity: Medium
  • Affected Feature: Markdown output generation (--markdown flag)
  • 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 #865</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@DrSatyr Looks similar to https://github.com//issues/865

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…leRender when schema is null

Co-authored-by: DrSatyr <8143518+DrSatyr@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix NullPointerException in markdown renderer Fix NullPointerException in MarkdownRender when schema is null Nov 28, 2025
Copilot AI requested a review from DrSatyr November 28, 2025 10:43
Copilot finished work on behalf of DrSatyr November 28, 2025 10:43
@DrSatyr
Copy link
Collaborator

DrSatyr commented Nov 28, 2025

@copilot let's use issue ID in test method names

Co-authored-by: DrSatyr <8143518+DrSatyr@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 28, 2025

@copilot let's use issue ID in test method names

Done in 4ca83f7. Renamed test methods to use issue870_ prefix following the existing pattern from HtmlRenderTest.

Copilot finished work on behalf of DrSatyr November 28, 2025 10:49
Copilot AI requested a review from DrSatyr November 28, 2025 11:06
Copilot finished work on behalf of DrSatyr November 28, 2025 11:06
Copilot finished work on behalf of DrSatyr November 28, 2025 11:33
@DrSatyr DrSatyr marked this pull request as ready for review November 28, 2025 12:02
@DrSatyr DrSatyr merged commit 82cca56 into master Nov 28, 2025
8 of 13 checks passed
@DrSatyr DrSatyr deleted the copilot/fix-nullpointer-markdown-renderer branch November 28, 2025 12:02
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.

NullPointerException in Markdown Renderer

2 participants