Skip to content

Commit

Permalink
fix(json-schema-2020-12): custom OAS 3.1 formats in type inferrence (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
char0n authored Jun 11, 2023
1 parent fd18aaa commit 12c7493
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/core/plugins/json-schema-2020-12/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ export const getType = (schema, processedSchemas = new WeakSet()) => {
Object.hasOwn(schema, "patternProperties")
) {
return "object"
} else if (
Object.hasOwn(schema, "pattern") ||
Object.hasOwn(schema, "format") ||
Object.hasOwn(schema, "minLength") ||
Object.hasOwn(schema, "maxLength")
) {
return "string"
} else if (["int32", "int64"].includes(schema.format)) {
// OpenAPI 3.1.0 integer custom formats
return "integer"
} else if (["float", "double"].includes(schema.format)) {
// OpenAPI 3.1.0 number custom formats
return "number"
} else if (
Object.hasOwn(schema, "minimum") ||
Object.hasOwn(schema, "maximum") ||
Expand All @@ -85,6 +84,13 @@ export const getType = (schema, processedSchemas = new WeakSet()) => {
Object.hasOwn(schema, "multipleOf")
) {
return "number | integer"
} else if (
Object.hasOwn(schema, "pattern") ||
Object.hasOwn(schema, "format") ||
Object.hasOwn(schema, "minLength") ||
Object.hasOwn(schema, "maxLength")
) {
return "string"
} else if (typeof schema.const !== "undefined") {
if (schema.const === null) {
return "null"
Expand Down

0 comments on commit 12c7493

Please # to comment.