RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.77k stars 1.29k forks source link

MediaType not generated in CSharp-codegeneration when used as $ref #3376

Open Debbus72 opened 3 years ago

Debbus72 commented 3 years ago

We are generating CSharp-clients based on our swagger-files. We found that if we inline the definition on a "custom" media-type like this:

paths:
  /orders/{id}
    patch:
      operationId: OrderByIdPatch
      requestBody:
        content:
          application/merge-patch+json:
            schema:
              type: object

we got a valid code-generation in the CSharp-generator with the correct media-type/content-type. But when we substitute the object with a $ref like this:

paths:
  /orders/{id}
    patch:
      operationId: OrderByIdPatch
      requestBody:
        $ref: '#/components/requestBodies/Order'
components:
  requestBodies:
    Order:
      content:
        application/merge-patch+json:
          schema:
            type: object

the client was generated with the standard application/json.

content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");

Is the second example not correct?

RicoSuter commented 3 years ago

There is no "requestBodies" property in the components class: https://github.com/RicoSuter/NSwag/blob/master/src/NSwag.Core/OpenApiComponents.cs

So it's surely not deserialized correctly and also not resolved... should this work according to the OAI spec?