Skip to content

Conversation

@slonikmak
Copy link

No description provided.

[:input {:type "submit" :value "Generate"}]]]]))

(defn gen-data-response [spec]
(let [decoded-spec (json-to-edn spec)]
Copy link

@astynax astynax Jan 14, 2025

Choose a reason for hiding this comment

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

Строго говоря, тут может и ошибка возникнуть, если JSON не получится декодировать.

UPD: вижу, что ниже эта ошибка обрабатывается. Но я бы ожидал отлов ошибки парсинга здесь, раз уж в этой функции вы уже responses возвращаете, в том числе и bad request.

(invalid-spec-response decoded-spec))))

(defn redirect-response [spec-json]
(see-other (str "/?spec=" (URLEncoder/encode ^String spec-json "UTF-8"))))
Copy link

Choose a reason for hiding this comment

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

Можно воспользоваться hiccup.util/url, раз уж hiccup всё равно используется в проекте

@astynax
Copy link

astynax commented Jan 14, 2025

Солидно! Отличная работа!

[ring.util.http-response :refer :all]
[hiccup.core :refer [html]]
[schema.core :as s])
(:gen-class)
Copy link

Choose a reason for hiding this comment

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

gen-class обычно в самом конце пишут. Или хотя бы require и import рядом располагают, как связанные по смыслу директивы

(GET "/" []
(html [:h1 "Hello World!"])))
{:port 8000}))
(run-jetty app {:port 8000 :join? false}))
Copy link

Choose a reason for hiding this comment

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

В main как раз нужно делать join, иначе если вы запустите программу не из REPL, то сервер тут же будет остановлен, поскольку главный поток завершит работу сразу же.

Comment on lines +8 to +9
(let [minimum (:minimum schema 0)
maximum (:maximum schema Integer/MAX_VALUE)]
Copy link

Choose a reason for hiding this comment

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

Можно попробовать вынести эти опции в деструктуризацию и указать значения по умолчанию там же через :or {minimum 0 ..}.

([schema count]
(gen/sample (gen-schema schema) count))
([schema]
(first (gen-example schema 1))))
Copy link

@astynax astynax Jan 14, 2025

Choose a reason for hiding this comment

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

Я бы не очень хотел, чтобы функция возвращала здесь не последовательность, а один элемент, даже если count подразумевается равным единице - не очень приятно получать результаты вызова функции, имеющие разные типы без особой на то нужды. Если хочется возвращать именно один элемент, то имеет смысл завести две функции: gen-example и gen-examples.

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.

2 participants