Spec form metadata is lost on visiting it during Swagger UI generation
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 45/100
Piste de recherche
Commencez par spec-tools.visitor/visit et spec-tools.impl/extract-form, puis exécutez la reproduction fournie sur le chemin de génération de Swagger UI pour les specs personnalisées dans :return et :body. Comparez les métadonnées du formulaire extrait avec le cas fonctionnel de s/coll-of ; c’est terminé lorsque les métadonnées attendues restent disponibles pour le visitor personnalisé.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Library Version(s)
2.0.0-alpha29
Problem
I need to redefine spec-tools.visitor/visit for my custom spec to change how spec is shown in Swagger UI. E.g. I have closed-keys custom spec, but want to visit it as s/keys, so that Swagger UI generates appropriate model examples from my spec.
Now, it can be cumbersome to parse the custom spec form to implement its visiting. So I want instead to rely on the metadata attached to the spec form (such easy to use metadata can be conveniently generated by closed-keys macro). I.e.:
(defmethod st-visitor/visit-spec `closed-keys
[spec accept options]
(let [form (st-impl/extract-form spec)
keys-form <generate from (meta form)>]
(st-visitor/visit-spec keys-form accept options)))
But this currently doesn't work because (meta form) is always nil in this function.
I only managed to trace it back to spec-tools.visitor/visit function: it seems to get already crooked spec with no metadata in its form.
The issue is reproducible for custom specs used in :return and :body. I didn't test other places.
Steps:
- Code:
(ns app.foo.handler
(:require [compojure.api.sweet :as c]
[ring.util.http-response :as r]
[clojure.spec.alpha :as s]
[spec-tools.visitor :as st-visitor]
[spec-tools.impl :as st-impl]))
; Helper to redefine spec form
(defn -with-form
[spec form]
{:pre [(s/spec? spec)]}
(reify s/Spec
(describe* [_] form)
; Do not modify other methods
(conform* [_ x] (s/conform* spec x))
(unform* [_ y] (s/unform* spec y))
(explain* [_ path via in x] (s/explain* spec path via in x))
(gen* [_ overrides path rmap] (s/gen* spec overrides path rmap))
(with-gen* [_ gfn] (s/with-gen* spec gfn))))
; Create spec with a custom form and metadata attached to the form
(s/def ::my-spec (-> (s/spec int?)
(-with-form
(with-meta (list 'my-spec 1 2 3) {:my-spec-form-meta [1 2 3]}))))
; Custom visiting which relies on metadata from the form
(defmethod st-visitor/visit-spec 'my-spec
[spec _accept _options]
(let [form (st-impl/extract-form spec)]
(prn :VISITED-FORM form :META (meta form))
nil))
; Handler code
(c/context "/my" []
(c/POST "/foo" []
:return ::my-spec
;:body [x ::my-spec]
(r/ok)))
- Run it and navigate to Swagger UI URL.
- Check console output.
Expected:
:VISITED-FORM (my-spec 1 2 3) :META {:my-spec-form-meta [1 2 3]}
Actual:
:VISITED-FORM (my-spec 1 2 3) :META nil
Workaround:
My current workaround is to attach metadata to the first symbol in the form instead of the whole form. Also in another case I just parse the form instead of relying on its metadata.
Interestingly, the issue is not reproducible when custom spec is "wrapped" by some other spec, specifically (s/coll-of ::my-spec) doesn't seem to have a problem.
- Langage dominant
- Clojure
- Étoiles
- 1.1k
- Forks
- 144
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de metosin/compojure-api
-
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
metosin/compojure-api#489 ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 30/100
metosin/compojure-api#468 ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 20/100
metosin/compojure-api#467 ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
metosin/compojure-api#464 ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 30/100
metosin/compojure-api#463 · 3 commentaires ·
Toutes les issues de metosin/compojure-api
Issues similaires
-
category:tooling
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 1 jour
-
.Needs Triage .Team/Gadget Priority:P3 Type:Bug
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
metabase/metabase#84431 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
IOP nitrate needs triage
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 1 jour
-
module:db module:terminology-service-local refactoring
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour