@@ -89,10 +89,21 @@ public static List<Format> parse(String value) {
8989 private String excludes ;
9090
9191 public void export (OpenAPI openAPI , Format format ) throws IOException {
92- if (!Files .exists (outputDir )) {
93- Files .createDirectories (outputDir );
92+ Path output ;
93+ if (openAPI instanceof OpenAPIExt ) {
94+ String source = ((OpenAPIExt ) openAPI ).getSource ();
95+ String [] names = source .split ("\\ ." );
96+ output = Stream .of (names ).limit (Math .max (0 , names .length - 2 ))
97+ .reduce (outputDir , Path ::resolve , Path ::resolve );
98+ output = output .resolve (names [names .length - 1 ] + "." + format .extension ());
99+ } else {
100+ output = outputDir .resolve ("openapi." + format .extension ());
94101 }
95- Path output = outputDir .resolve ("openapi" + "." + format .extension ());
102+
103+ if (!Files .exists (output .getParent ())) {
104+ Files .createDirectories (output .getParent ());
105+ }
106+
96107 log .info (" writing: " + output );
97108
98109 String content = format .toString (this , openAPI );
@@ -112,6 +123,7 @@ public OpenAPI generate(String classname) {
112123
113124 /** Create OpenAPI from template and make sure min required information is present: */
114125 OpenAPIExt openapi = OpenAPIExt .create (basedir , classLoader , templateName );
126+ openapi .setSource (classname );
115127
116128 defaults (classname , contextPath , openapi );
117129
0 commit comments