Skip to content

Commit

Permalink
feat(samples): add support for new values of format keyword (#8882)
Browse files Browse the repository at this point in the history
This change is specific to JSON Schema 2020-12
and OpenAPI 3.1.0.

Refs #8577
  • Loading branch information
char0n committed Jun 5, 2023
1 parent 53096ab commit 28b1233
Show file tree
Hide file tree
Showing 4 changed files with 2,715 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ settings:
rules:
semi: [2, never]
strict: 0
quotes: [2, double, { allowTemplateLiterals: true }]
quotes: [2, double, { avoidEscape: true, allowTemplateLiterals: true }]
no-unused-vars: 2
no-multi-spaces: 1
camelcase: 1
Expand All @@ -37,4 +37,4 @@ rules:
react/display-name: 0
mocha/no-exclusive-tests: 2
import/no-extraneous-dependencies: 2
react/jsx-filename-extension: 2
react/jsx-filename-extension: 2
25 changes: 21 additions & 4 deletions src/core/plugins/json-schema-2020-12/samples-extensions/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,39 @@ const generateStringFromRegex = (pattern) => {
}
}

/* eslint-disable camelcase */
const primitives = {
string: (schema) =>
schema.pattern ? generateStringFromRegex(schema.pattern) : "string",
string_email: () => "user@example.com",
"string_date-time": () => new Date().toISOString(),
string_date: () => new Date().toISOString().substring(0, 10),
string_uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"string_idn-email": () => "실례@example.com",
string_hostname: () => "example.com",
"string_idn-hostname": () => "실례.com",
string_ipv4: () => "198.51.100.42",
string_ipv6: () => "2001:0db8:5b96:0000:0000:426f:8e17:642a",
string_uri: () => "https://example.com/",
"string_uri-reference": () => "path/index.html",
string_iri: () => "https://실례.com/",
"string_iri-reference": () => "path/실례.html",
string_uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"string_uri-template": () => "https://example.com/dictionary/{term:1}/{term}",
"string_json-pointer": () => "/a/b/c",
"string_relative-json-pointer": () => "1/0",
"string_date-time": () => new Date().toISOString(),
string_date: () => new Date().toISOString().substring(0, 10),
string_time: () => new Date().toISOString().substring(11),
string_duration: () => "P3D", // expresses a duration of 3 days
string_password: () => "********",
number: () => 0,
number_float: () => 0.0,
number_float: () => 0.1,
number_double: () => 0.1,
integer: () => 0,
integer_int32: () => (2 ** 30) >>> 0,
integer_int64: () => 2 ** 53 - 1,
boolean: (schema) =>
typeof schema.default === "boolean" ? schema.default : true,
}
/* eslint-enable camelcase */

const primitive = (schema) => {
schema = objectify(schema)
Expand Down

0 comments on commit 28b1233

Please sign in to comment.