@scalar/oas-utils
Advanced tools
Comparing version 0.2.50 to 0.2.51
# @scalar/oas-utils | ||
## 0.2.51 | ||
### Patch Changes | ||
- ef49617: chore: improve performance of getExampleFromSchema | ||
- Updated dependencies [8f12149] | ||
- Updated dependencies [1026d81] | ||
- Updated dependencies [07b5439] | ||
- @scalar/types@0.0.12 | ||
- @scalar/themes@0.9.33 | ||
## 0.2.50 | ||
@@ -4,0 +15,0 @@ |
@@ -6,5 +6,5 @@ const defaultStateFactory = () => ({}); | ||
const ssrState = typeof window !== 'undefined' | ||
? window.__SCALAR__ ?? defaultStateFactory() | ||
? (window.__SCALAR__ ?? defaultStateFactory()) | ||
: defaultStateFactory(); | ||
export { defaultStateFactory, ssrState }; |
/** Hard limit for rendering circular references */ | ||
const MAX_LEVELS_DEEP = 5; | ||
const MAX_LEVELS_DEEP = 10; | ||
const genericExampleValues = { | ||
// 'date-time': '1970-01-01T00:00:00Z', | ||
'date-time': new Date().toISOString(), | ||
// 'date': '1970-01-01', | ||
'date': 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': 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', | ||
}; | ||
/** | ||
@@ -7,33 +37,3 @@ * We can use the `format` to generate some random values. | ||
function guessFromFormat(schema, fallback = '') { | ||
const exampleValues = { | ||
// 'date-time': '1970-01-01T00:00:00Z', | ||
'date-time': new Date().toISOString(), | ||
// 'date': '1970-01-01', | ||
'date': 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': 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; | ||
return genericExampleValues[schema.format] ?? fallback; | ||
} | ||
@@ -57,10 +57,7 @@ /** | ||
const makeUpRandomData = !!options?.emptyString; | ||
// Check if the property is read-only | ||
if (options?.mode === 'write' && schema.readOnly) { | ||
// Check if the property is read-only/write-only | ||
if ((options?.mode === 'write' && schema.readOnly) || | ||
(options?.mode === 'read' && schema.writeOnly)) { | ||
return undefined; | ||
} | ||
// Check if the property is write-only | ||
if (options?.mode === 'read' && schema.writeOnly) { | ||
return undefined; | ||
} | ||
// Use given variables as values | ||
@@ -91,3 +88,3 @@ if (schema['x-variable']) { | ||
// enum: [ 'available', 'pending', 'sold' ] | ||
if (schema.enum !== undefined) { | ||
if (Array.isArray(schema.enum) && schema.enum.length > 0) { | ||
return schema.enum[0]; | ||
@@ -114,10 +111,14 @@ } | ||
if (schema.properties !== undefined) { | ||
Object.keys(schema.properties).forEach((propertyName) => { | ||
const property = schema.properties[propertyName]; | ||
const propertyXmlTagName = options?.xml ? property.xml?.name : undefined; | ||
response[propertyXmlTagName ?? propertyName] = getExampleFromSchema(property, options, level + 1, schema, propertyName); | ||
if (typeof response[propertyXmlTagName ?? propertyName] === 'undefined') { | ||
delete response[propertyXmlTagName ?? propertyName]; | ||
for (const propertyName in schema.properties) { | ||
if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) { | ||
const property = schema.properties[propertyName]; | ||
const propertyXmlTagName = options?.xml | ||
? property.xml?.name | ||
: undefined; | ||
response[propertyXmlTagName ?? propertyName] = getExampleFromSchema(property, options, level + 1, schema, propertyName); | ||
if (typeof response[propertyXmlTagName ?? propertyName] === 'undefined') { | ||
delete response[propertyXmlTagName ?? propertyName]; | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
@@ -243,3 +244,3 @@ // Additional properties | ||
// Warn if the type is unknown … | ||
console.warn(`[getExampleFromSchema] Unknown property type "${schema.type}".`); | ||
// console.warn(`[getExampleFromSchema] Unknown property type "${schema.type}".`) | ||
// … and just return null for now. | ||
@@ -246,0 +247,0 @@ return null; |
@@ -19,3 +19,3 @@ { | ||
], | ||
"version": "0.2.50", | ||
"version": "0.2.51", | ||
"engines": { | ||
@@ -98,4 +98,4 @@ "node": ">=18" | ||
"@scalar/openapi-types": "0.1.1", | ||
"@scalar/themes": "0.9.32", | ||
"@scalar/types": "0.0.11" | ||
"@scalar/types": "0.0.12", | ||
"@scalar/themes": "0.9.33" | ||
}, | ||
@@ -109,3 +109,3 @@ "devDependencies": { | ||
"@scalar/build-tooling": "0.1.10", | ||
"@scalar/openapi-parser": "0.8.4", | ||
"@scalar/openapi-parser": "0.8.5", | ||
"@scalar/openapi-types": "0.1.1" | ||
@@ -112,0 +112,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
351469
7418
+ Added@scalar/themes@0.9.33(transitive)
+ Added@scalar/types@0.0.12(transitive)
+ Added@unhead/schema@1.11.12(transitive)
- Removed@scalar/themes@0.9.32(transitive)
- Removed@scalar/types@0.0.11(transitive)
- Removed@unhead/schema@1.11.13(transitive)
Updated@scalar/themes@0.9.33
Updated@scalar/types@0.0.12