Forum Discussion

fabianobonin's avatar
fabianobonin
Occasional Visitor
6 years ago

Generate spec file from OpenAPI.class java instance

Hi, I need to generate a spec file from a OpenAPI instance that was created programmatically in Java. Is it possible?   public static void main(String[] args) { OpenAPI spec = new OpenAPI();...
  • HKosova's avatar
    6 years ago

    Hi fabianobonin,

     

    You can convert an OpenAPI instance to YAML text as follows:

    import io.swagger.v3.core.util.Yaml;
    
    String specAsYaml = Yaml.pretty().writeValueAsString(spec);

    and then save the resulting string to a file.