-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(oas31): render JSON Schema 2020-12 in Operations and Webhooks (#…
- Loading branch information
Showing
15 changed files
with
268 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@import './model/model'; | ||
@import './models/models'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.model-box { | ||
// inferred names of Schema Objects | ||
& .json-schema-2020-12:not(.json-schema-2020-12--embedded) > .json-schema-2020-12-head .json-schema-2020-12__title:first-of-type { | ||
font-size: 16px; | ||
} | ||
|
||
& > .json-schema-2020-12 { | ||
margin: 0; | ||
} | ||
|
||
.json-schema-2020-12 { | ||
padding: 0; | ||
background-color: transparent; | ||
} | ||
|
||
.json-schema-2020-12-accordion, .json-schema-2020-12-expand-deep-button { | ||
background-color: transparent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import React, { forwardRef, useCallback } from "react" | ||
import PropTypes from "prop-types" | ||
import ImPropTypes from "react-immutable-proptypes" | ||
|
||
const decodeRefName = (uri) => { | ||
const unescaped = uri.replace(/~1/g, "/").replace(/~0/g, "~") | ||
try { | ||
return decodeURIComponent(unescaped) | ||
} catch { | ||
return unescaped | ||
} | ||
} | ||
const getModelName = (uri) => { | ||
if (typeof uri === "string" && uri.includes("#/components/schemas/")) { | ||
return decodeRefName(uri.replace(/^.*#\/components\/schemas\//, "")) | ||
} | ||
return null | ||
} | ||
|
||
const Model = forwardRef(({ schema, getComponent, onToggle }, ref) => { | ||
const JSONSchema202012 = getComponent("JSONSchema202012") | ||
const name = getModelName(schema.get("$$ref")) | ||
|
||
const handleExpand = useCallback( | ||
(e, expanded) => { | ||
onToggle(name, expanded) | ||
}, | ||
[name, onToggle] | ||
) | ||
|
||
return ( | ||
<JSONSchema202012 | ||
name={name} | ||
schema={schema.toJS()} | ||
ref={ref} | ||
onExpand={handleExpand} | ||
/> | ||
) | ||
}) | ||
|
||
Model.propTypes = { | ||
schema: ImPropTypes.map.isRequired, | ||
getComponent: PropTypes.func.isRequired, | ||
getConfigs: PropTypes.func.isRequired, | ||
specSelectors: PropTypes.object.isRequired, | ||
specPath: ImPropTypes.list.isRequired, | ||
name: PropTypes.string, | ||
displayName: PropTypes.string, | ||
isRef: PropTypes.bool, | ||
required: PropTypes.bool, | ||
expandDepth: PropTypes.number, | ||
depth: PropTypes.number, | ||
includeReadOnly: PropTypes.bool, | ||
includeWriteOnly: PropTypes.bool, | ||
onToggle: PropTypes.func, | ||
} | ||
|
||
Model.defaultProps = { | ||
name: "", | ||
displayName: "", | ||
isRef: false, | ||
required: false, | ||
expandDepth: 0, | ||
depth: 1, | ||
includeReadOnly: false, | ||
includeWriteOnly: false, | ||
onToggle: () => {}, | ||
} | ||
|
||
export default Model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.models .json-schema-2020-12:not(.json-schema-2020-12--embedded) > .json-schema-2020-12-head .json-schema-2020-12__title:first-of-type { | ||
font-size: 16px; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import React from "react" | ||
|
||
import { createOnlyOAS31ComponentWrapper } from "../fn" | ||
import { makeIsExpandable } from "../json-schema-2020-12-extensions/fn" | ||
|
||
const ModelWrapper = createOnlyOAS31ComponentWrapper( | ||
({ getSystem, ...props }) => { | ||
const system = getSystem() | ||
const { getComponent, fn, getConfigs } = system | ||
const configs = getConfigs() | ||
|
||
const Model = getComponent("OAS31Model") | ||
const JSONSchema = getComponent("JSONSchema202012") | ||
const Keyword$schema = getComponent("JSONSchema202012Keyword$schema") | ||
const Keyword$vocabulary = getComponent( | ||
"JSONSchema202012Keyword$vocabulary" | ||
) | ||
const Keyword$id = getComponent("JSONSchema202012Keyword$id") | ||
const Keyword$anchor = getComponent("JSONSchema202012Keyword$anchor") | ||
const Keyword$dynamicAnchor = getComponent( | ||
"JSONSchema202012Keyword$dynamicAnchor" | ||
) | ||
const Keyword$ref = getComponent("JSONSchema202012Keyword$ref") | ||
const Keyword$dynamicRef = getComponent( | ||
"JSONSchema202012Keyword$dynamicRef" | ||
) | ||
const Keyword$defs = getComponent("JSONSchema202012Keyword$defs") | ||
const Keyword$comment = getComponent("JSONSchema202012Keyword$comment") | ||
const KeywordAllOf = getComponent("JSONSchema202012KeywordAllOf") | ||
const KeywordAnyOf = getComponent("JSONSchema202012KeywordAnyOf") | ||
const KeywordOneOf = getComponent("JSONSchema202012KeywordOneOf") | ||
const KeywordNot = getComponent("JSONSchema202012KeywordNot") | ||
const KeywordIf = getComponent("JSONSchema202012KeywordIf") | ||
const KeywordThen = getComponent("JSONSchema202012KeywordThen") | ||
const KeywordElse = getComponent("JSONSchema202012KeywordElse") | ||
const KeywordDependentSchemas = getComponent( | ||
"JSONSchema202012KeywordDependentSchemas" | ||
) | ||
const KeywordPrefixItems = getComponent( | ||
"JSONSchema202012KeywordPrefixItems" | ||
) | ||
const KeywordItems = getComponent("JSONSchema202012KeywordItems") | ||
const KeywordContains = getComponent("JSONSchema202012KeywordContains") | ||
const KeywordProperties = getComponent("JSONSchema202012KeywordProperties") | ||
const KeywordPatternProperties = getComponent( | ||
"JSONSchema202012KeywordPatternProperties" | ||
) | ||
const KeywordAdditionalProperties = getComponent( | ||
"JSONSchema202012KeywordAdditionalProperties" | ||
) | ||
const KeywordPropertyNames = getComponent( | ||
"JSONSchema202012KeywordPropertyNames" | ||
) | ||
const KeywordUnevaluatedItems = getComponent( | ||
"JSONSchema202012KeywordUnevaluatedItems" | ||
) | ||
const KeywordUnevaluatedProperties = getComponent( | ||
"JSONSchema202012KeywordUnevaluatedProperties" | ||
) | ||
const KeywordType = getComponent("JSONSchema202012KeywordType") | ||
const KeywordEnum = getComponent("JSONSchema202012KeywordEnum") | ||
const KeywordConst = getComponent("JSONSchema202012KeywordConst") | ||
const KeywordConstraint = getComponent("JSONSchema202012KeywordConstraint") | ||
const KeywordDependentRequired = getComponent( | ||
"JSONSchema202012KeywordDependentRequired" | ||
) | ||
const KeywordContentSchema = getComponent( | ||
"JSONSchema202012KeywordContentSchema" | ||
) | ||
const KeywordTitle = getComponent("JSONSchema202012KeywordTitle") | ||
const KeywordDescription = getComponent( | ||
"JSONSchema202012KeywordDescription" | ||
) | ||
const KeywordDefault = getComponent("JSONSchema202012KeywordDefault") | ||
const KeywordDeprecated = getComponent("JSONSchema202012KeywordDeprecated") | ||
const KeywordReadOnly = getComponent("JSONSchema202012KeywordReadOnly") | ||
const KeywordWriteOnly = getComponent("JSONSchema202012KeywordWriteOnly") | ||
const Accordion = getComponent("JSONSchema202012Accordion") | ||
const ExpandDeepButton = getComponent("JSONSchema202012ExpandDeepButton") | ||
const ChevronRightIcon = getComponent("JSONSchema202012ChevronRightIcon") | ||
const withSchemaContext = getComponent("withJSONSchema202012Context") | ||
|
||
const ModelWithJSONSchemaContext = withSchemaContext(Model, { | ||
config: { | ||
default$schema: "https://spec.openapis.org/oas/3.1/dialect/base", | ||
defaultExpandedLevels: configs.defaultModelExpandDepth, | ||
includeReadOnly: Boolean(props.includeReadOnly), | ||
includeWriteOnly: Boolean(props.includeWriteOnly), | ||
}, | ||
components: { | ||
JSONSchema, | ||
Keyword$schema, | ||
Keyword$vocabulary, | ||
Keyword$id, | ||
Keyword$anchor, | ||
Keyword$dynamicAnchor, | ||
Keyword$ref, | ||
Keyword$dynamicRef, | ||
Keyword$defs, | ||
Keyword$comment, | ||
KeywordAllOf, | ||
KeywordAnyOf, | ||
KeywordOneOf, | ||
KeywordNot, | ||
KeywordIf, | ||
KeywordThen, | ||
KeywordElse, | ||
KeywordDependentSchemas, | ||
KeywordPrefixItems, | ||
KeywordItems, | ||
KeywordContains, | ||
KeywordProperties, | ||
KeywordPatternProperties, | ||
KeywordAdditionalProperties, | ||
KeywordPropertyNames, | ||
KeywordUnevaluatedItems, | ||
KeywordUnevaluatedProperties, | ||
KeywordType, | ||
KeywordEnum, | ||
KeywordConst, | ||
KeywordConstraint, | ||
KeywordDependentRequired, | ||
KeywordContentSchema, | ||
KeywordTitle, | ||
KeywordDescription, | ||
KeywordDefault, | ||
KeywordDeprecated, | ||
KeywordReadOnly, | ||
KeywordWriteOnly, | ||
Accordion, | ||
ExpandDeepButton, | ||
ChevronRightIcon, | ||
}, | ||
fn: { | ||
upperFirst: fn.upperFirst, | ||
isExpandable: makeIsExpandable( | ||
fn.jsonSchema202012.isExpandable, | ||
system | ||
), | ||
}, | ||
}) | ||
|
||
return <ModelWithJSONSchemaContext {...props} /> | ||
} | ||
) | ||
|
||
export default ModelWrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.