Skip to content

Throw exception when document's spec version is not recognized by Reader #177

Closed

Description

@scott-lin

The Reader code makes a "best effort" to deserialize the document as the latest spec version, V3 as of writing this issue, when the version number is not recognized. Instead, I would like the Reader to thrown an unsupported spec version exception.

Context of code
----------------
Class: https://github.com/Microsoft/OpenAPI.NET/blob/master/src/Microsoft.OpenApi.Readers/ParsingContext.cs
Method: Parse()

// If version number is not recognizable,
// our best effort will try to deserialize the document to V3.
this.VersionService = new OpenApiV3VersionService();
doc = this.VersionService.LoadDocument(this.RootNode);
diagnostic.SpecificationVersion = OpenApiSpecVersion.OpenApi3_0;

As a consumer of the Reader, I do not trust the Reader to parse a document it does not offer support for yet. For example, in the future, I could be passing a document of version 4, and this document may or may not be read correctly. Instead of potentially passing silently with issues, I'd rather know the library isn't updated to support V4 yet.

If this "best effort" default read case is in the library for a particular reason, perhaps there should be a "force" option that callers can specify to read unrecognized documents.

Activity

  1. PerthCharern commented on Jan 13, 2018

    @PerthCharern
    Contributor
  2. scott-lin commented on Jan 13, 2018

    @scott-lin
    ContributorAuthor

    Yeah, I'm happy to (not sure how issues get triaged and approved in this work stream yet. I'll sync with you on Tuesday regarding that).

  3. scott-lin commented on Jan 13, 2018

    @scott-lin
    ContributorAuthor

    Also, if this default "best effort" case is not implemented for a particular reason, I plan on removing it and throwing an exception with no "option to force" the current behavior. If you feel otherwise, please let me know and why.

  4. darrelmiller commented on Jan 13, 2018

    @darrelmiller
    Member

    My initial reaction was that we should do best effort on 3.x but fail on 4.x but after thinking some more, I agree that we should just fail on a version that is higher than 3.0.x. I don't think we can fail on a higher patch version.

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions