refactor: consolidate all JSON Schema 5 rendering code into json-schema-5 plugin (#9798)
This commit is contained in:
@@ -11,6 +11,7 @@ import DeepLinkingPlugin from "./plugins/deep-linking"
|
||||
import ErrPlugin from "./plugins/err"
|
||||
import FilterPlugin from "./plugins/filter"
|
||||
import IconsPlugin from "./plugins/icons"
|
||||
import JSONSchema5Plugin from "./plugins/json-schema-5"
|
||||
import JSONSchema202012Plugin from "./plugins/json-schema-2020-12"
|
||||
import JSONSchema202012SamplesPlugin from "./plugins/json-schema-2020-12-samples"
|
||||
import LayoutPlugin from "./plugins/layout"
|
||||
@@ -257,6 +258,7 @@ SwaggerUI.plugins = {
|
||||
Err: ErrPlugin,
|
||||
Filter: FilterPlugin,
|
||||
Icons: IconsPlugin,
|
||||
JSONSchema5: JSONSchema5Plugin,
|
||||
JSONSchema5Samples: JSONSchema5SamplesPlugin,
|
||||
JSONSchema202012: JSONSchema202012Plugin,
|
||||
JSONSchema202012Samples: JSONSchema202012SamplesPlugin,
|
||||
|
||||
34
src/core/plugins/json-schema-5/index.js
Normal file
34
src/core/plugins/json-schema-5/index.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
import ModelCollapse from "./components/model-collapse"
|
||||
import ModelExample from "./components/model-example"
|
||||
import ModelWrapper from "./components/model-wrapper"
|
||||
import Model from "./components/model"
|
||||
import Models from "./components/models"
|
||||
import EnumModel from "./components/enum-model"
|
||||
import ObjectModel from "./components/object-model"
|
||||
import ArrayModel from "./components/array-model"
|
||||
import PrimitiveModel from "./components/primitive-model"
|
||||
import Schemes from "./components/schemes"
|
||||
import SchemesContainer from "./containers/schemes"
|
||||
import * as JSONSchemaComponents from "./components/json-schema-components"
|
||||
|
||||
const JSONSchema5Plugin = () => ({
|
||||
components: {
|
||||
modelExample: ModelExample,
|
||||
ModelWrapper,
|
||||
ModelCollapse,
|
||||
Model,
|
||||
Models,
|
||||
EnumModel,
|
||||
ObjectModel,
|
||||
ArrayModel,
|
||||
PrimitiveModel,
|
||||
schemes: Schemes,
|
||||
SchemesContainer,
|
||||
...JSONSchemaComponents,
|
||||
},
|
||||
})
|
||||
|
||||
export default JSONSchema5Plugin
|
||||
@@ -1,7 +1,6 @@
|
||||
import React, { Component } from "react"
|
||||
import PropTypes from "prop-types"
|
||||
import { OAS3ComponentWrapFactory } from "../helpers"
|
||||
import Model from "core/components/model"
|
||||
|
||||
class ModelComponent extends Component {
|
||||
static propTypes = {
|
||||
@@ -13,10 +12,11 @@ class ModelComponent extends Component {
|
||||
expandDepth: PropTypes.number,
|
||||
includeReadOnly: PropTypes.bool,
|
||||
includeWriteOnly: PropTypes.bool,
|
||||
Ori: PropTypes.func.isRequired,
|
||||
}
|
||||
|
||||
render(){
|
||||
let { getConfigs, schema } = this.props
|
||||
let { getConfigs, schema, Ori: Model } = this.props
|
||||
let classes = ["model-box"]
|
||||
let isDeprecated = schema.get("deprecated") === true
|
||||
let message = null
|
||||
|
||||
@@ -11,6 +11,7 @@ import LayoutPlugin from "core/plugins/layout"
|
||||
import LogsPlugin from "core/plugins/logs"
|
||||
import OnCompletePlugin from "core/plugins/on-complete"
|
||||
import RequestSnippetsPlugin from "core/plugins/request-snippets"
|
||||
import JSONSchema5Plugin from "core/plugins/json-schema-5"
|
||||
import JSONSchema5SamplesPlugin from "core/plugins/json-schema-5-samples"
|
||||
import SpecPlugin from "core/plugins/spec"
|
||||
import SwaggerClientPlugin from "core/plugins/swagger-client"
|
||||
@@ -23,7 +24,6 @@ import SafeRenderPlugin from "core/plugins/safe-render"
|
||||
// ad-hoc plugins
|
||||
import CoreComponentsPlugin from "core/presets/base/plugins/core-components"
|
||||
import FormComponentsPlugin from "core/presets/base/plugins/form-components"
|
||||
import JSONSchemaComponentsPlugin from "core/presets/base/plugins/json-schema-components"
|
||||
|
||||
const BasePreset = () => [
|
||||
ConfigsPlugin,
|
||||
@@ -35,11 +35,11 @@ const BasePreset = () => [
|
||||
ErrPlugin,
|
||||
IconsPlugin,
|
||||
LayoutPlugin,
|
||||
JSONSchema5Plugin,
|
||||
JSONSchema5SamplesPlugin,
|
||||
CoreComponentsPlugin,
|
||||
FormComponentsPlugin,
|
||||
SwaggerClientPlugin,
|
||||
JSONSchemaComponentsPlugin,
|
||||
AuthPlugin,
|
||||
DownloadUrlPlugin,
|
||||
DeepLinkingPlugin,
|
||||
|
||||
@@ -51,17 +51,6 @@ import Footer from "core/components/footer"
|
||||
import FilterContainer from "core/containers/filter"
|
||||
import ParamBody from "core/components/param-body"
|
||||
import Curl from "core/components/curl"
|
||||
import Schemes from "core/components/schemes"
|
||||
import SchemesContainer from "core/containers/schemes"
|
||||
import ModelCollapse from "core/components/model-collapse"
|
||||
import ModelExample from "core/components/model-example"
|
||||
import ModelWrapper from "core/components/model-wrapper"
|
||||
import Model from "core/components/model"
|
||||
import Models from "core/components/models"
|
||||
import EnumModel from "core/components/enum-model"
|
||||
import ObjectModel from "core/components/object-model"
|
||||
import ArrayModel from "core/components/array-model"
|
||||
import PrimitiveModel from "core/components/primitive-model"
|
||||
import Property from "core/components/property"
|
||||
import TryItOutButton from "core/components/try-it-out-button"
|
||||
import VersionPragmaFilter from "core/components/version-pragma-filter"
|
||||
@@ -117,17 +106,6 @@ const CoreComponentsPlugin = () => ({
|
||||
FilterContainer,
|
||||
ParamBody: ParamBody,
|
||||
curl: Curl,
|
||||
schemes: Schemes,
|
||||
SchemesContainer,
|
||||
modelExample: ModelExample,
|
||||
ModelWrapper,
|
||||
ModelCollapse,
|
||||
Model,
|
||||
Models,
|
||||
EnumModel,
|
||||
ObjectModel,
|
||||
ArrayModel,
|
||||
PrimitiveModel,
|
||||
Property,
|
||||
TryItOutButton,
|
||||
Markdown,
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
import * as JSONSchemaComponents from "core/components/json-schema-components"
|
||||
|
||||
const JSONSchemaComponentsPlugin = () => ({
|
||||
components: { ...JSONSchemaComponents },
|
||||
})
|
||||
|
||||
export default JSONSchemaComponentsPlugin
|
||||
@@ -2,7 +2,7 @@
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
import Model from "../../../../src/core/components/model"
|
||||
import Model from "../../../../src/core/plugins/json-schema-5/components/model"
|
||||
|
||||
describe("getModelName", () => {
|
||||
const model = new Model()
|
||||
|
||||
@@ -2,7 +2,7 @@ import React from "react"
|
||||
import Immutable, { List } from "immutable"
|
||||
import { Select, Input, TextArea } from "core/components/layout-utils"
|
||||
import { mount, render } from "enzyme"
|
||||
import * as JsonSchemaComponents from "core/components/json-schema-components"
|
||||
import * as JsonSchemaComponents from "core/plugins/json-schema-5/components/json-schema-components"
|
||||
|
||||
const components = {...JsonSchemaComponents, Select, Input, TextArea}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from "react"
|
||||
import { shallow } from "enzyme"
|
||||
import ModelExample from "core/components/model-example"
|
||||
import ModelComponent from "core/components/model-wrapper"
|
||||
import ModelExample from "core/plugins/json-schema-5/components/model-example"
|
||||
import ModelComponent from "core/plugins/json-schema-5/components/model-wrapper"
|
||||
|
||||
describe("<ModelExample/>", function(){
|
||||
let components, props
|
||||
@@ -1,9 +1,9 @@
|
||||
import React from "react"
|
||||
import { shallow } from "enzyme"
|
||||
import { fromJS, Map } from "immutable"
|
||||
import Models from "core/components/models"
|
||||
import ModelCollapse from "core/components/model-collapse"
|
||||
import ModelComponent from "core/components/model-wrapper"
|
||||
import Models from "core/plugins/json-schema-5/components/models"
|
||||
import ModelCollapse from "core/plugins/json-schema-5/components/model-collapse"
|
||||
import ModelComponent from "core/plugins/json-schema-5/components/model-wrapper"
|
||||
|
||||
describe("<Models/>", function(){
|
||||
const dummyComponent = () => null
|
||||
@@ -1,11 +1,11 @@
|
||||
import React from "react"
|
||||
import { shallow } from "enzyme"
|
||||
import { List } from "immutable"
|
||||
import ObjectModel from "core/components/object-model"
|
||||
import ObjectModel from "core/plugins/json-schema-5/components/object-model"
|
||||
// import ModelExample from "core/components/model-example"
|
||||
import Immutable from "immutable"
|
||||
import Model from "core/components/model"
|
||||
import ModelCollapse from "core/components/model-collapse"
|
||||
import Model from "core/plugins/json-schema-5/components/model"
|
||||
import ModelCollapse from "core/plugins/json-schema-5/components/model-collapse"
|
||||
import Property from "core/components/property"
|
||||
// import { inferSchema } from "core/plugins/samples/fn"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import React from "react"
|
||||
import { shallow } from "enzyme"
|
||||
import { fromJS } from "immutable"
|
||||
import PrimitiveModel from "core/components/primitive-model"
|
||||
import ModelCollapse from "core/components/model-collapse"
|
||||
import PrimitiveModel from "core/plugins/json-schema-5/components/primitive-model"
|
||||
import ModelCollapse from "core/plugins/json-schema-5/components/model-collapse"
|
||||
|
||||
describe("<PrimitiveModel/>", function () {
|
||||
const dummyComponent = () => null
|
||||
@@ -6,7 +6,7 @@ import { shallow } from "enzyme"
|
||||
import { fromJS, List } from "immutable"
|
||||
|
||||
import Response from "core/components/response"
|
||||
import ModelExample from "core/components/model-example"
|
||||
import ModelExample from "core/plugins/json-schema-5/components/model-example"
|
||||
import {
|
||||
inferSchema,
|
||||
memoizedSampleFromSchema,
|
||||
@@ -1,8 +1,8 @@
|
||||
import React from "react"
|
||||
import { mount } from "enzyme"
|
||||
import { fromJS } from "immutable"
|
||||
import SchemesContainer from "core/containers/schemes"
|
||||
import Schemes from "core/components/schemes"
|
||||
import SchemesContainer from "core/plugins/json-schema-5/containers/schemes"
|
||||
import Schemes from "core/plugins/json-schema-5/components/schemes"
|
||||
import { Col } from "core/components/layout-utils"
|
||||
|
||||
describe("<SchemesContainer/>", function(){
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from "react"
|
||||
import { shallow } from "enzyme"
|
||||
import { fromJS } from "immutable"
|
||||
import Schemes from "core/components/schemes"
|
||||
import Schemes from "core/plugins/json-schema-5/components/schemes"
|
||||
|
||||
describe("<Schemes/>", function(){
|
||||
it("calls props.specActions.setScheme() when no currentScheme is selected", function(){
|
||||
Reference in New Issue
Block a user