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
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 Technical Writer
________________________
Vote up helpful replies.
Accept this reply if you think it's the best solution to your question.

View solution in original post

1 REPLY 1
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 Technical Writer
________________________
Vote up helpful replies.
Accept this reply if you think it's the best solution to your question.

View solution in original post

New Here?
Join us and watch the welcome video:
Watch the new Interview