microsoft / OpenAPI.NET

The OpenAPI.NET SDK contains a useful object model for OpenAPI documents in .NET along with common serializers to extract raw OpenAPI JSON and YAML documents from the model.
MIT License
1.38k stars 231 forks source link

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

Open KalleOlaviNiemitalo opened 4 years ago

KalleOlaviNiemitalo commented 4 years ago

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]

KalleOlaviNiemitalo commented 4 years ago

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

KalleOlaviNiemitalo commented 4 years ago

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