简体   繁体   中英

How can I create multiple versions of the same request with OpenAPI 3.0?

I use maven Swagger Codegen V3 plugin to generate API from a yaml file. I want to generate different versions of a rest request which has the same path but different body types.

I use this YAML code to generate it.

content:
    application/json;version=1.0.0:
      schema:
        $ref: '#/components/schemas/Object1'
    application/json;version=2.0.0:
      schema:
        $ref: '#/components/schemas/Object2'

And I get the following result:

@Consumes({ "application/json;version=1.0.0", "application/json;version=2.0.0" })
...
public void method(Object1 body);

@Consumes({ "application/json;version=1.0.0", "application/json;version=2.0.0" })
...
public void method(Object2 body);

But the result I need is like below.

@Consumes({ "application/json;version=1.0.0" })
...
public void method(Object1 body);

@Consumes({ "application/json;version=2.0.0" })
...
public void method(Object2 body);

I use the consumes parameter for the versioning. So is there a way to get the result I want?

It's a limitation Swagger Codegen v3 does not support multiple payload at the moment. The Petstore OpenAPI document has endpoints that can send either JSON or XML payload but the output (auto-generated code) only supports JSON at the moment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM