Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nshmp-ws
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ghsc
National Seismic Hazard Model Project
nshmp-ws
Commits
4d66ede5
Commit
4d66ede5
authored
1 year ago
by
Clayton, Brandon Scott
Browse files
Options
Downloads
Patches
Plain Diff
handle swagger
parent
d49e70b4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!223
Lambda
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/gov/usgs/earthquake/nshmp/www/SwaggerUIController.java
+29
-4
29 additions, 4 deletions
...va/gov/usgs/earthquake/nshmp/www/SwaggerUIController.java
with
29 additions
and
4 deletions
src/main/java/gov/usgs/earthquake/nshmp/www/SwaggerUIController.java
+
29
−
4
View file @
4d66ede5
...
...
@@ -9,6 +9,7 @@ import java.util.Optional;
import
org.apache.commons.io.IOUtils
;
import
io.micronaut.core.io.scan.ClassPathResourceLoader
;
import
io.micronaut.http.HttpResponse
;
import
io.micronaut.http.MediaType
;
import
io.micronaut.http.annotation.Controller
;
import
io.micronaut.http.annotation.Get
;
...
...
@@ -16,6 +17,7 @@ import io.micronaut.http.annotation.PathVariable;
import
io.micronaut.http.annotation.Produces
;
import
io.swagger.v3.oas.annotations.Hidden
;
import
jakarta.annotation.Nullable
;
import
jakarta.inject.Inject
;
/**
* Handle Swagger static resources.
...
...
@@ -26,6 +28,7 @@ import jakarta.annotation.Nullable;
MediaType
.
APPLICATION_YAML
,
MediaType
.
TEXT_HTML
,
MediaType
.
IMAGE_PNG
,
MediaType
.
TEXT_PLAIN
,
"font/woff"
,
"font/woff2"
,
"font/ttf"
,
...
...
@@ -41,16 +44,29 @@ public class SwaggerUIController {
this
.
loader
=
loader
;
}
@Inject
private
NshmpMicronautServlet
servlet
;
@Get
(
"{/path:.*}{.ext:png}"
)
@Produces
(
MediaType
.
IMAGE_PNG
)
@Produces
(
"image/png; charset=utf-8"
)
@Hidden
public
byte
[]
getSwagger
Ui
Image
(
public
byte
[]
getSwagger
Png
Image
s
(
@PathVariable
@Nullable
String
path
,
@PathVariable
@Nullable
String
ext
)
throws
IOException
{
Optional
<
URL
>
resource
=
loader
.
getResource
(
SWAGGER_UI_RESOURCE_LOCATION
+
path
+
"."
+
ext
);
return
IOUtils
.
toByteArray
(
resource
.
orElseThrow
().
openStream
());
}
@Get
(
"{/path:.*}{.ext:b4}"
)
@Produces
(
MediaType
.
TEXT_PLAIN
)
@Hidden
public
HttpResponse
<
String
>
getSwaggerBase64Images
(
@PathVariable
@Nullable
String
path
,
@PathVariable
@Nullable
String
ext
)
throws
IOException
{
return
HttpResponse
.
ok
(
getResourceString
(
SWAGGER_UI_RESOURCE_LOCATION
+
path
+
"."
+
ext
))
.
contentType
(
MediaType
.
TEXT_PLAIN
);
}
@Get
(
"{/path:.*}{.ext:css|js}"
)
@Produces
({
"text/css"
,
"text/javascript"
})
@Hidden
...
...
@@ -69,8 +85,17 @@ public class SwaggerUIController {
return
getResourceString
(
SWAGGER_UI_RESOURCE_LOCATION
+
path
+
"."
+
ext
);
}
@Get
(
"{/path:.*}{.ext:woff|woff2|ttf}"
)
@Produces
({
"font/woff"
,
"font/woff2"
,
"font/ttf"
})
@Get
(
"{/path:.*}{.ext:eot}"
)
@Produces
(
"application/vnd.ms-fontobject"
)
@Hidden
public
String
getSwaggerEotFont
(
@PathVariable
@Nullable
String
path
,
@PathVariable
@Nullable
String
ext
)
throws
IOException
{
return
getResourceString
(
SWAGGER_UI_RESOURCE_LOCATION
+
path
+
"."
+
ext
);
}
@Get
(
"{/path:.*}{.ext:woff|woff2|ttf|otf}"
)
@Produces
(
"font/*"
)
@Hidden
public
String
getSwaggerFont
(
@PathVariable
@Nullable
String
path
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment