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

Set JSON Schema types and formats for numbers properly #354

Merged
merged 2 commits into from
Jan 28, 2021

Conversation

Deraen
Copy link
Member

@Deraen Deraen commented Jan 26, 2021

  • Note that number formats aren't mentioned in JSON Schema spec, but are
    from OpenAPI spec.
  • Comparators shouldn't automatically set format to double.
  • Set format double for :double and double?.
  • decimal? is BigDecimal, so that is not a double.
  • Fix rational? type to number, double isn't valid type
  • Fix ratio? type to number, ratios aren't integers.

- Note that number formats aren't mentioned in JSON Schema spec, but are
  from OpenAPI spec.
- Comparators shouldn't automatically set format to double.
- Set format double for :double and double?.
- decimal? is BigDecimal, so that is not a double.
- Fix rational? type to number, double isn't valid type
- Fix ratio? type to number, ratios aren't integers.
@Deraen Deraen force-pushed the json-schema-number-formats branch 2 times, most recently from c6bcafa to 727c58f Compare January 26, 2021 17:54
@@ -105,7 +105,8 @@
(merge {:type "integer"} (-> schema m/properties (select-keys [:min :max]) (set/rename-keys {:min :minimum, :max :maximum}))))

(defmethod accept :double [_ schema _ _]
(merge {:type "number"} (-> schema m/properties (select-keys [:min :max]) (set/rename-keys {:min :minimum, :max :maximum}))))
(merge {:type "number"}
(-> schema m/properties (select-keys [:min :max]) (set/rename-keys {:min :minimum, :max :maximum}))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thks could be a helper in json-schema as it's now copied 3 times already.


(defmethod accept :int [_ schema _ _]
(merge {:type "integer" :format "int64"}
(-> schema m/properties (select-keys [:min :max]) (set/rename-keys {:min :minimum, :max :maximum}))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double-check: is this inclusive or exclusive? Json schema separates the two.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inclusive.

@nilern nilern added this to the 0.3.0 milestone Jan 27, 2021
@ikitommi ikitommi merged commit 0eb5c11 into master Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants