@scalar/oas-utils
Advanced tools
Comparing version 0.1.14 to 0.1.15
# @scalar/oas-utils | ||
## 0.1.15 | ||
### Patch Changes | ||
- f472998: feat: generated example values based on the given format | ||
## 0.1.14 | ||
@@ -4,0 +10,0 @@ |
@@ -112,2 +112,35 @@ import { parse, stringify } from 'yaml'; | ||
function guessFromFormat(schema, fallback = "") { | ||
const exampleValues = { | ||
// 'date-time': '1970-01-01T00:00:00Z', | ||
"date-time": (/* @__PURE__ */ new Date()).toISOString(), | ||
// 'date': '1970-01-01', | ||
"date": (/* @__PURE__ */ new Date()).toISOString().split("T")[0], | ||
"email": "hello@example.com", | ||
"hostname": "example.com", | ||
// https://tools.ietf.org/html/rfc6531#section-3.3 | ||
"idn-email": "jane.doe@example.com", | ||
// https://tools.ietf.org/html/rfc5890#section-2.3.2.3 | ||
"idn-hostname": "example.com", | ||
"ipv4": "127.0.0.1", | ||
"ipv6": "51d4:7fab:bfbf:b7d7:b2cb:d4b4:3dad:d998", | ||
"iri-reference": "/entitiy/1", | ||
// https://tools.ietf.org/html/rfc3987 | ||
"iri": "https://example.com/entity/123", | ||
"json-pointer": "/nested/objects", | ||
"password": "super-secret", | ||
"regex": "/[a-z]/", | ||
// https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01 | ||
"relative-json-pointer": "1/nested/objects", | ||
// full-time in https://tools.ietf.org/html/rfc3339#section-5.6 | ||
// 'time': '00:00:00Z', | ||
"time": (/* @__PURE__ */ new Date()).toISOString().split("T")[1].split(".")[0], | ||
// either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1 | ||
"uri-reference": "../folder", | ||
"uri-template": "https://example.com/{id}", | ||
"uri": "https://example.com", | ||
"uuid": "123e4567-e89b-12d3-a456-426614174000" | ||
}; | ||
return exampleValues[schema.format] ?? fallback; | ||
} | ||
const getExampleFromSchema = (schema, options, level = 0) => { | ||
@@ -117,2 +150,3 @@ if (level > 5) { | ||
} | ||
const makeUpRandomData = !!options?.emptyString; | ||
if (options?.mode === "write" && schema.readOnly) { | ||
@@ -246,3 +280,3 @@ return void 0; | ||
const exampleValues = { | ||
string: options?.emptyString ?? "", | ||
string: makeUpRandomData ? guessFromFormat(schema, options?.emptyString) : "", | ||
boolean: true, | ||
@@ -249,0 +283,0 @@ integer: schema.min ?? 1, |
@@ -19,3 +19,3 @@ { | ||
], | ||
"version": "0.1.14", | ||
"version": "0.1.15", | ||
"engines": { | ||
@@ -22,0 +22,0 @@ "node": ">=18" |
Sorry, the diff of this file is not supported yet
52855
1227