question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for "examples" field in "requestBody" for Open API 3 Swagger spec in NSwag core.

See original GitHub issue

Hi there, We are trying to upload a Open API 3 swagger spec using NSwag core. We are getting this error “Value cannot be null. [key]”.

After debugging, the following line doc.ToJson() is where we are getting the error:

var doc = OpenApiYamlDocument.FromYamlAsync(sd.Json).Result;
sd.Json = doc.ToJson();

The error is as follows:

"Value cannot be null. (Parameter 'key')"

I am not sure if its Json serialisation issue.

{
  "openapi": "3.0.1",
  "paths": {
    "/listener": {
      "requestBody": {
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/listenerPrimary"
            },
            "examples": {
              "creation-of-primary-mobileAccess": {
                "$ref": "#/components/examples/serviceCreationNotification"
              }
            }
          }
        },
        "description": "Notification Resource Models",
        "required": true
      }
    }
  },
  "servers": {},
  "components": {
    "schemas": {},
    "examples": {
      "serviceCreationNotification": {
        "value": {
          "eventId": "6a51c8e5-2629-47ef-b562-288b5569ac56",
          "eventTime": "string",
          "eventType": "serviceCreationNotification",
        }
      }
    }
  }

Turns out if we remove “examples” field from the “requestBody” it works fine. Below works fine:

{
  "openapi": "3.0.1",
  "paths": {
    "/listener": {
      "requestBody": {
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/listenerPrimary"
            },
          }
        },
        "description": "Notification Resource Models",
        "required": true
      }
    }
  },
  "servers": {},
  "components": {
    "schemas": {},
    "examples": {
      "serviceCreationNotification": {
        "value": {
          "eventId": "6a51c8e5-2629-47ef-b562-288b5569ac56",
          "eventTime": "string",
          "eventType": "serviceCreationNotification",
        }
      }
    }
  }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
RicoSutercommented, Feb 19, 2021

Ok the JSON above was failing, now fixed.

0reactions
pranay-91commented, Feb 20, 2021

Thanks @RicoSuter for the patch. I can confirm the file upload are working perfectly with the latest version 3.10.4. The team appreciates your help 👍 👏

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenAPI Specification - Version 3.0.3
The OpenAPI Specification defines a standard interface to RESTful APIs which allows both humans and computers to understand service capabilities without ...
Read more >
Describing Request Body
Request bodies are typically used with “create” and “update” operations (POST, PUT, PATCH). For example, when creating a resource using POST or PUT,...
Read more >
Get started with NSwag and ASP.NET Core
Install NSwag to: Generate the Swagger specification for the implemented web API. Serve the Swagger UI to browse and test the web API....
Read more >
Using OpenAPI and Swagger UI
This guide explains how your Quarkus application can expose its API description through an OpenAPI specification and how you can test it via...
Read more >
OpenAPI Specification v3.1.0 | Introduction, Definitions, & ...
The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found