Skip to content

Commit db563bf

Browse files
committed
- implementa Projected on script routes
- ref #3853
1 parent d7c7946 commit db563bf

File tree

11 files changed

+926
-59
lines changed

11 files changed

+926
-59
lines changed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.fasterxml.jackson.annotation.JsonIgnore;
1515
import io.jooby.Router;
1616
import io.swagger.v3.oas.models.*;
17+
import io.swagger.v3.oas.models.media.Schema;
1718
import io.swagger.v3.oas.models.parameters.Parameter;
1819
import io.swagger.v3.oas.models.security.SecurityScheme;
1920

@@ -39,12 +40,24 @@ public void setSource(String classname) {
3940
}
4041

4142
public void addSecuritySchemes(String name, SecurityScheme scheme) {
42-
var components = getComponents();
43-
if (components == null) {
44-
components = new Components();
45-
setComponents(components);
43+
getRequiredComponents().addSecuritySchemes(name, scheme);
44+
}
45+
46+
@JsonIgnore
47+
public Components getRequiredComponents() {
48+
if (getComponents() == null) {
49+
setComponents(new Components());
50+
}
51+
return getComponents();
52+
}
53+
54+
@JsonIgnore
55+
public Map<String, Schema> getRequiredSchemas() {
56+
var components = getRequiredComponents();
57+
if (components.getSchemas() == null) {
58+
components.setSchemas(new LinkedHashMap<>());
4659
}
47-
components.addSecuritySchemes(name, scheme);
60+
return components.getSchemas();
4861
}
4962

5063
@Override

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,9 @@ public OperationExt copy(String pattern) {
292292
public String getPath(Map<String, Object> pathParams) {
293293
return Router.reverse(getPath(), pathParams);
294294
}
295+
296+
@JsonIgnore
297+
public boolean isScript() {
298+
return getController() == null;
299+
}
295300
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@
5353
import com.fasterxml.jackson.databind.module.SimpleModule;
5454
import com.fasterxml.jackson.databind.type.SimpleType;
5555
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
56-
import io.jooby.Context;
57-
import io.jooby.FileUpload;
58-
import io.jooby.SneakyThrows;
59-
import io.jooby.StatusCode;
56+
import io.jooby.*;
6057
import io.jooby.internal.openapi.javadoc.JavaDocParser;
6158
import io.jooby.openapi.DebugOption;
6259
import io.swagger.v3.core.util.RefUtils;
@@ -172,6 +169,9 @@ public Schema schema(Class type) {
172169
if (isVoid(type.getName())) {
173170
return null;
174171
}
172+
if (type == Projected.class) {
173+
return new ObjectSchema().name("Projected");
174+
}
175175
if (type == String.class) {
176176
return new StringSchema();
177177
}
@@ -496,6 +496,13 @@ public MethodNode findMethodNode(Type type, String name) {
496496
.orElseThrow(() -> new IllegalArgumentException("Method not found: " + type + "." + name));
497497
}
498498

499+
public MethodNode findMethodNode(Type type, String name, String desc) {
500+
return nodes.computeIfAbsent(type, this::newClassNode).methods.stream()
501+
.filter(it -> it.name.equals(name) && it.desc.equals(desc))
502+
.findFirst()
503+
.orElseThrow(() -> new IllegalArgumentException("Method not found: " + type + "." + name));
504+
}
505+
499506
public ClassNode classNodeOrNull(Type type) {
500507
try {
501508
return nodes.computeIfAbsent(type, this::newClassNode);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private String patternToOperationId(String pattern) {
271271
return "";
272272
}
273273
return Stream.of(pattern.split("\\W+"))
274-
.filter(s -> s.length() > 0)
274+
.filter(s -> !s.isEmpty())
275275
.map(
276276
segment ->
277277
Character.toUpperCase(segment.charAt(0))

modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/asciidoc/AsciiDocContext.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,8 @@ public Map<String, Object> getGlobalVariables() {
163163
.toList();
164164
openapiRoot.put("tags", tags);
165165
// Schemas
166-
var components = context.openapi.getComponents();
167-
if (components != null && components.getSchemas() != null) {
168-
var schemas = components.getSchemas();
169-
openapiRoot.put("schemas", new ArrayList<>(schemas.values()));
170-
}
166+
var schemas = context.openapi.getRequiredSchemas();
167+
openapiRoot.put("schemas", new ArrayList<>(schemas.values()));
171168

172169
// make in to work without literal
173170
openapiRoot.put("query", "query");
@@ -466,9 +463,6 @@ public Schema<?> resolveSchema(String path) {
466463

467464
private Optional<Schema<?>> resolveSchemaInternal(String name) {
468465
var components = openapi.getComponents();
469-
if (components == null || components.getSchemas() == null) {
470-
throw new NoSuchElementException("No schema found");
471-
}
472466
if (name.startsWith(COMPONENTS_SCHEMAS_REF)) {
473467
name = name.substring(COMPONENTS_SCHEMAS_REF.length());
474468
}

0 commit comments

Comments
 (0)