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.

oneOf support in request body schema for NSwag.Generation.AspNetCore

See original GitHub issue

According to the checked list item in #945, oneOf should be supported. Specifically what we need is oneOf support for requestBody schemas, as shown in the first example here:

paths:
  /pets:
    patch:
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Dog'

We’re having difficulties implementing it, though, as we find no way to decorate our ASP.NET Core code to generate an OpenAPI document with requestBody.content.application/json.schema.oneOf defined.

Instead, NSwag attempts to generate an OpenAPI document with duplicate path definitions, causing the following code to be invoked and exception to be thrown:

https://github.com/RicoSuter/NSwag/blob/085e8aeb95e4f1723f956fa6137bbc07bd5527a6/src/NSwag.Generation.AspNetCore/AspNetCoreOpenApiDocumentGenerator.cs#L260-L263

Ideas and pointers in the right direction would be highly appreciated.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
asbjornucommented, Mar 3, 2020

@NullableInt, as pointed out by @RicoSuter on Twitter let’s discuss whether we can use inheritance to make this work somehow.

1reaction
asbjornucommented, Jan 27, 2020

@RicoSuter, if we were to fork and implement this ourselves, would you accept a pull request? Also, could you please point us in the right direction on where and how you’d like to see this implemented in the existing source code?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to support OneOf(OpenApi) in asp.net core WebApi
Is there any way I can support oneOf in asp.net core webapi. Can I support two different schemas in the request body? enter...
Read more >
bitbear@icosahedron.website
's NSwag seems to be the best option so far. However, we're currently stuck by the lack of support for `oneOf` in request...
Read more >
Get started with NSwag and ASP.NET Core
Learn how to use NSwag to generate documentation and help pages for an ASP.NET Core web API.
Read more >
oneOf, anyOf, allOf, not
oneOf. Use the oneOf keyword to ensure the given data is valid against one of the specified schemas. paths: /pets: patch: requestBody: content: ......
Read more >
Swashbuckle.AspNetCore
Swagger tooling for APIs built with ASP.NET Core. Generate beautiful API documentation, including a UI to explore and test operations, directly from your ......
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