Skip to content

Commit

Permalink
refactor: consolidate all JSON Schema 5 rendering code into json-sche…
Browse files Browse the repository at this point in the history
…ma-5 plugin (#9798)
  • Loading branch information
char0n authored Apr 10, 2024
1 parent 46c849b commit 3b72ee1
Show file tree
Hide file tree
Showing 27 changed files with 56 additions and 52 deletions.
2 changes: 2 additions & 0 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -257,6 +258,7 @@ SwaggerUI.plugins = {
Err: ErrPlugin,
Filter: FilterPlugin,
Icons: IconsPlugin,
JSONSchema5: JSONSchema5Plugin,
JSONSchema5Samples: JSONSchema5SamplesPlugin,
JSONSchema202012: JSONSchema202012Plugin,
JSONSchema202012Samples: JSONSchema202012SamplesPlugin,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions src/core/plugins/json-schema-5/index.js
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/core/plugins/oas3/wrap-components/model.jsx
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/core/presets/base/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -35,11 +35,11 @@ const BasePreset = () => [
ErrPlugin,
IconsPlugin,
LayoutPlugin,
JSONSchema5Plugin,
JSONSchema5SamplesPlugin,
CoreComponentsPlugin,
FormComponentsPlugin,
SwaggerClientPlugin,
JSONSchemaComponentsPlugin,
AuthPlugin,
DownloadUrlPlugin,
DeepLinkingPlugin,
Expand Down
22 changes: 0 additions & 22 deletions src/core/presets/base/plugins/core-components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions src/core/presets/base/plugins/json-schema-components/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/unit/core/helpers/get-model-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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(){
Expand Down
Original file line number Diff line number Diff line change
@@ -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(){
Expand Down

0 comments on commit 3b72ee1

Please sign in to comment.