refactor(samples): move example generation code to samples plugin (#8727)

Refs #8577
This commit is contained in:
Vladimír Gorej
2023-05-30 15:01:15 +02:00
parent ac3b69fb3c
commit 027f53c302
15 changed files with 360 additions and 160 deletions

View File

@@ -1,7 +1,7 @@
/**
* @prettier
*/
import { useFn } from "../hooks"
import { useFn } from "./hooks"
export const upperFirst = (value) => {
if (typeof value === "string") {

View File

@@ -56,7 +56,7 @@ import {
stringify,
stringifyConstraints,
getDependentRequired,
} from "./fn/index"
} from "./fn"
export const withJSONSchemaContext = (Component, overrides = {}) => {
const value = {

View File

@@ -43,15 +43,14 @@ import KeywordWriteOnly from "./components/keywords/WriteOnly"
import Accordion from "./components/Accordion/Accordion"
import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton"
import ChevronRightIcon from "./components/icons/ChevronRight"
import { upperFirst, hasKeyword, isExpandable } from "./fn/index"
import { upperFirst, hasKeyword, isExpandable } from "./fn"
import {
inferSchema,
sampleFromSchema,
sampleFromSchemaGeneric,
createXMLExample,
memoizedSampleFromSchema,
memoizedCreateXMLExample,
} from "./fn/samples"
} from "./samples-extensions/fn"
import { JSONSchemaDeepExpansionContext } from "./context"
import { useFn, useConfig, useComponent, useIsExpandedDeeply } from "./hooks"
import { withJSONSchemaContext } from "./hoc"
@@ -113,7 +112,6 @@ const JSONSchema202012Plugin = () => ({
useConfig,
useComponent,
useIsExpandedDeeply,
inferSchema,
sampleFromSchema,
sampleFromSchemaGeneric,
createXMLExample,

View File

@@ -709,16 +709,6 @@ export const sampleFromSchemaGeneric = (
return value
}
export const inferSchema = (thing) => {
if (thing.schema) thing = thing.schema
if (thing.properties) {
thing.type = "object"
}
return thing // Hopefully this will have something schema like in it... `type` for example
}
export const createXMLExample = (schema, config, o) => {
const json = sampleFromSchemaGeneric(schema, config, o, true)
if (!json) {