cancel
Showing results for 
Search instead for 
Did you mean: 

Generate spec file from OpenAPI.class java instance

SOLVED
Highlighted
Occasional Visitor

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();
		spec.setOpenapi("3.0.1");
		spec.setPaths(...);
		spec.setComponents(...);
		
		// generate OpenAPI file in C:/spec.yml
	}
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: Generate spec file from OpenAPI.class java instance

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.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today

View solution in original post

1 REPLY 1
Highlighted
Moderator

Re: Generate spec file from OpenAPI.class java instance

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.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors