anchor.diff:                       :test #'equalp
                        :value #'identity))
   
  -(defun encode-swagger-operation (operation)
  -  (flet ((encode-parameter (parameter required-p)
  -           (if (not required-p)
  -               (with-accessors ((name argument-name)
  -                                (type argument-type)
  -                                (default-value argument-default)
  -                                (documentation argument-documentation))
  -                   parameter
  -                 (declare (ignore default-value))
  -                 (json:with-object ()
  -                   (json:encode-object-member :name name)
  -                   (json:encode-object-member :type type)
  -                   (json:encode-object-member :param-type "query")
  -                   (json:encode-object-member :description documentation)
  -                   (json:encode-object-member :required :false)
  -                   (json:encode-object-member :allow-multiple :false)))
  -               (with-accessors ((name argument-name)
  -                                (type argument-type)
  -                                (documentation argument-documentation))
  -                   parameter
  -                 (json:with-object ()
  -                   (json:encode-object-member :name name)
  -                   (json:encode-object-member :type type)
  -                   (json:encode-object-member :param-type "path")
  -                   (json:encode-object-member :description documentation)
  -                   (json:encode-object-member :required t)
  -                   (json:encode-object-member :allow-multiple :false))))))
  -    (json:with-object ()
  -      (json:encode-object-member :method (string-upcase (symbol-name (request-method operation))))
  -      (json:encode-object-member :summary (api-summary operation))
  -      (json:encode-object-member :notes (api-documentation operation))
  -      (json:encode-object-member :nickname (symbol-name (name operation)))
  -      #+nil(json:encode-object-member :type (resource-operation-type operation))
  -      (when (produces operation)
  -        (json:encode-object-member :produces (mapcar #'mime-to-string (produces operation))))
  -      (when (consumes operation)
  -        (json:encode-object-member :consumes (mapcar #'mime-to-string (consumes operation))))
  -      (json:as-object-member (:parameters)
  -        (json:with-array ()
  -          (loop for parameter in (required-arguments operation)
  -             do
  -               (json:as-array-member ()
  -                 (encode-parameter parameter t)))
  -          (loop for parameter in (optional-arguments operation)
  -             do
  -               (json:as-array-member ()
  -                 (encode-parameter parameter nil)))
  -          (when (member (request-method operation) (list :post :put :patch))
  -            (json:as-array-member ()
  -              (json:with-object ()
  -                (json:encode-object-member :name "body")
  -                (json:encode-object-member :type (string-downcase (princ-to-string (body-type operation))))
  -                (json:encode-object-member :param-type "body")
  -                (json:encode-object-member :description "The content")
  -                (json:encode-object-member :required t)
  -                (json:encode-object-member :allow-multiple :false))))))
  -      (json:as-object-member (:authorizations)
  -        (encode-swagger-authorizations (authorizations operation)))
  -      )))
  +(defun encode-swagger-operation (operation &optional (stream json:*json-output*))
  +  (let ((json:*json-output* stream))
  +    (flet ((encode-parameter (parameter required-p)
  +             (if (not required-p)
  +                 (with-accessors ((name argument-name)
  +                                  (type argument-type)
  +                                  (default-value argument-default)
  +                                  (documentation argument-documentation))
  +                     parameter
  +                   (declare (ignore default-value))
  +                   (json:with-object ()
  +                     (json:encode-object-member :name name)
  +                     (json:encode-object-member :type type)
  +                     (json:encode-object-member :param-type "query")
  +                     (json:encode-object-member :description documentation)
  +                     (json:encode-object-member :required :false)
  +                     (json:encode-object-member :allow-multiple :false)))
  +                 (with-accessors ((name argument-name)
  +                                  (type argument-type)
  +                                  (documentation argument-documentation))
  +                     parameter
  +                   (json:with-object ()
  +                     (json:encode-object-member :name name)
  +                     (json:encode-object-member :type type)
  +                     (json:encode-object-member :param-type "path")
  +                     (json:encode-object-member :description documentation)
  +                     (json:encode-object-member :required t)
  +                     (json:encode-object-member :allow-multiple :false))))))
  +      (json:as-object-member ((string-downcase (princ-to-string (request-method operation))))
  +                             (json:with-object ()
  +                               (json:encode-object-member :method (string-upcase (symbol-name (request-method operation))))
  +                               (json:encode-object-member :summary (api-summary operation))
  +                               (json:encode-object-member :notes (api-documentation operation))
  +                               (json:encode-object-member :nickname (symbol-name (name operation)))
  +                               #+nil(json:encode-object-member :type (resource-operation-type operation))
  +                               (when (produces operation)
  +                                 (json:encode-object-member :produces (mapcar #'mime-to-string (produces operation))))
  +                               (when (consumes operation)
  +                                 (json:encode-object-member :consumes (mapcar #'mime-to-string (consumes operation))))
  +                               (json:as-object-member (:parameters)
  +                                                      (json:with-array ()
  +                                                        (loop for parameter in (required-arguments operation)
  +                                                           do
  +                                                             (json:as-array-member ()
  +                                                               (encode-parameter parameter t)))
  +                                                        (loop for parameter in (optional-arguments operation)
  +                                                           do
  +                                                             (json:as-array-member ()
  +                                                               (encode-parameter parameter nil)))
  +                                                        (when (member (request-method operation) (list :post :put :patch))
  +                                                          (json:as-array-member ()
  +                                                            (json:with-object ()
  +                                                              (json:encode-object-member :name "body")
  +                                                              (json:encode-object-member :type (string-downcase (princ-to-string (body-type operation))))
  +                                                              (json:encode-object-member :param-type "body")
  +                                                              (json:encode-object-member :description "The content")
  +                                                              (json:encode-object-member :required t)
  +                                                              (json:encode-object-member :allow-multiple :false))))))
  +                               #+nil(json:as-object-member (:security)
  +                                                      (encode-swagger-authorizations (authorizations operation)))
  +                               )))))
  +
  +(defun encode-swagger-path (path stream)
  +  (let ((json:*json-output* stream))
  +    (json:as-object-member ((first path))
  +      (json:with-object ()
  +        (loop for operation in (cdr path)
  +           do (encode-swagger-operation operation stream))))))
  +  
  +(defun encode-swagger-resource (resource stream)
  +  (let ((json:*json-output* stream))
  +    (json:as-object-member ((resource-path resource))
  +      (json:with-object ()
  +        (loop for operation in (alexandria:hash-table-values (resource-operations resource))
  +           do (encode-swagger-operation operation stream))))))
   
   (defun swagger-resource-spec (api resource base-url)
     (setf (hunchentoot:header-out "Content-Type") "application/json")
     (setf (hunchentoot:header-out "Access-Control-Allow-Origin") "*")
     (with-output-to-string (json:*json-output*)
  -    (json:with-object ()
  -      (json:encode-object-member
  -       :api-version (or (version api) "0.1"))
  -      (json:encode-object-member
  -       :swagger-version "1.2")
  -      (json:encode-object-member
  -       :base-path base-url)
  -      (json:encode-object-member
  -       :resource-path (resource-path resource))
  -      (json:encode-object-member
  -       :produces (mapcar #'mime-to-string (resource-produces resource)))
  -      (json:as-object-member (:apis)
  -        (json:with-array ()
  -          (loop for api in (resource-apis resource)
  -             do
  -               (json:as-array-member ()
  -                 (destructuring-bind (path &rest operations) api
  -                   (json:with-object ()
  -                     (json:encode-object-member :path path)
  -                     (json:as-object-member (:operations)
  -                       (json:with-array ()
  -                         (loop for operation in operations
  -                            do (json:as-array-member ()
  -                                 (encode-swagger-operation operation)))))))))))
  -      (json:as-object-member (:models)
  -        (encode-swagger-models (mapcar #'rs.schema:find-schema (resource-models resource))))
  -      )))
  +    (encode-swagger-resource resource json:*json-output*)))
   
   (defun mime-to-string (mime-type)
     (cond
  
positive.code:         (json:with-object ()
            (json:encode-object-member :title (or (title api)
                                                  (name api)))
            (json:encode-object-member :description (api-documentation api)))))))
  
  (defun resource-apis (resource)
    "Get Swagger apis from the resource"
  
negative.code:        (:xml "application/xml")
         (:plain "text/plain")
         (:html "text/html")
         (:sexp "application/sexp")
         (:raw "application/octets")))
      (t (error "Invalid mime type ~S" mime-type))))
  
  (defun encode-swagger-model (schema-element)
  