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 11 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 an 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,29 @@ | ||
| = 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 loaded in an iframe from `solr/webapp/web/libs/scalar/index.html` 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. | ||
|
|
||
| == Usage | ||
|
|
||
| Build and start a local Solr with `./gradlew dev` and `bin/solr start -c`. | ||
| Open the *API Explorer* item in the Admin UI's left nav to browse endpoints and send requests. | ||
| 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 | ||
|
|
||
| `solr/webapp/scalar` downloads the `@scalar/api-reference` npm package at build time and | ||
| copies its `dist/browser/standalone.js` into the webapp's war, so the bundle is never | ||
| checked into source control. Its version is recorded as `scalar-api-reference` in | ||
| `gradle/libs.versions.toml`; bump that version to upgrade, and review the new version's | ||
| license and bundled dependencies. The MIT license text is recorded in the root `NOTICE.txt`. | ||
| The initializer lives in `solr/webapp/web/libs/scalar/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. |
| 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,59 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| import com.github.gradle.node.npm.task.NpmTask | ||
|
|
||
| // Downloads the pre-built @scalar/api-reference browser bundle via npm, for :solr:webapp to | ||
| // include in the war. Keeps the large generated bundle out of source control, unlike a | ||
| // hand-vendored copy. | ||
|
|
||
| plugins { | ||
| id("base") | ||
| alias(libs.plugins.nodegradle.node) | ||
| } | ||
|
|
||
| description = "Downloads the Scalar API Reference browser bundle for the Admin UI's API Explorer" | ||
|
|
||
| val scalarBundleDir = layout.buildDirectory.dir("scalarBundle").get().asFile | ||
|
epugh marked this conversation as resolved.
Resolved
|
||
|
|
||
| val scalarBundle = configurations.create("scalarBundle") { | ||
| isCanBeConsumed = true | ||
| isCanBeResolved = false | ||
| } | ||
|
|
||
| val downloadScalarApiReference = tasks.register<NpmTask>("downloadScalarApiReference") { | ||
| args.set(listOf("install", "@scalar/api-reference@${libs.versions.scalar.api.reference.get()}")) | ||
|
|
||
| inputs.property("scalar-api-reference version", libs.versions.scalar.api.reference.get()) | ||
| outputs.dir(project.extra["nodeProjectDir"].toString() + "/node_modules/@scalar/api-reference") | ||
| } | ||
|
|
||
| val copyScalarBundle = tasks.register<Sync>("copyScalarBundle") { | ||
| dependsOn(downloadScalarApiReference) | ||
|
|
||
| from(project.extra["nodeProjectDir"].toString() + "/node_modules/@scalar/api-reference/dist/browser") { | ||
| include("standalone.js") | ||
| } | ||
|
|
||
| into(scalarBundleDir) | ||
| } | ||
|
|
||
| artifacts { | ||
| add("scalarBundle", scalarBundleDir) { | ||
| builtBy(copyScalarBundle) | ||
| } | ||
| } | ||

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.
[ques] is this comment suited here? or should be in some dev docs?
if i am right, we are adding frame-src 'self'; entry here. there were many entries here already, so just adding for 1 we should avoid.