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 @@ -28,6 +28,7 @@ public class ThingifierApiDocumentationDefn {
private String ogType = "";
private String twitterCard = "";
private String twitterSite = "";
private boolean showSwaggerUiLink = true;
private Map<String, HeaderMatch> customHeadersForRoutesThatDoNotMatch;

// todo: convert internal documentation to use a ThingifierApiDefn rather than a direct
Expand Down Expand Up @@ -183,6 +184,15 @@ public ThingifierApiDocumentationDefn setTwitterSite(final String twitterSite) {
return this;
}

public boolean willShowSwaggerUiLink() {
return showSwaggerUiLink;
}

public ThingifierApiDocumentationDefn setShowSwaggerUiLink(final boolean showSwaggerUiLink) {
this.showSwaggerUiLink = showSwaggerUiLink;
return this;
}

/**
* Given a skeletal RoutingDefinition used to match the verb and the endpoint If
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ public String getApiDocumentation(
}
}

output.append(paragraph(href("Open Swagger UI", prependPath + "/docs/swagger-ui")));
if (apiDocDefn.willShowSwaggerUiLink()) {
output.append(paragraph(href("Open Swagger UI", prependPath + "/docs/swagger-ui")));
}
output.append(
paragraph(href("[download normal swagger file]", prependPath + "/docs/swagger")));
output.append(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package uk.co.compendiumdev.thingifier.htmlgui.htmlgen;

import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import uk.co.compendiumdev.thingifier.Thingifier;
import uk.co.compendiumdev.thingifier.api.docgen.ApiRoutingDefinition;
import uk.co.compendiumdev.thingifier.api.docgen.ThingifierApiDocumentationDefn;

class RestApiDocumentationGeneratorTest {

@Test
void apiDocumentationShowsSwaggerUiLinkByDefault() {
final Thingifier thingifier = new Thingifier();
final ThingifierApiDocumentationDefn apiDocDefn = new ThingifierApiDocumentationDefn();

final String docs =
new RestApiDocumentationGenerator(thingifier, new DefaultGUIHTML())
.getApiDocumentation(
new ApiRoutingDefinition(),
List.of(),
apiDocDefn,
"/mirror",
"https://example.com/mirror/docs");

Assertions.assertTrue(docs.contains("href='/mirror/docs/swagger-ui'"));
Assertions.assertTrue(docs.contains("Open Swagger UI"));
}

@Test
void apiDocumentationCanHideSwaggerUiLink() {
final Thingifier thingifier = new Thingifier();
final ThingifierApiDocumentationDefn apiDocDefn =
new ThingifierApiDocumentationDefn().setShowSwaggerUiLink(false);

final String docs =
new RestApiDocumentationGenerator(thingifier, new DefaultGUIHTML())
.getApiDocumentation(
new ApiRoutingDefinition(),
List.of(),
apiDocDefn,
"/mirror",
"https://example.com/mirror/docs");

Assertions.assertFalse(docs.contains("href='/mirror/docs/swagger-ui'"));
Assertions.assertFalse(docs.contains("Open Swagger UI"));
Assertions.assertTrue(docs.contains("href='/mirror/docs/swagger'"));
}
}
Loading