@scalar/api-client 3.24.0 → 3.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/style.css +50 -42
- package/dist/v2/blocks/request-block/components/RequestBody.vue.d.ts +2 -2
- package/dist/v2/blocks/request-block/components/RequestBody.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBody.vue.js +1 -1
- package/dist/v2/blocks/request-block/components/RequestBody.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBody.vue_vue_type_script_setup_true_lang.js +40 -4
- package/dist/v2/blocks/request-block/components/RequestBody.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBodyForm.vue.d.ts +3 -1
- package/dist/v2/blocks/request-block/components/RequestBodyForm.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBodyForm.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBodyForm.vue_vue_type_script_setup_true_lang.js +20 -5
- package/dist/v2/blocks/request-block/components/RequestBodyForm.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBodyMultipart.vue.d.ts +15 -0
- package/dist/v2/blocks/request-block/components/RequestBodyMultipart.vue.d.ts.map +1 -0
- package/dist/v2/blocks/request-block/components/RequestBodyMultipart.vue.js +7 -0
- package/dist/v2/blocks/request-block/components/RequestBodyMultipart.vue.js.map +1 -0
- package/dist/v2/blocks/request-block/components/RequestBodyMultipart.vue_vue_type_script_setup_true_lang.js +156 -0
- package/dist/v2/blocks/request-block/components/RequestBodyMultipart.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/v2/blocks/request-block/components/RequestTable.vue.d.ts +2 -0
- package/dist/v2/blocks/request-block/components/RequestTable.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTable.vue.js +1 -1
- package/dist/v2/blocks/request-block/components/RequestTable.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTable.vue_vue_type_script_setup_true_lang.js +6 -0
- package/dist/v2/blocks/request-block/components/RequestTable.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTableRow.vue.d.ts +4 -0
- package/dist/v2/blocks/request-block/components/RequestTableRow.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTableRow.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTableRow.vue_vue_type_script_setup_true_lang.js +10 -3
- package/dist/v2/blocks/request-block/components/RequestTableRow.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/v2/blocks/request-block/helpers/get-form-body-rows.d.ts +2 -2
- package/dist/v2/blocks/request-block/helpers/get-form-body-rows.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/helpers/get-form-body-rows.js +8 -4
- package/dist/v2/blocks/request-block/helpers/get-form-body-rows.js.map +1 -1
- package/dist/v2/blocks/request-block/helpers/multipart-body.d.ts +18 -0
- package/dist/v2/blocks/request-block/helpers/multipart-body.d.ts.map +1 -0
- package/dist/v2/blocks/request-block/helpers/multipart-body.js +80 -0
- package/dist/v2/blocks/request-block/helpers/multipart-body.js.map +1 -0
- package/dist/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue.d.ts +2 -2
- package/dist/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue_vue_type_script_setup_true_lang.js +2 -0
- package/dist/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.js +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.js.map +1 -1
- package/dist/v2/constants.js +1 -1
- package/dist/v2/features/localization/locales/ar.d.ts +3 -0
- package/dist/v2/features/localization/locales/ar.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/ar.js +3 -0
- package/dist/v2/features/localization/locales/ar.js.map +1 -1
- package/dist/v2/features/localization/locales/de.d.ts +3 -0
- package/dist/v2/features/localization/locales/de.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/de.js +3 -0
- package/dist/v2/features/localization/locales/de.js.map +1 -1
- package/dist/v2/features/localization/locales/es.d.ts +3 -0
- package/dist/v2/features/localization/locales/es.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/es.js +3 -0
- package/dist/v2/features/localization/locales/es.js.map +1 -1
- package/dist/v2/features/localization/locales/fr.d.ts +3 -0
- package/dist/v2/features/localization/locales/fr.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/fr.js +3 -0
- package/dist/v2/features/localization/locales/fr.js.map +1 -1
- package/dist/v2/features/localization/locales/pt.d.ts +3 -0
- package/dist/v2/features/localization/locales/pt.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/pt.js +3 -0
- package/dist/v2/features/localization/locales/pt.js.map +1 -1
- package/dist/v2/features/localization/locales/ru.d.ts +3 -0
- package/dist/v2/features/localization/locales/ru.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/ru.js +3 -0
- package/dist/v2/features/localization/locales/ru.js.map +1 -1
- package/dist/v2/features/localization/locales/zh-cn.d.ts +3 -0
- package/dist/v2/features/localization/locales/zh-cn.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/zh-cn.js +3 -0
- package/dist/v2/features/localization/locales/zh-cn.js.map +1 -1
- package/dist/v2/features/localization/locales/zh-tw.d.ts +3 -0
- package/dist/v2/features/localization/locales/zh-tw.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/zh-tw.js +3 -0
- package/dist/v2/features/localization/locales/zh-tw.js.map +1 -1
- package/dist/v2/features/localization/translations.d.ts +3 -0
- package/dist/v2/features/localization/translations.d.ts.map +1 -1
- package/dist/v2/features/localization/translations.js +3 -0
- package/dist/v2/features/localization/translations.js.map +1 -1
- package/dist/vue-styles.css +4 -4
- package/package.json +15 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @scalar/api-client
|
|
2
2
|
|
|
3
|
+
## 3.25.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#10871](https://github.com/scalar/scalar/pull/10871): Add schema-aware file controls for multipart/mixed and multipart/related parts, preserving part order and encodings. Restrict multipart/form-data uploads to file fields when a request body schema is available.
|
|
8
|
+
|
|
9
|
+
Honor binary encoding content types on multipart fields and share file-schema detection with example generation, including nullable, composed, and typeless file placeholders.
|
|
10
|
+
|
|
11
|
+
- [#10731](https://github.com/scalar/scalar/pull/10731): Support OpenID Connect flow defaults, including client ID, selected scopes, and PKCE, after discovery. Prefer a sole configured flow while retaining other discovered flows. Add typed OpenID Connect authentication configuration for .NET.
|
|
12
|
+
|
|
3
13
|
## 3.24.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/dist/style.css
CHANGED
|
@@ -1921,17 +1921,17 @@
|
|
|
1921
1921
|
border-radius: var(--scalar-radius);
|
|
1922
1922
|
}
|
|
1923
1923
|
|
|
1924
|
-
.request-card[data-v-41f67ce2], .request-card[data-v-
|
|
1924
|
+
.request-card[data-v-41f67ce2], .request-card[data-v-9ef20696] {
|
|
1925
1925
|
color: var(--scalar-color-1);
|
|
1926
1926
|
font-size: var(--scalar-font-size-3);
|
|
1927
1927
|
}
|
|
1928
1928
|
|
|
1929
|
-
.request-method[data-v-
|
|
1929
|
+
.request-method[data-v-9ef20696] {
|
|
1930
1930
|
font-family: var(--scalar-font-code);
|
|
1931
1931
|
margin-right: 6px;
|
|
1932
1932
|
}
|
|
1933
1933
|
|
|
1934
|
-
.request-card-footer[data-v-
|
|
1934
|
+
.request-card-footer[data-v-9ef20696] {
|
|
1935
1935
|
flex-shrink: 0;
|
|
1936
1936
|
justify-content: flex-end;
|
|
1937
1937
|
padding: 6px;
|
|
@@ -1939,30 +1939,30 @@
|
|
|
1939
1939
|
position: relative;
|
|
1940
1940
|
}
|
|
1941
1941
|
|
|
1942
|
-
.request-card-footer--wraps[data-v-
|
|
1942
|
+
.request-card-footer--wraps[data-v-9ef20696] {
|
|
1943
1943
|
flex-wrap: wrap;
|
|
1944
1944
|
row-gap: 4px;
|
|
1945
1945
|
}
|
|
1946
1946
|
|
|
1947
|
-
.request-card-footer-start[data-v-
|
|
1947
|
+
.request-card-footer-start[data-v-9ef20696] {
|
|
1948
1948
|
flex: 1 0 auto;
|
|
1949
1949
|
align-items: center;
|
|
1950
1950
|
display: flex;
|
|
1951
1951
|
}
|
|
1952
1952
|
|
|
1953
|
-
.request-card-footer-addon[data-v-
|
|
1953
|
+
.request-card-footer-addon[data-v-9ef20696] {
|
|
1954
1954
|
flex: 1;
|
|
1955
1955
|
align-items: center;
|
|
1956
1956
|
min-width: 0;
|
|
1957
1957
|
display: flex;
|
|
1958
1958
|
}
|
|
1959
1959
|
|
|
1960
|
-
.request-editor-section[data-v-
|
|
1960
|
+
.request-editor-section[data-v-9ef20696] {
|
|
1961
1961
|
flex: 1;
|
|
1962
1962
|
display: flex;
|
|
1963
1963
|
}
|
|
1964
1964
|
|
|
1965
|
-
.request-card-simple[data-v-
|
|
1965
|
+
.request-card-simple[data-v-9ef20696] {
|
|
1966
1966
|
font-size: var(--scalar-small);
|
|
1967
1967
|
flex-wrap: wrap;
|
|
1968
1968
|
justify-content: space-between;
|
|
@@ -1972,30 +1972,30 @@
|
|
|
1972
1972
|
display: flex;
|
|
1973
1973
|
}
|
|
1974
1974
|
|
|
1975
|
-
.request-header[data-v-
|
|
1975
|
+
.request-header[data-v-9ef20696] {
|
|
1976
1976
|
overflow-wrap: anywhere;
|
|
1977
1977
|
flex: 999 auto;
|
|
1978
1978
|
min-width: 0;
|
|
1979
1979
|
}
|
|
1980
1980
|
|
|
1981
|
-
.request-card-actions[data-v-
|
|
1981
|
+
.request-card-actions[data-v-9ef20696] {
|
|
1982
1982
|
flex: 1 0 auto;
|
|
1983
1983
|
}
|
|
1984
1984
|
|
|
1985
|
-
.code-snippet[data-v-
|
|
1985
|
+
.code-snippet[data-v-9ef20696] {
|
|
1986
1986
|
flex-direction: column;
|
|
1987
1987
|
width: 100%;
|
|
1988
1988
|
display: flex;
|
|
1989
1989
|
}
|
|
1990
1990
|
|
|
1991
|
-
.property-example[data-v-
|
|
1991
|
+
.property-example[data-v-a431d692] {
|
|
1992
1992
|
font-size: var(--scalar-mini);
|
|
1993
1993
|
flex-direction: column;
|
|
1994
1994
|
display: flex;
|
|
1995
1995
|
position: relative;
|
|
1996
1996
|
}
|
|
1997
1997
|
|
|
1998
|
-
.property-example[data-v-
|
|
1998
|
+
.property-example[data-v-a431d692]:hover:before {
|
|
1999
1999
|
pointer-events: none;
|
|
2000
2000
|
content: "";
|
|
2001
2001
|
border-radius: var(--scalar-radius);
|
|
@@ -2006,7 +2006,7 @@
|
|
|
2006
2006
|
left: 0;
|
|
2007
2007
|
}
|
|
2008
2008
|
|
|
2009
|
-
.property-example-value[data-v-
|
|
2009
|
+
.property-example-value[data-v-a431d692] {
|
|
2010
2010
|
font-family: var(--scalar-font-code);
|
|
2011
2011
|
align-items: center;
|
|
2012
2012
|
gap: 8px;
|
|
@@ -2015,28 +2015,28 @@
|
|
|
2015
2015
|
display: flex;
|
|
2016
2016
|
}
|
|
2017
2017
|
|
|
2018
|
-
.property-example-value span[data-v-
|
|
2018
|
+
.property-example-value span[data-v-a431d692] {
|
|
2019
2019
|
text-overflow: ellipsis;
|
|
2020
|
-
white-space:
|
|
2020
|
+
white-space: pre;
|
|
2021
2021
|
display: block;
|
|
2022
2022
|
overflow: hidden;
|
|
2023
2023
|
}
|
|
2024
2024
|
|
|
2025
|
-
.property-example-value[data-v-
|
|
2025
|
+
.property-example-value[data-v-a431d692] svg {
|
|
2026
2026
|
color: var(--scalar-color-3);
|
|
2027
2027
|
}
|
|
2028
2028
|
|
|
2029
|
-
.property-example-value[data-v-
|
|
2029
|
+
.property-example-value[data-v-a431d692]:hover svg {
|
|
2030
2030
|
color: var(--scalar-color-1);
|
|
2031
2031
|
}
|
|
2032
2032
|
|
|
2033
|
-
.property-example-value[data-v-
|
|
2033
|
+
.property-example-value[data-v-a431d692] {
|
|
2034
2034
|
background: var(--scalar-background-2);
|
|
2035
2035
|
border: var(--scalar-border-width) solid var(--scalar-border-color);
|
|
2036
2036
|
border-radius: var(--scalar-radius);
|
|
2037
2037
|
}
|
|
2038
2038
|
|
|
2039
|
-
.property-example-value-list[data-v-
|
|
2039
|
+
.property-example-value-list[data-v-a431d692] {
|
|
2040
2040
|
background-color: var(--scalar-background-1);
|
|
2041
2041
|
box-shadow: var(--scalar-shadow-1);
|
|
2042
2042
|
border-radius: var(--scalar-radius-lg);
|
|
@@ -2055,12 +2055,12 @@
|
|
|
2055
2055
|
transform: translate(-50%);
|
|
2056
2056
|
}
|
|
2057
2057
|
|
|
2058
|
-
.property-example-value-list-start[data-v-
|
|
2058
|
+
.property-example-value-list-start[data-v-a431d692] {
|
|
2059
2059
|
left: 0;
|
|
2060
2060
|
transform: none;
|
|
2061
2061
|
}
|
|
2062
2062
|
|
|
2063
|
-
.property-example:hover .property-example-value-list[data-v-
|
|
2063
|
+
.property-example:hover .property-example-value-list[data-v-a431d692] {
|
|
2064
2064
|
display: flex;
|
|
2065
2065
|
}
|
|
2066
2066
|
|
|
@@ -2486,7 +2486,7 @@ code.property-detail-value[data-v-8b57daa7] {
|
|
|
2486
2486
|
flex: 1;
|
|
2487
2487
|
}
|
|
2488
2488
|
|
|
2489
|
-
.property-heading[data-v-
|
|
2489
|
+
.property-heading[data-v-09888606] {
|
|
2490
2490
|
white-space: nowrap;
|
|
2491
2491
|
flex-wrap: wrap;
|
|
2492
2492
|
align-items: baseline;
|
|
@@ -2494,19 +2494,19 @@ code.property-detail-value[data-v-8b57daa7] {
|
|
|
2494
2494
|
display: flex;
|
|
2495
2495
|
}
|
|
2496
2496
|
|
|
2497
|
-
:is(.property-heading[data-v-
|
|
2497
|
+
:is(.property-heading[data-v-09888606]:has( + .children), .property-heading[data-v-09888606]:has( + .property-rule)) {
|
|
2498
2498
|
margin-bottom: 9px;
|
|
2499
2499
|
}
|
|
2500
2500
|
|
|
2501
|
-
.property-heading[data-v-
|
|
2501
|
+
.property-heading[data-v-09888606] > * {
|
|
2502
2502
|
margin-right: 9px;
|
|
2503
2503
|
}
|
|
2504
2504
|
|
|
2505
|
-
.property-heading[data-v-
|
|
2505
|
+
.property-heading[data-v-09888606]:last-child {
|
|
2506
2506
|
margin-right: 0;
|
|
2507
2507
|
}
|
|
2508
2508
|
|
|
2509
|
-
.property-name[data-v-
|
|
2509
|
+
.property-name[data-v-09888606] {
|
|
2510
2510
|
max-width: 100%;
|
|
2511
2511
|
font-family: var(--scalar-font-code);
|
|
2512
2512
|
font-weight: var(--scalar-bold);
|
|
@@ -2515,45 +2515,45 @@ code.property-detail-value[data-v-8b57daa7] {
|
|
|
2515
2515
|
overflow-wrap: break-word;
|
|
2516
2516
|
}
|
|
2517
2517
|
|
|
2518
|
-
.property-additional[data-v-
|
|
2518
|
+
.property-additional[data-v-09888606] {
|
|
2519
2519
|
font-family: var(--scalar-font-code);
|
|
2520
2520
|
}
|
|
2521
2521
|
|
|
2522
|
-
.property-required[data-v-
|
|
2522
|
+
.property-required[data-v-09888606], .property-optional[data-v-09888606] {
|
|
2523
2523
|
color: var(--scalar-color-2);
|
|
2524
2524
|
}
|
|
2525
2525
|
|
|
2526
|
-
.property-required[data-v-
|
|
2526
|
+
.property-required[data-v-09888606] {
|
|
2527
2527
|
font-size: var(--scalar-mini);
|
|
2528
2528
|
color: var(--scalar-color-orange);
|
|
2529
2529
|
}
|
|
2530
2530
|
|
|
2531
|
-
.light-mode .property-required[data-v-
|
|
2531
|
+
.light-mode .property-required[data-v-09888606] {
|
|
2532
2532
|
color: var(--scalar-color-orange);
|
|
2533
2533
|
}
|
|
2534
2534
|
|
|
2535
2535
|
@supports (color: color-mix(in lab, red, red)) {
|
|
2536
|
-
.light-mode .property-required[data-v-
|
|
2536
|
+
.light-mode .property-required[data-v-09888606] {
|
|
2537
2537
|
color: color-mix(in srgb, var(--scalar-color-orange), var(--scalar-color-1) 32%);
|
|
2538
2538
|
}
|
|
2539
2539
|
}
|
|
2540
2540
|
|
|
2541
|
-
.property-read-only[data-v-
|
|
2541
|
+
.property-read-only[data-v-09888606] {
|
|
2542
2542
|
font-size: var(--scalar-mini);
|
|
2543
2543
|
color: var(--scalar-color-blue);
|
|
2544
2544
|
}
|
|
2545
2545
|
|
|
2546
|
-
.property-write-only[data-v-
|
|
2546
|
+
.property-write-only[data-v-09888606] {
|
|
2547
2547
|
font-size: var(--scalar-mini);
|
|
2548
2548
|
color: var(--scalar-color-green);
|
|
2549
2549
|
}
|
|
2550
2550
|
|
|
2551
|
-
.property-discriminator[data-v-
|
|
2551
|
+
.property-discriminator[data-v-09888606] {
|
|
2552
2552
|
font-size: var(--scalar-mini);
|
|
2553
2553
|
color: var(--scalar-color-purple);
|
|
2554
2554
|
}
|
|
2555
2555
|
|
|
2556
|
-
.property-detail[data-v-
|
|
2556
|
+
.property-detail[data-v-09888606] {
|
|
2557
2557
|
font-size: var(--scalar-mini);
|
|
2558
2558
|
color: var(--scalar-color-2);
|
|
2559
2559
|
align-items: center;
|
|
@@ -2561,11 +2561,11 @@ code.property-detail-value[data-v-8b57daa7] {
|
|
|
2561
2561
|
display: flex;
|
|
2562
2562
|
}
|
|
2563
2563
|
|
|
2564
|
-
.property-const[data-v-
|
|
2564
|
+
.property-const[data-v-09888606] {
|
|
2565
2565
|
color: var(--scalar-color-1);
|
|
2566
2566
|
}
|
|
2567
2567
|
|
|
2568
|
-
.deprecated[data-v-
|
|
2568
|
+
.deprecated[data-v-09888606] {
|
|
2569
2569
|
text-decoration: line-through;
|
|
2570
2570
|
}
|
|
2571
2571
|
|
|
@@ -3138,6 +3138,10 @@ code.property-detail-value[data-v-8b57daa7] {
|
|
|
3138
3138
|
margin: 4px;
|
|
3139
3139
|
}
|
|
3140
3140
|
|
|
3141
|
+
.scalar-app .m-3 {
|
|
3142
|
+
margin: 12px;
|
|
3143
|
+
}
|
|
3144
|
+
|
|
3141
3145
|
.scalar-app .m-auto {
|
|
3142
3146
|
margin: auto;
|
|
3143
3147
|
}
|
|
@@ -4153,6 +4157,10 @@ code.property-detail-value[data-v-8b57daa7] {
|
|
|
4153
4157
|
resize: none;
|
|
4154
4158
|
}
|
|
4155
4159
|
|
|
4160
|
+
.scalar-app .resize-y {
|
|
4161
|
+
resize: vertical;
|
|
4162
|
+
}
|
|
4163
|
+
|
|
4156
4164
|
.scalar-app .scroll-mt-24 {
|
|
4157
4165
|
scroll-margin-top: 96px;
|
|
4158
4166
|
}
|
|
@@ -7761,20 +7769,20 @@ to {
|
|
|
7761
7769
|
background: color-mix(in srgb, var(--scalar-background-3), transparent 40%);
|
|
7762
7770
|
}
|
|
7763
7771
|
|
|
7764
|
-
[data-v-
|
|
7772
|
+
[data-v-321c6212] .code-input-lite__editor {
|
|
7765
7773
|
background-color: transparent;
|
|
7766
7774
|
font-family: var(--scalar-font);
|
|
7767
7775
|
font-size: var(--scalar-small);
|
|
7768
7776
|
padding: 5px 8px;
|
|
7769
7777
|
}
|
|
7770
|
-
[data-v-
|
|
7778
|
+
[data-v-321c6212] .scalar-pill:not(:last-of-type) {
|
|
7771
7779
|
margin-right: 0.15em;
|
|
7772
7780
|
}
|
|
7773
|
-
[data-v-
|
|
7781
|
+
[data-v-321c6212] .scalar-pill:not(:first-of-type) {
|
|
7774
7782
|
margin-left: 0.5px;
|
|
7775
7783
|
}
|
|
7776
7784
|
|
|
7777
|
-
[data-v-
|
|
7785
|
+
[data-v-b8f0fb41] .cm-content {
|
|
7778
7786
|
font-size: var(--scalar-small);
|
|
7779
7787
|
}
|
|
7780
7788
|
|
|
@@ -36,7 +36,7 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
|
|
|
36
36
|
meta: import("@scalar/workspace-store/events").OperationExampleMeta;
|
|
37
37
|
}, "payload" | "contentType">) => any;
|
|
38
38
|
"update:value": (payload: Pick<{
|
|
39
|
-
payload: string | File | undefined;
|
|
39
|
+
payload: string | File | unknown[] | Record<string, unknown> | undefined;
|
|
40
40
|
contentType: string;
|
|
41
41
|
meta: import("@scalar/workspace-store/events").OperationExampleMeta;
|
|
42
42
|
}, "payload" | "contentType">) => any;
|
|
@@ -62,7 +62,7 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
|
|
|
62
62
|
meta: import("@scalar/workspace-store/events").OperationExampleMeta;
|
|
63
63
|
}, "payload" | "contentType">) => any) | undefined;
|
|
64
64
|
"onUpdate:value"?: ((payload: Pick<{
|
|
65
|
-
payload: string | File | undefined;
|
|
65
|
+
payload: string | File | unknown[] | Record<string, unknown> | undefined;
|
|
66
66
|
contentType: string;
|
|
67
67
|
meta: import("@scalar/workspace-store/events").OperationExampleMeta;
|
|
68
68
|
}, "payload" | "contentType">) => any) | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestBody.vue.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/request-block/components/RequestBody.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RequestBody.vue.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/request-block/components/RequestBody.vue"],"names":[],"mappings":"AAovBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2EAA2E,CAAA;AACnH,OAAO,KAAK,EAEV,iBAAiB,EAElB,MAAM,8DAA8D,CAAA;AA4BrE,KAAK,WAAW,GAAG;IACjB,mBAAmB;IACnB,WAAW,CAAC,EAAE,iBAAiB,CAAA;IAC/B,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAA;IAClB,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,2BAA2B;IAC3B,WAAW,EAAE,kBAAkB,CAAA;IAC/B,+DAA+D;IAC/D,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,sEAAsE;IACtE,+BAA+B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxD;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;CAC7B,CAAC;AA4kCF,QAAA,MAAM,YAAY;;qBA/jCqB,MAAM;;;;;;;+BA7F7C,CA5Y4B;mBA4Y5B,CA5Y2D;;;;;;;;;;;eA0eb,MAAM;;;qBAuBF,MAAM;;;;qBAxBjB,MAAM;;;;;;;+BA7F7C,CA5Y4B;mBA4Y5B,CA5Y2D;;;;;;;;;;;eA0eb,MAAM;;;qBAuBF,MAAM;;kFA0iCtD,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -2,7 +2,7 @@ import _plugin_vue_export_helper_default from "../../../../_virtual/_plugin-vue_
|
|
|
2
2
|
import RequestBody_vue_vue_type_script_setup_true_lang_default from "./RequestBody.vue_vue_type_script_setup_true_lang.js";
|
|
3
3
|
/* empty css */
|
|
4
4
|
//#region src/v2/blocks/request-block/components/RequestBody.vue
|
|
5
|
-
var RequestBody_default = /*#__PURE__*/ _plugin_vue_export_helper_default(RequestBody_vue_vue_type_script_setup_true_lang_default, [["__scopeId", "data-v-
|
|
5
|
+
var RequestBody_default = /*#__PURE__*/ _plugin_vue_export_helper_default(RequestBody_vue_vue_type_script_setup_true_lang_default, [["__scopeId", "data-v-b8f0fb41"]]);
|
|
6
6
|
//#endregion
|
|
7
7
|
export { RequestBody_default as default };
|
|
8
8
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestBody.vue.js","names":["_sfc_main"],"sources":["../../../../../src/v2/blocks/request-block/components/RequestBody.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { Schema } from '@scalar/blocks/schema'\nimport { ScalarButton } from '@scalar/components/button'\nimport { ScalarCodeBlockCopy } from '@scalar/components/code-block'\nimport { ScalarCopyBackdrop } from '@scalar/components/copy'\nimport { ScalarIcon } from '@scalar/components/icon'\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { ScalarListbox } from '@scalar/components/listbox'\nimport { CONTENT_TYPES } from '@scalar/helpers/http/content-types'\nimport { isXmlMediaType } from '@scalar/helpers/http/is-xml-media-type'\nimport { parseMimeType } from '@scalar/helpers/http/mime-type'\nimport { isObject } from '@scalar/helpers/object/is-object'\nimport { objectEntries } from '@scalar/helpers/object/object-entries'\nimport {\n ScalarIconArrowCounterClockwise,\n ScalarIconMagicWand,\n} from '@scalar/icons'\nimport type { ApiReferenceEvents } from '@scalar/workspace-store/events'\nimport {\n getExampleValue,\n getExplicitExampleText,\n} from '@scalar/workspace-store/helpers/get-example-value'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n getExampleFromBody,\n getSchemaExampleFromBody,\n getSelectedBodyContentType,\n} from '@scalar/workspace-store/request-example'\nimport { resolve } from '@scalar/workspace-store/resolve'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport type {\n RequestBodyObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { isObjectSchema } from '@scalar/workspace-store/schemas/v3.2/strict/type-guards'\nimport { computed, ref, watch } from 'vue'\n\nimport { useFileDialog } from '@/hooks/use-file-dialog'\nimport RequestBodyForm from '@/v2/blocks/request-block/components/RequestBodyForm.vue'\nimport RequestBodyStructured from '@/v2/blocks/request-block/components/RequestBodyStructured.vue'\nimport RequestBodyViewToggle from '@/v2/blocks/request-block/components/RequestBodyViewToggle.vue'\nimport { getFileName } from '@/v2/blocks/request-block/helpers/files'\nimport {\n getFormBodyRows,\n getFormBodyValue,\n} from '@/v2/blocks/request-block/helpers/get-form-body-rows'\nimport { getStructuredBodyCodec } from '@/v2/blocks/request-block/helpers/structured-body-codec'\nimport { CodeInput } from '@/v2/components/code-input'\nimport {\n DataTable,\n DataTableHeader,\n DataTableRow,\n} from '@/v2/components/data-table'\nimport { CollapsibleSection } from '@/v2/components/layout'\nimport { useLocalization } from '@/v2/features/localization'\n\nconst {\n requestBody,\n exampleKey,\n environment,\n requestBodyCompositionSelection,\n openapiVersion,\n title,\n defaultView = 'raw',\n} = defineProps<{\n /** Request body */\n requestBody?: RequestBodyObject\n /** Currently selected example key for the current operation */\n exampleKey: string\n /** Display title */\n title: string\n /** Selected environment */\n environment: XScalarEnvironment\n /** Originating OpenAPI version, used for XML mapping rules. */\n openapiVersion?: string\n /** Selected anyOf/oneOf request-body variants keyed by schema path */\n requestBodyCompositionSelection?: Record<string, number>\n /**\n * Initial view for structured (JSON/YAML) bodies. Comes from the\n * `x-scalar-default-request-body-view` document extension and falls back to `raw`\n * whenever the body cannot be shown as a form.\n */\n defaultView?: 'form' | 'raw'\n}>()\n\nconst emits = defineEmits<{\n (e: 'reset', payload: { contentType: string }): void\n (e: 'update:contentType', payload: { value: string }): void\n /** We use this event to update raw values */\n (\n e: 'update:value',\n payload: Pick<\n ApiReferenceEvents['operation:update:requestBody:value'],\n 'payload' | 'contentType'\n >,\n ): void\n /** We use this event when updating form data only */\n (\n e: 'update:formValue',\n payload: Pick<\n ApiReferenceEvents['operation:update:requestBody:formValue'],\n 'payload' | 'contentType'\n >,\n ): void\n /**\n * Create a new example seeded with values generated from the request body schema.\n *\n * The block itself owns the document and operation identity needed to create an example, so we\n * only report the content type the user is currently looking at.\n */\n (e: 'generate:example', payload: { contentType: string }): void\n}>()\n\nconst { translate } = useLocalization()\n\n// Map a content type to a language for the code editor\nconst contentTypeToLanguageMap = {\n 'application/json': 'json',\n 'application/xml': 'xml',\n 'application/yaml': 'yaml',\n} as const\n\n/** Selected content type with default */\nconst selectedContentType = computed(\n () => getSelectedBodyContentType(requestBody, exampleKey) ?? 'none',\n)\n\n/** Keep the editor and copy label aligned with the selected content type. */\nconst selectedLanguage = computed(() =>\n isXmlMediaType(selectedContentType.value)\n ? 'xml'\n : (contentTypeToLanguageMap[\n selectedContentType.value as keyof typeof contentTypeToLanguageMap\n ] ?? 'plaintext'),\n)\n\n/**\n * Strips MIME parameters (such as `charset=utf-8`) for dropdown labels, aligned with how we treat\n * media types elsewhere (see api-reference `normalizeMimeType` / WHATWG essence).\n */\nconst contentTypeLabel = (raw: string): string => parseMimeType(raw).essence\n\n/**\n * Build the dropdown options for the content type selector.\n *\n * The list is composed of two groups:\n * 1. The built-in content types we ship friendly labels for (JSON, XML, Multipart Form, etc.).\n * 2. Any additional content types defined on the OpenAPI request body that are not in the built-in list\n * (for example `text/csv`, `application/pdf`, vendor types like `application/vnd.api+json`, ...).\n *\n * The OpenAPI-defined extras are appended at the bottom so the well-known options stay on top, and\n * users can always pick the exact content type the operation actually accepts.\n */\n/** MIME values remain stable while their human-readable labels follow the locale. */\nconst localizedContentTypes = computed(() => ({\n ...CONTENT_TYPES,\n 'multipart/form-data': translate('apiClient.requestBody.multipartForm'),\n 'application/x-www-form-urlencoded': translate(\n 'apiClient.requestBody.formUrlEncoded',\n ),\n 'application/octet-stream': translate('apiClient.requestBody.binaryFile'),\n 'other': translate('apiClient.requestBody.other'),\n 'none': translate('apiClient.requestBody.none'),\n}))\n\nconst contentTypeOptions = computed<{ id: string; label: string }[]>(() => {\n const builtIn = objectEntries(localizedContentTypes.value).map(\n ([id, label]) => ({\n id,\n label,\n }),\n )\n\n const extras = Object.keys(requestBody?.content ?? {})\n .filter((type) => {\n if (type in CONTENT_TYPES) {\n return false\n }\n // Same essence as a built-in (e.g. `application/json; charset=utf-8`) — do not duplicate the row.\n return !(contentTypeLabel(type) in CONTENT_TYPES)\n })\n .map((type) => ({ id: type, label: contentTypeLabel(type) }))\n\n return [...builtIn, ...extras]\n})\n\nconst selectedContentTypeModel = computed<{ id: string; label: string }>({\n get: () => {\n const found = contentTypeOptions.value.find(\n (it) => it.id === selectedContentType.value,\n )\n if (found) {\n return found\n }\n\n const essence = contentTypeLabel(selectedContentType.value)\n const friendly =\n localizedContentTypes.value[essence as keyof typeof CONTENT_TYPES] ??\n essence\n\n return {\n id: selectedContentType.value,\n label: friendly,\n }\n },\n set: (v) => {\n emits('update:contentType', { value: v.id })\n },\n})\n\nfunction handleFileUpload(callback: (file: File) => void) {\n const { open } = useFileDialog({\n onChange: (files) => {\n const file = files?.[0]\n if (file) {\n callback(file)\n }\n },\n multiple: false,\n accept: '*/*',\n })\n void open()\n}\n\n/** Dereferenced example */\nconst example = computed(\n () =>\n requestBody &&\n getExampleFromBody(\n requestBody,\n selectedContentType.value,\n exampleKey,\n requestBodyCompositionSelection,\n openapiVersion,\n ),\n)\n\n/** Convert the example value to a string for the code editor */\nconst bodyValue = computed(() => {\n if (!example.value) {\n return ''\n }\n\n const selected = getExampleValue(example.value)\n const explicitText = getExplicitExampleText(\n selected,\n selectedContentType.value,\n 2,\n )\n if (explicitText !== undefined) {\n return explicitText\n }\n const value = selected?.value\n if (typeof value === 'string') {\n return value\n }\n\n return JSON.stringify(value, null, 2)\n})\n\n/** Resolved schema for the request body */\nconst bodySchema = computed<SchemaObject | undefined>(() => {\n return resolve.schema(\n requestBody?.content?.[selectedContentType.value]?.schema ??\n requestBody?.content?.[selectedContentType.value]?.itemSchema,\n )\n})\n\n/** Codec for structured (JSON/YAML) bodies, undefined for everything else */\nconst structuredCodec = computed(() =>\n selectedContentType.value === 'none'\n ? undefined\n : getStructuredBodyCodec(selectedContentType.value),\n)\n\n/** Parsed body value for the form view — `ok: false` when the raw text is not parseable */\nconst parsedBody = computed<{ ok: boolean; value?: unknown }>(() => {\n const codec = structuredCodec.value\n if (!codec) {\n return { ok: false }\n }\n\n const selected = getExampleValue(example.value ?? undefined)\n // Structured data is already parsed; parsing strings again changes the payload type.\n if (example.value?.dataValue !== undefined) {\n return { ok: true, value: example.value.dataValue }\n }\n const raw = selected?.value\n // An empty body is still form-editable: rows come from the schema.\n if (raw === undefined || raw === null || raw === '') {\n return { ok: true, value: {} }\n }\n if (typeof raw === 'string') {\n try {\n return { ok: true, value: codec.parse(raw) }\n } catch {\n return { ok: false }\n }\n }\n // Spec-provided examples can be stored as objects directly.\n return { ok: true, value: raw }\n})\n\n/**\n * An edited example normally takes precedence over schema-generated data. When a different\n * composition branch is selected, however, keeping that example leaves the editor showing the\n * previous branch. Track the selection itself instead of inspecting discriminator fields so this\n * also works for compositions whose members are distinguished only by their shape.\n */\nconst compositionSelectionKey = computed(() =>\n JSON.stringify(requestBodyCompositionSelection ?? {}),\n)\n\n// Switching operations changes the body (and often the selection) at once, which is not a branch\n// change, so we only regenerate the body when the selection changes while the operation and example\n// stay the same. Watching all three together and comparing against the watcher's own previous values\n// keeps this correct regardless of the order in which props update or watchers flush.\nwatch(\n [() => requestBody, () => exampleKey, compositionSelectionKey],\n (\n [, , selection],\n [previousRequestBody, previousExampleKey, previousSelection],\n ) => {\n const operationChanged =\n requestBody !== previousRequestBody || exampleKey !== previousExampleKey\n const selectionChanged = selection !== previousSelection\n\n // Going from no selection to a populated one is the modal applying the reference's selection as\n // the panel opens, not the user switching branches. Resetting here would discard the body's named\n // example on the very first open (issue #10075), so only a change between two populated selections\n // counts as a real branch switch.\n const hadNoPreviousSelection = previousSelection === '{}'\n\n // Only a genuine branch switch within the same operation should reset the edited body. An empty\n // selection means there is no composition to switch between (or the selection was cleared on an\n // operation change), so there is nothing to reset.\n if (\n operationChanged ||\n !selectionChanged ||\n hadNoPreviousSelection ||\n Object.keys(requestBodyCompositionSelection ?? {}).length === 0\n ) {\n return\n }\n\n const codec = structuredCodec.value\n const isXml = isXmlMediaType(selectedContentType.value)\n const isForm =\n selectedContentType.value === 'multipart/form-data' ||\n selectedContentType.value === 'application/x-www-form-urlencoded'\n if (!requestBody || (!codec && !isXml && !isForm)) {\n return\n }\n\n // Regenerate through the same helper the initial example uses so a reset produces exactly the\n // value a fresh render of this branch would, rather than a hand-copied second code path.\n const selectedValue = getSchemaExampleFromBody(\n requestBody,\n selectedContentType.value,\n requestBodyCompositionSelection,\n openapiVersion,\n )\n\n if (isForm) {\n const rows = getFormBodyRows(\n { value: selectedValue },\n selectedContentType.value,\n bodySchema.value,\n requestBodyCompositionSelection,\n )\n emits('update:formValue', {\n contentType: selectedContentType.value,\n payload: rows.map((row) => ({\n name: row.name,\n value:\n selectedContentType.value === 'multipart/form-data'\n ? getFormBodyValue(row)\n : (row.value ?? undefined),\n isDisabled: row.isDisabled ?? false,\n ...(row.isDisabledByDefault ? { isDisabledByDefault: true } : {}),\n ...(row.isArray ? { isArray: true } : {}),\n })),\n })\n return\n }\n\n // A branch with no writable content clears the editor instead of writing null.\n let payload = ''\n if (selectedValue != null) {\n payload = isXml ? String(selectedValue) : codec!.stringify(selectedValue)\n }\n emits('update:value', {\n payload,\n contentType: selectedContentType.value,\n })\n },\n)\n\n/** The form view only works on an object-shaped body root */\nconst isFormViewAvailable = computed(\n () => parsedBody.value.ok && isObject(parsedBody.value.value),\n)\n\n/**\n * Show the Form/Raw toggle for structured bodies that are (or per schema should be)\n * an object at the root. Non-object roots (arrays, primitives) stay raw-only.\n */\nconst showBodyViewToggle = computed(\n () =>\n Boolean(structuredCodec.value) &&\n (isFormViewAvailable.value ||\n Boolean(bodySchema.value && isObjectSchema(bodySchema.value))),\n)\n\n/** Selected body view, seeded from the document default (raw unless configured) */\nconst bodyView = ref<'form' | 'raw' | 'schema'>(defaultView)\n\n/** Schema inspection is available for every media type with a schema, independently of its example. */\nconst isSchemaViewAvailable = computed(\n () => selectedContentType.value !== 'none' && bodySchema.value !== undefined,\n)\n\n// A different operation must start a fresh tree, including its expansion and composition state.\nwatch(\n () => requestBody,\n () => {\n if (bodyView.value === 'schema') {\n bodyView.value = isFormViewAvailable.value ? defaultView : 'raw'\n }\n },\n)\n\nwatch(isSchemaViewAvailable, (available) => {\n if (!available && bodyView.value === 'schema') {\n bodyView.value = 'raw'\n }\n})\n\n// Fall back to raw when the form view stops being available (e.g. the content type\n// changed to a non-structured one, or an external edit made the body unparseable).\nwatch(\n isFormViewAvailable,\n (ok) => {\n if (!ok && bodyView.value === 'form') {\n bodyView.value = 'raw'\n }\n },\n { immediate: true },\n)\n\n/**\n * Whether we can offer to generate a fresh example from the schema.\n *\n * Only structured (JSON/YAML) bodies qualify: they have a schema to generate from and a text\n * representation we can seed the new example with. Binary and form bodies have their own editors,\n * so the button would have nothing meaningful to write.\n */\nconst canGenerateExample = computed(() =>\n Boolean(structuredCodec.value && bodySchema.value),\n)\n</script>\n<template>\n <CollapsibleSection>\n <template #title>{{ title }}</template>\n <DataTable\n :columns=\"['']\"\n presentational>\n <DataTableHeader\n class=\"relative col-span-full flex h-8 cursor-pointer items-center justify-between border-r-0 !p-0\">\n <ScalarListbox\n v-model=\"selectedContentTypeModel\"\n :options=\"contentTypeOptions\"\n teleport>\n <ScalarButton\n class=\"text-c-2 hover:text-c-1 flex h-full w-fit gap-1.5 px-3 font-normal\"\n fullWidth\n variant=\"ghost\">\n <span>{{ selectedContentTypeModel.label }}</span>\n <ScalarIcon\n icon=\"ChevronDown\"\n size=\"md\" />\n </ScalarButton>\n </ScalarListbox>\n <div class=\"flex items-center gap-1\">\n <ScalarIconButton\n v-if=\"selectedContentType !== 'none'\"\n :aria-label=\"translate('apiClient.requestBody.restoreOriginalBody')\"\n :icon=\"ScalarIconArrowCounterClockwise\"\n :label=\"translate('apiClient.requestBody.restoreOriginalBody')\"\n size=\"sm\"\n tooltip\n @click.stop=\"\n emits('reset', { contentType: selectedContentType })\n \" />\n <!--\n Generates a new example from the schema so the auto-generated fields stay reachable\n even once the document ships custom examples.\n -->\n <ScalarIconButton\n v-if=\"canGenerateExample\"\n :aria-label=\"\n translate('apiClient.requestBody.createExampleFromSchema')\n \"\n :icon=\"ScalarIconMagicWand\"\n :label=\"translate('apiClient.requestBody.createExampleFromSchema')\"\n size=\"sm\"\n tooltip\n @click.stop=\"\n emits('generate:example', { contentType: selectedContentType })\n \" />\n <RequestBodyViewToggle\n v-if=\"showBodyViewToggle || isSchemaViewAvailable\"\n :disabled=\"!isFormViewAvailable\"\n :modelValue=\"bodyView\"\n :rawLabel=\"\n structuredCodec\n ? undefined\n : translate('apiClient.requestBodyStructured.body')\n \"\n :showForm=\"showBodyViewToggle\"\n :showSchema=\"isSchemaViewAvailable\"\n @update:modelValue=\"(v) => (bodyView = v)\" />\n </div>\n </DataTableHeader>\n <DataTableRow>\n <!-- Inspecting the schema never changes the selected example or request payload. -->\n <div\n v-if=\"bodyView === 'schema' && isSchemaViewAvailable\"\n class=\"min-w-0 border-t py-3 ps-10 pe-6\">\n <Schema\n :key=\"selectedContentType\"\n :eventBus=\"null\"\n :options=\"{\n hideReadOnly: true,\n hideModels: true,\n schemaKeyboardNav: true,\n }\"\n :schema=\"bodySchema\" />\n </div>\n\n <!-- No Body -->\n <template v-else-if=\"selectedContentType === 'none'\">\n <div\n class=\"text-c-3 flex min-h-10 w-full items-center justify-center border-t p-2 text-sm\">\n <span>{{ translate('apiClient.requestBody.noBody') }}</span>\n </div>\n </template>\n\n <!-- Binary File -->\n <template\n v-else-if=\"selectedContentType === 'application/octet-stream'\">\n <div\n class=\"flex items-center justify-center overflow-hidden border-t p-1.5\">\n <template\n v-if=\"\n getFileName(unpackProxyObject(example?.value)) !== undefined\n \">\n <span\n class=\"text-c-2 w-full max-w-full overflow-hidden rounded border px-1.5 py-1 text-xs whitespace-nowrap\">\n {{ getFileName(unpackProxyObject(example?.value)) }}\n </span>\n <ScalarButton\n class=\"bg-b-2 hover:bg-b-3 text-c-2 ml-1 border-0 shadow-none\"\n size=\"sm\"\n variant=\"outlined\"\n @click=\"\n emits('update:value', {\n payload: undefined,\n contentType: selectedContentType,\n })\n \">\n {{ translate('apiClient.requestBody.delete') }}\n </ScalarButton>\n </template>\n <template v-else>\n <ScalarButton\n class=\"bg-b-2 hover:bg-b-3 text-c-2 border-0 shadow-none\"\n size=\"sm\"\n variant=\"outlined\"\n @click=\"\n () =>\n handleFileUpload((file) =>\n emits('update:value', {\n payload: file,\n contentType: selectedContentType,\n }),\n )\n \">\n <span>{{ translate('apiClient.requestBody.selectFile') }}</span>\n <ScalarIcon\n class=\"ml-1\"\n icon=\"Upload\"\n size=\"xs\"\n thickness=\"2.5\" />\n </ScalarButton>\n </template>\n </div>\n </template>\n\n <!-- Form Data / URL Encoded -->\n <template\n v-else-if=\"\n selectedContentType === 'multipart/form-data' ||\n selectedContentType === 'application/x-www-form-urlencoded'\n \">\n <RequestBodyForm\n :bodySchema\n :compositionSelection=\"requestBodyCompositionSelection\"\n :environment\n :example\n :selectedContentType\n @update:formValue=\"\n (payload) =>\n emits('update:formValue', {\n payload,\n contentType: selectedContentType,\n })\n \" />\n </template>\n\n <!-- Code/Other -->\n <template v-else>\n <!-- Schema-driven form view for structured (JSON/YAML) bodies -->\n <RequestBodyStructured\n v-if=\"bodyView === 'form' && isFormViewAvailable\"\n :bodySchema\n :contentType=\"selectedContentType\"\n :environment\n :parsedValue=\"parsedBody.value\"\n @update:value=\"\n (value) =>\n emits('update:value', {\n payload: value,\n contentType: selectedContentType,\n })\n \" />\n <!-- Editable raw body with a copy button revealed on hover/focus -->\n <div\n v-else\n class=\"group/code-block relative min-w-0 border-t\">\n <CodeInput\n class=\"px-3\"\n content=\"\"\n :environment=\"environment\"\n :language=\"selectedLanguage\"\n lineNumbers\n lint\n :modelValue=\"bodyValue\"\n withFakeData\n @update:modelValue=\"\n (value) =>\n emits('update:value', {\n payload: value,\n contentType: selectedContentType,\n })\n \" />\n <ScalarCodeBlockCopy\n v-if=\"bodyValue\"\n class=\"absolute top-1.5 right-1.5\"\n :content=\"bodyValue\"\n :lang=\"selectedLanguage\"\n showLang>\n <template #backdrop>\n <ScalarCopyBackdrop class=\"-top-1 -right-1.5\" />\n </template>\n </ScalarCodeBlockCopy>\n </div>\n </template>\n </DataTableRow>\n </DataTable>\n </CollapsibleSection>\n</template>\n<style scoped>\n:deep(.cm-content) {\n font-size: var(--scalar-small);\n}\n</style>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"RequestBody.vue.js","names":["_sfc_main"],"sources":["../../../../../src/v2/blocks/request-block/components/RequestBody.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { Schema } from '@scalar/blocks/schema'\nimport { ScalarButton } from '@scalar/components/button'\nimport { ScalarCodeBlockCopy } from '@scalar/components/code-block'\nimport { ScalarCopyBackdrop } from '@scalar/components/copy'\nimport { ScalarIcon } from '@scalar/components/icon'\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { ScalarListbox } from '@scalar/components/listbox'\nimport { CONTENT_TYPES } from '@scalar/helpers/http/content-types'\nimport { isXmlMediaType } from '@scalar/helpers/http/is-xml-media-type'\nimport { parseMimeType } from '@scalar/helpers/http/mime-type'\nimport { isObject } from '@scalar/helpers/object/is-object'\nimport { objectEntries } from '@scalar/helpers/object/object-entries'\nimport {\n ScalarIconArrowCounterClockwise,\n ScalarIconMagicWand,\n} from '@scalar/icons'\nimport type { ApiReferenceEvents } from '@scalar/workspace-store/events'\nimport {\n getExampleValue,\n getExplicitExampleText,\n} from '@scalar/workspace-store/helpers/get-example-value'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n getExampleFromBody,\n getSchemaExampleFromBody,\n getSelectedBodyContentType,\n} from '@scalar/workspace-store/request-example'\nimport { resolve } from '@scalar/workspace-store/resolve'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport type {\n MediaTypeObject,\n RequestBodyObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { isObjectSchema } from '@scalar/workspace-store/schemas/v3.2/strict/type-guards'\nimport { computed, ref, watch } from 'vue'\n\nimport { useFileDialog } from '@/hooks/use-file-dialog'\nimport RequestBodyForm from '@/v2/blocks/request-block/components/RequestBodyForm.vue'\nimport RequestBodyMultipart from '@/v2/blocks/request-block/components/RequestBodyMultipart.vue'\nimport RequestBodyStructured from '@/v2/blocks/request-block/components/RequestBodyStructured.vue'\nimport RequestBodyViewToggle from '@/v2/blocks/request-block/components/RequestBodyViewToggle.vue'\nimport { getFileName } from '@/v2/blocks/request-block/helpers/files'\nimport {\n getFormBodyRows,\n getFormBodyValue,\n} from '@/v2/blocks/request-block/helpers/get-form-body-rows'\nimport {\n parseMultipartBody,\n type MultipartBodyValue,\n} from '@/v2/blocks/request-block/helpers/multipart-body'\nimport { getStructuredBodyCodec } from '@/v2/blocks/request-block/helpers/structured-body-codec'\nimport { CodeInput } from '@/v2/components/code-input'\nimport {\n DataTable,\n DataTableHeader,\n DataTableRow,\n} from '@/v2/components/data-table'\nimport { CollapsibleSection } from '@/v2/components/layout'\nimport { useLocalization } from '@/v2/features/localization'\n\nconst {\n requestBody,\n exampleKey,\n environment,\n requestBodyCompositionSelection,\n openapiVersion,\n title,\n defaultView = 'raw',\n} = defineProps<{\n /** Request body */\n requestBody?: RequestBodyObject\n /** Currently selected example key for the current operation */\n exampleKey: string\n /** Display title */\n title: string\n /** Selected environment */\n environment: XScalarEnvironment\n /** Originating OpenAPI version, used for XML mapping rules. */\n openapiVersion?: string\n /** Selected anyOf/oneOf request-body variants keyed by schema path */\n requestBodyCompositionSelection?: Record<string, number>\n /**\n * Initial view for structured (JSON/YAML) bodies. Comes from the\n * `x-scalar-default-request-body-view` document extension and falls back to `raw`\n * whenever the body cannot be shown as a form.\n */\n defaultView?: 'form' | 'raw'\n}>()\n\nconst emits = defineEmits<{\n (e: 'reset', payload: { contentType: string }): void\n (e: 'update:contentType', payload: { value: string }): void\n /** We use this event to update raw values */\n (\n e: 'update:value',\n payload: Pick<\n ApiReferenceEvents['operation:update:requestBody:value'],\n 'payload' | 'contentType'\n >,\n ): void\n /** We use this event when updating form data only */\n (\n e: 'update:formValue',\n payload: Pick<\n ApiReferenceEvents['operation:update:requestBody:formValue'],\n 'payload' | 'contentType'\n >,\n ): void\n /**\n * Create a new example seeded with values generated from the request body schema.\n *\n * The block itself owns the document and operation identity needed to create an example, so we\n * only report the content type the user is currently looking at.\n */\n (e: 'generate:example', payload: { contentType: string }): void\n}>()\n\nconst { translate } = useLocalization()\n\n// Map a content type to a language for the code editor\nconst contentTypeToLanguageMap = {\n 'application/json': 'json',\n 'application/xml': 'xml',\n 'application/yaml': 'yaml',\n} as const\n\n/** Selected content type with default */\nconst selectedContentType = computed(\n () => getSelectedBodyContentType(requestBody, exampleKey) ?? 'none',\n)\n\n/** Keep the editor and copy label aligned with the selected content type. */\nconst selectedLanguage = computed(() =>\n isXmlMediaType(selectedContentType.value)\n ? 'xml'\n : (contentTypeToLanguageMap[\n selectedContentType.value as keyof typeof contentTypeToLanguageMap\n ] ?? 'plaintext'),\n)\n\n/**\n * Strips MIME parameters (such as `charset=utf-8`) for dropdown labels, aligned with how we treat\n * media types elsewhere (see api-reference `normalizeMimeType` / WHATWG essence).\n */\nconst contentTypeLabel = (raw: string): string => parseMimeType(raw).essence\n\n/**\n * Build the dropdown options for the content type selector.\n *\n * The list is composed of two groups:\n * 1. The built-in content types we ship friendly labels for (JSON, XML, Multipart Form, etc.).\n * 2. Any additional content types defined on the OpenAPI request body that are not in the built-in list\n * (for example `text/csv`, `application/pdf`, vendor types like `application/vnd.api+json`, ...).\n *\n * The OpenAPI-defined extras are appended at the bottom so the well-known options stay on top, and\n * users can always pick the exact content type the operation actually accepts.\n */\n/** MIME values remain stable while their human-readable labels follow the locale. */\nconst localizedContentTypes = computed(() => ({\n ...CONTENT_TYPES,\n 'multipart/form-data': translate('apiClient.requestBody.multipartForm'),\n 'application/x-www-form-urlencoded': translate(\n 'apiClient.requestBody.formUrlEncoded',\n ),\n 'application/octet-stream': translate('apiClient.requestBody.binaryFile'),\n 'other': translate('apiClient.requestBody.other'),\n 'none': translate('apiClient.requestBody.none'),\n}))\n\nconst contentTypeOptions = computed<{ id: string; label: string }[]>(() => {\n const builtIn = objectEntries(localizedContentTypes.value).map(\n ([id, label]) => ({\n id,\n label,\n }),\n )\n\n const extras = Object.keys(requestBody?.content ?? {})\n .filter((type) => {\n if (type in CONTENT_TYPES) {\n return false\n }\n // Same essence as a built-in (e.g. `application/json; charset=utf-8`) — do not duplicate the row.\n return !(contentTypeLabel(type) in CONTENT_TYPES)\n })\n .map((type) => ({ id: type, label: contentTypeLabel(type) }))\n\n return [...builtIn, ...extras]\n})\n\nconst selectedContentTypeModel = computed<{ id: string; label: string }>({\n get: () => {\n const found = contentTypeOptions.value.find(\n (it) => it.id === selectedContentType.value,\n )\n if (found) {\n return found\n }\n\n const essence = contentTypeLabel(selectedContentType.value)\n const friendly =\n localizedContentTypes.value[essence as keyof typeof CONTENT_TYPES] ??\n essence\n\n return {\n id: selectedContentType.value,\n label: friendly,\n }\n },\n set: (v) => {\n emits('update:contentType', { value: v.id })\n },\n})\n\nfunction handleFileUpload(callback: (file: File) => void) {\n const { open } = useFileDialog({\n onChange: (files) => {\n const file = files?.[0]\n if (file) {\n callback(file)\n }\n },\n multiple: false,\n accept: '*/*',\n })\n void open()\n}\n\n/** Dereferenced example */\nconst example = computed(\n () =>\n requestBody &&\n getExampleFromBody(\n requestBody,\n selectedContentType.value,\n exampleKey,\n requestBodyCompositionSelection,\n openapiVersion,\n ),\n)\n\n/** Convert the example value to a string for the code editor */\nconst bodyValue = computed(() => {\n if (!example.value) {\n return ''\n }\n\n const selected = getExampleValue(example.value)\n const explicitText = getExplicitExampleText(\n selected,\n selectedContentType.value,\n 2,\n )\n if (explicitText !== undefined) {\n return explicitText\n }\n const value = selected?.value\n if (typeof value === 'string') {\n return value\n }\n\n return JSON.stringify(value, null, 2)\n})\n\n/** Resolved schema for the request body */\nconst bodySchema = computed<SchemaObject | undefined>(() => {\n return resolve.schema(\n requestBody?.content?.[selectedContentType.value]?.schema ??\n requestBody?.content?.[selectedContentType.value]?.itemSchema,\n )\n})\n\n/** Mixed and related bodies keep their ordered parts instead of named form-data rows. */\nconst multipartBody = computed<\n { media: MediaTypeObject; value: MultipartBodyValue } | undefined\n>(() => {\n const essence = parseMimeType(selectedContentType.value).essence\n if (essence !== 'multipart/mixed' && essence !== 'multipart/related') {\n return undefined\n }\n const media = requestBody?.content?.[selectedContentType.value]\n const value = parseMultipartBody(example.value)\n return media && value !== undefined ? { media, value } : undefined\n})\n\n/** Codec for structured (JSON/YAML) bodies, undefined for everything else */\nconst structuredCodec = computed(() =>\n selectedContentType.value === 'none'\n ? undefined\n : getStructuredBodyCodec(selectedContentType.value),\n)\n\n/** Parsed body value for the form view — `ok: false` when the raw text is not parseable */\nconst parsedBody = computed<{ ok: boolean; value?: unknown }>(() => {\n const codec = structuredCodec.value\n if (!codec) {\n return { ok: false }\n }\n\n const selected = getExampleValue(example.value ?? undefined)\n // Structured data is already parsed; parsing strings again changes the payload type.\n if (example.value?.dataValue !== undefined) {\n return { ok: true, value: example.value.dataValue }\n }\n const raw = selected?.value\n // An empty body is still form-editable: rows come from the schema.\n if (raw === undefined || raw === null || raw === '') {\n return { ok: true, value: {} }\n }\n if (typeof raw === 'string') {\n try {\n return { ok: true, value: codec.parse(raw) }\n } catch {\n return { ok: false }\n }\n }\n // Spec-provided examples can be stored as objects directly.\n return { ok: true, value: raw }\n})\n\n/**\n * An edited example normally takes precedence over schema-generated data. When a different\n * composition branch is selected, however, keeping that example leaves the editor showing the\n * previous branch. Track the selection itself instead of inspecting discriminator fields so this\n * also works for compositions whose members are distinguished only by their shape.\n */\nconst compositionSelectionKey = computed(() =>\n JSON.stringify(requestBodyCompositionSelection ?? {}),\n)\n\n// Switching operations changes the body (and often the selection) at once, which is not a branch\n// change, so we only regenerate the body when the selection changes while the operation and example\n// stay the same. Watching all three together and comparing against the watcher's own previous values\n// keeps this correct regardless of the order in which props update or watchers flush.\nwatch(\n [() => requestBody, () => exampleKey, compositionSelectionKey],\n (\n [, , selection],\n [previousRequestBody, previousExampleKey, previousSelection],\n ) => {\n const operationChanged =\n requestBody !== previousRequestBody || exampleKey !== previousExampleKey\n const selectionChanged = selection !== previousSelection\n\n // Going from no selection to a populated one is the modal applying the reference's selection as\n // the panel opens, not the user switching branches. Resetting here would discard the body's named\n // example on the very first open (issue #10075), so only a change between two populated selections\n // counts as a real branch switch.\n const hadNoPreviousSelection = previousSelection === '{}'\n\n // Only a genuine branch switch within the same operation should reset the edited body. An empty\n // selection means there is no composition to switch between (or the selection was cleared on an\n // operation change), so there is nothing to reset.\n if (\n operationChanged ||\n !selectionChanged ||\n hadNoPreviousSelection ||\n Object.keys(requestBodyCompositionSelection ?? {}).length === 0\n ) {\n return\n }\n\n const codec = structuredCodec.value\n const isXml = isXmlMediaType(selectedContentType.value)\n const isForm =\n selectedContentType.value === 'multipart/form-data' ||\n selectedContentType.value === 'application/x-www-form-urlencoded'\n const isMultipart = ['multipart/mixed', 'multipart/related'].includes(\n parseMimeType(selectedContentType.value).essence,\n )\n if (!requestBody || (!codec && !isXml && !isForm && !isMultipart)) {\n return\n }\n\n // Regenerate through the same helper the initial example uses so a reset produces exactly the\n // value a fresh render of this branch would, rather than a hand-copied second code path.\n const selectedValue = getSchemaExampleFromBody(\n requestBody,\n selectedContentType.value,\n requestBodyCompositionSelection,\n openapiVersion,\n )\n\n if (isForm) {\n const rows = getFormBodyRows(\n { value: selectedValue },\n selectedContentType.value,\n bodySchema.value,\n requestBodyCompositionSelection,\n )\n emits('update:formValue', {\n contentType: selectedContentType.value,\n payload: rows.map((row) => ({\n name: row.name,\n value:\n selectedContentType.value === 'multipart/form-data'\n ? getFormBodyValue(row)\n : (row.value ?? undefined),\n isDisabled: row.isDisabled ?? false,\n ...(row.isDisabledByDefault ? { isDisabledByDefault: true } : {}),\n ...(row.isArray ? { isArray: true } : {}),\n })),\n })\n return\n }\n\n if (isMultipart) {\n emits('update:value', {\n payload:\n Array.isArray(selectedValue) || isObject(selectedValue)\n ? selectedValue\n : '',\n contentType: selectedContentType.value,\n })\n return\n }\n\n // A branch with no writable content clears the editor instead of writing null.\n let payload = ''\n if (selectedValue != null) {\n payload = isXml ? String(selectedValue) : codec!.stringify(selectedValue)\n }\n emits('update:value', {\n payload,\n contentType: selectedContentType.value,\n })\n },\n)\n\n/** The form view only works on an object-shaped body root */\nconst isFormViewAvailable = computed(\n () => parsedBody.value.ok && isObject(parsedBody.value.value),\n)\n\n/**\n * Show the Form/Raw toggle for structured bodies that are (or per schema should be)\n * an object at the root. Non-object roots (arrays, primitives) stay raw-only.\n */\nconst showBodyViewToggle = computed(\n () =>\n Boolean(structuredCodec.value) &&\n (isFormViewAvailable.value ||\n Boolean(bodySchema.value && isObjectSchema(bodySchema.value))),\n)\n\n/** Selected body view, seeded from the document default (raw unless configured) */\nconst bodyView = ref<'form' | 'raw' | 'schema'>(defaultView)\n\n/** Schema inspection is available for every media type with a schema, independently of its example. */\nconst isSchemaViewAvailable = computed(\n () => selectedContentType.value !== 'none' && bodySchema.value !== undefined,\n)\n\n// A different operation must start a fresh tree, including its expansion and composition state.\nwatch(\n () => requestBody,\n () => {\n if (bodyView.value === 'schema') {\n bodyView.value = isFormViewAvailable.value ? defaultView : 'raw'\n }\n },\n)\n\nwatch(isSchemaViewAvailable, (available) => {\n if (!available && bodyView.value === 'schema') {\n bodyView.value = 'raw'\n }\n})\n\n// Fall back to raw when the form view stops being available (e.g. the content type\n// changed to a non-structured one, or an external edit made the body unparseable).\nwatch(\n isFormViewAvailable,\n (ok) => {\n if (!ok && bodyView.value === 'form') {\n bodyView.value = 'raw'\n }\n },\n { immediate: true },\n)\n\n/**\n * Whether we can offer to generate a fresh example from the schema.\n *\n * Only structured (JSON/YAML) bodies qualify: they have a schema to generate from and a text\n * representation we can seed the new example with. Binary and form bodies have their own editors,\n * so the button would have nothing meaningful to write.\n */\nconst canGenerateExample = computed(() =>\n Boolean(structuredCodec.value && bodySchema.value),\n)\n</script>\n<template>\n <CollapsibleSection>\n <template #title>{{ title }}</template>\n <DataTable\n :columns=\"['']\"\n presentational>\n <DataTableHeader\n class=\"relative col-span-full flex h-8 cursor-pointer items-center justify-between border-r-0 !p-0\">\n <ScalarListbox\n v-model=\"selectedContentTypeModel\"\n :options=\"contentTypeOptions\"\n teleport>\n <ScalarButton\n class=\"text-c-2 hover:text-c-1 flex h-full w-fit gap-1.5 px-3 font-normal\"\n fullWidth\n variant=\"ghost\">\n <span>{{ selectedContentTypeModel.label }}</span>\n <ScalarIcon\n icon=\"ChevronDown\"\n size=\"md\" />\n </ScalarButton>\n </ScalarListbox>\n <div class=\"flex items-center gap-1\">\n <ScalarIconButton\n v-if=\"selectedContentType !== 'none'\"\n :aria-label=\"translate('apiClient.requestBody.restoreOriginalBody')\"\n :icon=\"ScalarIconArrowCounterClockwise\"\n :label=\"translate('apiClient.requestBody.restoreOriginalBody')\"\n size=\"sm\"\n tooltip\n @click.stop=\"\n emits('reset', { contentType: selectedContentType })\n \" />\n <!--\n Generates a new example from the schema so the auto-generated fields stay reachable\n even once the document ships custom examples.\n -->\n <ScalarIconButton\n v-if=\"canGenerateExample\"\n :aria-label=\"\n translate('apiClient.requestBody.createExampleFromSchema')\n \"\n :icon=\"ScalarIconMagicWand\"\n :label=\"translate('apiClient.requestBody.createExampleFromSchema')\"\n size=\"sm\"\n tooltip\n @click.stop=\"\n emits('generate:example', { contentType: selectedContentType })\n \" />\n <RequestBodyViewToggle\n v-if=\"showBodyViewToggle || isSchemaViewAvailable\"\n :disabled=\"!isFormViewAvailable\"\n :modelValue=\"bodyView\"\n :rawLabel=\"\n structuredCodec\n ? undefined\n : translate('apiClient.requestBodyStructured.body')\n \"\n :showForm=\"showBodyViewToggle\"\n :showSchema=\"isSchemaViewAvailable\"\n @update:modelValue=\"(v) => (bodyView = v)\" />\n </div>\n </DataTableHeader>\n <DataTableRow>\n <!-- Inspecting the schema never changes the selected example or request payload. -->\n <div\n v-if=\"bodyView === 'schema' && isSchemaViewAvailable\"\n class=\"min-w-0 border-t py-3 ps-10 pe-6\">\n <Schema\n :key=\"selectedContentType\"\n :eventBus=\"null\"\n :options=\"{\n hideReadOnly: true,\n hideModels: true,\n schemaKeyboardNav: true,\n }\"\n :schema=\"bodySchema\" />\n </div>\n\n <!-- No Body -->\n <template v-else-if=\"selectedContentType === 'none'\">\n <div\n class=\"text-c-3 flex min-h-10 w-full items-center justify-center border-t p-2 text-sm\">\n <span>{{ translate('apiClient.requestBody.noBody') }}</span>\n </div>\n </template>\n\n <!-- Binary File -->\n <template\n v-else-if=\"selectedContentType === 'application/octet-stream'\">\n <div\n class=\"flex items-center justify-center overflow-hidden border-t p-1.5\">\n <template\n v-if=\"\n getFileName(unpackProxyObject(example?.value)) !== undefined\n \">\n <span\n class=\"text-c-2 w-full max-w-full overflow-hidden rounded border px-1.5 py-1 text-xs whitespace-nowrap\">\n {{ getFileName(unpackProxyObject(example?.value)) }}\n </span>\n <ScalarButton\n class=\"bg-b-2 hover:bg-b-3 text-c-2 ml-1 border-0 shadow-none\"\n size=\"sm\"\n variant=\"outlined\"\n @click=\"\n emits('update:value', {\n payload: undefined,\n contentType: selectedContentType,\n })\n \">\n {{ translate('apiClient.requestBody.delete') }}\n </ScalarButton>\n </template>\n <template v-else>\n <ScalarButton\n class=\"bg-b-2 hover:bg-b-3 text-c-2 border-0 shadow-none\"\n size=\"sm\"\n variant=\"outlined\"\n @click=\"\n () =>\n handleFileUpload((file) =>\n emits('update:value', {\n payload: file,\n contentType: selectedContentType,\n }),\n )\n \">\n <span>{{ translate('apiClient.requestBody.selectFile') }}</span>\n <ScalarIcon\n class=\"ml-1\"\n icon=\"Upload\"\n size=\"xs\"\n thickness=\"2.5\" />\n </ScalarButton>\n </template>\n </div>\n </template>\n\n <!-- Form Data / URL Encoded -->\n <template\n v-else-if=\"\n selectedContentType === 'multipart/form-data' ||\n selectedContentType === 'application/x-www-form-urlencoded'\n \">\n <RequestBodyForm\n :bodySchema\n :compositionSelection=\"requestBodyCompositionSelection\"\n :encoding=\"requestBody?.content?.[selectedContentType]?.encoding\"\n :environment\n :example\n :selectedContentType\n @update:formValue=\"\n (payload) =>\n emits('update:formValue', {\n payload,\n contentType: selectedContentType,\n })\n \" />\n </template>\n\n <RequestBodyMultipart\n v-else-if=\"multipartBody\"\n :key=\"selectedContentType\"\n :compositionSelection=\"requestBodyCompositionSelection\"\n :media=\"multipartBody.media\"\n :value=\"multipartBody.value\"\n @update:value=\"\n (payload) =>\n emits('update:value', {\n payload,\n contentType: selectedContentType,\n })\n \" />\n\n <!-- Code/Other -->\n <template v-else>\n <!-- Schema-driven form view for structured (JSON/YAML) bodies -->\n <RequestBodyStructured\n v-if=\"bodyView === 'form' && isFormViewAvailable\"\n :bodySchema\n :contentType=\"selectedContentType\"\n :environment\n :parsedValue=\"parsedBody.value\"\n @update:value=\"\n (value) =>\n emits('update:value', {\n payload: value,\n contentType: selectedContentType,\n })\n \" />\n <!-- Editable raw body with a copy button revealed on hover/focus -->\n <div\n v-else\n class=\"group/code-block relative min-w-0 border-t\">\n <CodeInput\n class=\"px-3\"\n content=\"\"\n :environment=\"environment\"\n :language=\"selectedLanguage\"\n lineNumbers\n lint\n :modelValue=\"bodyValue\"\n withFakeData\n @update:modelValue=\"\n (value) =>\n emits('update:value', {\n payload: value,\n contentType: selectedContentType,\n })\n \" />\n <ScalarCodeBlockCopy\n v-if=\"bodyValue\"\n class=\"absolute top-1.5 right-1.5\"\n :content=\"bodyValue\"\n :lang=\"selectedLanguage\"\n showLang>\n <template #backdrop>\n <ScalarCopyBackdrop class=\"-top-1 -right-1.5\" />\n </template>\n </ScalarCodeBlockCopy>\n </div>\n </template>\n </DataTableRow>\n </DataTable>\n </CollapsibleSection>\n</template>\n<style scoped>\n:deep(.cm-content) {\n font-size: var(--scalar-small);\n}\n</style>\n"],"mappings":""}
|
package/dist/v2/blocks/request-block/components/RequestBody.vue_vue_type_script_setup_true_lang.js
CHANGED
|
@@ -7,6 +7,8 @@ import DataTableRow_default from "../../../components/data-table/DataTableRow.vu
|
|
|
7
7
|
import { getFileName } from "../helpers/files.js";
|
|
8
8
|
import { getFormBodyRows, getFormBodyValue } from "../helpers/get-form-body-rows.js";
|
|
9
9
|
import RequestBodyForm_default from "./RequestBodyForm.vue.js";
|
|
10
|
+
import { parseMultipartBody } from "../helpers/multipart-body.js";
|
|
11
|
+
import RequestBodyMultipart_default from "./RequestBodyMultipart.vue.js";
|
|
10
12
|
import { getStructuredBodyCodec } from "../helpers/structured-body-codec.js";
|
|
11
13
|
import RequestBodyStructured_default from "./RequestBodyStructured.vue.js";
|
|
12
14
|
import RequestBodyViewToggle_default from "./RequestBodyViewToggle.vue.js";
|
|
@@ -160,6 +162,17 @@ var RequestBody_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
160
162
|
const bodySchema = computed(() => {
|
|
161
163
|
return resolve.schema(__props.requestBody?.content?.[selectedContentType.value]?.schema ?? __props.requestBody?.content?.[selectedContentType.value]?.itemSchema);
|
|
162
164
|
});
|
|
165
|
+
/** Mixed and related bodies keep their ordered parts instead of named form-data rows. */
|
|
166
|
+
const multipartBody = computed(() => {
|
|
167
|
+
const essence = parseMimeType(selectedContentType.value).essence;
|
|
168
|
+
if (essence !== "multipart/mixed" && essence !== "multipart/related") return;
|
|
169
|
+
const media = __props.requestBody?.content?.[selectedContentType.value];
|
|
170
|
+
const value = parseMultipartBody(example.value);
|
|
171
|
+
return media && value !== void 0 ? {
|
|
172
|
+
media,
|
|
173
|
+
value
|
|
174
|
+
} : void 0;
|
|
175
|
+
});
|
|
163
176
|
/** Codec for structured (JSON/YAML) bodies, undefined for everything else */
|
|
164
177
|
const structuredCodec = computed(() => selectedContentType.value === "none" ? void 0 : getStructuredBodyCodec(selectedContentType.value));
|
|
165
178
|
/** Parsed body value for the form view — `ok: false` when the raw text is not parseable */
|
|
@@ -205,7 +218,8 @@ var RequestBody_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
205
218
|
const codec = structuredCodec.value;
|
|
206
219
|
const isXml = isXmlMediaType(selectedContentType.value);
|
|
207
220
|
const isForm = selectedContentType.value === "multipart/form-data" || selectedContentType.value === "application/x-www-form-urlencoded";
|
|
208
|
-
|
|
221
|
+
const isMultipart = ["multipart/mixed", "multipart/related"].includes(parseMimeType(selectedContentType.value).essence);
|
|
222
|
+
if (!__props.requestBody || !codec && !isXml && !isForm && !isMultipart) return;
|
|
209
223
|
const selectedValue = getSchemaExampleFromBody(__props.requestBody, selectedContentType.value, __props.requestBodyCompositionSelection, __props.openapiVersion);
|
|
210
224
|
if (isForm) {
|
|
211
225
|
const rows = getFormBodyRows({ value: selectedValue }, selectedContentType.value, bodySchema.value, __props.requestBodyCompositionSelection);
|
|
@@ -221,6 +235,13 @@ var RequestBody_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
221
235
|
});
|
|
222
236
|
return;
|
|
223
237
|
}
|
|
238
|
+
if (isMultipart) {
|
|
239
|
+
emits("update:value", {
|
|
240
|
+
payload: Array.isArray(selectedValue) || isObject(selectedValue) ? selectedValue : "",
|
|
241
|
+
contentType: selectedContentType.value
|
|
242
|
+
});
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
224
245
|
let payload = "";
|
|
225
246
|
if (selectedValue != null) payload = isXml ? String(selectedValue) : codec.stringify(selectedValue);
|
|
226
247
|
emits("update:value", {
|
|
@@ -368,6 +389,7 @@ var RequestBody_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
368
389
|
key: 3,
|
|
369
390
|
bodySchema: bodySchema.value,
|
|
370
391
|
compositionSelection: __props.requestBodyCompositionSelection,
|
|
392
|
+
encoding: __props.requestBody?.content?.[selectedContentType.value]?.encoding,
|
|
371
393
|
environment: __props.environment,
|
|
372
394
|
example: example.value,
|
|
373
395
|
selectedContentType: selectedContentType.value,
|
|
@@ -378,16 +400,30 @@ var RequestBody_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
378
400
|
}, null, 8, [
|
|
379
401
|
"bodySchema",
|
|
380
402
|
"compositionSelection",
|
|
403
|
+
"encoding",
|
|
381
404
|
"environment",
|
|
382
405
|
"example",
|
|
383
406
|
"selectedContentType"
|
|
384
|
-
])) :
|
|
407
|
+
])) : multipartBody.value ? (openBlock(), createBlock(RequestBodyMultipart_default, {
|
|
408
|
+
key: selectedContentType.value,
|
|
409
|
+
compositionSelection: __props.requestBodyCompositionSelection,
|
|
410
|
+
media: multipartBody.value.media,
|
|
411
|
+
value: multipartBody.value.value,
|
|
412
|
+
"onUpdate:value": _cache[7] || (_cache[7] = (payload) => emits("update:value", {
|
|
413
|
+
payload,
|
|
414
|
+
contentType: selectedContentType.value
|
|
415
|
+
}))
|
|
416
|
+
}, null, 8, [
|
|
417
|
+
"compositionSelection",
|
|
418
|
+
"media",
|
|
419
|
+
"value"
|
|
420
|
+
])) : (openBlock(), createElementBlock(Fragment, { key: 5 }, [bodyView.value === "form" && isFormViewAvailable.value ? (openBlock(), createBlock(RequestBodyStructured_default, {
|
|
385
421
|
key: 0,
|
|
386
422
|
bodySchema: bodySchema.value,
|
|
387
423
|
contentType: selectedContentType.value,
|
|
388
424
|
environment: __props.environment,
|
|
389
425
|
parsedValue: parsedBody.value.value,
|
|
390
|
-
"onUpdate:value": _cache[
|
|
426
|
+
"onUpdate:value": _cache[8] || (_cache[8] = (value) => emits("update:value", {
|
|
391
427
|
payload: value,
|
|
392
428
|
contentType: selectedContentType.value
|
|
393
429
|
}))
|
|
@@ -405,7 +441,7 @@ var RequestBody_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
405
441
|
lint: "",
|
|
406
442
|
modelValue: bodyValue.value,
|
|
407
443
|
withFakeData: "",
|
|
408
|
-
"onUpdate:modelValue": _cache[
|
|
444
|
+
"onUpdate:modelValue": _cache[9] || (_cache[9] = (value) => emits("update:value", {
|
|
409
445
|
payload: value,
|
|
410
446
|
contentType: selectedContentType.value
|
|
411
447
|
}))
|