Skip to content

OpenApiError.Pointer skips a level if extension parser throws OpenApiException #501

Closed

Description

To reproduce

Microsoft.OpenApi.Readers 1.2.2

OpenAPI 2.0 document:

{
  "swagger": "2.0",
  "info": {
    "title": "Demo",
    "version": "1"
  },
  "paths": {},
  "definitions": {
    "demo": {
      "x-tag": null
    }
  }
}

Read with an extension parser that throws OpenApiException:

var settings = new OpenApiReaderSettings()
{
    ExtensionParsers =
    {
        { "x-tag", (any, version) => throw new OpenApiException("Testing") },
    },
};
var apiReader = new OpenApiStreamReader(settings);
OpenApiDocument document = apiReader.Read(stream, out OpenApiDiagnostic diagnostic);
Console.Error.WriteLine(diagnostic.Errors[0]);

Expected result

Testing [#/definitions/demo/x-tag]

Actual result

Testing [#/definitions/x-tag]

Activity

  1. KalleOlaviNiemitalo commented on Jul 16, 2020

    @KalleOlaviNiemitalo
    Author

    The extension parser itself cannot set OpenApiException.Pointer because it does not have enough information.

  2. KalleOlaviNiemitalo commented on Jul 16, 2020

    @KalleOlaviNiemitalo
    Author

    I'd really prefer having a line number in the diagnostic but I'm not sure whether that could be implemented cleanly.

  3. added this to the 1.3 milestone on Sep 28, 2020
  4. modified the milestones: 1.3, on May 15, 2021
  5. modified the milestones: , 2.0 on Feb 10, 2022
  6. added
    priority:p2Medium. Generally has a work-around and a smaller sub-set of customers is affected. SLA <=30 days
    on Dec 22, 2025
  7. baywet commented on Dec 22, 2025

    @baywet
    Member

    Hi Kalle Olavi Niemitalo (@KalleOlaviNiemitalo)
    Thank you for using the SDK and for reaching out.
    Thank you for your patience.

    This is implemented here (3 other instances)

    if (node.Context.ExtensionParsers is not null && node.Context.ExtensionParsers.TryGetValue(name, out var parser))

    And that's happening because the call to the parser should be surrounded by a try catch, and when an exception is thrown, it should be captured, the pointer amended, and logged as an error in the context with the right pointer.

    Additional tests should be added in this file.

    I'll assign copilot to get a fix for this in v2 and v3, but we won't be addressing this in v1.

    Let us know if you have any additional comments or questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

WIPhelp wantedpriority:p2Medium. Generally has a work-around and a smaller sub-set of customers is affected. SLA <=30 daystype:bugA broken experience

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions