Skip to content
Open
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
23 changes: 23 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,26 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

==========================================================================
The following license applies to the Scalar API Reference JavaScript library
--------------------------------------------------------------------------
Copyright (c) 2023-present Scalar, https://github.com/scalar/scalar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

3 changes: 3 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ License: ISC https://github.com/d3/d3/blob/main/LICENSE
This product includes the highlight.js Javascript library created by Ivan Sagalaev
Copyright (c) 2006, Ivan Sagalaev, https://github.com/isagalaev/highlight.js

This product includes the Scalar API Reference JavaScript library.
Copyright (c) 2023-present Scalar, https://github.com/scalar/scalar

This product includes the Chosen Javascript library created by Patrick Filler
Copyright (c) 2011-2014 by Harvest, https://github.com/harvesthq/chosen

Expand Down
7 changes: 7 additions & 0 deletions changelog/unreleased/PR-5201-api-explorer.yml
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
38 changes: 38 additions & 0 deletions dev-docs/api-explorer.adoc

Copy link
Copy Markdown
Contributor Author

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-docs just exploding with ai generated docs...

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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`.
2 changes: 2 additions & 0 deletions dev-docs/apis.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Many libraries implement the JAX-RS spec: Solr currently uses the implementation
These v2 API definitions consist of two parts: a JAX-RS annotated interface in the `api` module "defining" the API, and a class in `core` "implementing" the interface.
Separating the API "definition" and "implementation" in this way allows us to only define each API in a single place, and use code generators to produce other API-related bits such as SolrJ code and ref-guide documentation.

One of those other bits is an OpenAPI spec - see link:api-explorer.adoc[api-explorer.adoc] for how to browse it with the API Explorer against a running local Solr.

=== Writing JAX-RS APIs

Writing a new v2 API may appear daunting, but additions in reality are actually pretty simple:
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ perfmark = "0.27.0"
picocli = "4.7.6"
prometheus-metrics = "1.8.0"
quicktheories = "0.26"
# @keep Scalar API Reference version used by the webapp
scalar-api-reference = "1.46.4"
selenium = "4.47.0"
semver4j = "6.0.0"
slf4j = "2.0.20"
Expand Down Expand Up @@ -449,6 +451,7 @@ picocli-codegen = { module = "info.picocli:picocli-codegen", version.ref = "pico
prometheus-metrics-expositionformats = { module = "io.prometheus:prometheus-metrics-exposition-formats", version.ref = "prometheus-metrics" }
prometheus-metrics-model = { module = "io.prometheus:prometheus-metrics-model", version.ref = "prometheus-metrics" }
quicktheories-quicktheories = { module = "org.quicktheories:quicktheories", version.ref = "quicktheories" }
scalar-api-reference = { module = "@scalar:api-reference", version.ref = "scalar-api-reference" }
selenium-chromedriver = { module = "org.seleniumhq.selenium:selenium-chrome-driver", version.ref = "selenium" }
semver4j-semver4j = { module = "org.semver4j:semver4j", version.ref = "semver4j" }
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ gradle.ext.withJsClient = disableJsClientValue == null || disableJsClientValue !
if (gradle.ext.withJsClient) {
include(":solr:webapp:js-client")
}
include(":solr:webapp:scalar")

// Configures development for joint Lucene/ Solr composite build.
apply from: file('gradle/lucene-dev/lucene-dev-repo-composite.gradle')
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import io.swagger.v3.oas.annotations.servers.Server;

@OpenAPIDefinition(
info =
@Info(
title = "v2 API",
description = "OpenAPI spec for Solr's v2 API endpoints",
license = @License(name = "ASL 2.0"),
version = SolrVersion.LATEST_STRING))
version = SolrVersion.LATEST_STRING),
// A relative URL keeps API-explorer tooling (e.g. Swagger UI) same-origin with
// whichever node ends up serving it, so "try it out" calls need no CORS setup.
servers = @Server(url = "/api", description = "This Solr node"))
public class ApiMetadata {}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
HttpHeaders.CONTENT_SECURITY_POLICY,
"default-src 'none'; base-uri 'none'; connect-src "
+ connectSrc
+ "; form-action 'self'; font-src 'self'; frame-ancestors 'none'; img-src 'self' data:; media-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';");
+ "; form-action 'self'; font-src 'self'; frame-ancestors 'none'; frame-src 'self'; img-src 'self' data:; media-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';");

// We have to close this to flush OutputStreamWriter buffer
try (Writer out =
Expand Down
16 changes: 16 additions & 0 deletions solr/server/etc/jetty.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@
</New>
</Arg>
</Call>
<!-- The Admin UI's API Explorer loads this one page in an iframe (Scalar manages its
own URL hash for deep-linking, which conflicts with ngRoute if mounted directly);
this narrower rule runs after the blanket rule above and overrides frame-ancestors
for just this path, so same-origin framing isn't blocked. -->
<Call name="addRule">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">
<Set name="pattern">/solr/libs/scalar/index.html</Set>
<Set name="headerName">Content-Security-Policy</Set>
<Set name="headerValue">default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self'; font-src 'self'; frame-ancestors 'self'; img-src 'self' data:; media-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';</Set>
</New>
</Arg>
</Call>
<!-- Note: /solr/index.html (and /solr/) is served by LoadAdminUiServlet (see web.xml),
which sets its own Content-Security-Policy that overrides anything set here - its
frame-src 'self' addition (needed by the API Explorer iframe above) lives there. -->
<Call name="addRule">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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] ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see other sections also have a screenshot of their UI, should we also keep home page screenshot of the api explorer in this section.

something similar to this should work?

Screenshot 2026-11-13 at 12 58 44 AM


=== 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.
Expand Down
31 changes: 31 additions & 0 deletions solr/webapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ configurations {
solrCore
generatedJSClientBundle
uiBundle
openapiSpec
scalarBundle
}

dependencies {
Expand All @@ -53,6 +55,10 @@ dependencies {
generatedJSClientBundle project(path: ":solr:webapp:js-client", configuration: "jsClientBundle")
}
uiBundle files(layout.buildDirectory.dir("generated/ui-resources")) { builtBy tasks.named('prepareUiResources') }
// Supplies the generated specification to the API Explorer.
openapiSpec project(path: ":solr:api", configuration: "openapiSpec")
// Supplies the API Explorer, a standalone Scalar page the Admin UI loads in an iframe.
scalarBundle project(path: ":solr:webapp:scalar", configuration: "scalarBundle")

// Browser-based tests of the AngularJS Admin UI (see src/test)
testImplementation project(':solr:core')
Expand Down Expand Up @@ -108,6 +114,20 @@ tasks.withType(Test).configureEach {
logger.warn('NOTE: :solr:webapp tests are disabled because -PdisableJsClient=true ' +
'excludes the js-client bundle the Admin UI tests need.')
}

// The API Explorer (its own project) and the OpenAPI spec it fetches are built separately
// and mounted into the war; like the js-client bundle above, neither exists in the source
// tree these tests serve.
if (seleniumEnabled) {
def scalarBundle = configurations.scalarBundle
def openapiSpec = configurations.openapiSpec
inputs.files(scalarBundle).withPropertyName('scalarBundle')
inputs.files(openapiSpec).withPropertyName('openapiSpec')
doFirst {
systemProperty 'tests.ui.scalar.bundle', scalarBundle.singleFile
systemProperty 'tests.ui.scalar.spec', openapiSpec.singleFile
}
}
}

war {
Expand All @@ -121,6 +141,17 @@ war {
from(configurations.uiBundle, {
into "ui"
})

// Supplies the generated specification to the API Explorer.
from(configurations.openapiSpec, {
into "libs/scalar"
rename { "spec.json" }
})

// Supplies the API Explorer, a standalone Scalar page the Admin UI loads in an iframe.
from(configurations.scalarBundle, {
into "libs/scalar"
})
}

// Expose 'war' archive as an artifact so that it can be packaged in the distribution.
Expand Down
2 changes: 1 addition & 1 deletion solr/webapp/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,4 @@ org.slf4j:jul-to-slf4j:2.0.20=serverLib
org.slf4j:slf4j-api:2.0.20=jarValidation,serverLib,solrCore,testCompileClasspath,testRuntimeClasspath
org.testcontainers:testcontainers:2.0.5=jarValidation,testRuntimeClasspath
org.xerial.snappy:snappy-java:1.1.10.8=jarValidation,solrCore,testRuntimeClasspath
empty=compileClasspath,generatedJSClientBundle,generatedUIBundle,missingdoclet,providedCompile,providedRuntime,runtimeClasspath,uiBundle,war
empty=compileClasspath,generatedJSClientBundle,generatedUIBundle,missingdoclet,openapiSpec,providedCompile,providedRuntime,runtimeClasspath,scalarBundle,uiBundle,war
88 changes: 88 additions & 0 deletions solr/webapp/scalar/build.gradle.kts
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)
}
}
6 changes: 6 additions & 0 deletions solr/webapp/scalar/gradle.lockfile
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
36 changes: 36 additions & 0 deletions solr/webapp/scalar/web/index.html
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>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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>
Loading
Loading