Skip to content

v2: Unexpected error when loading sample OpenAPI document #2055

Closed
@captainsafia

Description

@captainsafia

I am running into unexpected errors when loading an OpenAPI document from tests via the OpenApiDocument.Load APIs in 2.0.0-preview4.

Repro code:

using Microsoft.OpenApi;
using Microsoft.OpenApi.Models;
using System.IO;
using System.Text;

var contents = """
{
  "openapi": "3.1.1",
  "info": {
    "title": "GetDocumentSample | v1",
    "version": "1.0.0"
  },
  "paths": {
    "/hello/{name}": {
      "get": {
        "tags": [
          {
            "name": "GetDocumentSample"
          }
        ],
        "parameters": [
          {
            "name": "name",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "GetDocumentSample"
    }
  ]
}
""";

var (Document, Diagnostic) = OpenApiDocument.Load(new MemoryStream(Encoding.UTF8.GetBytes(contents)), "json");
foreach (var error in Diagnostic.Errors)
{
	System.Console.WriteLine(error);
}

Produces the following error:

Expected a value.

There is no node associated with the error so it's not possible to determine what aspect of the document are incorrect. This document was serialized using the same version of the Microsoft.OpenApi package.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions