Skip to content

Commit 6606ca2

Browse files
committed
openapi: clean up
- remove unused `META-INF` scanning, we dont generate that anymore - ref #2403
1 parent 8d35777 commit 6606ca2

8 files changed

Lines changed: 3 additions & 180 deletions

File tree

modules/jooby-maven-plugin/src/main/java/io/jooby/maven/OpenAPIMojo.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,12 @@ protected void doExecute(@NonNull List<MavenProject> projects, @NonNull String m
5050
ClassLoader classLoader = createClassLoader(projects);
5151
Path outputDir = Paths.get(project.getBuild().getOutputDirectory());
5252
// Reduce lookup to current project: See https://github.com/jooby-project/jooby/issues/2756
53-
String metaInf =
54-
outputDir
55-
.resolve("META-INF")
56-
.resolve("services")
57-
.resolve("io.jooby.MvcFactory")
58-
.toAbsolutePath()
59-
.toString();
6053

6154
getLog().info("Generating OpenAPI: " + mainClass);
6255
getLog().debug("Using classloader: " + classLoader);
6356
getLog().debug("Output directory: " + outputDir);
64-
getLog().debug("META-INF: " + metaInf);
6557

66-
OpenAPIGenerator tool = new OpenAPIGenerator(metaInf);
58+
OpenAPIGenerator tool = new OpenAPIGenerator();
6759
tool.setClassLoader(classLoader);
6860
tool.setOutputDir(outputDir);
6961
trim(includes).ifPresent(tool::setIncludes);

modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/RouteParser.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717
import static io.jooby.internal.openapi.TypeFactory.STRING_ARRAY;
1818
import static org.objectweb.asm.Opcodes.GETSTATIC;
1919

20-
import java.io.IOException;
2120
import java.lang.reflect.Modifier;
22-
import java.nio.charset.StandardCharsets;
2321
import java.util.*;
2422
import java.util.concurrent.atomic.AtomicInteger;
2523
import java.util.function.BiPredicate;
2624
import java.util.function.Consumer;
2725
import java.util.function.Function;
28-
import java.util.function.Predicate;
2926
import java.util.stream.Collectors;
3027
import java.util.stream.Stream;
3128

@@ -59,23 +56,9 @@
5956

6057
public class RouteParser {
6158

62-
private String metaInf;
63-
64-
public RouteParser(String metaInf) {
65-
this.metaInf = metaInf;
66-
}
67-
6859
public List<OperationExt> parse(ParserContext ctx, OpenAPIExt openapi) {
6960
List<OperationExt> operations = parse(ctx, null, ctx.classNode(ctx.getRouter()));
7061

71-
// Checkout controllers without explicit mapping, just META-INF
72-
Set<String> controllers =
73-
operations.stream()
74-
.map(OperationExt::getControllerName)
75-
.filter(Objects::nonNull)
76-
.collect(Collectors.toSet());
77-
operations.addAll(metaInf(ctx, null, name -> !controllers.contains(name)));
78-
7962
operations.addAll(parseManuallyRegisteredControllers(ctx));
8063

8164
String applicationName =
@@ -280,28 +263,6 @@ public List<OperationExt> parse(ParserContext ctx, String prefix, ClassNode node
280263
return handlerList;
281264
}
282265

283-
private List<OperationExt> metaInf(
284-
ParserContext ctx, String prefix, Predicate<String> predicate) {
285-
// META-INF (Spring or similar)
286-
try {
287-
String content = new String(ctx.loadResource(metaInf), StandardCharsets.UTF_8);
288-
String[] lines = content.split("\\n");
289-
List<OperationExt> handlerList = new ArrayList<>();
290-
for (String line : lines) {
291-
String controller = line.replace("$Module", "").trim();
292-
if (!controller.isEmpty()) {
293-
Type type = TypeFactory.fromJavaName(controller);
294-
if (predicate.test(type.getInternalName())) {
295-
handlerList.addAll(AnnotationParser.parse(ctx, prefix, type));
296-
}
297-
}
298-
}
299-
return handlerList;
300-
} catch (IOException ex) {
301-
return Collections.emptyList();
302-
}
303-
}
304-
305266
private List<OperationExt> parseManuallyRegisteredControllers(ParserContext ctx) {
306267
List<OperationExt> handlerList = new ArrayList<>();
307268
ClassNode classNode = ctx.classNode(ctx.getRouter());

modules/jooby-openapi/src/main/java/io/jooby/openapi/OpenAPIGenerator.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,6 @@ public String toString(OpenAPIGenerator tool, OpenAPI result) {
100100

101101
private String excludes;
102102

103-
private String metaInf;
104-
105-
/**
106-
* Test Only.
107-
*
108-
* @param metaInf Location of meta-inf directory.
109-
*/
110-
public OpenAPIGenerator(String metaInf) {
111-
this.metaInf = metaInf;
112-
}
113-
114-
/** Creates a new instance. */
115-
public OpenAPIGenerator() {
116-
this("META-INF/services/io.jooby.MvcFactory");
117-
}
118-
119103
/**
120104
* Export an {@link OpenAPI} model to the given format.
121105
*
@@ -169,7 +153,7 @@ public OpenAPIGenerator() {
169153
OpenAPIExt openapi =
170154
OpenApiTemplate.fromTemplate(basedir, classLoader, templateName).orElseGet(OpenAPIExt::new);
171155

172-
RouteParser routes = new RouteParser(metaInf);
156+
RouteParser routes = new RouteParser();
173157
ParserContext ctx = new ParserContext(source, TypeFactory.fromJavaName(classname), debug);
174158
List<OperationExt> operations = routes.parse(ctx, openapi);
175159

modules/jooby-openapi/src/test/java/io/jooby/openapi/OpenAPIExtension.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,7 @@ public void afterEach(ExtensionContext ctx) {
8282
}
8383

8484
private OpenAPIGenerator newTool(Set<DebugOption> debug, Class klass) {
85-
String metaInf =
86-
Optional.ofNullable(klass.getPackage())
87-
.map(Package::getName)
88-
.map(name -> name.replace(".", "/") + "/")
89-
.orElse("")
90-
+ klass.getSimpleName();
91-
92-
OpenAPIGenerator tool = new OpenAPIGenerator(metaInf);
85+
OpenAPIGenerator tool = new OpenAPIGenerator();
9386
tool.setDebug(debug);
9487
return tool;
9588
}

modules/jooby-openapi/src/test/java/issues/i2403/App2403.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

modules/jooby-openapi/src/test/java/issues/i2403/Controller2403.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

modules/jooby-openapi/src/test/java/issues/i2403/Controller2403Copy.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

modules/jooby-openapi/src/test/java/issues/i2403/Issue2403.java

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)