-
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(samples): add support for contentSchema keyword (#8907)
This change is specific to JSON Schema 2020-12 and OpenAPI 3.1.0. Refs #8577
- Loading branch information
Showing
9 changed files
with
174 additions
and
35 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/core/plugins/json-schema-2020-12/samples-extensions/fn/core/constants.js
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,6 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
export const SCALAR_TYPES = ["integer", "number", "string", "boolean", "null"] | ||
|
||
export const ALL_TYPES = ["array", "object", ...SCALAR_TYPES] |
24 changes: 24 additions & 0 deletions
24
src/core/plugins/json-schema-2020-12/samples-extensions/fn/core/fold-type.js
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,24 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import { ALL_TYPES } from "./constants" | ||
|
||
const foldType = (type) => { | ||
if (Array.isArray(type)) { | ||
if (type.includes("array")) { | ||
return "array" | ||
} else if (type.includes("object")) { | ||
return "object" | ||
} else if (ALL_TYPES.includes(type.at(0))) { | ||
return type.at(0) | ||
} | ||
} | ||
|
||
if (typeof type === "string" && ALL_TYPES.includes(type)) { | ||
return type | ||
} | ||
|
||
return null | ||
} | ||
|
||
export default foldType |
24 changes: 24 additions & 0 deletions
24
src/core/plugins/json-schema-2020-12/samples-extensions/fn/core/predicates.js
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,24 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import isPlainObject from "lodash/isPlainObject" | ||
|
||
export const isURI = (uri) => { | ||
try { | ||
return new URL(uri) && true | ||
} catch { | ||
return false | ||
} | ||
} | ||
|
||
export const isBooleanJSONSchema = (schema) => { | ||
return typeof schema === "boolean" | ||
} | ||
|
||
export const isJSONSchemaObject = (schema) => { | ||
return isPlainObject(schema) | ||
} | ||
|
||
export const isJSONSchema = (schema) => { | ||
return isBooleanJSONSchema(schema) || isJSONSchemaObject(schema) | ||
} |
23 changes: 18 additions & 5 deletions
23
src/core/plugins/json-schema-2020-12/samples-extensions/fn/core/utils.js
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 |
---|---|---|
@@ -1,10 +1,23 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
export const isURI = (uri) => { | ||
try { | ||
return new URL(uri) && true | ||
} catch { | ||
return false | ||
import { isBooleanJSONSchema, isJSONSchemaObject } from "./predicates" | ||
|
||
export const fromJSONBooleanSchema = (schema) => { | ||
if (schema === false) { | ||
return { not: {} } | ||
} | ||
|
||
return {} | ||
} | ||
|
||
export const typeCast = (schema) => { | ||
if (isBooleanJSONSchema(schema)) { | ||
return fromJSONBooleanSchema(schema) | ||
} | ||
if (!isJSONSchemaObject(schema)) { | ||
return {} | ||
} | ||
|
||
return schema | ||
} |
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