<commit_before>package org.scalatra
package swagger

import Symbols._
import collection.JavaConverters._
import util.RicherString._
import javax.servlet.{ Servlet, Filter, Registration }
import com.wordnik.swagger.core.ApiPropertiesReader
import grizzled.slf4j.Logger

/**
 * Provides the necessary support for adding documentation to your routes.
 */
trait SwaggerSupport extends Initializable { self: ScalatraBase =>

  protected implicit def swagger: Swagger

  protected def applicationName: Option[String] = None
  protected def applicationDescription: String

  private[this] def throwAFit =
    throw new IllegalStateException("I can't work out which servlet registration this is.")

  private[this] def registerInSwagger(name: String, servPath: String) = {
    val thePath = {
      val p = if (servPath.endsWith("/*")) servPath.dropRight(2) else servPath
      if (p.startsWith("/")) p else "/" + p
    }
    val listingPath = {
      val inferred = inferListingPath()
      inferred map { lp =>
        val p = if (lp.endsWith("/*")) lp.dropRight(2) else lp
        val sp = applicationName getOrElse  (if (servPath.endsWith("/*")) servPath.dropRight(2) else servPath)
        val ssp = if (sp.startsWith("/")) sp else "/" + sp
        val lpp = if (p.startsWith("/")) p else "/" + p 
        if (lpp == "/") ssp else lpp + ssp
      }
    }

    println("The listing path: %s" format listingPath)

    swagger.register(name, thePath, applicationDescription, this, listingPath)<commit_msg>Make SwaggerSupport inherit CorsSupport so it works from swagger-ui<commit_after>package org.scalatra
package swagger

import Symbols._
import collection.JavaConverters._
import util.RicherString._
import javax.servlet.{ Servlet, Filter, Registration }
import com.wordnik.swagger.core.ApiPropertiesReader
import grizzled.slf4j.Logger

/**
 * Provides the necessary support for adding documentation to your routes.
 */
trait SwaggerSupport extends Initializable with CorsSupport { self: ScalatraBase =>

  protected implicit def swagger: Swagger

  protected def applicationName: Option[String] = None
  protected def applicationDescription: String

  private[this] def throwAFit =
    throw new IllegalStateException("I can't work out which servlet registration this is.")

  private[this] def registerInSwagger(name: String, servPath: String) = {
    val thePath = {
      val p = if (servPath.endsWith("/*")) servPath.dropRight(2) else servPath
      if (p.startsWith("/")) p else "/" + p
    }
    val listingPath = {
      val inferred = inferListingPath()
      inferred map { lp =>
        val p = if (lp.endsWith("/*")) lp.dropRight(2) else lp
        val sp = applicationName getOrElse  (if (servPath.endsWith("/*")) servPath.dropRight(2) else servPath)
        val ssp = if (sp.startsWith("/")) sp else "/" + sp
        val lpp = if (p.startsWith("/")) p else "/" + p 
        if (lpp == "/") ssp else lpp + ssp
      }
    }

    println("The listing path: %s" format listingPath)

    swagger.register(name, thePath, applicationDescription, this, listingPath)
{'fraction_non_alphanumeric': 0.1104594330400782, 'fraction_numerical': 0.002606712284131639, 'mean_word_length': 3.582089552238806, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5043850', 'n_tokens_mistral': 908, 'n_tokens_neox': 888, 'n_words': 285}