anchor.diff:    (setf (hunchentoot:header-out "Content-Type") "application/json")
     (setf (hunchentoot:header-out "Access-Control-Allow-Origin") "*")
     (with-output-to-string (json:*json-output*)
  -    (render-swagger-api-spec api json:*json-output*)))
  +    (encode-swagger-api api json:*json-output*)))
     
  -(defun render-swagger-api-spec (api stream)
  +(defun encode-swagger-api (api stream)
     (let ((json:*json-output* stream))
       (json:with-object ()
         (json:encode-object-member :api-version (or (version api) "0.1"))
  -      (json:encode-object-member :swagger-version "1.2")
  -      (json:as-object-member (:apis)
  +      (json:encode-object-member :swagger "2.0")
  +      (json:as-object-member (:paths)
           (json:with-array ()
             (loop for resource in (list-api-resources api)
                when (not (equalp (resource-name resource) 'api-docs))
  
positive.code:                      :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 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))))
        )))
  
  (defun mime-to-string (mime-type)
    (cond
  
negative.code:         (json:with-object ()
            (json:encode-object-member :title (or (title api)
                                                  (name api)))
            (json:encode-object-member :description (api-documentation api))))
        (json:as-object-member (:paths)
                               (json:with-object ()
                                 (loop for path in (list-api-paths api)
                                    do
                                      (encode-swagger-path path stream))))
        #+nil(json:as-object-member (:definitions)
          (loop for resource in (list-api-resources api)
             do
               (encode-swagger-models (mapcar #'rs.schema:find-schema (resource-models resource)))))
        )))
  
  (defun list-api-paths (api)
    (let ((api-operations (alexandria:flatten
                           (loop for resource in (list-api-resources api)
                             collect (alexandria:hash-table-values
                                        (resource-operations resource))))))
      (group-by:group-by api-operations
                         :key #'rest-server::path
                         :test #'equalp
                         :value #'identity)))
  
  (defun resource-apis (resource)
    "Get Swagger apis from the resource"
  