Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle exclusiveMinimum/exclusiveMaximum in bodies #37

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ const isParameterSchemaUnsupported = (schema: ParsedSpecJsonSchemaCore): boolean

// draft-06 onwards converts exclusiveMinimum and exclusiveMaximum to numbers
const upgradeSchema = (schema: ParsedSpecJsonSchemaCore): ParsedSpecJsonSchemaCore => {
if (schema.exclusiveMaximum) {
schema.exclusiveMaximum = schema.maximum;
}
if (schema.exclusiveMinimum) {
schema.exclusiveMinimum = schema.minimum;
}
schema.exclusiveMaximum = schema.exclusiveMaximum ? schema.maximum : undefined;
schema.exclusiveMinimum = schema.exclusiveMinimum ? schema.minimum : undefined;
return schema;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const transformSchema = (
}
});

// draft-06 onwards converts exclusiveMinimum and exclusiveMaximum to numbers
traverseJsonSchema(modifiedSchema, (mutableSchema) => {
mutableSchema.exclusiveMaximum = mutableSchema.exclusiveMaximum ? mutableSchema.maximum : undefined;
mefellows marked this conversation as resolved.
Show resolved Hide resolved
mutableSchema.exclusiveMinimum = mutableSchema.exclusiveMinimum ? mutableSchema.minimum : undefined;
});

return modifiedSchema;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ const transformSchema = (
}
});

// draft-06 onwards converts exclusiveMinimum and exclusiveMaximum to numbers
traverseJsonSchema(modifiedSchema, (mutableSchema) => {
mutableSchema.exclusiveMaximum = mutableSchema.exclusiveMaximum ? mutableSchema.maximum : undefined;
mutableSchema.exclusiveMinimum = mutableSchema.exclusiveMinimum ? mutableSchema.minimum : undefined;
});

return modifiedSchema;
};

Expand Down
6 changes: 6 additions & 0 deletions test/e2e/fixtures/openapi3-provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ components:
type: string
email:
type: string
age:
type: integer
minimum: 19
exclusiveMinimum: true
maximum: 100
exclusiveMaximum: false
required:
- userId
- firstName
Expand Down
Loading