microsoft / OpenAPI.NET

The OpenAPI.NET SDK contains a useful object model for OpenAPI documents in .NET along with common serializers to extract raw OpenAPI JSON and YAML documents from the model.
MIT License
1.4k stars 231 forks source link

Missing body parameters in OpenAPI v2 document #467

Open korygin opened 4 years ago

korygin commented 4 years ago

Hi,

We experience the issue with generating OpenAPI v2 (Swagger) documents which have multiple entries (media types) in the request body's content dictionary. In such cases, produced documents do not have body parameters. If content dictionaries have a single entry then body parameters appear in the generated documents as expected. Is this behavior by design?

Thanks,

Alex

darrelmiller commented 4 years ago

Hi @korygin Would you be able to provide an example of either the document you are trying to generate or what you are trying to parse. An OpenAPI V2 document can only have a single body parameter. There can be multiple "produces" or "consumes" values, but there can only be one schema. in a V3 document each media type object can have its own schema.

korygin commented 4 years ago

Hi Darrel,

If one of request body's media types is "application/x-www-form-urlencoded" and is assigned the schema object that has a definition reference (not properties), Open API writer fails to write the body parameter when SerializeAsV2() method is called.

SerializeAsV3() correctly outputs the body parameter with "application/x-www-form-urlencoded" content type and corresponding schema reference.

Hope this helps.

Alex

darrelmiller commented 4 years ago

@korygin It would really help if you could provide at least a partial OpenAPI description of what you are trying to parse and render. Thanks.

korygin commented 4 years ago

Hi Darrel,

There is nothing to parse, I’m assembling a brand new OpenAPI document object using your library from some other metadata. So this would have to be reproduced with code / unit test.

Create a simple OpenAPI document object with:

  1. One reusable schema object in components.
  2. One operation that requires a request body, i.e. Post/Put/Patch.
  3. Populate the request‘s body content map with application/x-www-form-urlencoded entry and media type object whose schema references reusable schema created in step 1.

Now try to output / write the created document as v2 (Swagger) json or yaml. You will see that the output document is missing the request body all together.

Hope this helps.

Regards,

Alex

On Apr 26, 2020, at 12:59, Darrel notifications@github.com wrote:



@koryginhttps://github.com/korygin It would really help if you could provide at least a partial OpenAPI description of what you are trying to parse and render. Thanks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/microsoft/OpenAPI.NET/issues/467#issuecomment-619585357, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADLM2QSCS5OKKPC6GWDM6W3RORR73ANCNFSM4LGSAX3A.