diff --git a/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/BoundingReaderGroundMotions.java b/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/BoundingReaderGroundMotions.java index 7bc3056d2f5380dc53d8e27482c893f1161811de..3ae3faa722fe7f7b3733d3d63f0f80b64e129298 100644 --- a/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/BoundingReaderGroundMotions.java +++ b/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/BoundingReaderGroundMotions.java @@ -26,7 +26,7 @@ import ucar.nc2.dataset.NetcdfDatasets; */ public class BoundingReaderGroundMotions extends BoundingReader<XySequence> { - public static final double PGA_VALUE = 0.001; + public static final double PGA_VALUE = 0.0; public static final double PGV_VALUE = 0.0001; public BoundingReaderGroundMotions(NetcdfGroundMotions netcdf, Location site) { diff --git a/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfController.java b/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfController.java index 468d324cacde34140b8d321d964410c76c5efe84..1934308e15e35ad52760cbba7849c145ae02f5f2 100644 --- a/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfController.java +++ b/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfController.java @@ -74,7 +74,7 @@ public class NetcdfController { "### Service call pattern\n" + "This service call is slashed delimited with pattern: " + - "`/spectra/{longitude}/{latitude}/{siteClass}`\n" + + "`/spectra/{latitude}/{longitude}/{siteClass}`\n" + "<br><br>" + "Example: `/spectra/-118/34/A`", operationId = "aashto-slash") @@ -84,7 +84,7 @@ public class NetcdfController { content = @Content( mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Response.class))) - @Get(uri = "/{longitude}/{latitude}/{siteClass}", produces = MediaType.APPLICATION_JSON) + @Get(uri = "/{latitude}/{longitude}/{siteClass}", produces = MediaType.APPLICATION_JSON) public HttpResponse<String> doGetSlashBySite( HttpRequest<?> request, @Schema(required = true) @PathVariable @Nullable Double longitude, @@ -102,6 +102,7 @@ public class NetcdfController { * @param latitude Latitude of the site * @param siteClass The site class (optional) */ + @Hidden @Operation( summary = "Returns risk-targeted design response spectra from a query based call", description = "### Returns a risk-targeted design response spectrum for a " + @@ -111,9 +112,9 @@ public class NetcdfController { "### Service call pattern\n" + "This service call is query based with pattern: " + - "`/spectra?longitude={number}&latitude={number}&siteClass={string}`\n" + + "`/spectra?latitude={number}&longitude={number}&siteClass={string}`\n" + "<br><br>" + - "Example: `/spectra?longitude=-118&latitude=34&siteClass=A`", + "Example: `/spectra?latitude=34&longitude=-118&siteClass=A`", operationId = "aashto-query") @ApiResponse( description = "Spatially interpolates data from https://doi.org/10.5066/P9Z206HY", @@ -121,7 +122,7 @@ public class NetcdfController { content = @Content( mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Response.class))) - @Get(uri = "{?longitude,latitude,siteClass}", produces = MediaType.APPLICATION_JSON) + @Get(uri = "{?latitude,longitude,siteClass}", produces = MediaType.APPLICATION_JSON) public HttpResponse<String> doGet( HttpRequest<?> request, @Schema(required = true) @QueryValue @Nullable Double longitude, @@ -139,12 +140,13 @@ public class NetcdfController { * @param latitude Latitude of the site */ @Hidden - @Get(uri = "/{longitude}/{latitude}", produces = MediaType.APPLICATION_JSON) + @Get(uri = "/{latitude}/{longitude}", produces = MediaType.APPLICATION_JSON) public HttpResponse<String> doGetSlash( HttpRequest<?> request, @Schema(required = true) @PathVariable @Nullable Double longitude, @Schema(required = true) @PathVariable @Nullable Double latitude) { - return doGet(request, longitude, latitude, null); + var query = new Query(longitude, latitude, null); + return service.handleServiceCall(request, query); } // For Swagger schema diff --git a/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/SwaggerController.java b/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/SwaggerController.java index 130036728df36567bdbbe5ed4af910125cb767e7..c56272ff454d18f904d5d4f8718cbac5ed9e9780 100644 --- a/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/SwaggerController.java +++ b/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/SwaggerController.java @@ -1,5 +1,6 @@ package gov.usgs.earthquake.nshmp.netcdf.www; +import java.io.IOException; import java.nio.file.Path; import gov.usgs.earthquake.nshmp.netcdf.NetcdfGroundMotions; @@ -49,10 +50,58 @@ public class SwaggerController { @Get(produces = MediaType.TEXT_EVENT_STREAM) public HttpResponse<String> doGet(HttpRequest<?> request) { try { - var openApi = NetcdfWsUtils.getOpenApi(request, netcdf.netcdfData(), "/spectra"); + var openApi = NetcdfWsUtils.getOpenApi( + request, + netcdf.netcdfData(), + servicePatternSection(request)); return HttpResponse.ok(Yaml.pretty(openApi)); } catch (Exception e) { return NetcdfWsUtils.handleError(e, "Swagger", request.getUri().getPath()); } } + + private static String servicePatternSection(HttpRequest<?> request) + throws IOException { + var url = NetcdfWsUtils.getRequestUrl(request); + url = url.endsWith("/swagger") ? url.replace("/swagger", "") : url; + + return new StringBuilder() + .append( + "<details>\n" + + "<summary>Service Call Patterns</summary>\n") + .append( + "### Query Pattern\n" + + + "The query based service call is in the form of:\n" + + + "```text\n" + + url + "/spectra?latitude={number}&longitude={number}\n" + + url + "/spectra?latitude={number}&longitude={number}&siteClass={string}\n" + + "````\n" + + + "Example:\n" + + "```text\n" + + url + "/spectra?latitude=34&longitude=-118\n" + + url + "/spectra?latitude=34&longitude=-118&siteClass=BC\n" + + "```\n") + .append( + "### Slash Pattern\n" + + + "The slash based service call is in the form of:\n" + + + "```text\n" + + url + "/spectra/{latitude}/{longitude}\n" + + url + "/spectra/{latitude}/{longitude}/{siteClass}\n" + + "```\n" + + + "Example:\n" + + + "```text\n" + + url + "/spectra/34/-118\n" + + url + "/spectra/34/-118/BC\n" + + "```\n") + .append("</details>") + .toString(); + } + } diff --git a/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/SwaggerController.java b/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/SwaggerController.java index 6db0187140d5ef18d430615a9407388672959997..ac31adec41786e82aabe251c57e2f0fa945abfc6 100644 --- a/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/SwaggerController.java +++ b/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/SwaggerController.java @@ -1,5 +1,6 @@ package gov.usgs.earthquake.nshmp.netcdf.www; +import java.io.IOException; import java.nio.file.Path; import gov.usgs.earthquake.nshmp.netcdf.NetcdfHazardCurves; @@ -50,11 +51,63 @@ public class SwaggerController { @Get(produces = MediaType.TEXT_EVENT_STREAM) public HttpResponse<String> doGet(HttpRequest<?> request) { try { - var openApi = NetcdfWsUtils.getOpenApi(request, netcdf.netcdfData(), "/hazard"); + var openApi = NetcdfWsUtils.getOpenApi( + request, + netcdf.netcdfData(), + servicePatternSection(request)); SwaggerUtils.imtSchema(openApi.getComponents().getSchemas(), netcdf.netcdfData().imts()); return HttpResponse.ok(Yaml.pretty(openApi)); } catch (Exception e) { return NetcdfWsUtils.handleError(e, "Swagger", request.getUri().getPath()); } } + + private static String servicePatternSection(HttpRequest<?> request) + throws IOException { + var url = NetcdfWsUtils.getRequestUrl(request); + url = url.endsWith("/swagger") ? url.replace("/swagger", "") : url; + + return new StringBuilder() + .append( + "<details>\n" + + "<summary>Service Call Patterns</summary>\n") + .append( + "### Query Pattern\n" + + + "The query based service call is in the form of:\n" + + + "```text\n" + + url + "/hazard?longitude={number}&latitude={number}\n" + + url + "/hazard?longitude={number}&latitude={number}&siteClass={string}\n" + + url + + "/hazard?longitude={number}&latitude={number}&siteClass={string}&imt={string}\n" + + "````\n" + + + "Example:\n" + + "```text\n" + + url + "/hazard?longitude=-118&latitude=34\n" + + url + "/hazard?longitude=-118&latitude=34&siteClass=BC\n" + + url + "/hazard?longitude=-118&latitude=34&siteClass=BC&imt=PGA\n" + + "```\n") + .append( + "### Slash Pattern\n" + + + "The slash based service call is in the form of:\n" + + + "```text\n" + + url + "/hazard/{longitude}/{latitude}\n" + + url + "/hazard/{longitude}/{latitude}/{siteClass}\n" + + url + "/hazard/{longitude}/{latitude}/{siteClass}/{imt}\n" + + "```\n" + + + "Example:\n" + + + "```text\n" + + url + "/hazard/-118/34\n" + + url + "/hazard/-118/34/BC\n" + + url + "/hazard/-118/34/BC/PGA\n" + + "```\n") + .append("</details>") + .toString(); + } } diff --git a/src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfWsUtils.java b/src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfWsUtils.java index b6146b01560bbdd0c7cdb8b6401a11ef75315b34..83ac0be052b7eb5c05829a310588ecdad126754c 100644 --- a/src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfWsUtils.java +++ b/src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfWsUtils.java @@ -66,8 +66,10 @@ public class NetcdfWsUtils { return HttpResponse.serverError(response); } - public static OpenAPI getOpenApi(HttpRequest<?> request, NetcdfData netcdfData, - String servicePath) throws IOException { + public static OpenAPI getOpenApi( + HttpRequest<?> request, + NetcdfData netcdfData, + String serviceSection) throws IOException { var openApi = new OpenAPIV3Parser().read("META-INF/swagger/nshmp-ws-static.yml"); var scienceBaseMetadata = netcdfData.scienceBaseMetadata(); SwaggerUtils.addLocationBounds(openApi, netcdfData.minimumBounds(), netcdfData.maximumBounds()); @@ -81,7 +83,7 @@ public class NetcdfWsUtils { // Update description var description = new StringBuilder() .append(scienceBaseMetadata.description + "\n") - .append(servicePatternSection(request, servicePath)) + .append(serviceSection) .append(swaggerParameterSection(netcdfData)) .append(swaggerScienceBaseSection(scienceBaseMetadata)) .toString(); @@ -102,59 +104,24 @@ public class NetcdfWsUtils { } } - private static String servicePatternSection(HttpRequest<?> request, String servicePath) - throws IOException { - var url = NetcdfWsUtils.getRequestUrl(request); - url = url.endsWith("/swagger") ? url.replace("/swagger", "") : url; - - return new StringBuilder() - .append("## Service Call Patterns\n") - .append( - "### Query Pattern\n" + - - "The query based service call is in the form of:\n" + - - "```text\n" + - url + servicePath + "?longitude={number}&latitude={number}&siteClass={string}\n" + - "````\n" + - - "Example:\n" + - "```text\n" + - url + servicePath + "?longitude=-118&latitude=34&siteClass=BC\n" + - "```\n") - .append( - "### Slash Pattern\n" + - - "The slash based service call is in the form of:\n" + - - "```text\n" + - url + servicePath + "/{longitude}/{latitude}/{siteClass}\n" + - "```\n" + - - "Example:\n" + - - "```text\n" + - url + servicePath + "/-118/34/BC\n" + - "```\n" + - - "> Note: To obtain data for all site classes simply " + - "call the query or slashed based service with no site class parameter.\n") - .toString(); - } - private static String swaggerParameterSection(NetcdfData netcdfData) { return new StringBuilder() - .append("\n## Parameters\n") + .append( + "<details>\n" + + "<summary>Parameters</summary>\n") .append( SwaggerUtils.locationBoundsInfo(netcdfData.minimumBounds(), netcdfData.maximumBounds(), Optional.of("###"))) .append(SwaggerUtils.siteClassInfo(netcdfData.siteClasses(), Optional.of("###"))) + .append("</details>") .toString(); } private static String swaggerScienceBaseSection(ScienceBaseMetadata scienceBaseMetadata) { return new StringBuilder() - .append("## ScienceBase\n") + .append( + "<details>\n" + + "<summary>ScienceBase Information</summary>\n") .append("Data history: " + scienceBaseMetadata.history) .append("<br><br>") .append( @@ -165,6 +132,7 @@ public class NetcdfWsUtils { .append(Arrays.stream(scienceBaseMetadata.scienceBaseInfo) .map(info -> String.format("- [%s](%s)", info.url, info.url)) .collect(Collectors.joining("\n"))) + .append("</details>") .toString(); } } diff --git a/src/lib/src/main/resources/swagger/index.css b/src/lib/src/main/resources/swagger/index.css index f0cc2b6fd69c034cb833e9f5484ab4b9aedfe3d0..65654e10316ec39c136e0937bd29b88cce034669 100644 --- a/src/lib/src/main/resources/swagger/index.css +++ b/src/lib/src/main/resources/swagger/index.css @@ -94,3 +94,26 @@ body { position: absolute; top: -.2em; } + +details { + cursor: pointer; + box-shadow: 0 3px 1px -2px #0003, 0 2px 2px #00000024, 0 1px 5px #0000001f; +} + +details:hover { + background-color: #f3f3f3; +} + +details[open] { + background-color: initial; + padding: 0 1.5em 1.5em 1.5em; +} + +summary { + font-weight: bold; + padding: 1.5em; +} + +details[open] > summary { + margin-left: -1.5em; +}