refactor(samples): move example generation code to samples plugin (#8727)
Refs #8577
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
import { useFn } from "../hooks"
|
||||
import { useFn } from "./hooks"
|
||||
|
||||
export const upperFirst = (value) => {
|
||||
if (typeof value === "string") {
|
||||
@@ -56,7 +56,7 @@ import {
|
||||
stringify,
|
||||
stringifyConstraints,
|
||||
getDependentRequired,
|
||||
} from "./fn/index"
|
||||
} from "./fn"
|
||||
|
||||
export const withJSONSchemaContext = (Component, overrides = {}) => {
|
||||
const value = {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
Reference in New Issue
Block a user