0

I'm looking for a solution of converting swagger.json (generated by swagger2) to openapi3 json file in my CI/CD process (Git Actions).

I'm doing my job with Java, and I found some ways like:

  1. Swagger inspector -> I guess it works in web env only.
  2. SwaggerHub gradle plugin
  3. Swagger codegen

but I have no experience of my task. which one is proper way to solve my problem? or is there any other way?

grateful for reading my question :)

tofan
  • 17
  • 3
  • Related: [How to convert OpenAPI 2.0 to OpenAPI 3.0?](https://stackoverflow.com/q/59749513/113116) – Helen Jul 06 '22 at 08:50

1 Answers1

0

Renew) I solved it completely, with using Swagger-parser

https://github.com/swagger-api/swagger-parser

example code is here:

@Test
public void parsingTest() throws Exception {
    String outputDir = System.getProperty(YOUR_PATH_HERE);
    SwaggerParseResult result = new OpenAPIParser().readLocation(YOUR_PATH_HERE, null, null);
    OpenAPI api = result.getOpenAPI();

    // POJO -> JSON
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.writeValue(new File(YOUR_PATH_HERE), api);
}

hope it makes helpful someone!

tofan
  • 17
  • 3
  • 1
    What about adding a link to `Swagger2markup` and some example code. This way others can benefit from you answer. – hc_dev Jul 06 '22 at 07:04
  • Hi. I read your advice and I'll update my answer. Thank you for your advice :) – tofan Jul 06 '22 at 23:15