Repository navigation
API Explorer for V2 APIs (based on Scalar OpenAPI UI) #5201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
df2cbfa
8ecd5d0
22a1745
0c0f5d8
fc062de
a2ab1d1
45af954
3f9faa9
ed41081
2b86b44
f835137
b508e7b
44a18db
c907ccf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| title: Add a Scalar based API Explorer to the Solr Admin UI | ||
| type: added | ||
| authors: | ||
| - name: Eric Pugh | ||
| links: | ||
| - name: PR#5201 | ||
| url: https://github.com/apache/solr/pull/5201 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| = Browsing the V2 API with the API Explorer | ||
|
|
||
| Solr's v2 (JAX-RS) API is described by an OpenAPI spec generated at build time | ||
| from the annotated interfaces in `solr/api/src/java/.../client/api/endpoint`. | ||
| The API Explorer is bundled in the Admin UI and renders the generated spec using Scalar. | ||
| It's a standalone page in its own project, `solr/webapp/scalar`, loaded in an iframe | ||
| rather than mounted directly into the Angular app: Scalar manages its own URL hash for deep-linking to operations, | ||
| which conflicts with AngularJS's `ngRoute` (both rewrite `window.location.hash`), causing an | ||
| infinite digest/navigation loop. A dedicated document/window avoids the conflict entirely. | ||
| The project owns everything the explorer needs (`web/index.html`, `web/scalar-init.js`, | ||
| and the Scalar bundle itself), and `:solr:webapp` mounts its | ||
| output at `libs/scalar` in the WAR. | ||
| `LoadAdminUiServlet` permits same-origin frames; the Scalar-specific headers in | ||
| `solr/server/etc/jetty.xml` permit the explorer page to be framed by the Admin UI. | ||
|
|
||
| == Usage | ||
|
|
||
| Start solr as usual. | ||
| Open the *API Explorer* item in the Admin UI's left nav to browse endpoints and send requests. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets add 1 or 2 screenshots as well? |
||
| The page and its assets are served locally; API requests go directly to the same Solr origin. | ||
| Executing a request can change the running instance, just as calling its API directly can. | ||
|
|
||
| Rebuild the webapp after changing API annotations to refresh the explorer's spec. | ||
|
|
||
| == Maintaining Scalar | ||
|
|
||
| The build downloads the pinned `@scalar/api-reference` npm archive directly | ||
| (not through npm) and copies its `dist/browser/standalone.js` next to the page. | ||
| The version is recorded as `scalar-api-reference` in `gradle/libs.versions.toml`. | ||
| The archive comes from npm's registry, or from a mirror set with `solr.npm.registry` / | ||
| `SOLR_NPM_REGISTRY` (the same override the node-based builds use); once cached, `--offline` works. | ||
|
|
||
| The initializer lives in `web/scalar-init.js` as a | ||
| separate script so it also works with a policy that disallows inline scripts. | ||
| Default CDN fonts, the request proxy, AI chat, hosted-client links, developer tools, and telemetry are disabled. | ||
|
|
||
| As with the Admin UI's other JavaScript libraries, Scalar's MIT license is recorded in the | ||
| root `LICENSE.txt` and `NOTICE.txt` rather than in `solr/licenses`. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,12 @@ The path to the Solr Admin UI given above is `\http://hostname:port/solr`, which | |
| A convenience redirect is also supported, so simply accessing the Admin UI at `\http://hostname:port/` will also redirect to `\http://hostname:port/solr/#/`. | ||
| ==== | ||
|
|
||
| === API Explorer | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we be refreshing the base image on this adoc as well to keep the docs consistent with latest state? image::solr-admin-ui/dashboard.png[image,height=400] ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should... |
||
|
|
||
| The *API Explorer* item in the Admin UI's left-hand navigation opens interactive documentation for Solr's v2 API. | ||
| It renders the OpenAPI specification bundled with Solr and lets you browse endpoints and send requests to the running instance. | ||
| Requests use the instance's authentication and authorization rules and can modify its data or configuration. | ||
|
Comment on lines
+54
to
+56
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| === Login Screen | ||
|
|
||
| If authentication has been enabled, Solr will present a login screen to unauthenticated users before allowing them further access to the Admin UI. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // The Admin UI's API Explorer: a standalone page that renders the generated OpenAPI spec with | ||
| // Scalar. It can't be an ordinary Admin UI screen because Scalar manages its own URL hash for | ||
| // deep-linking, which conflicts with AngularJS's ngRoute (both rewrite window.location.hash) and | ||
| // causes an infinite digest/navigation loop. The Admin UI instead loads this page in an iframe, | ||
| // and :solr:webapp mounts this project's output at libs/scalar in the war. | ||
|
|
||
| plugins { | ||
| id("base") | ||
| } | ||
|
|
||
| description = "The Admin UI's API Explorer, a standalone Scalar page loaded in an iframe" | ||
|
|
||
| // Scalar's prebuilt browser bundle is published only to npm. Fetch the package archive directly | ||
| // (from npm's registry, or the mirror the node-based builds use) rather than running npm. | ||
| val propertyOrEnvOrDefault: groovy.lang.Closure<*> by extra | ||
| val npmRegistry = propertyOrEnvOrDefault.call("solr.npm.registry", "SOLR_NPM_REGISTRY", "") | ||
| .toString() | ||
| .ifEmpty { "https://registry.npmjs.org" } | ||
|
|
||
| repositories { | ||
| exclusiveContent { | ||
| forRepository { | ||
| ivy { | ||
| name = "scalarNpm" | ||
| url = uri(npmRegistry) | ||
| patternLayout { | ||
| artifact("[organisation]/[module]/-/[module]-[revision].[ext]") | ||
| } | ||
| metadataSources { artifact() } | ||
| } | ||
| } | ||
| filter { includeModule("@scalar", "api-reference") } | ||
| } | ||
| } | ||
|
|
||
| val scalarArchive = configurations.create("scalarArchive") { | ||
| isTransitive = false | ||
| } | ||
|
|
||
| dependencies { | ||
| scalarArchive(libs.scalar.api.reference) { | ||
| artifact { | ||
| type = "tgz" | ||
| extension = "tgz" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| val scalarBundleDir = layout.buildDirectory.dir("scalarBundle") | ||
|
|
||
| val scalarBundle = configurations.create("scalarBundle") { | ||
| isCanBeConsumed = true | ||
| isCanBeResolved = false | ||
| } | ||
|
|
||
| val assembleScalarBundle = tasks.register<Sync>("assembleScalarBundle") { | ||
| from("web") | ||
| from(provider { tarTree(resources.gzip(scalarArchive.singleFile)) }) { | ||
| include("package/dist/browser/standalone.js") | ||
| eachFile { path = name } | ||
| includeEmptyDirs = false | ||
| } | ||
|
|
||
| into(scalarBundleDir) | ||
| } | ||
|
|
||
| artifacts { | ||
| add("scalarBundle", scalarBundleDir) { | ||
| builtBy(assembleScalarBundle) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # This is a Gradle generated file for dependency locking. | ||
| # Manual edits can break the build and are not advised. | ||
| # This file is expected to be part of source control. | ||
| # To regenerate this file, run: ./gradlew :solr:webapp:scalar:dependencies --write-locks | ||
| @scalar:api-reference:1.46.4=scalarArchive | ||
| empty=jarValidation |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one or more | ||
| contributor license agreements. See the NOTICE file distributed with | ||
| this work for additional information regarding copyright ownership. | ||
| The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --> | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
| <title>Solr V2 API Explorer</title> | ||
| </head> | ||
| <body> | ||
| <!-- | ||
| Loaded in an iframe by the Admin UI's API Explorer page, rather than mounted directly | ||
| into the Angular app: Scalar manages its own URL hash for deep-linking to operations, | ||
| which conflicts with AngularJS's ngRoute (both rewrite window.location.hash), causing an | ||
| infinite digest/navigation loop. A dedicated document gives Scalar its own window and | ||
| history, with no shared hash to contend over. | ||
| --> | ||
| <div id="app"></div> | ||
| <script src="standalone.js" charset="UTF-8"></script> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [for-my-knowledge] we dont have this file: 'standalong.js' in our codebase. how this linking works then?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Brought in at build time by Gradle. |
||
| <script src="scalar-init.js" charset="UTF-8"></script> | ||
| </body> | ||
| </html> | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking about deleting this file... I'm not sure it's really provindg a ton of value? And one more thing to update? I could see
dev-docsjust exploding with ai generated docs...