@stoplight/elements-core 8.3.1 → 8.3.3

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.
@@ -20,6 +20,7 @@ export declare function exampleOptions(parameter: ParameterSpec): {
20
20
  }[] | null;
21
21
  export declare function parameterSupportsFileUpload(parameter?: Pick<ParameterSpec, 'schema'>): boolean | undefined;
22
22
  export declare function getPlaceholderForParameter(parameter: ParameterSpec): string;
23
+ export declare function getPlaceholderForSelectedParameter(parameter: ParameterSpec): string | undefined;
23
24
  export declare const initialParameterValues: (params: readonly ParameterSpec[]) => Record<string, string>;
24
25
  export declare function mapSchemaPropertiesToParameters(properties: {
25
26
  [key: string]: JSONSchema7Definition;
package/index.esm.js CHANGED
@@ -1346,6 +1346,13 @@ function getPlaceholderForParameter(parameter) {
1346
1346
  return `${isDefault ? 'defaults to' : 'example'}: ${parameterValue}`;
1347
1347
  return String((_b = (_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : '');
1348
1348
  }
1349
+ function getPlaceholderForSelectedParameter(parameter) {
1350
+ const { value: parameterValue, isDefault } = getValueForParameter(parameter);
1351
+ if (isDefault) {
1352
+ return `select an option (defaults to: ${parameterValue})`;
1353
+ }
1354
+ return undefined;
1355
+ }
1349
1356
  function retrieveDefaultFromSchema(parameter) {
1350
1357
  var _a;
1351
1358
  const defaultValue = (_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.default;
@@ -1424,7 +1431,7 @@ const ParameterEditor = ({ parameter, value, onChange, isOptional, onChangeOptio
1424
1431
  return (React.createElement(React.Fragment, null,
1425
1432
  React.createElement(Text, { as: "label", "aria-hidden": "true", "data-testid": "param-label", htmlFor: inputId, fontSize: "base" }, parameterDisplayName),
1426
1433
  React.createElement(Text, { mx: 3 }, ":"),
1427
- React.createElement("div", null, parameterValueOptions ? (React.createElement(Select, { flex: 1, "aria-label": parameter.name, options: parameterValueOptions, value: value || '', onChange: onChange })) : (React.createElement(Flex, { flex: 1 },
1434
+ React.createElement("div", null, parameterValueOptions ? (React.createElement(Select, { flex: 1, "aria-label": parameter.name, options: parameterValueOptions, value: value || '', onChange: onChange, placeholder: getPlaceholderForSelectedParameter(parameter) })) : (React.createElement(Flex, { flex: 1 },
1428
1435
  React.createElement(Input, { id: inputId, "aria-label": parameter.name, appearance: requiredButEmpty ? 'default' : 'minimal', flex: 1, placeholder: getPlaceholderForParameter(parameter), type: ((_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.type) === 'number' ? 'number' : 'text', required: true, intent: requiredButEmpty ? 'danger' : 'default', value: value || '', onChange: e => onChange && onChange(e.currentTarget.value) }),
1429
1436
  examples && (React.createElement(Select, { "aria-label": `${parameter.name}-select`, flex: 1, value: selectedExample.value, options: examples, onChange: onChange }))))),
1430
1437
  canChangeOptional && !parameter.required && (React.createElement(React.Fragment, null,
@@ -2546,42 +2553,43 @@ const oauthFlowNames = {
2546
2553
  function getDefaultDescription(scheme) {
2547
2554
  switch (scheme.type) {
2548
2555
  case 'apiKey':
2549
- return getApiKeyDescription(scheme.in, scheme.name);
2556
+ return getApiKeyDescription(scheme);
2550
2557
  case 'http':
2551
2558
  switch (scheme.scheme) {
2552
2559
  case 'basic':
2553
- return getBasicAuthDescription();
2560
+ return getBasicAuthDescription(scheme);
2554
2561
  case 'bearer':
2555
- return getBearerAuthDescription();
2562
+ return getBearerAuthDescription(scheme);
2556
2563
  case 'digest':
2557
- return getDigestAuthDescription();
2564
+ return getDigestAuthDescription(scheme);
2558
2565
  }
2559
2566
  case 'oauth2':
2560
2567
  return getOAuthDescription(scheme);
2561
2568
  }
2562
2569
  return '';
2563
2570
  }
2564
- function getApiKeyDescription(inProperty, name) {
2571
+ function getApiKeyDescription(scheme) {
2572
+ const { in: inProperty, name } = scheme;
2565
2573
  return `An API key is a token that you provide when making API calls. Include the token in a ${inProperty} parameter called \`${name}\`.
2566
2574
 
2567
- Example: ${inProperty === 'query' ? `\`?${name}=123\`` : `\`${name}: 123\``}`;
2575
+ Example: ${inProperty === 'query' ? `\`?${name}=123\`` : `\`${name}: 123\``}${getSecuritySchemeRoles(scheme)}`;
2568
2576
  }
2569
- function getBasicAuthDescription() {
2577
+ function getBasicAuthDescription(schema) {
2570
2578
  return `Basic authentication is a simple authentication scheme built into the HTTP protocol.
2571
2579
  To use it, send your HTTP requests with an Authorization header that contains the word Basic
2572
2580
  followed by a space and a base64-encoded string \`username:password\`.
2573
2581
 
2574
- Example: \`Authorization: Basic ZGVtbzpwQDU1dzByZA==\``;
2582
+ Example: \`Authorization: Basic ZGVtbzpwQDU1dzByZA==\`${getSecuritySchemeRoles(schema)}`;
2575
2583
  }
2576
- function getBearerAuthDescription() {
2584
+ function getBearerAuthDescription(schema) {
2577
2585
  return `Provide your bearer token in the Authorization header when making requests to protected resources.
2578
2586
 
2579
- Example: \`Authorization: Bearer 123\``;
2587
+ Example: \`Authorization: Bearer 123\`${getSecuritySchemeRoles(schema)}`;
2580
2588
  }
2581
- function getDigestAuthDescription() {
2589
+ function getDigestAuthDescription(schema) {
2582
2590
  return `Provide your encrypted digest scheme data in the Authorization header when making requests to protected resources.
2583
2591
 
2584
- Example: \`Authorization: Digest username=guest, realm="test", nonce="2", uri="/uri", response="123"\``;
2592
+ Example: \`Authorization: Digest username=guest, realm="test", nonce="2", uri="/uri", response="123"\`${getSecuritySchemeRoles(schema)}`;
2585
2593
  }
2586
2594
  function getOAuthDescription(scheme) {
2587
2595
  const flows = keys(scheme.flows);
@@ -2604,6 +2612,11 @@ function getOAuthFlowDescription(title, flow) {
2604
2612
  ${scopes.map(([key, value]) => `- \`${key}\` - ${value}`).join('\n')}`;
2605
2613
  }
2606
2614
  return description;
2615
+ }
2616
+ function getSecuritySchemeRoles(scheme) {
2617
+ var _a;
2618
+ const scopes = (_a = scheme.extensions) === null || _a === void 0 ? void 0 : _a['x-scopes'];
2619
+ return Array.isArray(scopes) ? `\n\nRoles: ${scopes.map(scope => `\`${scope}\``).join(', ')}` : '';
2607
2620
  }
2608
2621
 
2609
2622
  const PanelContent = ({ schemes }) => {
package/index.js CHANGED
@@ -1407,6 +1407,13 @@ function getPlaceholderForParameter(parameter) {
1407
1407
  return `${isDefault ? 'defaults to' : 'example'}: ${parameterValue}`;
1408
1408
  return String((_b = (_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : '');
1409
1409
  }
1410
+ function getPlaceholderForSelectedParameter(parameter) {
1411
+ const { value: parameterValue, isDefault } = getValueForParameter(parameter);
1412
+ if (isDefault) {
1413
+ return `select an option (defaults to: ${parameterValue})`;
1414
+ }
1415
+ return undefined;
1416
+ }
1410
1417
  function retrieveDefaultFromSchema(parameter) {
1411
1418
  var _a;
1412
1419
  const defaultValue = (_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.default;
@@ -1485,7 +1492,7 @@ const ParameterEditor = ({ parameter, value, onChange, isOptional, onChangeOptio
1485
1492
  return (React__namespace.createElement(React__namespace.Fragment, null,
1486
1493
  React__namespace.createElement(mosaic.Text, { as: "label", "aria-hidden": "true", "data-testid": "param-label", htmlFor: inputId, fontSize: "base" }, parameterDisplayName),
1487
1494
  React__namespace.createElement(mosaic.Text, { mx: 3 }, ":"),
1488
- React__namespace.createElement("div", null, parameterValueOptions ? (React__namespace.createElement(mosaic.Select, { flex: 1, "aria-label": parameter.name, options: parameterValueOptions, value: value || '', onChange: onChange })) : (React__namespace.createElement(mosaic.Flex, { flex: 1 },
1495
+ React__namespace.createElement("div", null, parameterValueOptions ? (React__namespace.createElement(mosaic.Select, { flex: 1, "aria-label": parameter.name, options: parameterValueOptions, value: value || '', onChange: onChange, placeholder: getPlaceholderForSelectedParameter(parameter) })) : (React__namespace.createElement(mosaic.Flex, { flex: 1 },
1489
1496
  React__namespace.createElement(mosaic.Input, { id: inputId, "aria-label": parameter.name, appearance: requiredButEmpty ? 'default' : 'minimal', flex: 1, placeholder: getPlaceholderForParameter(parameter), type: ((_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.type) === 'number' ? 'number' : 'text', required: true, intent: requiredButEmpty ? 'danger' : 'default', value: value || '', onChange: e => onChange && onChange(e.currentTarget.value) }),
1490
1497
  examples && (React__namespace.createElement(mosaic.Select, { "aria-label": `${parameter.name}-select`, flex: 1, value: selectedExample.value, options: examples, onChange: onChange }))))),
1491
1498
  canChangeOptional && !parameter.required && (React__namespace.createElement(React__namespace.Fragment, null,
@@ -2607,42 +2614,43 @@ const oauthFlowNames = {
2607
2614
  function getDefaultDescription(scheme) {
2608
2615
  switch (scheme.type) {
2609
2616
  case 'apiKey':
2610
- return getApiKeyDescription(scheme.in, scheme.name);
2617
+ return getApiKeyDescription(scheme);
2611
2618
  case 'http':
2612
2619
  switch (scheme.scheme) {
2613
2620
  case 'basic':
2614
- return getBasicAuthDescription();
2621
+ return getBasicAuthDescription(scheme);
2615
2622
  case 'bearer':
2616
- return getBearerAuthDescription();
2623
+ return getBearerAuthDescription(scheme);
2617
2624
  case 'digest':
2618
- return getDigestAuthDescription();
2625
+ return getDigestAuthDescription(scheme);
2619
2626
  }
2620
2627
  case 'oauth2':
2621
2628
  return getOAuthDescription(scheme);
2622
2629
  }
2623
2630
  return '';
2624
2631
  }
2625
- function getApiKeyDescription(inProperty, name) {
2632
+ function getApiKeyDescription(scheme) {
2633
+ const { in: inProperty, name } = scheme;
2626
2634
  return `An API key is a token that you provide when making API calls. Include the token in a ${inProperty} parameter called \`${name}\`.
2627
2635
 
2628
- Example: ${inProperty === 'query' ? `\`?${name}=123\`` : `\`${name}: 123\``}`;
2636
+ Example: ${inProperty === 'query' ? `\`?${name}=123\`` : `\`${name}: 123\``}${getSecuritySchemeRoles(scheme)}`;
2629
2637
  }
2630
- function getBasicAuthDescription() {
2638
+ function getBasicAuthDescription(schema) {
2631
2639
  return `Basic authentication is a simple authentication scheme built into the HTTP protocol.
2632
2640
  To use it, send your HTTP requests with an Authorization header that contains the word Basic
2633
2641
  followed by a space and a base64-encoded string \`username:password\`.
2634
2642
 
2635
- Example: \`Authorization: Basic ZGVtbzpwQDU1dzByZA==\``;
2643
+ Example: \`Authorization: Basic ZGVtbzpwQDU1dzByZA==\`${getSecuritySchemeRoles(schema)}`;
2636
2644
  }
2637
- function getBearerAuthDescription() {
2645
+ function getBearerAuthDescription(schema) {
2638
2646
  return `Provide your bearer token in the Authorization header when making requests to protected resources.
2639
2647
 
2640
- Example: \`Authorization: Bearer 123\``;
2648
+ Example: \`Authorization: Bearer 123\`${getSecuritySchemeRoles(schema)}`;
2641
2649
  }
2642
- function getDigestAuthDescription() {
2650
+ function getDigestAuthDescription(schema) {
2643
2651
  return `Provide your encrypted digest scheme data in the Authorization header when making requests to protected resources.
2644
2652
 
2645
- Example: \`Authorization: Digest username=guest, realm="test", nonce="2", uri="/uri", response="123"\``;
2653
+ Example: \`Authorization: Digest username=guest, realm="test", nonce="2", uri="/uri", response="123"\`${getSecuritySchemeRoles(schema)}`;
2646
2654
  }
2647
2655
  function getOAuthDescription(scheme) {
2648
2656
  const flows = keys__default["default"](scheme.flows);
@@ -2665,6 +2673,11 @@ function getOAuthFlowDescription(title, flow) {
2665
2673
  ${scopes.map(([key, value]) => `- \`${key}\` - ${value}`).join('\n')}`;
2666
2674
  }
2667
2675
  return description;
2676
+ }
2677
+ function getSecuritySchemeRoles(scheme) {
2678
+ var _a;
2679
+ const scopes = (_a = scheme.extensions) === null || _a === void 0 ? void 0 : _a['x-scopes'];
2680
+ return Array.isArray(scopes) ? `\n\nRoles: ${scopes.map(scope => `\`${scope}\``).join(', ')}` : '';
2668
2681
  }
2669
2682
 
2670
2683
  const PanelContent = ({ schemes }) => {
package/index.mjs CHANGED
@@ -1346,6 +1346,13 @@ function getPlaceholderForParameter(parameter) {
1346
1346
  return `${isDefault ? 'defaults to' : 'example'}: ${parameterValue}`;
1347
1347
  return String((_b = (_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : '');
1348
1348
  }
1349
+ function getPlaceholderForSelectedParameter(parameter) {
1350
+ const { value: parameterValue, isDefault } = getValueForParameter(parameter);
1351
+ if (isDefault) {
1352
+ return `select an option (defaults to: ${parameterValue})`;
1353
+ }
1354
+ return undefined;
1355
+ }
1349
1356
  function retrieveDefaultFromSchema(parameter) {
1350
1357
  var _a;
1351
1358
  const defaultValue = (_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.default;
@@ -1424,7 +1431,7 @@ const ParameterEditor = ({ parameter, value, onChange, isOptional, onChangeOptio
1424
1431
  return (React.createElement(React.Fragment, null,
1425
1432
  React.createElement(Text, { as: "label", "aria-hidden": "true", "data-testid": "param-label", htmlFor: inputId, fontSize: "base" }, parameterDisplayName),
1426
1433
  React.createElement(Text, { mx: 3 }, ":"),
1427
- React.createElement("div", null, parameterValueOptions ? (React.createElement(Select, { flex: 1, "aria-label": parameter.name, options: parameterValueOptions, value: value || '', onChange: onChange })) : (React.createElement(Flex, { flex: 1 },
1434
+ React.createElement("div", null, parameterValueOptions ? (React.createElement(Select, { flex: 1, "aria-label": parameter.name, options: parameterValueOptions, value: value || '', onChange: onChange, placeholder: getPlaceholderForSelectedParameter(parameter) })) : (React.createElement(Flex, { flex: 1 },
1428
1435
  React.createElement(Input, { id: inputId, "aria-label": parameter.name, appearance: requiredButEmpty ? 'default' : 'minimal', flex: 1, placeholder: getPlaceholderForParameter(parameter), type: ((_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.type) === 'number' ? 'number' : 'text', required: true, intent: requiredButEmpty ? 'danger' : 'default', value: value || '', onChange: e => onChange && onChange(e.currentTarget.value) }),
1429
1436
  examples && (React.createElement(Select, { "aria-label": `${parameter.name}-select`, flex: 1, value: selectedExample.value, options: examples, onChange: onChange }))))),
1430
1437
  canChangeOptional && !parameter.required && (React.createElement(React.Fragment, null,
@@ -2546,42 +2553,43 @@ const oauthFlowNames = {
2546
2553
  function getDefaultDescription(scheme) {
2547
2554
  switch (scheme.type) {
2548
2555
  case 'apiKey':
2549
- return getApiKeyDescription(scheme.in, scheme.name);
2556
+ return getApiKeyDescription(scheme);
2550
2557
  case 'http':
2551
2558
  switch (scheme.scheme) {
2552
2559
  case 'basic':
2553
- return getBasicAuthDescription();
2560
+ return getBasicAuthDescription(scheme);
2554
2561
  case 'bearer':
2555
- return getBearerAuthDescription();
2562
+ return getBearerAuthDescription(scheme);
2556
2563
  case 'digest':
2557
- return getDigestAuthDescription();
2564
+ return getDigestAuthDescription(scheme);
2558
2565
  }
2559
2566
  case 'oauth2':
2560
2567
  return getOAuthDescription(scheme);
2561
2568
  }
2562
2569
  return '';
2563
2570
  }
2564
- function getApiKeyDescription(inProperty, name) {
2571
+ function getApiKeyDescription(scheme) {
2572
+ const { in: inProperty, name } = scheme;
2565
2573
  return `An API key is a token that you provide when making API calls. Include the token in a ${inProperty} parameter called \`${name}\`.
2566
2574
 
2567
- Example: ${inProperty === 'query' ? `\`?${name}=123\`` : `\`${name}: 123\``}`;
2575
+ Example: ${inProperty === 'query' ? `\`?${name}=123\`` : `\`${name}: 123\``}${getSecuritySchemeRoles(scheme)}`;
2568
2576
  }
2569
- function getBasicAuthDescription() {
2577
+ function getBasicAuthDescription(schema) {
2570
2578
  return `Basic authentication is a simple authentication scheme built into the HTTP protocol.
2571
2579
  To use it, send your HTTP requests with an Authorization header that contains the word Basic
2572
2580
  followed by a space and a base64-encoded string \`username:password\`.
2573
2581
 
2574
- Example: \`Authorization: Basic ZGVtbzpwQDU1dzByZA==\``;
2582
+ Example: \`Authorization: Basic ZGVtbzpwQDU1dzByZA==\`${getSecuritySchemeRoles(schema)}`;
2575
2583
  }
2576
- function getBearerAuthDescription() {
2584
+ function getBearerAuthDescription(schema) {
2577
2585
  return `Provide your bearer token in the Authorization header when making requests to protected resources.
2578
2586
 
2579
- Example: \`Authorization: Bearer 123\``;
2587
+ Example: \`Authorization: Bearer 123\`${getSecuritySchemeRoles(schema)}`;
2580
2588
  }
2581
- function getDigestAuthDescription() {
2589
+ function getDigestAuthDescription(schema) {
2582
2590
  return `Provide your encrypted digest scheme data in the Authorization header when making requests to protected resources.
2583
2591
 
2584
- Example: \`Authorization: Digest username=guest, realm="test", nonce="2", uri="/uri", response="123"\``;
2592
+ Example: \`Authorization: Digest username=guest, realm="test", nonce="2", uri="/uri", response="123"\`${getSecuritySchemeRoles(schema)}`;
2585
2593
  }
2586
2594
  function getOAuthDescription(scheme) {
2587
2595
  const flows = keys(scheme.flows);
@@ -2604,6 +2612,11 @@ function getOAuthFlowDescription(title, flow) {
2604
2612
  ${scopes.map(([key, value]) => `- \`${key}\` - ${value}`).join('\n')}`;
2605
2613
  }
2606
2614
  return description;
2615
+ }
2616
+ function getSecuritySchemeRoles(scheme) {
2617
+ var _a;
2618
+ const scopes = (_a = scheme.extensions) === null || _a === void 0 ? void 0 : _a['x-scopes'];
2619
+ return Array.isArray(scopes) ? `\n\nRoles: ${scopes.map(scope => `\`${scope}\``).join(', ')}` : '';
2607
2620
  }
2608
2621
 
2609
2622
  const PanelContent = ({ schemes }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoplight/elements-core",
3
- "version": "8.3.1",
3
+ "version": "8.3.3",
4
4
  "main": "./index.js",
5
5
  "sideEffects": [
6
6
  "web-components.min.js",
@@ -24,7 +24,7 @@
24
24
  "react-dom": ">=16.8"
25
25
  },
26
26
  "dependencies": {
27
- "@stoplight/http-spec": "^7.0.3",
27
+ "@stoplight/http-spec": "^7.1.0",
28
28
  "@stoplight/json": "^3.21.0",
29
29
  "@stoplight/json-schema-ref-parser": "^9.2.7",
30
30
  "@stoplight/json-schema-sampler": "0.3.0",