Skip to content

Commit ce27969

Browse files
authored
🤖 Merge PR DefinitelyTyped#72526 feat(swagger-ui): type support for internal presets and subpath mods by @tasshi-me
1 parent efd4d34 commit ce27969

File tree

6 files changed

+59
-2
lines changed

6 files changed

+59
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare var html: any;
2+
3+
export = html;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { SwaggerUIPreset } from "../index";
2+
3+
declare var StandalonePreset: SwaggerUIPreset;
4+
5+
export = StandalonePreset;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare var css: any;
2+
3+
export = css;

‎types/swagger-ui/index.d.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ declare namespace SwaggerUI {
5757
* An array of presets to use in Swagger UI.
5858
* Usually, you'll want to include ApisPreset if you use this option.
5959
*/
60-
presets?: SwaggerUIPlugin[] | undefined;
60+
presets?: SwaggerUIPlugin[] | SwaggerUIPreset[] | undefined;
6161

6262
// Display
6363

@@ -303,9 +303,24 @@ declare namespace SwaggerUI {
303303
};
304304
}
305305

306+
/**
307+
* Presets are arrays of plugins
308+
* See https://swagger.io/docs/open-source-tools/swagger-ui/customization/overview/#presets
309+
*/
310+
type SwaggerUIPreset = SwaggerUIPlugin[];
311+
306312
interface Indexable {
307313
[index: string]: any;
308314
}
315+
316+
/**
317+
* Internal presets
318+
* See https://swagger.io/docs/open-source-tools/swagger-ui/customization/overview/#presets
319+
*/
320+
var presets: {
321+
base: SwaggerUIPreset;
322+
apis: SwaggerUIPreset;
323+
};
309324
}
310325

311326
interface SwaggerUI {

‎types/swagger-ui/package.json‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
{
22
"private": true,
33
"name": "@types/swagger-ui",
4-
"version": "3.52.9999",
4+
"version": "5.21.9999",
55
"projects": [
66
"https://github.com/swagger-api/swagger-ui"
77
],
8+
"exports": {
9+
".": {
10+
"types": "./index.d.ts"
11+
},
12+
"./dist/oauth2-redirect.html": {
13+
"types": "./dist/oauth2-redirect.html.d.ts"
14+
},
15+
"./dist/swagger-ui.css": {
16+
"types": "./dist/swagger-ui.css.d.ts"
17+
},
18+
"./dist/swagger-ui-standalone-preset": {
19+
"types": "./dist/swagger-ui-standalone-preset.d.ts"
20+
}
21+
},
822
"devDependencies": {
923
"@types/swagger-ui": "workspace:."
1024
},

‎types/swagger-ui/swagger-ui-tests.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ const swaggerUI = SwaggerUI({
8484
syntaxHighlight: false,
8585
});
8686

87+
// $ExpectType SwaggerUIPreset
88+
const _basePreset = SwaggerUI.presets.base;
89+
// $ExpectType SwaggerUIPreset
90+
const _apisPreset = SwaggerUI.presets.apis;
91+
8792
swaggerUI.initOAuth({});
8893
swaggerUI.preauthorizeApiKey("abc", "dec");
8994
swaggerUI.preauthorizeBasic("key", "user", "password");
95+
96+
import SwaggerUIStandalonePreset from "swagger-ui/dist/swagger-ui-standalone-preset";
97+
// $ExpectType SwaggerUIPreset
98+
const _standAlonePreset = SwaggerUIStandalonePreset;
99+
100+
import SwaggerUICSS from "swagger-ui/dist/swagger-ui.css";
101+
// $ExpectType any
102+
const _css = SwaggerUICSS;
103+
104+
import OAuth2RedirectHTML from "swagger-ui/dist/oauth2-redirect.html";
105+
// $ExpectType any
106+
const _html = OAuth2RedirectHTML;

0 commit comments

Comments
 (0)