Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ public ThingifierAutoDocGenRouting(
System.out.println(
"Possibly incomplete swagger generation, api not defined from model");
}
if (config.includeMethodNotAllowedEndpoints && !config.includeFieldValidation) {
nameprefix = nameprefix + "permissive-";
}
nameprefix = nameprefix + variantFilenamePrefix(config);
response.header("Content-Type", "application/octet-stream");
response.header(
"Content-Disposition",
Expand Down Expand Up @@ -152,11 +150,7 @@ private void registerOpenApiEndpoint(
response.header(
"Content-Disposition",
"attachment; filename=\"%s\""
.formatted(
openApiDownloadFilename(
path,
config.includeMethodNotAllowedEndpoints
&& !config.includeFieldValidation)));
.formatted(openApiDownloadFilename(path, config)));
}
return new Swaggerizer(apiDefn)
.asJsonWithPreferredServer(config, HttpRequestOrigin.from(request));
Expand Down Expand Up @@ -192,11 +186,26 @@ private SwaggerGenerationConfig.PathParameterPlacement pathParameterPlacement(
return SwaggerGenerationConfig.PathParameterPlacement.PATH;
}

private String openApiDownloadFilename(final String path, final boolean permissive) {
private String openApiDownloadFilename(
final String path, final SwaggerGenerationConfig config) {
final String filename = path.substring(path.lastIndexOf("/") + 1);
if (permissive) {
return "permissive-" + filename;
return variantFilenamePrefix(config) + filename;
}

private String variantFilenamePrefix(final SwaggerGenerationConfig config) {
final StringBuilder prefix = new StringBuilder();

if (config.includeMethodNotAllowedEndpoints) {
prefix.append("permissive-");
}
return filename;
if (config.strongSchemas) {
prefix.append("strong-");
}
if (config.pathParameterPlacement
== SwaggerGenerationConfig.PathParameterPlacement.OPERATION) {
prefix.append("operational-");
}

return prefix.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.co.compendiumdev.thingifier.adapter.javalin;

import io.javalin.http.Context;
import io.javalin.http.HandlerType;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -28,6 +29,9 @@ public String body() {
public void body(final String body) {
bodySet = true;
context.attribute(RESPONSE_BODY_ATTRIBUTE, body == null ? "" : body);
if (context.method() == HandlerType.HEAD) {
return;
}
context.result((body == null ? "" : body).getBytes(StandardCharsets.UTF_8));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public ApiRoutingDefinition generate(String apiPathPrefix) {
optionsDocumentationFor(pluralUrl),
RoutingVerb.OPTIONS,
pluralUrl,
RoutingStatus.returnValue(204, "the endpoint verb options"),
RoutingStatus.returnValue(200, "the endpoint verb options"),
new ResponseHeader("Allow", "OPTIONS, GET, HEAD, POST, QUERY"));

// the following are not handled so return 405
Expand Down Expand Up @@ -357,7 +357,7 @@ public ApiRoutingDefinition generate(String apiPathPrefix) {
optionsDocumentationFor(aUrlWGuid),
RoutingVerb.OPTIONS,
aUrlWGuid,
RoutingStatus.returnValue(204),
RoutingStatus.returnValue(200),
new ResponseHeader("Allow", "OPTIONS, GET, HEAD, POST, PUT, DELETE"))
.addRequestUrlParam(entityDefn.getField(uniqueIdFieldName));

Expand Down
Loading
Loading