Skip to content

Commit bd84a5f

Browse files
authored
feat: laravel 12 compatibility, new JS API, configuration changes (#7)
* chore: don’t auto update dependencies * ci: test laravel 12 * feat: allow laravel 12 * ci: use testbench 10 * chore: update dependencies * feat: use new JS API * feat: merge url with configuration * chore: make compatible with laravel 12 * fix: tests * chore: use testbench 9 with laravel 11 * chore: make testbench requirement work with laravel 10/11/12 * chore: allow older version of pest php laravel plugin * chore: allow older pestphp versions * feat: make /scalar the default path * chore: whitespace
1 parent 0d6d80e commit bd84a5f

File tree

7 files changed

+47
-57
lines changed

7 files changed

+47
-57
lines changed

.github/workflows/dependabot-auto-merge.yml

-33
This file was deleted.

.github/workflows/run-tests.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ jobs:
1818
matrix:
1919
os: [ubuntu-latest, windows-latest]
2020
php: [8.3, 8.2]
21-
laravel: [11.*, 10.*]
21+
laravel: [12.*, 11.*, 10.*]
2222
stability: [prefer-lowest, prefer-stable]
2323
include:
24+
- laravel: 12.*
25+
testbench: 10.*
26+
carbon: ^3.0
2427
- laravel: 11.*
2528
testbench: 9.*
2629
carbon: ^2.63

composer.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
"require": {
2020
"php": "^8.2",
2121
"spatie/laravel-package-tools": "^1.16",
22-
"illuminate/contracts": "^10.0||^11.0"
22+
"illuminate/contracts": "^10.0||^11.0||^12.0"
2323
},
2424
"require-dev": {
2525
"laravel/pint": "^1.14",
26-
"nunomaduro/collision": "^8.1.1||^7.10.0",
27-
"orchestra/testbench": "^9.0.0||^8.22.0",
28-
"pestphp/pest": "^2.34",
29-
"pestphp/pest-plugin-arch": "^2.7",
30-
"pestphp/pest-plugin-laravel": "^2.3"
26+
"nunomaduro/collision": "^8.7.0||^7.10.0",
27+
"orchestra/testbench": "^8.0||^9.0||^10.0",
28+
"pestphp/pest": "^2.3.4||^3.7.4",
29+
"pestphp/pest-plugin-arch": "^2.7.0||^3.0.0",
30+
"pestphp/pest-plugin-laravel": "^2.3.0||^3.1.0"
3131
},
3232
"autoload": {
3333
"psr-4": {

config/scalar.php

+28-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
| affect the paths of its internal API that aren't exposed to users.
2525
|
2626
*/
27-
'path' => '/reference',
27+
'path' => '/scalar',
2828

2929
/*
3030
|--------------------------------------------------------------------------
@@ -87,36 +87,48 @@
8787
// 'saturn',
8888
// 'solarized',
8989
// 'none',
90+
9091
/** The layout to use for the references */
9192
'layout' => 'modern',
93+
9294
/** URL to a request proxy for the API client */
93-
'proxy' => 'https://proxy.scalar.com',
95+
'proxyUrl' => 'https://proxy.scalar.com',
96+
9497
/** Whether to show the sidebar */
9598
'showSidebar' => true,
99+
96100
/**
97101
* Whether to show models in the sidebar, search, and content.
98102
*/
99103
'hideModels' => false,
104+
100105
/**
101106
* Whether to show the “Download OpenAPI Document” button
102107
*/
103108
'hideDownloadButton' => false,
109+
104110
/**
105111
* Whether to show the “Test Request” button
106112
*/
107113
'hideTestRequestButton' => false,
114+
108115
/**
109116
* Whether to show the sidebar search bar
110117
*/
111118
'hideSearch' => false,
119+
112120
/** Whether dark mode is on or off initially (light mode) */
113121
'darkMode' => false,
122+
114123
/** forceDarkModeState makes it always this state no matter what*/
115124
'forceDarkModeState' => 'dark',
125+
116126
/** Whether to show the dark mode toggle */
117127
'hideDarkModeToggle' => false,
128+
118129
/** Key used with CTRL/CMD to open the search modal (defaults to 'k' e.g. CMD+k) */
119130
'searchHotKey' => 'k',
131+
120132
/**
121133
* If used, passed data will be added to the HTML header
122134
*
@@ -125,50 +137,58 @@
125137
'metaData' => [
126138
'title' => config('app.name').' API Reference',
127139
],
140+
128141
/**
129142
* Path to a favicon image
130143
*
131144
* @example '/favicon.svg'
132145
*/
133146
'favicon' => '',
147+
134148
/**
135149
* List of httpsnippet clients to hide from the clients menu
136150
* By default hides Unirest, pass `[]` to show all clients
137151
*/
138152
'hiddenClients' => [
139153

140154
],
155+
141156
/** Determine the HTTP client that’s selected by default */
142157
'defaultHttpClient' => [
143158
'targetId' => 'shell',
144159
'clientKey' => 'curl',
145160
],
161+
146162
/** Custom CSS to be added to the page */
147-
'customCss' => '',
163+
// 'customCss' => '',
164+
148165
/** Prefill authentication */
149-
'authentication' => [
150-
// TODO
151-
],
166+
// 'authentication' => [
167+
// // TODO
168+
// ],
169+
152170
/**
153171
* The baseServerURL is used when the spec servers are relative paths and we are using SSR.
154172
* On the client we can grab the window.location.origin but on the server we need
155173
* to use this prop.
156174
*/
157-
'baseServerURL' => '',
175+
// 'baseServerURL' => '',
176+
158177
/**
159178
* List of servers to override the openapi spec servers
160179
*/
161-
'servers' => null,
162180
// 'servers' => [
163181
// [
164182
// 'url' => 'https://api.scalar.com',
165183
// 'description' => 'Production server',
166184
// ],
167185
// ],
186+
168187
/**
169188
* We’re using Inter and JetBrains Mono as the default fonts. If you want to use your own fonts, set this to false.
170189
*/
171190
'withDefaultFonts' => true,
191+
172192
/**
173193
* By default we only open the relevant tag based on the url, however if you want all the tags open by default then set this configuration option :)
174194
*/

resources/views/reference.blade.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
@extends('scalar::layout')
22

33
@section('content')
4-
<script id="api-reference" data-url="{{ \Scalar\Scalar::url() }}"></script>
4+
<div id="app"></div>
5+
6+
<script src="{{ \Scalar\Scalar::cdn() }}"></script>
57

68
<script>
7-
document.getElementById('api-reference').dataset.configuration =
8-
JSON.stringify({!! \Scalar\Scalar::configuration() !!})
9+
Scalar.createApiReference('#app', {!! \Scalar\Scalar::configuration() !!})
910
</script>
10-
11-
<script src="{{ \Scalar\Scalar::cdn() }}"></script>
1211
@endsection

src/Scalar.php

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public static function configuration()
3838
/** Render as JSON */
3939
return collect($configuration)->merge([
4040
'theme' => $theme,
41+
'url' => config('scalar.url'),
4142
]);
4243
}
4344
}

tests/ScalarTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
$response = $this->get(config('scalar.path'));
2424

2525
$response->assertOk()
26-
->assertSee('data-url')
27-
->assertSee(config('scalar.url'));
26+
->assertSee('Scalar.createApiReference')
27+
->assertSee(str_replace('/', '\/', config('scalar.url')));
2828
});
2929

3030
it('contains the jsDelivr URL', function () {
3131
$response = $this->get(config('scalar.path'));
3232

3333
$response->assertOk()
34-
->assertSee('https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.json');
34+
->assertSee('https:\/\/cdn.jsdelivr.net\/npm\/@scalar\/galaxy\/dist\/latest.json');
3535
});
3636

3737
it('reflects changes in the config', function () {
@@ -41,7 +41,7 @@
4141
// Modify config
4242
config()->set('scalar.cdn', 'https://example.com/cdn');
4343

44-
$response = $this->get('/reference');
44+
$response = $this->get('/scalar');
4545

4646
$response->assertOk()
4747
->assertSee('https://example.com/cdn')

0 commit comments

Comments
 (0)