vitepress-openapi 0.1.14 → 0.1.15

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.
@@ -234,6 +234,7 @@ class UiPropertyFactory {
234
234
  schema.items.properties,
235
235
  schema.items.required || [],
236
236
  schema.items.additionalProperties,
237
+ schema.items['x-additionalPropertiesName'],
237
238
  )
238
239
  : undefined
239
240
 
@@ -334,6 +335,7 @@ class UiPropertyFactory {
334
335
  schema.properties,
335
336
  schema.required || [],
336
337
  schema.additionalProperties,
338
+ schema['x-additionalPropertiesName'],
337
339
  )
338
340
  } else if (schema.type === undefined) {
339
341
  if (schema.properties || schema.additionalProperties) {
@@ -342,6 +344,7 @@ class UiPropertyFactory {
342
344
  schema.properties,
343
345
  schema.required || [],
344
346
  schema.additionalProperties,
347
+ schema['x-additionalPropertiesName'],
345
348
  )
346
349
  }
347
350
  }
@@ -353,6 +356,7 @@ class UiPropertyFactory {
353
356
  propertiesNode?: Record<string, OpenAPI.SchemaObject>,
354
357
  requiredProperties: string[] = [],
355
358
  additionalPropertiesNode?: OpenAPI.SchemaObject | boolean,
359
+ additionalPropertiesName?: string,
356
360
  ): OAProperty[] {
357
361
  const properties: OAProperty[] = []
358
362
 
@@ -368,12 +372,11 @@ class UiPropertyFactory {
368
372
  ? additionalPropertiesNode
369
373
  : { type: 'string' }
370
374
 
371
- properties.push({
372
- name: 'additionalProperties',
373
- types: [additionalProps.type as JSONSchemaType],
374
- required: false,
375
- meta: { isAdditionalProperties: true },
376
- })
375
+ const name = additionalPropertiesName || 'additionalProperties'
376
+ const property = UiPropertyFactory.schemaToUiProperty(name, additionalProps)
377
+ property.required = false
378
+ property.meta = { ...(property.meta || {}), isAdditionalProperties: true }
379
+ properties.push(property)
377
380
  }
378
381
 
379
382
  return properties
@@ -0,0 +1,48 @@
1
+ import type { PlaygroundExampleBehavior } from '../../composables/useTheme'
2
+ import { getPlaygroundSpecificExample, getStandardExample } from '../examples/getPropertyExample'
3
+
4
+ export function useExampleForPlaceholder(behavior: PlaygroundExampleBehavior): boolean {
5
+ return behavior !== 'ignore'
6
+ }
7
+
8
+ export function useExampleForValue(behavior: PlaygroundExampleBehavior): boolean {
9
+ return behavior === 'value'
10
+ }
11
+
12
+ export function resolveExampleForValue(
13
+ property: any,
14
+ behavior: PlaygroundExampleBehavior,
15
+ xExampleBehavior: PlaygroundExampleBehavior = 'value',
16
+ ): any {
17
+ if (useExampleForValue(xExampleBehavior)) {
18
+ const specific = getPlaygroundSpecificExample(property)
19
+ if (specific !== null) {
20
+ return specific
21
+ }
22
+ }
23
+
24
+ if (useExampleForValue(behavior)) {
25
+ return getStandardExample(property)
26
+ }
27
+
28
+ return null
29
+ }
30
+
31
+ export function resolveExampleForPlaceholder(
32
+ property: any,
33
+ behavior: PlaygroundExampleBehavior,
34
+ xExampleBehavior: PlaygroundExampleBehavior = 'value',
35
+ ): any {
36
+ if (useExampleForPlaceholder(xExampleBehavior)) {
37
+ const specific = getPlaygroundSpecificExample(property)
38
+ if (specific !== null) {
39
+ return specific
40
+ }
41
+ }
42
+
43
+ if (useExampleForPlaceholder(behavior)) {
44
+ return getStandardExample(property)
45
+ }
46
+
47
+ return null
48
+ }