Skip to content

Commit 3b72ee1

Browse files
authored
refactor: consolidate all JSON Schema 5 rendering code into json-schema-5 plugin (#9798)
1 parent 46c849b commit 3b72ee1

27 files changed

+56
-52
lines changed

src/core/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import DeepLinkingPlugin from "./plugins/deep-linking"
1111
import ErrPlugin from "./plugins/err"
1212
import FilterPlugin from "./plugins/filter"
1313
import IconsPlugin from "./plugins/icons"
14+
import JSONSchema5Plugin from "./plugins/json-schema-5"
1415
import JSONSchema202012Plugin from "./plugins/json-schema-2020-12"
1516
import JSONSchema202012SamplesPlugin from "./plugins/json-schema-2020-12-samples"
1617
import LayoutPlugin from "./plugins/layout"
@@ -257,6 +258,7 @@ SwaggerUI.plugins = {
257258
Err: ErrPlugin,
258259
Filter: FilterPlugin,
259260
Icons: IconsPlugin,
261+
JSONSchema5: JSONSchema5Plugin,
260262
JSONSchema5Samples: JSONSchema5SamplesPlugin,
261263
JSONSchema202012: JSONSchema202012Plugin,
262264
JSONSchema202012Samples: JSONSchema202012SamplesPlugin,
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @prettier
3+
*/
4+
import ModelCollapse from "./components/model-collapse"
5+
import ModelExample from "./components/model-example"
6+
import ModelWrapper from "./components/model-wrapper"
7+
import Model from "./components/model"
8+
import Models from "./components/models"
9+
import EnumModel from "./components/enum-model"
10+
import ObjectModel from "./components/object-model"
11+
import ArrayModel from "./components/array-model"
12+
import PrimitiveModel from "./components/primitive-model"
13+
import Schemes from "./components/schemes"
14+
import SchemesContainer from "./containers/schemes"
15+
import * as JSONSchemaComponents from "./components/json-schema-components"
16+
17+
const JSONSchema5Plugin = () => ({
18+
components: {
19+
modelExample: ModelExample,
20+
ModelWrapper,
21+
ModelCollapse,
22+
Model,
23+
Models,
24+
EnumModel,
25+
ObjectModel,
26+
ArrayModel,
27+
PrimitiveModel,
28+
schemes: Schemes,
29+
SchemesContainer,
30+
...JSONSchemaComponents,
31+
},
32+
})
33+
34+
export default JSONSchema5Plugin

src/core/plugins/oas3/wrap-components/model.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { Component } from "react"
22
import PropTypes from "prop-types"
33
import { OAS3ComponentWrapFactory } from "../helpers"
4-
import Model from "core/components/model"
54

65
class ModelComponent extends Component {
76
static propTypes = {
@@ -13,10 +12,11 @@ class ModelComponent extends Component {
1312
expandDepth: PropTypes.number,
1413
includeReadOnly: PropTypes.bool,
1514
includeWriteOnly: PropTypes.bool,
15+
Ori: PropTypes.func.isRequired,
1616
}
1717

1818
render(){
19-
let { getConfigs, schema } = this.props
19+
let { getConfigs, schema, Ori: Model } = this.props
2020
let classes = ["model-box"]
2121
let isDeprecated = schema.get("deprecated") === true
2222
let message = null

src/core/presets/base/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import LayoutPlugin from "core/plugins/layout"
1111
import LogsPlugin from "core/plugins/logs"
1212
import OnCompletePlugin from "core/plugins/on-complete"
1313
import RequestSnippetsPlugin from "core/plugins/request-snippets"
14+
import JSONSchema5Plugin from "core/plugins/json-schema-5"
1415
import JSONSchema5SamplesPlugin from "core/plugins/json-schema-5-samples"
1516
import SpecPlugin from "core/plugins/spec"
1617
import SwaggerClientPlugin from "core/plugins/swagger-client"
@@ -23,7 +24,6 @@ import SafeRenderPlugin from "core/plugins/safe-render"
2324
// ad-hoc plugins
2425
import CoreComponentsPlugin from "core/presets/base/plugins/core-components"
2526
import FormComponentsPlugin from "core/presets/base/plugins/form-components"
26-
import JSONSchemaComponentsPlugin from "core/presets/base/plugins/json-schema-components"
2727

2828
const BasePreset = () => [
2929
ConfigsPlugin,
@@ -35,11 +35,11 @@ const BasePreset = () => [
3535
ErrPlugin,
3636
IconsPlugin,
3737
LayoutPlugin,
38+
JSONSchema5Plugin,
3839
JSONSchema5SamplesPlugin,
3940
CoreComponentsPlugin,
4041
FormComponentsPlugin,
4142
SwaggerClientPlugin,
42-
JSONSchemaComponentsPlugin,
4343
AuthPlugin,
4444
DownloadUrlPlugin,
4545
DeepLinkingPlugin,

src/core/presets/base/plugins/core-components/index.js

-22
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,6 @@ import Footer from "core/components/footer"
5151
import FilterContainer from "core/containers/filter"
5252
import ParamBody from "core/components/param-body"
5353
import Curl from "core/components/curl"
54-
import Schemes from "core/components/schemes"
55-
import SchemesContainer from "core/containers/schemes"
56-
import ModelCollapse from "core/components/model-collapse"
57-
import ModelExample from "core/components/model-example"
58-
import ModelWrapper from "core/components/model-wrapper"
59-
import Model from "core/components/model"
60-
import Models from "core/components/models"
61-
import EnumModel from "core/components/enum-model"
62-
import ObjectModel from "core/components/object-model"
63-
import ArrayModel from "core/components/array-model"
64-
import PrimitiveModel from "core/components/primitive-model"
6554
import Property from "core/components/property"
6655
import TryItOutButton from "core/components/try-it-out-button"
6756
import VersionPragmaFilter from "core/components/version-pragma-filter"
@@ -117,17 +106,6 @@ const CoreComponentsPlugin = () => ({
117106
FilterContainer,
118107
ParamBody: ParamBody,
119108
curl: Curl,
120-
schemes: Schemes,
121-
SchemesContainer,
122-
modelExample: ModelExample,
123-
ModelWrapper,
124-
ModelCollapse,
125-
Model,
126-
Models,
127-
EnumModel,
128-
ObjectModel,
129-
ArrayModel,
130-
PrimitiveModel,
131109
Property,
132110
TryItOutButton,
133111
Markdown,

src/core/presets/base/plugins/json-schema-components/index.js

-10
This file was deleted.

test/unit/core/helpers/get-model-name.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @prettier
33
*/
44

5-
import Model from "../../../../src/core/components/model"
5+
import Model from "../../../../src/core/plugins/json-schema-5/components/model"
66

77
describe("getModelName", () => {
88
const model = new Model()

test/unit/components/json-schema-form.jsx renamed to test/unit/core/plugins/json-schema-5/components/json-schema-form.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react"
22
import Immutable, { List } from "immutable"
33
import { Select, Input, TextArea } from "core/components/layout-utils"
44
import { mount, render } from "enzyme"
5-
import * as JsonSchemaComponents from "core/components/json-schema-components"
5+
import * as JsonSchemaComponents from "core/plugins/json-schema-5/components/json-schema-components"
66

77
const components = {...JsonSchemaComponents, Select, Input, TextArea}
88

test/unit/components/model-example.jsx renamed to test/unit/core/plugins/json-schema-5/components/model-example.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react"
22
import { shallow } from "enzyme"
3-
import ModelExample from "core/components/model-example"
4-
import ModelComponent from "core/components/model-wrapper"
3+
import ModelExample from "core/plugins/json-schema-5/components/model-example"
4+
import ModelComponent from "core/plugins/json-schema-5/components/model-wrapper"
55

66
describe("<ModelExample/>", function(){
77
let components, props

test/unit/components/models.jsx renamed to test/unit/core/plugins/json-schema-5/components/models.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from "react"
22
import { shallow } from "enzyme"
33
import { fromJS, Map } from "immutable"
4-
import Models from "core/components/models"
5-
import ModelCollapse from "core/components/model-collapse"
6-
import ModelComponent from "core/components/model-wrapper"
4+
import Models from "core/plugins/json-schema-5/components/models"
5+
import ModelCollapse from "core/plugins/json-schema-5/components/model-collapse"
6+
import ModelComponent from "core/plugins/json-schema-5/components/model-wrapper"
77

88
describe("<Models/>", function(){
99
const dummyComponent = () => null

test/unit/components/object-model.jsx renamed to test/unit/core/plugins/json-schema-5/components/object-model.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from "react"
22
import { shallow } from "enzyme"
33
import { List } from "immutable"
4-
import ObjectModel from "core/components/object-model"
4+
import ObjectModel from "core/plugins/json-schema-5/components/object-model"
55
// import ModelExample from "core/components/model-example"
66
import Immutable from "immutable"
7-
import Model from "core/components/model"
8-
import ModelCollapse from "core/components/model-collapse"
7+
import Model from "core/plugins/json-schema-5/components/model"
8+
import ModelCollapse from "core/plugins/json-schema-5/components/model-collapse"
99
import Property from "core/components/property"
1010
// import { inferSchema } from "core/plugins/samples/fn"
1111

test/unit/components/primitive-model.jsx renamed to test/unit/core/plugins/json-schema-5/components/primitive-model.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from "react"
22
import { shallow } from "enzyme"
33
import { fromJS } from "immutable"
4-
import PrimitiveModel from "core/components/primitive-model"
5-
import ModelCollapse from "core/components/model-collapse"
4+
import PrimitiveModel from "core/plugins/json-schema-5/components/primitive-model"
5+
import ModelCollapse from "core/plugins/json-schema-5/components/model-collapse"
66

77
describe("<PrimitiveModel/>", function () {
88
const dummyComponent = () => null

test/unit/components/response.jsx renamed to test/unit/core/plugins/json-schema-5/components/response.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { shallow } from "enzyme"
66
import { fromJS, List } from "immutable"
77

88
import Response from "core/components/response"
9-
import ModelExample from "core/components/model-example"
9+
import ModelExample from "core/plugins/json-schema-5/components/model-example"
1010
import {
1111
inferSchema,
1212
memoizedSampleFromSchema,

test/unit/components/schemes-wrapper.jsx renamed to test/unit/core/plugins/json-schema-5/components/schemes-wrapper.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from "react"
22
import { mount } from "enzyme"
33
import { fromJS } from "immutable"
4-
import SchemesContainer from "core/containers/schemes"
5-
import Schemes from "core/components/schemes"
4+
import SchemesContainer from "core/plugins/json-schema-5/containers/schemes"
5+
import Schemes from "core/plugins/json-schema-5/components/schemes"
66
import { Col } from "core/components/layout-utils"
77

88
describe("<SchemesContainer/>", function(){

test/unit/components/schemes.jsx renamed to test/unit/core/plugins/json-schema-5/components/schemes.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react"
22
import { shallow } from "enzyme"
33
import { fromJS } from "immutable"
4-
import Schemes from "core/components/schemes"
4+
import Schemes from "core/plugins/json-schema-5/components/schemes"
55

66
describe("<Schemes/>", function(){
77
it("calls props.specActions.setScheme() when no currentScheme is selected", function(){

0 commit comments

Comments
 (0)