From 88474621987be4d63edc5a5014119e02bd89e325 Mon Sep 17 00:00:00 2001 From: Newell Zhu Date: Thu, 12 May 2016 01:12:44 +0800 Subject: [PATCH 1/5] setup rails 5 basic structure --- bin/rails5-petstore-server.sh | 31 ++ bin/windows/rails-petstore-server.bat | 10 + .../languages/Rails5ServerCodegen.java | 323 ++++++++++++++++++ .../services/io.swagger.codegen.CodegenConfig | 1 + .../src/main/resources/rails5/.keep | 0 .../src/main/resources/rails5/404.html | 67 ++++ .../src/main/resources/rails5/422.html | 67 ++++ .../src/main/resources/rails5/500.html | 66 ++++ .../src/main/resources/rails5/Gemfile | 36 ++ .../src/main/resources/rails5/README.md | 25 ++ .../src/main/resources/rails5/Rakefile | 6 + ...e_record_belongs_to_required_by_default.rb | 6 + .../rails5/apple-touch-icon-precomposed.png | 0 .../resources/rails5/apple-touch-icon.png | 0 .../src/main/resources/rails5/application.rb | 30 ++ .../rails5/application_controller.rb | 2 + .../rails5/application_controller_renderer.rb | 6 + .../main/resources/rails5/application_job.rb | 2 + .../resources/rails5/application_mailer.rb | 4 + .../resources/rails5/application_record.rb | 3 + .../resources/rails5/backtrace_silencers.rb | 7 + .../src/main/resources/rails5/boot.rb | 3 + .../src/main/resources/rails5/bundle | 3 + .../src/main/resources/rails5/cable.yml | 10 + .../resources/rails5/callback_terminator.rb | 6 + .../src/main/resources/rails5/channel.rb | 5 + .../src/main/resources/rails5/config.ru | 5 + .../src/main/resources/rails5/connection.rb | 5 + .../main/resources/rails5/controller.mustache | 22 ++ .../src/main/resources/rails5/cors.rb | 16 + .../src/main/resources/rails5/database.yml | 54 +++ .../src/main/resources/rails5/development.rb | 47 +++ .../src/main/resources/rails5/en.yml | 23 ++ .../src/main/resources/rails5/environment.rb | 5 + .../src/main/resources/rails5/favicon.ico | 0 .../rails5/filter_parameter_logging.rb | 4 + .../src/main/resources/rails5/inflections.rb | 16 + .../src/main/resources/rails5/mailer.html.erb | 13 + .../src/main/resources/rails5/mailer.text.erb | 1 + .../src/main/resources/rails5/mime_types.rb | 4 + .../src/main/resources/rails5/production.rb | 80 +++++ .../src/main/resources/rails5/puma.rb | 47 +++ .../src/main/resources/rails5/rails | 4 + .../src/main/resources/rails5/rake | 4 + .../src/main/resources/rails5/restart.txt | 0 .../src/main/resources/rails5/robots.txt | 5 + .../src/main/resources/rails5/routes.mustache | 3 + .../src/main/resources/rails5/schema.rb | 16 + .../src/main/resources/rails5/secrets.yml | 22 ++ .../src/main/resources/rails5/seeds.rb | 7 + .../src/main/resources/rails5/setup | 34 ++ .../src/main/resources/rails5/spring.rb | 6 + .../src/main/resources/rails5/ssl_options.rb | 4 + .../src/main/resources/rails5/test.rb | 42 +++ .../src/main/resources/rails5/test_helper.rb | 10 + .../rails5/to_time_preserves_timezone.rb | 10 + .../src/main/resources/rails5/update | 29 ++ .../main/resources/rails5/wrap_parameters.rb | 14 + .../options/Rails5ServerOptionsProvider.java | 23 ++ 59 files changed, 1294 insertions(+) create mode 100755 bin/rails5-petstore-server.sh create mode 100644 bin/windows/rails-petstore-server.bat create mode 100644 modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Rails5ServerCodegen.java create mode 100644 modules/swagger-codegen/src/main/resources/rails5/.keep create mode 100644 modules/swagger-codegen/src/main/resources/rails5/404.html create mode 100644 modules/swagger-codegen/src/main/resources/rails5/422.html create mode 100644 modules/swagger-codegen/src/main/resources/rails5/500.html create mode 100644 modules/swagger-codegen/src/main/resources/rails5/Gemfile create mode 100644 modules/swagger-codegen/src/main/resources/rails5/README.md create mode 100644 modules/swagger-codegen/src/main/resources/rails5/Rakefile create mode 100644 modules/swagger-codegen/src/main/resources/rails5/active_record_belongs_to_required_by_default.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/apple-touch-icon-precomposed.png create mode 100644 modules/swagger-codegen/src/main/resources/rails5/apple-touch-icon.png create mode 100644 modules/swagger-codegen/src/main/resources/rails5/application.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/application_controller.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/application_controller_renderer.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/application_job.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/application_mailer.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/application_record.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/backtrace_silencers.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/boot.rb create mode 100755 modules/swagger-codegen/src/main/resources/rails5/bundle create mode 100644 modules/swagger-codegen/src/main/resources/rails5/cable.yml create mode 100644 modules/swagger-codegen/src/main/resources/rails5/callback_terminator.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/channel.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/config.ru create mode 100644 modules/swagger-codegen/src/main/resources/rails5/connection.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/controller.mustache create mode 100644 modules/swagger-codegen/src/main/resources/rails5/cors.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/database.yml create mode 100644 modules/swagger-codegen/src/main/resources/rails5/development.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/en.yml create mode 100644 modules/swagger-codegen/src/main/resources/rails5/environment.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/favicon.ico create mode 100644 modules/swagger-codegen/src/main/resources/rails5/filter_parameter_logging.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/inflections.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/mailer.html.erb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/mailer.text.erb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/mime_types.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/production.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/puma.rb create mode 100755 modules/swagger-codegen/src/main/resources/rails5/rails create mode 100755 modules/swagger-codegen/src/main/resources/rails5/rake create mode 100644 modules/swagger-codegen/src/main/resources/rails5/restart.txt create mode 100644 modules/swagger-codegen/src/main/resources/rails5/robots.txt create mode 100644 modules/swagger-codegen/src/main/resources/rails5/routes.mustache create mode 100644 modules/swagger-codegen/src/main/resources/rails5/schema.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/secrets.yml create mode 100644 modules/swagger-codegen/src/main/resources/rails5/seeds.rb create mode 100755 modules/swagger-codegen/src/main/resources/rails5/setup create mode 100644 modules/swagger-codegen/src/main/resources/rails5/spring.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/ssl_options.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/test.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/test_helper.rb create mode 100644 modules/swagger-codegen/src/main/resources/rails5/to_time_preserves_timezone.rb create mode 100755 modules/swagger-codegen/src/main/resources/rails5/update create mode 100644 modules/swagger-codegen/src/main/resources/rails5/wrap_parameters.rb create mode 100644 modules/swagger-codegen/src/test/java/io/swagger/codegen/options/Rails5ServerOptionsProvider.java diff --git a/bin/rails5-petstore-server.sh b/bin/rails5-petstore-server.sh new file mode 100755 index 00000000000..28b3ca3069b --- /dev/null +++ b/bin/rails5-petstore-server.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +SCRIPT="$0" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" + +if [ ! -f "$executable" ] +then + mvn clean package +fi + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" +ags="$@ generate -t modules/swagger-codegen/src/main/resources/rails5 -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l rails5 -o samples/server/petstore/rails5" + +java $JAVA_OPTS -jar $executable $ags diff --git a/bin/windows/rails-petstore-server.bat b/bin/windows/rails-petstore-server.bat new file mode 100644 index 00000000000..55677b55197 --- /dev/null +++ b/bin/windows/rails-petstore-server.bat @@ -0,0 +1,10 @@ +set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar + +If Not Exist %executable% ( + mvn clean package +) + +set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties +set ags=generate -t modules\swagger-codegen\src\main\resources\rails5 -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l aspnet5 -o samples\server\petstore\rails5\ + +java %JAVA_OPTS% -jar %executable% %ags% diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Rails5ServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Rails5ServerCodegen.java new file mode 100644 index 00000000000..cbf77338ab3 --- /dev/null +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Rails5ServerCodegen.java @@ -0,0 +1,323 @@ +package io.swagger.codegen.languages; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import io.swagger.codegen.CodegenConfig; +import io.swagger.codegen.CodegenType; +import io.swagger.codegen.DefaultCodegen; +import io.swagger.codegen.SupportingFile; +import io.swagger.models.properties.ArrayProperty; +import io.swagger.models.properties.MapProperty; +import io.swagger.models.properties.Property; +import io.swagger.models.Swagger; +import io.swagger.util.Yaml; + +import java.io.File; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Rails5ServerCodegen extends DefaultCodegen implements CodegenConfig { + + private static final Logger LOGGER = LoggerFactory.getLogger(Rails5ServerCodegen.class); + + protected String gemName; + protected String moduleName; + protected String gemVersion = "1.0.0"; + protected String appFolder = "app"; + protected String channelsFolder = appFolder + File.separator + "channels"; + protected String applicationCableFolder = channelsFolder + File.separator + "application_cable"; + protected String controllersFolder = appFolder + File.separator + "controllers"; + protected String jobsFolder = appFolder + File.separator + "jobs"; + protected String mailersFolder = appFolder + File.separator + "mailers"; + protected String modelsFolder = appFolder + File.separator + "models"; + protected String viewsFolder = appFolder + File.separator + "views"; + protected String layoutsFolder = viewsFolder + File.separator + "layouts"; + protected String binFolder = "bin"; + protected String configFolder = "config"; + protected String environmentsFolder = configFolder + File.separator + "config"; + protected String initializersFolder = configFolder + File.separator + "initializers"; + protected String localesFolder = configFolder + File.separator + "locales"; + protected String dbFolder = "db"; + protected String migrateFolder = dbFolder + File.separator + "migrate"; + protected String libFolder = "lib"; + protected String tasksFolder = libFolder + File.separator + "tasks"; + protected String logFolder = "log"; + protected String publicFolder = "public"; + protected String testFolder = "test"; + protected String tmpFolder = "tmp"; + protected String cacheFolder = tmpFolder + File.separator + "cache"; + protected String pidFolder = tmpFolder + File.separator + "pids"; + protected String socketsFolder = tmpFolder + File.separator + "sockets"; + protected String vendorFolder = "vendor"; + + public Rails5ServerCodegen() { + super(); + apiPackage = "app/controllers"; + outputFolder = "generated-code" + File.separator + "rails5"; + + // no model + modelTemplateFiles.clear(); + apiTemplateFiles.put("controller.mustache", ".rb"); + embeddedTemplateDir = templateDir = "rails5"; + + typeMapping.clear(); + languageSpecificPrimitives.clear(); + + setReservedWordsLowerCase( + Arrays.asList( + "__FILE__", "and", "def", "end", "in", "or", "self", "unless", "__LINE__", + "begin", "defined?", "ensure", "module", "redo", "super", "until", "BEGIN", + "break", "do", "false", "next", "rescue", "then", "when", "END", "case", + "else", "for", "nil", "retry", "true", "while", "alias", "class", "elsif", + "if", "not", "return", "undef", "yield") + ); + + languageSpecificPrimitives.add("int"); + languageSpecificPrimitives.add("array"); + languageSpecificPrimitives.add("map"); + languageSpecificPrimitives.add("string"); + languageSpecificPrimitives.add("DateTime"); + + typeMapping.put("long", "int"); + typeMapping.put("integer", "int"); + typeMapping.put("Array", "array"); + typeMapping.put("String", "string"); + typeMapping.put("List", "array"); + typeMapping.put("map", "map"); + //TODO binary should be mapped to byte array + // mapped to String as a workaround + typeMapping.put("binary", "string"); + + // remove modelPackage and apiPackage added by default + cliOptions.clear(); + } + + @Override + public void processOpts() { + super.processOpts(); + + // use constant model/api package (folder path) + //setModelPackage("models"); + setApiPackage("app/controllers"); + + supportingFiles.add(new SupportingFile("Gemfile", "", "Gemfile")); + supportingFiles.add(new SupportingFile("README.md", "", "README.md")); + supportingFiles.add(new SupportingFile("Rakefile", "", "Rakefile")); + supportingFiles.add(new SupportingFile("config.ru", "", "config.ru")); + supportingFiles.add(new SupportingFile("channel.rb", applicationCableFolder, "channel.rb")); + supportingFiles.add(new SupportingFile("connection.rb", applicationCableFolder, "connection.rb")); + supportingFiles.add(new SupportingFile("application_controller.rb", controllersFolder, "application_controller.rb")); + supportingFiles.add(new SupportingFile("application_job.rb", jobsFolder, "application_job.rb")); + supportingFiles.add(new SupportingFile("application_mailer.rb", mailersFolder, "application_mailer.rb")); + supportingFiles.add(new SupportingFile("application_record.rb", modelsFolder, "application_record.rb")); + supportingFiles.add(new SupportingFile("mailer.html.erb", layoutsFolder, "mailer.html.erb")); + supportingFiles.add(new SupportingFile("mailer.text.erb", layoutsFolder, "mailer.text.erb")); + supportingFiles.add(new SupportingFile("bundle", binFolder, "bundle")); + supportingFiles.add(new SupportingFile("rails", binFolder, "rails")); + supportingFiles.add(new SupportingFile("rake", binFolder, "rake")); + supportingFiles.add(new SupportingFile("setup", binFolder, "setup")); + supportingFiles.add(new SupportingFile("update", binFolder, "update")); + supportingFiles.add(new SupportingFile("development.rb", environmentsFolder, "development.rb")); + supportingFiles.add(new SupportingFile("production.rb", environmentsFolder, "production.rb")); + supportingFiles.add(new SupportingFile("active_record_belongs_to_required_by_default.rb", initializersFolder, "active_record_belongs_to_required_by_default.rb")); + supportingFiles.add(new SupportingFile("application_controller_renderer.rb", initializersFolder, "application_controller_renderer.rb")); + supportingFiles.add(new SupportingFile("backtrace_silencers.rb", initializersFolder, "backtrace_silencers.rb")); + supportingFiles.add(new SupportingFile("callback_terminator.rb", initializersFolder, "callback_terminator.rb")); + supportingFiles.add(new SupportingFile("cors.rb", initializersFolder, "cors.rb")); + supportingFiles.add(new SupportingFile("filter_parameter_logging.rb", initializersFolder, "filter_parameter_logging.rb")); + supportingFiles.add(new SupportingFile("inflections.rb", initializersFolder, "inflections.rb")); + supportingFiles.add(new SupportingFile("mime_types.rb", initializersFolder, "mime_types.rb")); + supportingFiles.add(new SupportingFile("ssl_options.rb", initializersFolder, "ssl_options.rb")); + supportingFiles.add(new SupportingFile("to_time_preserves_timezone.rb", initializersFolder, "to_time_preserves_timezone.rb")); + supportingFiles.add(new SupportingFile("en.yml", localesFolder, "en.yml")); + supportingFiles.add(new SupportingFile("application.rb", configFolder, "application.rb")); + supportingFiles.add(new SupportingFile("boot.rb", configFolder, "boot.rb")); + supportingFiles.add(new SupportingFile("cable.yml", configFolder, "cable.yml")); + supportingFiles.add(new SupportingFile("database.yml", configFolder, "database.yml")); + supportingFiles.add(new SupportingFile("environment.rb", configFolder, "environment.rb")); + supportingFiles.add(new SupportingFile("puma.rb", configFolder, "puma.rb")); + supportingFiles.add(new SupportingFile("routes.mustache", configFolder, "routes.rb")); + supportingFiles.add(new SupportingFile("secrets.yml", configFolder, "secrets.yml")); + supportingFiles.add(new SupportingFile("spring.rb", configFolder, "spring.rb")); + supportingFiles.add(new SupportingFile(".keep", migrateFolder, ".keep")); + supportingFiles.add(new SupportingFile("schema.rb", dbFolder, "schema.rb")); + supportingFiles.add(new SupportingFile("seeds.rb", dbFolder, "seeds.rb")); + supportingFiles.add(new SupportingFile(".keep", tasksFolder, ".keep")); + supportingFiles.add(new SupportingFile(".keep", logFolder, ".keep")); + supportingFiles.add(new SupportingFile("404.html", publicFolder, "404.html")); + supportingFiles.add(new SupportingFile("422.html", publicFolder, "422.html")); + supportingFiles.add(new SupportingFile("500.html", publicFolder, "500.html")); + supportingFiles.add(new SupportingFile("apple-touch-icon-precomposed.png", publicFolder, "apple-touch-icon-precomposed.png")); + supportingFiles.add(new SupportingFile("apple-touch-icon.png", publicFolder, "apple-touch-icon.png")); + supportingFiles.add(new SupportingFile("favicon.ico", publicFolder, "favicon.ico")); + supportingFiles.add(new SupportingFile("robots.txt", publicFolder, "robots.txt")); + supportingFiles.add(new SupportingFile("robots.txt", publicFolder, "robots.txt")); + supportingFiles.add(new SupportingFile("test_helper.rb", testFolder, "test_helper.rb")); + supportingFiles.add(new SupportingFile(".keep", cacheFolder, ".keep")); + supportingFiles.add(new SupportingFile(".keep", pidFolder, ".keep")); + supportingFiles.add(new SupportingFile(".keep", socketsFolder, ".keep")); + supportingFiles.add(new SupportingFile("restart.txt", tmpFolder, "restart.txt")); + supportingFiles.add(new SupportingFile(".keep", vendorFolder, ".keep")); + } + + @Override + public CodegenType getTag() { + return CodegenType.SERVER; + } + + @Override + public String getName() { + return "rails5"; + } + + @Override + public String getHelp() { + return "Generates a Rails5 server library."; + } + + @Override + public String escapeReservedWord(String name) { + return "_" + name; + } + + @Override + public String apiFileFolder() { + return outputFolder + File.separator + apiPackage.replace("/", File.separator); + } + + @Override + public String getTypeDeclaration(Property p) { + if (p instanceof ArrayProperty) { + ArrayProperty ap = (ArrayProperty) p; + Property inner = ap.getItems(); + return getSwaggerType(p) + "[" + getTypeDeclaration(inner) + "]"; + } else if (p instanceof MapProperty) { + MapProperty mp = (MapProperty) p; + Property inner = mp.getAdditionalProperties(); + return getSwaggerType(p) + "[string," + getTypeDeclaration(inner) + "]"; + } + return super.getTypeDeclaration(p); + } + + @Override + public String getSwaggerType(Property p) { + String swaggerType = super.getSwaggerType(p); + String type = null; + if (typeMapping.containsKey(swaggerType)) { + type = typeMapping.get(swaggerType); + if (languageSpecificPrimitives.contains(type)) { + return type; + } + } else { + type = swaggerType; + } + if (type == null) { + return null; + } + return type; + } + + @Override + public String toDefaultValue(Property p) { + return "null"; + } + + @Override + public String toVarName(String name) { + // replace - with _ e.g. created-at => created_at + name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. + + // if it's all uppper case, convert to lower case + if (name.matches("^[A-Z_]*$")) { + name = name.toLowerCase(); + } + + // camelize (lower first character) the variable name + // petId => pet_id + name = underscore(name); + + // for reserved word or word starting with number, append _ + if (isReservedWord(name) || name.matches("^\\d.*")) { + name = escapeReservedWord(name); + } + + return name; + } + + @Override + public String toParamName(String name) { + // should be the same as variable name + return toVarName(name); + } + + @Override + public String toModelName(String name) { + // model name cannot use reserved keyword, e.g. return + if (isReservedWord(name)) { + throw new RuntimeException(name + " (reserved word) cannot be used as a model name"); + } + + // camelize the model name + // phone_number => PhoneNumber + return camelize(name); + } + + @Override + public String toModelFilename(String name) { + // model name cannot use reserved keyword, e.g. return + if (isReservedWord(name)) { + throw new RuntimeException(name + " (reserved word) cannot be used as a model name"); + } + + // underscore the model file name + // PhoneNumber.rb => phone_number.rb + return underscore(name); + } + + @Override + public String toApiFilename(String name) { + // replace - with _ e.g. created-at => created_at + name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. + + // e.g. PhoneNumberApi.rb => phone_number_api.rb + return underscore(name) + "_controllers"; + } + + @Override + public String toApiName(String name) { + if (name.length() == 0) { + return "ApiController"; + } + // e.g. phone_number_api => PhoneNumberApi + return camelize(name) + "Controller"; + } + + @Override + public String toOperationId(String operationId) { + // method name cannot use reserved keyword, e.g. return + if (isReservedWord(operationId)) { + throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); + } + + return underscore(operationId); + } + + @Override + public Map postProcessSupportingFileData(Map objs) { + Swagger swagger = (Swagger)objs.get("swagger"); + if(swagger != null) { + try { + objs.put("swagger-yaml", Yaml.mapper().writeValueAsString(swagger)); + } catch (JsonProcessingException e) { + LOGGER.error(e.getMessage(), e); + } + } + return super.postProcessSupportingFileData(objs); + } + +} diff --git a/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig b/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig index c84abac129c..f0d0fde5e57 100644 --- a/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig +++ b/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig @@ -27,6 +27,7 @@ io.swagger.codegen.languages.ScalaClientCodegen io.swagger.codegen.languages.ScalatraServerCodegen io.swagger.codegen.languages.SilexServerCodegen io.swagger.codegen.languages.SinatraServerCodegen +io.swagger.codegen.languages.Rails5ServerCodegen io.swagger.codegen.languages.SlimFrameworkServerCodegen io.swagger.codegen.languages.SpringBootServerCodegen io.swagger.codegen.languages.SpringMVCServerCodegen diff --git a/modules/swagger-codegen/src/main/resources/rails5/.keep b/modules/swagger-codegen/src/main/resources/rails5/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/modules/swagger-codegen/src/main/resources/rails5/404.html b/modules/swagger-codegen/src/main/resources/rails5/404.html new file mode 100644 index 00000000000..b612547fc21 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/modules/swagger-codegen/src/main/resources/rails5/422.html b/modules/swagger-codegen/src/main/resources/rails5/422.html new file mode 100644 index 00000000000..a21f82b3bdb --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/modules/swagger-codegen/src/main/resources/rails5/500.html b/modules/swagger-codegen/src/main/resources/rails5/500.html new file mode 100644 index 00000000000..061abc587dc --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/modules/swagger-codegen/src/main/resources/rails5/Gemfile b/modules/swagger-codegen/src/main/resources/rails5/Gemfile new file mode 100644 index 00000000000..b553bf7355d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/Gemfile @@ -0,0 +1,36 @@ +source 'https://rubygems.org' + + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '>= 5.0.0.racecar1', '< 5.1' +# Use mysql as the database for Active Record +gem 'mysql2', '>= 0.3.18', '< 0.5' +# Use Puma as the app server +gem 'puma', '~> 3.0' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.0' +# Use Redis adapter to run Action Cable in production +# gem 'redis', '~> 3.0' +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible +# gem 'rack-cors' + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug', platform: :mri +end + +group :development do + gem 'listen', '~> 3.0.5' + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.0' +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] diff --git a/modules/swagger-codegen/src/main/resources/rails5/README.md b/modules/swagger-codegen/src/main/resources/rails5/README.md new file mode 100644 index 00000000000..c5cb90075a6 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/README.md @@ -0,0 +1,25 @@ +# Swagger for Rails 5 + +This is a project to provide Swagger support inside the [Sinatra](http://rubyonrails.org/) framework. + +## Prerequisites +You need to install ruby >= 2.2.2 and run: + +``` +bundle install +``` + +## Getting started + +This sample was generated with the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. + +``` +bin/rake db:create +bin/rails s +``` + +To list all your routes, use: + +``` +bin/rake routes +``` diff --git a/modules/swagger-codegen/src/main/resources/rails5/Rakefile b/modules/swagger-codegen/src/main/resources/rails5/Rakefile new file mode 100644 index 00000000000..e85f913914b --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative 'config/application' + +Rails.application.load_tasks diff --git a/modules/swagger-codegen/src/main/resources/rails5/active_record_belongs_to_required_by_default.rb b/modules/swagger-codegen/src/main/resources/rails5/active_record_belongs_to_required_by_default.rb new file mode 100644 index 00000000000..f613b40f804 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/active_record_belongs_to_required_by_default.rb @@ -0,0 +1,6 @@ +# Be sure to restart your server when you modify this file. + +# Require `belongs_to` associations by default. This is a new Rails 5.0 +# default, so it is introduced as a configuration option to ensure that apps +# made on earlier versions of Rails are not affected when upgrading. +Rails.application.config.active_record.belongs_to_required_by_default = true diff --git a/modules/swagger-codegen/src/main/resources/rails5/apple-touch-icon-precomposed.png b/modules/swagger-codegen/src/main/resources/rails5/apple-touch-icon-precomposed.png new file mode 100644 index 00000000000..e69de29bb2d diff --git a/modules/swagger-codegen/src/main/resources/rails5/apple-touch-icon.png b/modules/swagger-codegen/src/main/resources/rails5/apple-touch-icon.png new file mode 100644 index 00000000000..e69de29bb2d diff --git a/modules/swagger-codegen/src/main/resources/rails5/application.rb b/modules/swagger-codegen/src/main/resources/rails5/application.rb new file mode 100644 index 00000000000..70bea9ecf69 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/application.rb @@ -0,0 +1,30 @@ +require_relative 'boot' + +require "rails" +# Pick the frameworks you want: +require "active_model/railtie" +require "active_job/railtie" +require "active_record/railtie" +require "action_controller/railtie" +require "action_mailer/railtie" +require "action_view/railtie" +require "action_cable/engine" +# require "sprockets/railtie" +require "rails/test_unit/railtie" + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module ApiDemo + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Only loads a smaller set of middleware suitable for API only apps. + # Middleware like session, flash, cookies can be added back manually. + # Skip views, helpers and assets when generating a new resource. + config.api_only = true + end +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/application_controller.rb b/modules/swagger-codegen/src/main/resources/rails5/application_controller.rb new file mode 100644 index 00000000000..4ac8823b095 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::API +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/application_controller_renderer.rb b/modules/swagger-codegen/src/main/resources/rails5/application_controller_renderer.rb new file mode 100644 index 00000000000..51639b67a00 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/application_controller_renderer.rb @@ -0,0 +1,6 @@ +# Be sure to restart your server when you modify this file. + +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) diff --git a/modules/swagger-codegen/src/main/resources/rails5/application_job.rb b/modules/swagger-codegen/src/main/resources/rails5/application_job.rb new file mode 100644 index 00000000000..a009ace51cc --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/application_mailer.rb b/modules/swagger-codegen/src/main/resources/rails5/application_mailer.rb new file mode 100644 index 00000000000..286b2239d13 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/application_record.rb b/modules/swagger-codegen/src/main/resources/rails5/application_record.rb new file mode 100644 index 00000000000..10a4cba84df --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/backtrace_silencers.rb b/modules/swagger-codegen/src/main/resources/rails5/backtrace_silencers.rb new file mode 100644 index 00000000000..59385cdf379 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/modules/swagger-codegen/src/main/resources/rails5/boot.rb b/modules/swagger-codegen/src/main/resources/rails5/boot.rb new file mode 100644 index 00000000000..30f5120df69 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/boot.rb @@ -0,0 +1,3 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/modules/swagger-codegen/src/main/resources/rails5/bundle b/modules/swagger-codegen/src/main/resources/rails5/bundle new file mode 100755 index 00000000000..66e9889e8b4 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/modules/swagger-codegen/src/main/resources/rails5/cable.yml b/modules/swagger-codegen/src/main/resources/rails5/cable.yml new file mode 100644 index 00000000000..aa4e832748c --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/cable.yml @@ -0,0 +1,10 @@ +# Action Cable uses Redis by default to administer connections, channels, and sending/receiving messages over the WebSocket. +production: + adapter: redis + url: redis://localhost:6379/1 + +development: + adapter: async + +test: + adapter: async diff --git a/modules/swagger-codegen/src/main/resources/rails5/callback_terminator.rb b/modules/swagger-codegen/src/main/resources/rails5/callback_terminator.rb new file mode 100644 index 00000000000..649e82280e1 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/callback_terminator.rb @@ -0,0 +1,6 @@ +# Be sure to restart your server when you modify this file. + +# Do not halt callback chains when a callback returns false. This is a new +# Rails 5.0 default, so it is introduced as a configuration option to ensure +# that apps made with earlier versions of Rails are not affected when upgrading. +ActiveSupport.halt_callback_chains_on_return_false = false diff --git a/modules/swagger-codegen/src/main/resources/rails5/channel.rb b/modules/swagger-codegen/src/main/resources/rails5/channel.rb new file mode 100644 index 00000000000..d56fa30f4d8 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/channel.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading. +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/config.ru b/modules/swagger-codegen/src/main/resources/rails5/config.ru new file mode 100644 index 00000000000..f7ba0b527b1 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/config.ru @@ -0,0 +1,5 @@ +# This file is used by Rack-based servers to start the application. + +require_relative 'config/environment' + +run Rails.application diff --git a/modules/swagger-codegen/src/main/resources/rails5/connection.rb b/modules/swagger-codegen/src/main/resources/rails5/connection.rb new file mode 100644 index 00000000000..b4f41389ad0 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/connection.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading. +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/controller.mustache b/modules/swagger-codegen/src/main/resources/rails5/controller.mustache new file mode 100644 index 00000000000..5fac9b34d30 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/controller.mustache @@ -0,0 +1,22 @@ +class ProductController < ApplicationController + + def index + # Your code here + end + + def show + # Your code here + end + + def create + # Your code here + end + + def update + # Your code here + end + + def destroy + # Your code here + end +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/cors.rb b/modules/swagger-codegen/src/main/resources/rails5/cors.rb new file mode 100644 index 00000000000..3b1c1b5ed14 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/cors.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Avoid CORS issues when API is called from the frontend app. +# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. + +# Read more: https://github.com/cyu/rack-cors + +# Rails.application.config.middleware.insert_before 0, Rack::Cors do +# allow do +# origins 'example.com' +# +# resource '*', +# headers: :any, +# methods: [:get, :post, :put, :patch, :delete, :options, :head] +# end +# end diff --git a/modules/swagger-codegen/src/main/resources/rails5/database.yml b/modules/swagger-codegen/src/main/resources/rails5/database.yml new file mode 100644 index 00000000000..e536d9f37dc --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/database.yml @@ -0,0 +1,54 @@ +# MySQL. Versions 5.0 and up are supported. +# +# Install the MySQL driver +# gem install mysql2 +# +# Ensure the MySQL gem is defined in your Gemfile +# gem 'mysql2' +# +# And be sure to use new-style password hashing: +# http://dev.mysql.com/doc/refman/5.7/en/old-client.html +# +default: &default + adapter: mysql2 + encoding: utf8 + pool: 5 + username: root + password: + socket: /tmp/mysql.sock + +development: + <<: *default + database: api_demo_development + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: api_demo_test + +# As with config/secrets.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password as a unix environment variable when you boot +# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full rundown on how to provide these environment variables in a +# production deployment. +# +# On Heroku and other platform providers, you may have a full connection URL +# available as an environment variable. For example: +# +# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" +# +# You can use this database configuration with: +# +# production: +# url: <%= ENV['DATABASE_URL'] %> +# +production: + <<: *default + database: api_demo_production + username: api_demo + password: <%= ENV['API_DEMO_DATABASE_PASSWORD'] %> diff --git a/modules/swagger-codegen/src/main/resources/rails5/development.rb b/modules/swagger-codegen/src/main/resources/rails5/development.rb new file mode 100644 index 00000000000..082a013ab36 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/development.rb @@ -0,0 +1,47 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + if Rails.root.join('tmp/caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=172800' + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/en.yml b/modules/swagger-codegen/src/main/resources/rails5/en.yml new file mode 100644 index 00000000000..0653957166e --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/en.yml @@ -0,0 +1,23 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/modules/swagger-codegen/src/main/resources/rails5/environment.rb b/modules/swagger-codegen/src/main/resources/rails5/environment.rb new file mode 100644 index 00000000000..426333bb469 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative 'application' + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/modules/swagger-codegen/src/main/resources/rails5/favicon.ico b/modules/swagger-codegen/src/main/resources/rails5/favicon.ico new file mode 100644 index 00000000000..e69de29bb2d diff --git a/modules/swagger-codegen/src/main/resources/rails5/filter_parameter_logging.rb b/modules/swagger-codegen/src/main/resources/rails5/filter_parameter_logging.rb new file mode 100644 index 00000000000..4a994e1e7bb --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/modules/swagger-codegen/src/main/resources/rails5/inflections.rb b/modules/swagger-codegen/src/main/resources/rails5/inflections.rb new file mode 100644 index 00000000000..ac033bf9dc8 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/modules/swagger-codegen/src/main/resources/rails5/mailer.html.erb b/modules/swagger-codegen/src/main/resources/rails5/mailer.html.erb new file mode 100644 index 00000000000..cbd34d2e9dd --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/modules/swagger-codegen/src/main/resources/rails5/mailer.text.erb b/modules/swagger-codegen/src/main/resources/rails5/mailer.text.erb new file mode 100644 index 00000000000..37f0bddbd74 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/modules/swagger-codegen/src/main/resources/rails5/mime_types.rb b/modules/swagger-codegen/src/main/resources/rails5/mime_types.rb new file mode 100644 index 00000000000..dc1899682b0 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/modules/swagger-codegen/src/main/resources/rails5/production.rb b/modules/swagger-codegen/src/main/resources/rails5/production.rb new file mode 100644 index 00000000000..6cb0a8fe61c --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/production.rb @@ -0,0 +1,80 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Action Cable endpoint configuration + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Don't mount Action Cable in the main server process. + # config.action_cable.mount_path = nil + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "api_demo_#{Rails.env}" + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/puma.rb b/modules/swagger-codegen/src/main/resources/rails5/puma.rb new file mode 100644 index 00000000000..c7f311f8116 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/puma.rb @@ -0,0 +1,47 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum, this matches the default thread size of Active Record. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests, default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. If you use this option +# you need to make sure to reconnect any threads in the `on_worker_boot` +# block. +# +# preload_app! + +# The code in the `on_worker_boot` will be called if you are using +# clustered mode by specifying a number of `workers`. After each worker +# process is booted this block will be run, if you are using `preload_app!` +# option you will want to use this block to reconnect to any threads +# or connections that may have been created at application boot, Ruby +# cannot share connections between processes. +# +# on_worker_boot do +# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) +# end + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/modules/swagger-codegen/src/main/resources/rails5/rails b/modules/swagger-codegen/src/main/resources/rails5/rails new file mode 100755 index 00000000000..07396602377 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/modules/swagger-codegen/src/main/resources/rails5/rake b/modules/swagger-codegen/src/main/resources/rails5/rake new file mode 100755 index 00000000000..17240489f64 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/modules/swagger-codegen/src/main/resources/rails5/restart.txt b/modules/swagger-codegen/src/main/resources/rails5/restart.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/modules/swagger-codegen/src/main/resources/rails5/robots.txt b/modules/swagger-codegen/src/main/resources/rails5/robots.txt new file mode 100644 index 00000000000..3c9c7c01f30 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/robots.txt @@ -0,0 +1,5 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/modules/swagger-codegen/src/main/resources/rails5/routes.mustache b/modules/swagger-codegen/src/main/resources/rails5/routes.mustache new file mode 100644 index 00000000000..df5d7e453fe --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/routes.mustache @@ -0,0 +1,3 @@ +Rails.application.routes.draw do + resources :product +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/schema.rb b/modules/swagger-codegen/src/main/resources/rails5/schema.rb new file mode 100644 index 00000000000..4dfbb16804e --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/schema.rb @@ -0,0 +1,16 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 0) do + +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/secrets.yml b/modules/swagger-codegen/src/main/resources/rails5/secrets.yml new file mode 100644 index 00000000000..179b066b84d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/secrets.yml @@ -0,0 +1,22 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rails secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +development: + secret_key_base: 2e13a003477a557ba3fcc6260c2ec69e411238b9b8b530c3c70e71f7cfc905b5f746f5c195a0282342a77ad6acd4e6ef8949106723200a99414fe83393d67344 + +test: + secret_key_base: fedf54236a94882c00e2fa0af308a4135f50941396437b9fbc38dd340c0a8bcf38cfcf6264cc2abc2af5bda26252293fe48e9a3e90fbfc4d25d6886d6d14b300 + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/modules/swagger-codegen/src/main/resources/rails5/seeds.rb b/modules/swagger-codegen/src/main/resources/rails5/seeds.rb new file mode 100644 index 00000000000..1beea2accd7 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) +# Character.create(name: 'Luke', movie: movies.first) diff --git a/modules/swagger-codegen/src/main/resources/rails5/setup b/modules/swagger-codegen/src/main/resources/rails5/setup new file mode 100755 index 00000000000..e620b4dadb2 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/setup @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/spring.rb b/modules/swagger-codegen/src/main/resources/rails5/spring.rb new file mode 100644 index 00000000000..c9119b40c08 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/spring.rb @@ -0,0 +1,6 @@ +%w( + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +).each { |path| Spring.watch(path) } diff --git a/modules/swagger-codegen/src/main/resources/rails5/ssl_options.rb b/modules/swagger-codegen/src/main/resources/rails5/ssl_options.rb new file mode 100644 index 00000000000..1775dea1e76 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/ssl_options.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure SSL options to enable HSTS with subdomains. +Rails.application.config.ssl_options = { hsts: { subdomains: true } } diff --git a/modules/swagger-codegen/src/main/resources/rails5/test.rb b/modules/swagger-codegen/src/main/resources/rails5/test.rb new file mode 100644 index 00000000000..30587ef6d5e --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/test.rb @@ -0,0 +1,42 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=3600' + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/test_helper.rb b/modules/swagger-codegen/src/main/resources/rails5/test_helper.rb new file mode 100644 index 00000000000..92e39b2d78c --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/test_helper.rb @@ -0,0 +1,10 @@ +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +require 'rails/test_help' + +class ActiveSupport::TestCase + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all + + # Add more helper methods to be used by all tests here... +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/to_time_preserves_timezone.rb b/modules/swagger-codegen/src/main/resources/rails5/to_time_preserves_timezone.rb new file mode 100644 index 00000000000..8674be3227e --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/to_time_preserves_timezone.rb @@ -0,0 +1,10 @@ +# Be sure to restart your server when you modify this file. + +# Preserve the timezone of the receiver when calling to `to_time`. +# Ruby 2.4 will change the behavior of `to_time` to preserve the timezone +# when converting to an instance of `Time` instead of the previous behavior +# of converting to the local system timezone. +# +# Rails 5.0 introduced this config option so that apps made with earlier +# versions of Rails are not affected when upgrading. +ActiveSupport.to_time_preserves_timezone = true diff --git a/modules/swagger-codegen/src/main/resources/rails5/update b/modules/swagger-codegen/src/main/resources/rails5/update new file mode 100755 index 00000000000..a8e4462f203 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/modules/swagger-codegen/src/main/resources/rails5/wrap_parameters.rb b/modules/swagger-codegen/src/main/resources/rails5/wrap_parameters.rb new file mode 100644 index 00000000000..bbfc3961bff --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/rails5/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/Rails5ServerOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/Rails5ServerOptionsProvider.java new file mode 100644 index 00000000000..c75053b84e2 --- /dev/null +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/Rails5ServerOptionsProvider.java @@ -0,0 +1,23 @@ +package io.swagger.codegen.options; + +import com.google.common.collect.ImmutableMap; + +import java.util.Map; + +public class Rails5ServerOptionsProvider implements OptionsProvider { + @Override + public String getLanguage() { + return "Rails5"; + } + + @Override + public Map createOptions() { + //Rails5ServerCodegen doesn't have its own options and base options are cleared + return ImmutableMap.of(); + } + + @Override + public boolean isServer() { + return true; + } +} From da50a6e1f0bc7def00de69470291fd3dc25ba0e9 Mon Sep 17 00:00:00 2001 From: Newell Zhu Date: Fri, 13 May 2016 01:44:20 +0800 Subject: [PATCH 2/5] Complete controller mustache --- .../io/swagger/codegen/CodegenOperation.java | 80 ++++++++++++++++++- .../io/swagger/codegen/DefaultCodegen.java | 8 ++ .../main/resources/rails5/controller.mustache | 37 +++++++-- 3 files changed, 119 insertions(+), 6 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java index 48858a0d504..9dfe0d45c88 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java @@ -7,13 +7,16 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Arrays; public class CodegenOperation { public final List responseHeaders = new ArrayList(); public Boolean hasAuthMethods, hasConsumes, hasProduces, hasParams, hasOptionalParams, returnTypeIsPrimitive, returnSimpleType, subresourceOperation, isMapContainer, isListContainer, isMultipart, hasMore = Boolean.TRUE, - isResponseBinary = Boolean.FALSE, hasReference = Boolean.FALSE; + isResponseBinary = Boolean.FALSE, hasReference = Boolean.FALSE, + isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy, + isRestful; public String path, operationId, returnType, httpMethod, returnBaseType, returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse, discriminator; public List> consumes, produces; @@ -88,6 +91,81 @@ public class CodegenOperation { return nonempty(formParams); } + /** + * Check if act as Restful index method + * + * @return true if act as Restful index method, false otherwise + */ + public boolean isRestfulIndex() { + return "GET".equals(httpMethod) && "".equals(pathWithoutBaseName()); + } + + /** + * Check if act as Restful show method + * + * @return true if act as Restful show method, false otherwise + */ + public boolean isRestfulShow() { + return "GET".equals(httpMethod) && isMemberPath(); + } + + /** + * Check if act as Restful create method + * + * @return true if act as Restful create method, false otherwise + */ + public boolean isRestfulCreate() { + return "POST".equals(httpMethod) && "".equals(pathWithoutBaseName()); + } + + /** + * Check if act as Restful update method + * + * @return true if act as Restful update method, false otherwise + */ + public boolean isRestfulUpdate() { + return Arrays.asList("PUT", "PATCH").contains(httpMethod) && isMemberPath(); + } + + /** + * Check if act as Restful destroy method + * + * @return true if act as Restful destroy method, false otherwise + */ + public boolean isRestfulDestroy() { + return "DELETE".equals(httpMethod) && isMemberPath(); + } + + /** + * Check if Restful-style + * + * @return true if Restful-style, false otherwise + */ + public boolean isRestful() { + return isRestfulIndex() || isRestfulShow() || isRestfulCreate() || isRestfulUpdate() || isRestfulDestroy(); + } + + /** + * Get the substring except baseName from path + * + * @return the substring + */ + private String pathWithoutBaseName() { + return baseName != null ? path.replace("/" + baseName.toLowerCase(), "") : path; + } + + /** + * Check if the path match format /xxx/:id + * + * @return true if path act as member + */ + private boolean isMemberPath() { + if (pathParams.size() != 1) return false; + + String id = pathParams.get(0).baseName; + return ("/{" + id + "}").equals(pathWithoutBaseName()); + } + @Override public String toString() { return String.format("%s(%s)", baseName, path); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index be0f698c5b7..8f3fc7be632 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -1847,6 +1847,14 @@ public class DefaultCodegen { } op.externalDocs = operation.getExternalDocs(); + // set Restful Flag + op.isRestfulShow = op.isRestfulShow(); + op.isRestfulIndex = op.isRestfulIndex(); + op.isRestfulCreate = op.isRestfulCreate(); + op.isRestfulUpdate = op.isRestfulUpdate(); + op.isRestfulDestroy = op.isRestfulDestroy(); + op.isRestful = op.isRestful(); + return op; } diff --git a/modules/swagger-codegen/src/main/resources/rails5/controller.mustache b/modules/swagger-codegen/src/main/resources/rails5/controller.mustache index 5fac9b34d30..321960875d8 100644 --- a/modules/swagger-codegen/src/main/resources/rails5/controller.mustache +++ b/modules/swagger-codegen/src/main/resources/rails5/controller.mustache @@ -1,22 +1,49 @@ -class ProductController < ApplicationController +class {{classname}} < ApplicationController +{{#operations}} +{{#operation}} +{{#isRestfulIndex}} def index # Your code here - end + render json: {"message" => "yes, it worked"} + end +{{/isRestfulIndex}} +{{#isRestfulShow}} def show # Your code here - end + render json: {"message" => "yes, it worked"} + end +{{/isRestfulShow}} +{{#isRestfulCreate}} def create # Your code here - end + render json: {"message" => "yes, it worked"} + end +{{/isRestfulCreate}} +{{#isRestfulUpdate}} def update # Your code here - end + render json: {"message" => "yes, it worked"} + end +{{/isRestfulUpdate}} +{{#isRestfulDestroy}} def destroy # Your code here + + render json: {"message" => "yes, it worked"} end +{{/isRestfulDestroy}} +{{^isRestful}} + def {{nickname}} + # Your code here + + render json: {"message" => "yes, it worked"} + end +{{/isRestful}} +{{/operation}} +{{/operations}} end From d0dcec85cc26648b4afbe75da5289ed51f2e5394 Mon Sep 17 00:00:00 2001 From: Newell Zhu Date: Sat, 14 May 2016 23:30:46 +0800 Subject: [PATCH 3/5] build route.mustache --- .../src/main/resources/rails5/routes.mustache | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/rails5/routes.mustache b/modules/swagger-codegen/src/main/resources/rails5/routes.mustache index df5d7e453fe..e6b95be33a4 100644 --- a/modules/swagger-codegen/src/main/resources/rails5/routes.mustache +++ b/modules/swagger-codegen/src/main/resources/rails5/routes.mustache @@ -1,3 +1,31 @@ Rails.application.routes.draw do - resources :product + + def add_swagger_route http_method, path, opts = {} + full_path = path.gsub(/{(.*?)}/, ':\1') + action = + (opts[:isRestfulIndex] && :index) || + (opts[:isRestfulShow] && :show) || + (opts[:isRestfulCreate] && :create) || + (opts[:isRestfulUpdate] && :update) || + (opts[:isRestfulDestroy] && :destroy) || + opts[:nickname] + + match full_path, to: "#{opts.fetch(:classVarName)}##{action}", via: http_method + end + +{{#apiInfo}} +{{#apis}} +{{#operations}} +{{#operation}} + add_swagger_route '{{httpMethod}}', '{{basePathWithoutHost}}{{path}}', + classVarName: '{{classVarName}}', nickname: '{{nickname}}', + isRestfulIndex: {{#isRestfulIndex}}true{{/isRestfulIndex}}{{^isRestfulIndex}}false{{/isRestfulIndex}}, + isRestfulCreate: {{#isRestfulCreate}}true{{/isRestfulCreate}}{{^isRestfulCreate}}false{{/isRestfulCreate}}, + isRestfulUpdate: {{#isRestfulUpdate}}true{{/isRestfulUpdate}}{{^isRestfulUpdate}}false{{/isRestfulUpdate}}, + isRestfulShow: {{#isRestfulShow}}true{{/isRestfulShow}}{{^isRestfulShow}}false{{/isRestfulShow}}, + isRestfulDestroy: {{#isRestfulDestroy}}true{{/isRestfulDestroy}}{{^isRestfulDestroy}}false{{/isRestfulDestroy}} +{{/operation}} +{{/operations}} +{{/apis}} +{{/apiInfo}} end From 83b5c2eeec18845e6efa51b2054d405979ba43d8 Mon Sep 17 00:00:00 2001 From: Newell Zhu Date: Sun, 15 May 2016 00:19:51 +0800 Subject: [PATCH 4/5] Add Rails5 sample --- samples/server/petstore/rails5/Gemfile | 36 ++++ samples/server/petstore/rails5/Gemfile.lock | 141 ++++++++++++++++ samples/server/petstore/rails5/README.md | 25 +++ samples/server/petstore/rails5/Rakefile | 6 + .../app/channels/application_cable/channel.rb | 5 + .../channels/application_cable/connection.rb | 5 + .../app/controllers/application_controller.rb | 2 + .../rails5/app/controllers/pet_controllers.rb | 50 ++++++ .../app/controllers/store_controllers.rb | 26 +++ .../app/controllers/user_controllers.rb | 50 ++++++ .../rails5/app/jobs/application_job.rb | 2 + .../rails5/app/mailers/application_mailer.rb | 4 + .../rails5/app/models/application_record.rb | 3 + .../rails5/app/views/layouts/mailer.html.erb | 13 ++ .../rails5/app/views/layouts/mailer.text.erb | 1 + samples/server/petstore/rails5/bin/bundle | 3 + samples/server/petstore/rails5/bin/rails | 4 + samples/server/petstore/rails5/bin/rake | 4 + samples/server/petstore/rails5/bin/setup | 34 ++++ samples/server/petstore/rails5/bin/update | 29 ++++ samples/server/petstore/rails5/config.ru | 5 + .../petstore/rails5/config/application.rb | 30 ++++ samples/server/petstore/rails5/config/boot.rb | 3 + .../server/petstore/rails5/config/cable.yml | 10 ++ .../rails5/config/config/development.rb | 47 ++++++ .../rails5/config/config/production.rb | 80 +++++++++ .../petstore/rails5/config/database.yml | 54 ++++++ .../petstore/rails5/config/environment.rb | 5 + ...e_record_belongs_to_required_by_default.rb | 6 + .../application_controller_renderer.rb | 6 + .../initializers/backtrace_silencers.rb | 7 + .../initializers/callback_terminator.rb | 6 + .../rails5/config/initializers/cors.rb | 16 ++ .../initializers/filter_parameter_logging.rb | 4 + .../rails5/config/initializers/inflections.rb | 16 ++ .../rails5/config/initializers/mime_types.rb | 4 + .../rails5/config/initializers/ssl_options.rb | 4 + .../to_time_preserves_timezone.rb | 10 ++ .../petstore/rails5/config/locales/en.yml | 23 +++ samples/server/petstore/rails5/config/puma.rb | 47 ++++++ .../server/petstore/rails5/config/routes.rb | 156 ++++++++++++++++++ .../server/petstore/rails5/config/secrets.yml | 22 +++ .../server/petstore/rails5/config/spring.rb | 6 + .../server/petstore/rails5/db/migrate/.keep | 0 samples/server/petstore/rails5/db/schema.rb | 16 ++ samples/server/petstore/rails5/db/seeds.rb | 7 + .../server/petstore/rails5/lib/tasks/.keep | 0 samples/server/petstore/rails5/log/.keep | 0 .../petstore/rails5/log/development.log | 0 .../server/petstore/rails5/public/404.html | 67 ++++++++ .../server/petstore/rails5/public/422.html | 67 ++++++++ .../server/petstore/rails5/public/500.html | 66 ++++++++ .../public/apple-touch-icon-precomposed.png | 0 .../rails5/public/apple-touch-icon.png | 0 .../server/petstore/rails5/public/favicon.ico | 0 .../server/petstore/rails5/public/robots.txt | 5 + .../petstore/rails5/test/test_helper.rb | 10 ++ .../server/petstore/rails5/tmp/cache/.keep | 0 samples/server/petstore/rails5/tmp/pids/.keep | 0 .../server/petstore/rails5/tmp/restart.txt | 0 .../server/petstore/rails5/tmp/sockets/.keep | 0 samples/server/petstore/rails5/vendor/.keep | 0 62 files changed, 1248 insertions(+) create mode 100644 samples/server/petstore/rails5/Gemfile create mode 100644 samples/server/petstore/rails5/Gemfile.lock create mode 100644 samples/server/petstore/rails5/README.md create mode 100644 samples/server/petstore/rails5/Rakefile create mode 100644 samples/server/petstore/rails5/app/channels/application_cable/channel.rb create mode 100644 samples/server/petstore/rails5/app/channels/application_cable/connection.rb create mode 100644 samples/server/petstore/rails5/app/controllers/application_controller.rb create mode 100644 samples/server/petstore/rails5/app/controllers/pet_controllers.rb create mode 100644 samples/server/petstore/rails5/app/controllers/store_controllers.rb create mode 100644 samples/server/petstore/rails5/app/controllers/user_controllers.rb create mode 100644 samples/server/petstore/rails5/app/jobs/application_job.rb create mode 100644 samples/server/petstore/rails5/app/mailers/application_mailer.rb create mode 100644 samples/server/petstore/rails5/app/models/application_record.rb create mode 100644 samples/server/petstore/rails5/app/views/layouts/mailer.html.erb create mode 100644 samples/server/petstore/rails5/app/views/layouts/mailer.text.erb create mode 100755 samples/server/petstore/rails5/bin/bundle create mode 100755 samples/server/petstore/rails5/bin/rails create mode 100755 samples/server/petstore/rails5/bin/rake create mode 100755 samples/server/petstore/rails5/bin/setup create mode 100755 samples/server/petstore/rails5/bin/update create mode 100644 samples/server/petstore/rails5/config.ru create mode 100644 samples/server/petstore/rails5/config/application.rb create mode 100644 samples/server/petstore/rails5/config/boot.rb create mode 100644 samples/server/petstore/rails5/config/cable.yml create mode 100644 samples/server/petstore/rails5/config/config/development.rb create mode 100644 samples/server/petstore/rails5/config/config/production.rb create mode 100644 samples/server/petstore/rails5/config/database.yml create mode 100644 samples/server/petstore/rails5/config/environment.rb create mode 100644 samples/server/petstore/rails5/config/initializers/active_record_belongs_to_required_by_default.rb create mode 100644 samples/server/petstore/rails5/config/initializers/application_controller_renderer.rb create mode 100644 samples/server/petstore/rails5/config/initializers/backtrace_silencers.rb create mode 100644 samples/server/petstore/rails5/config/initializers/callback_terminator.rb create mode 100644 samples/server/petstore/rails5/config/initializers/cors.rb create mode 100644 samples/server/petstore/rails5/config/initializers/filter_parameter_logging.rb create mode 100644 samples/server/petstore/rails5/config/initializers/inflections.rb create mode 100644 samples/server/petstore/rails5/config/initializers/mime_types.rb create mode 100644 samples/server/petstore/rails5/config/initializers/ssl_options.rb create mode 100644 samples/server/petstore/rails5/config/initializers/to_time_preserves_timezone.rb create mode 100644 samples/server/petstore/rails5/config/locales/en.yml create mode 100644 samples/server/petstore/rails5/config/puma.rb create mode 100644 samples/server/petstore/rails5/config/routes.rb create mode 100644 samples/server/petstore/rails5/config/secrets.yml create mode 100644 samples/server/petstore/rails5/config/spring.rb create mode 100644 samples/server/petstore/rails5/db/migrate/.keep create mode 100644 samples/server/petstore/rails5/db/schema.rb create mode 100644 samples/server/petstore/rails5/db/seeds.rb create mode 100644 samples/server/petstore/rails5/lib/tasks/.keep create mode 100644 samples/server/petstore/rails5/log/.keep create mode 100644 samples/server/petstore/rails5/log/development.log create mode 100644 samples/server/petstore/rails5/public/404.html create mode 100644 samples/server/petstore/rails5/public/422.html create mode 100644 samples/server/petstore/rails5/public/500.html create mode 100644 samples/server/petstore/rails5/public/apple-touch-icon-precomposed.png create mode 100644 samples/server/petstore/rails5/public/apple-touch-icon.png create mode 100644 samples/server/petstore/rails5/public/favicon.ico create mode 100644 samples/server/petstore/rails5/public/robots.txt create mode 100644 samples/server/petstore/rails5/test/test_helper.rb create mode 100644 samples/server/petstore/rails5/tmp/cache/.keep create mode 100644 samples/server/petstore/rails5/tmp/pids/.keep create mode 100644 samples/server/petstore/rails5/tmp/restart.txt create mode 100644 samples/server/petstore/rails5/tmp/sockets/.keep create mode 100644 samples/server/petstore/rails5/vendor/.keep diff --git a/samples/server/petstore/rails5/Gemfile b/samples/server/petstore/rails5/Gemfile new file mode 100644 index 00000000000..b553bf7355d --- /dev/null +++ b/samples/server/petstore/rails5/Gemfile @@ -0,0 +1,36 @@ +source 'https://rubygems.org' + + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '>= 5.0.0.racecar1', '< 5.1' +# Use mysql as the database for Active Record +gem 'mysql2', '>= 0.3.18', '< 0.5' +# Use Puma as the app server +gem 'puma', '~> 3.0' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.0' +# Use Redis adapter to run Action Cable in production +# gem 'redis', '~> 3.0' +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible +# gem 'rack-cors' + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug', platform: :mri +end + +group :development do + gem 'listen', '~> 3.0.5' + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.0' +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] diff --git a/samples/server/petstore/rails5/Gemfile.lock b/samples/server/petstore/rails5/Gemfile.lock new file mode 100644 index 00000000000..f544bc0f702 --- /dev/null +++ b/samples/server/petstore/rails5/Gemfile.lock @@ -0,0 +1,141 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.0.0.rc1) + actionpack (= 5.0.0.rc1) + nio4r (~> 1.2) + websocket-driver (~> 0.6.1) + actionmailer (5.0.0.rc1) + actionpack (= 5.0.0.rc1) + actionview (= 5.0.0.rc1) + activejob (= 5.0.0.rc1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (5.0.0.rc1) + actionview (= 5.0.0.rc1) + activesupport (= 5.0.0.rc1) + rack (~> 2.x) + rack-test (~> 0.6.3) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.0.0.rc1) + activesupport (= 5.0.0.rc1) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (5.0.0.rc1) + activesupport (= 5.0.0.rc1) + globalid (>= 0.3.6) + activemodel (5.0.0.rc1) + activesupport (= 5.0.0.rc1) + activerecord (5.0.0.rc1) + activemodel (= 5.0.0.rc1) + activesupport (= 5.0.0.rc1) + arel (~> 7.0) + activesupport (5.0.0.rc1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) + minitest (~> 5.1) + tzinfo (~> 1.1) + arel (7.0.0) + builder (3.2.2) + byebug (9.0.0) + concurrent-ruby (1.0.2) + erubis (2.7.0) + ffi (1.9.10) + globalid (0.3.6) + activesupport (>= 4.1.0) + i18n (0.7.0) + jbuilder (2.4.1) + activesupport (>= 3.0.0, < 5.1) + multi_json (~> 1.2) + json (1.8.3) + listen (3.0.7) + rb-fsevent (>= 0.9.3) + rb-inotify (>= 0.9.7) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.4) + mime-types (>= 1.16, < 4) + method_source (0.8.2) + mime-types (3.0) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0221) + mini_portile2 (2.0.0) + minitest (5.8.4) + multi_json (1.12.0) + mysql2 (0.4.4) + nio4r (1.2.1) + nokogiri (1.6.7.2) + mini_portile2 (~> 2.0.0.rc2) + puma (3.4.0) + rack (2.0.0.rc1) + json + rack-test (0.6.3) + rack (>= 1.0) + rails (5.0.0.rc1) + actioncable (= 5.0.0.rc1) + actionmailer (= 5.0.0.rc1) + actionpack (= 5.0.0.rc1) + actionview (= 5.0.0.rc1) + activejob (= 5.0.0.rc1) + activemodel (= 5.0.0.rc1) + activerecord (= 5.0.0.rc1) + activesupport (= 5.0.0.rc1) + bundler (>= 1.3.0, < 2.0) + railties (= 5.0.0.rc1) + sprockets-rails (>= 2.0.0) + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.7) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6.0) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (5.0.0.rc1) + actionpack (= 5.0.0.rc1) + activesupport (= 5.0.0.rc1) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (11.1.2) + rb-fsevent (0.9.7) + rb-inotify (0.9.7) + ffi (>= 0.5.0) + spring (1.7.1) + spring-watcher-listen (2.0.0) + listen (>= 2.7, < 4.0) + spring (~> 1.2) + sprockets (3.6.0) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.0.4) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + thor (0.19.1) + thread_safe (0.3.5) + tzinfo (1.2.2) + thread_safe (~> 0.1) + websocket-driver (0.6.3) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.2) + +PLATFORMS + ruby + +DEPENDENCIES + byebug + jbuilder (~> 2.0) + listen (~> 3.0.5) + mysql2 (>= 0.3.18, < 0.5) + puma (~> 3.0) + rails (>= 5.0.0.racecar1, < 5.1) + spring + spring-watcher-listen (~> 2.0.0) + tzinfo-data + +BUNDLED WITH + 1.11.2 diff --git a/samples/server/petstore/rails5/README.md b/samples/server/petstore/rails5/README.md new file mode 100644 index 00000000000..c5cb90075a6 --- /dev/null +++ b/samples/server/petstore/rails5/README.md @@ -0,0 +1,25 @@ +# Swagger for Rails 5 + +This is a project to provide Swagger support inside the [Sinatra](http://rubyonrails.org/) framework. + +## Prerequisites +You need to install ruby >= 2.2.2 and run: + +``` +bundle install +``` + +## Getting started + +This sample was generated with the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. + +``` +bin/rake db:create +bin/rails s +``` + +To list all your routes, use: + +``` +bin/rake routes +``` diff --git a/samples/server/petstore/rails5/Rakefile b/samples/server/petstore/rails5/Rakefile new file mode 100644 index 00000000000..e85f913914b --- /dev/null +++ b/samples/server/petstore/rails5/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative 'config/application' + +Rails.application.load_tasks diff --git a/samples/server/petstore/rails5/app/channels/application_cable/channel.rb b/samples/server/petstore/rails5/app/channels/application_cable/channel.rb new file mode 100644 index 00000000000..d56fa30f4d8 --- /dev/null +++ b/samples/server/petstore/rails5/app/channels/application_cable/channel.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading. +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/samples/server/petstore/rails5/app/channels/application_cable/connection.rb b/samples/server/petstore/rails5/app/channels/application_cable/connection.rb new file mode 100644 index 00000000000..b4f41389ad0 --- /dev/null +++ b/samples/server/petstore/rails5/app/channels/application_cable/connection.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading. +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/samples/server/petstore/rails5/app/controllers/application_controller.rb b/samples/server/petstore/rails5/app/controllers/application_controller.rb new file mode 100644 index 00000000000..4ac8823b095 --- /dev/null +++ b/samples/server/petstore/rails5/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::API +end diff --git a/samples/server/petstore/rails5/app/controllers/pet_controllers.rb b/samples/server/petstore/rails5/app/controllers/pet_controllers.rb new file mode 100644 index 00000000000..fa7e2557947 --- /dev/null +++ b/samples/server/petstore/rails5/app/controllers/pet_controllers.rb @@ -0,0 +1,50 @@ +class PetController < ApplicationController + + def create + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def destroy + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def find_pets_by_status + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def find_pets_by_tags + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def show + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def update_pet + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def update_pet_with_form + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def upload_file + # Your code here + + render json: {"message" => "yes, it worked"} + end +end diff --git a/samples/server/petstore/rails5/app/controllers/store_controllers.rb b/samples/server/petstore/rails5/app/controllers/store_controllers.rb new file mode 100644 index 00000000000..71fef4d92f8 --- /dev/null +++ b/samples/server/petstore/rails5/app/controllers/store_controllers.rb @@ -0,0 +1,26 @@ +class StoreController < ApplicationController + + def delete_order + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def get_inventory + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def get_order_by_id + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def place_order + # Your code here + + render json: {"message" => "yes, it worked"} + end +end diff --git a/samples/server/petstore/rails5/app/controllers/user_controllers.rb b/samples/server/petstore/rails5/app/controllers/user_controllers.rb new file mode 100644 index 00000000000..b8b2ce93634 --- /dev/null +++ b/samples/server/petstore/rails5/app/controllers/user_controllers.rb @@ -0,0 +1,50 @@ +class UserController < ApplicationController + + def create + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def create_users_with_array_input + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def create_users_with_list_input + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def destroy + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def show + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def login_user + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def logout_user + # Your code here + + render json: {"message" => "yes, it worked"} + end + + def update + # Your code here + + render json: {"message" => "yes, it worked"} + end +end diff --git a/samples/server/petstore/rails5/app/jobs/application_job.rb b/samples/server/petstore/rails5/app/jobs/application_job.rb new file mode 100644 index 00000000000..a009ace51cc --- /dev/null +++ b/samples/server/petstore/rails5/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/samples/server/petstore/rails5/app/mailers/application_mailer.rb b/samples/server/petstore/rails5/app/mailers/application_mailer.rb new file mode 100644 index 00000000000..286b2239d13 --- /dev/null +++ b/samples/server/petstore/rails5/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/samples/server/petstore/rails5/app/models/application_record.rb b/samples/server/petstore/rails5/app/models/application_record.rb new file mode 100644 index 00000000000..10a4cba84df --- /dev/null +++ b/samples/server/petstore/rails5/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/samples/server/petstore/rails5/app/views/layouts/mailer.html.erb b/samples/server/petstore/rails5/app/views/layouts/mailer.html.erb new file mode 100644 index 00000000000..cbd34d2e9dd --- /dev/null +++ b/samples/server/petstore/rails5/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/samples/server/petstore/rails5/app/views/layouts/mailer.text.erb b/samples/server/petstore/rails5/app/views/layouts/mailer.text.erb new file mode 100644 index 00000000000..37f0bddbd74 --- /dev/null +++ b/samples/server/petstore/rails5/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/samples/server/petstore/rails5/bin/bundle b/samples/server/petstore/rails5/bin/bundle new file mode 100755 index 00000000000..66e9889e8b4 --- /dev/null +++ b/samples/server/petstore/rails5/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/samples/server/petstore/rails5/bin/rails b/samples/server/petstore/rails5/bin/rails new file mode 100755 index 00000000000..07396602377 --- /dev/null +++ b/samples/server/petstore/rails5/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/samples/server/petstore/rails5/bin/rake b/samples/server/petstore/rails5/bin/rake new file mode 100755 index 00000000000..17240489f64 --- /dev/null +++ b/samples/server/petstore/rails5/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/samples/server/petstore/rails5/bin/setup b/samples/server/petstore/rails5/bin/setup new file mode 100755 index 00000000000..e620b4dadb2 --- /dev/null +++ b/samples/server/petstore/rails5/bin/setup @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/samples/server/petstore/rails5/bin/update b/samples/server/petstore/rails5/bin/update new file mode 100755 index 00000000000..a8e4462f203 --- /dev/null +++ b/samples/server/petstore/rails5/bin/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/samples/server/petstore/rails5/config.ru b/samples/server/petstore/rails5/config.ru new file mode 100644 index 00000000000..f7ba0b527b1 --- /dev/null +++ b/samples/server/petstore/rails5/config.ru @@ -0,0 +1,5 @@ +# This file is used by Rack-based servers to start the application. + +require_relative 'config/environment' + +run Rails.application diff --git a/samples/server/petstore/rails5/config/application.rb b/samples/server/petstore/rails5/config/application.rb new file mode 100644 index 00000000000..70bea9ecf69 --- /dev/null +++ b/samples/server/petstore/rails5/config/application.rb @@ -0,0 +1,30 @@ +require_relative 'boot' + +require "rails" +# Pick the frameworks you want: +require "active_model/railtie" +require "active_job/railtie" +require "active_record/railtie" +require "action_controller/railtie" +require "action_mailer/railtie" +require "action_view/railtie" +require "action_cable/engine" +# require "sprockets/railtie" +require "rails/test_unit/railtie" + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module ApiDemo + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Only loads a smaller set of middleware suitable for API only apps. + # Middleware like session, flash, cookies can be added back manually. + # Skip views, helpers and assets when generating a new resource. + config.api_only = true + end +end diff --git a/samples/server/petstore/rails5/config/boot.rb b/samples/server/petstore/rails5/config/boot.rb new file mode 100644 index 00000000000..30f5120df69 --- /dev/null +++ b/samples/server/petstore/rails5/config/boot.rb @@ -0,0 +1,3 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/samples/server/petstore/rails5/config/cable.yml b/samples/server/petstore/rails5/config/cable.yml new file mode 100644 index 00000000000..aa4e832748c --- /dev/null +++ b/samples/server/petstore/rails5/config/cable.yml @@ -0,0 +1,10 @@ +# Action Cable uses Redis by default to administer connections, channels, and sending/receiving messages over the WebSocket. +production: + adapter: redis + url: redis://localhost:6379/1 + +development: + adapter: async + +test: + adapter: async diff --git a/samples/server/petstore/rails5/config/config/development.rb b/samples/server/petstore/rails5/config/config/development.rb new file mode 100644 index 00000000000..082a013ab36 --- /dev/null +++ b/samples/server/petstore/rails5/config/config/development.rb @@ -0,0 +1,47 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + if Rails.root.join('tmp/caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=172800' + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker +end diff --git a/samples/server/petstore/rails5/config/config/production.rb b/samples/server/petstore/rails5/config/config/production.rb new file mode 100644 index 00000000000..6cb0a8fe61c --- /dev/null +++ b/samples/server/petstore/rails5/config/config/production.rb @@ -0,0 +1,80 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Action Cable endpoint configuration + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Don't mount Action Cable in the main server process. + # config.action_cable.mount_path = nil + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "api_demo_#{Rails.env}" + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/samples/server/petstore/rails5/config/database.yml b/samples/server/petstore/rails5/config/database.yml new file mode 100644 index 00000000000..e536d9f37dc --- /dev/null +++ b/samples/server/petstore/rails5/config/database.yml @@ -0,0 +1,54 @@ +# MySQL. Versions 5.0 and up are supported. +# +# Install the MySQL driver +# gem install mysql2 +# +# Ensure the MySQL gem is defined in your Gemfile +# gem 'mysql2' +# +# And be sure to use new-style password hashing: +# http://dev.mysql.com/doc/refman/5.7/en/old-client.html +# +default: &default + adapter: mysql2 + encoding: utf8 + pool: 5 + username: root + password: + socket: /tmp/mysql.sock + +development: + <<: *default + database: api_demo_development + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: api_demo_test + +# As with config/secrets.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password as a unix environment variable when you boot +# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full rundown on how to provide these environment variables in a +# production deployment. +# +# On Heroku and other platform providers, you may have a full connection URL +# available as an environment variable. For example: +# +# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" +# +# You can use this database configuration with: +# +# production: +# url: <%= ENV['DATABASE_URL'] %> +# +production: + <<: *default + database: api_demo_production + username: api_demo + password: <%= ENV['API_DEMO_DATABASE_PASSWORD'] %> diff --git a/samples/server/petstore/rails5/config/environment.rb b/samples/server/petstore/rails5/config/environment.rb new file mode 100644 index 00000000000..426333bb469 --- /dev/null +++ b/samples/server/petstore/rails5/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative 'application' + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/samples/server/petstore/rails5/config/initializers/active_record_belongs_to_required_by_default.rb b/samples/server/petstore/rails5/config/initializers/active_record_belongs_to_required_by_default.rb new file mode 100644 index 00000000000..f613b40f804 --- /dev/null +++ b/samples/server/petstore/rails5/config/initializers/active_record_belongs_to_required_by_default.rb @@ -0,0 +1,6 @@ +# Be sure to restart your server when you modify this file. + +# Require `belongs_to` associations by default. This is a new Rails 5.0 +# default, so it is introduced as a configuration option to ensure that apps +# made on earlier versions of Rails are not affected when upgrading. +Rails.application.config.active_record.belongs_to_required_by_default = true diff --git a/samples/server/petstore/rails5/config/initializers/application_controller_renderer.rb b/samples/server/petstore/rails5/config/initializers/application_controller_renderer.rb new file mode 100644 index 00000000000..51639b67a00 --- /dev/null +++ b/samples/server/petstore/rails5/config/initializers/application_controller_renderer.rb @@ -0,0 +1,6 @@ +# Be sure to restart your server when you modify this file. + +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) diff --git a/samples/server/petstore/rails5/config/initializers/backtrace_silencers.rb b/samples/server/petstore/rails5/config/initializers/backtrace_silencers.rb new file mode 100644 index 00000000000..59385cdf379 --- /dev/null +++ b/samples/server/petstore/rails5/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/samples/server/petstore/rails5/config/initializers/callback_terminator.rb b/samples/server/petstore/rails5/config/initializers/callback_terminator.rb new file mode 100644 index 00000000000..649e82280e1 --- /dev/null +++ b/samples/server/petstore/rails5/config/initializers/callback_terminator.rb @@ -0,0 +1,6 @@ +# Be sure to restart your server when you modify this file. + +# Do not halt callback chains when a callback returns false. This is a new +# Rails 5.0 default, so it is introduced as a configuration option to ensure +# that apps made with earlier versions of Rails are not affected when upgrading. +ActiveSupport.halt_callback_chains_on_return_false = false diff --git a/samples/server/petstore/rails5/config/initializers/cors.rb b/samples/server/petstore/rails5/config/initializers/cors.rb new file mode 100644 index 00000000000..3b1c1b5ed14 --- /dev/null +++ b/samples/server/petstore/rails5/config/initializers/cors.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Avoid CORS issues when API is called from the frontend app. +# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. + +# Read more: https://github.com/cyu/rack-cors + +# Rails.application.config.middleware.insert_before 0, Rack::Cors do +# allow do +# origins 'example.com' +# +# resource '*', +# headers: :any, +# methods: [:get, :post, :put, :patch, :delete, :options, :head] +# end +# end diff --git a/samples/server/petstore/rails5/config/initializers/filter_parameter_logging.rb b/samples/server/petstore/rails5/config/initializers/filter_parameter_logging.rb new file mode 100644 index 00000000000..4a994e1e7bb --- /dev/null +++ b/samples/server/petstore/rails5/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/samples/server/petstore/rails5/config/initializers/inflections.rb b/samples/server/petstore/rails5/config/initializers/inflections.rb new file mode 100644 index 00000000000..ac033bf9dc8 --- /dev/null +++ b/samples/server/petstore/rails5/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/samples/server/petstore/rails5/config/initializers/mime_types.rb b/samples/server/petstore/rails5/config/initializers/mime_types.rb new file mode 100644 index 00000000000..dc1899682b0 --- /dev/null +++ b/samples/server/petstore/rails5/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/samples/server/petstore/rails5/config/initializers/ssl_options.rb b/samples/server/petstore/rails5/config/initializers/ssl_options.rb new file mode 100644 index 00000000000..1775dea1e76 --- /dev/null +++ b/samples/server/petstore/rails5/config/initializers/ssl_options.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure SSL options to enable HSTS with subdomains. +Rails.application.config.ssl_options = { hsts: { subdomains: true } } diff --git a/samples/server/petstore/rails5/config/initializers/to_time_preserves_timezone.rb b/samples/server/petstore/rails5/config/initializers/to_time_preserves_timezone.rb new file mode 100644 index 00000000000..8674be3227e --- /dev/null +++ b/samples/server/petstore/rails5/config/initializers/to_time_preserves_timezone.rb @@ -0,0 +1,10 @@ +# Be sure to restart your server when you modify this file. + +# Preserve the timezone of the receiver when calling to `to_time`. +# Ruby 2.4 will change the behavior of `to_time` to preserve the timezone +# when converting to an instance of `Time` instead of the previous behavior +# of converting to the local system timezone. +# +# Rails 5.0 introduced this config option so that apps made with earlier +# versions of Rails are not affected when upgrading. +ActiveSupport.to_time_preserves_timezone = true diff --git a/samples/server/petstore/rails5/config/locales/en.yml b/samples/server/petstore/rails5/config/locales/en.yml new file mode 100644 index 00000000000..0653957166e --- /dev/null +++ b/samples/server/petstore/rails5/config/locales/en.yml @@ -0,0 +1,23 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/samples/server/petstore/rails5/config/puma.rb b/samples/server/petstore/rails5/config/puma.rb new file mode 100644 index 00000000000..c7f311f8116 --- /dev/null +++ b/samples/server/petstore/rails5/config/puma.rb @@ -0,0 +1,47 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum, this matches the default thread size of Active Record. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests, default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. If you use this option +# you need to make sure to reconnect any threads in the `on_worker_boot` +# block. +# +# preload_app! + +# The code in the `on_worker_boot` will be called if you are using +# clustered mode by specifying a number of `workers`. After each worker +# process is booted this block will be run, if you are using `preload_app!` +# option you will want to use this block to reconnect to any threads +# or connections that may have been created at application boot, Ruby +# cannot share connections between processes. +# +# on_worker_boot do +# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) +# end + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/samples/server/petstore/rails5/config/routes.rb b/samples/server/petstore/rails5/config/routes.rb new file mode 100644 index 00000000000..502140c332b --- /dev/null +++ b/samples/server/petstore/rails5/config/routes.rb @@ -0,0 +1,156 @@ +Rails.application.routes.draw do + + def add_swagger_route http_method, path, opts = {} + full_path = path.gsub(/{(.*?)}/, ':\1') + action = + (opts[:isRestfulIndex] && :index) || + (opts[:isRestfulShow] && :show) || + (opts[:isRestfulCreate] && :create) || + (opts[:isRestfulUpdate] && :update) || + (opts[:isRestfulDestroy] && :destroy) || + opts[:nickname] + + match full_path, to: "#{opts.fetch(:classVarName)}##{action}", via: http_method + end + + add_swagger_route 'POST', '/v2/pet', + classVarName: 'pet', nickname: 'add_pet', + isRestfulIndex: false, + isRestfulCreate: true, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: false + add_swagger_route 'DELETE', '/v2/pet/{petId}', + classVarName: 'pet', nickname: 'delete_pet', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: true + add_swagger_route 'GET', '/v2/pet/findByStatus', + classVarName: 'pet', nickname: 'find_pets_by_status', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: false + add_swagger_route 'GET', '/v2/pet/findByTags', + classVarName: 'pet', nickname: 'find_pets_by_tags', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: false + add_swagger_route 'GET', '/v2/pet/{petId}', + classVarName: 'pet', nickname: 'get_pet_by_id', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: true, + isRestfulDestroy: false + add_swagger_route 'PUT', '/v2/pet', + classVarName: 'pet', nickname: 'update_pet', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: false + add_swagger_route 'POST', '/v2/pet/{petId}', + classVarName: 'pet', nickname: 'update_pet_with_form', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: false + add_swagger_route 'POST', '/v2/pet/{petId}/uploadImage', + classVarName: 'pet', nickname: 'upload_file', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: false + add_swagger_route 'DELETE', '/v2/store/order/{orderId}', + classVarName: 'store', nickname: 'delete_order', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: false + add_swagger_route 'GET', '/v2/store/inventory', + classVarName: 'store', nickname: 'get_inventory', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: false + add_swagger_route 'GET', '/v2/store/order/{orderId}', + classVarName: 'store', nickname: 'get_order_by_id', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: false + add_swagger_route 'POST', '/v2/store/order', + classVarName: 'store', nickname: 'place_order', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: false + add_swagger_route 'POST', '/v2/user', + classVarName: 'user', nickname: 'create_user', + isRestfulIndex: false, + isRestfulCreate: true, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: false + add_swagger_route 'POST', '/v2/user/createWithArray', + classVarName: 'user', nickname: 'create_users_with_array_input', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: false + add_swagger_route 'POST', '/v2/user/createWithList', + classVarName: 'user', nickname: 'create_users_with_list_input', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: false + add_swagger_route 'DELETE', '/v2/user/{username}', + classVarName: 'user', nickname: 'delete_user', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: true + add_swagger_route 'GET', '/v2/user/{username}', + classVarName: 'user', nickname: 'get_user_by_name', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: true, + isRestfulDestroy: false + add_swagger_route 'GET', '/v2/user/login', + classVarName: 'user', nickname: 'login_user', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: false + add_swagger_route 'GET', '/v2/user/logout', + classVarName: 'user', nickname: 'logout_user', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: false, + isRestfulShow: false, + isRestfulDestroy: false + add_swagger_route 'PUT', '/v2/user/{username}', + classVarName: 'user', nickname: 'update_user', + isRestfulIndex: false, + isRestfulCreate: false, + isRestfulUpdate: true, + isRestfulShow: false, + isRestfulDestroy: false +end diff --git a/samples/server/petstore/rails5/config/secrets.yml b/samples/server/petstore/rails5/config/secrets.yml new file mode 100644 index 00000000000..179b066b84d --- /dev/null +++ b/samples/server/petstore/rails5/config/secrets.yml @@ -0,0 +1,22 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rails secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +development: + secret_key_base: 2e13a003477a557ba3fcc6260c2ec69e411238b9b8b530c3c70e71f7cfc905b5f746f5c195a0282342a77ad6acd4e6ef8949106723200a99414fe83393d67344 + +test: + secret_key_base: fedf54236a94882c00e2fa0af308a4135f50941396437b9fbc38dd340c0a8bcf38cfcf6264cc2abc2af5bda26252293fe48e9a3e90fbfc4d25d6886d6d14b300 + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/samples/server/petstore/rails5/config/spring.rb b/samples/server/petstore/rails5/config/spring.rb new file mode 100644 index 00000000000..c9119b40c08 --- /dev/null +++ b/samples/server/petstore/rails5/config/spring.rb @@ -0,0 +1,6 @@ +%w( + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +).each { |path| Spring.watch(path) } diff --git a/samples/server/petstore/rails5/db/migrate/.keep b/samples/server/petstore/rails5/db/migrate/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/samples/server/petstore/rails5/db/schema.rb b/samples/server/petstore/rails5/db/schema.rb new file mode 100644 index 00000000000..4dfbb16804e --- /dev/null +++ b/samples/server/petstore/rails5/db/schema.rb @@ -0,0 +1,16 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 0) do + +end diff --git a/samples/server/petstore/rails5/db/seeds.rb b/samples/server/petstore/rails5/db/seeds.rb new file mode 100644 index 00000000000..1beea2accd7 --- /dev/null +++ b/samples/server/petstore/rails5/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) +# Character.create(name: 'Luke', movie: movies.first) diff --git a/samples/server/petstore/rails5/lib/tasks/.keep b/samples/server/petstore/rails5/lib/tasks/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/samples/server/petstore/rails5/log/.keep b/samples/server/petstore/rails5/log/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/samples/server/petstore/rails5/log/development.log b/samples/server/petstore/rails5/log/development.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/samples/server/petstore/rails5/public/404.html b/samples/server/petstore/rails5/public/404.html new file mode 100644 index 00000000000..b612547fc21 --- /dev/null +++ b/samples/server/petstore/rails5/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/samples/server/petstore/rails5/public/422.html b/samples/server/petstore/rails5/public/422.html new file mode 100644 index 00000000000..a21f82b3bdb --- /dev/null +++ b/samples/server/petstore/rails5/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/samples/server/petstore/rails5/public/500.html b/samples/server/petstore/rails5/public/500.html new file mode 100644 index 00000000000..061abc587dc --- /dev/null +++ b/samples/server/petstore/rails5/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/samples/server/petstore/rails5/public/apple-touch-icon-precomposed.png b/samples/server/petstore/rails5/public/apple-touch-icon-precomposed.png new file mode 100644 index 00000000000..e69de29bb2d diff --git a/samples/server/petstore/rails5/public/apple-touch-icon.png b/samples/server/petstore/rails5/public/apple-touch-icon.png new file mode 100644 index 00000000000..e69de29bb2d diff --git a/samples/server/petstore/rails5/public/favicon.ico b/samples/server/petstore/rails5/public/favicon.ico new file mode 100644 index 00000000000..e69de29bb2d diff --git a/samples/server/petstore/rails5/public/robots.txt b/samples/server/petstore/rails5/public/robots.txt new file mode 100644 index 00000000000..3c9c7c01f30 --- /dev/null +++ b/samples/server/petstore/rails5/public/robots.txt @@ -0,0 +1,5 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/samples/server/petstore/rails5/test/test_helper.rb b/samples/server/petstore/rails5/test/test_helper.rb new file mode 100644 index 00000000000..92e39b2d78c --- /dev/null +++ b/samples/server/petstore/rails5/test/test_helper.rb @@ -0,0 +1,10 @@ +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +require 'rails/test_help' + +class ActiveSupport::TestCase + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all + + # Add more helper methods to be used by all tests here... +end diff --git a/samples/server/petstore/rails5/tmp/cache/.keep b/samples/server/petstore/rails5/tmp/cache/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/samples/server/petstore/rails5/tmp/pids/.keep b/samples/server/petstore/rails5/tmp/pids/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/samples/server/petstore/rails5/tmp/restart.txt b/samples/server/petstore/rails5/tmp/restart.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/samples/server/petstore/rails5/tmp/sockets/.keep b/samples/server/petstore/rails5/tmp/sockets/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/samples/server/petstore/rails5/vendor/.keep b/samples/server/petstore/rails5/vendor/.keep new file mode 100644 index 00000000000..e69de29bb2d From 33a1d24e1ecc6cf1577d6ba54fb1b022d2bd1db6 Mon Sep 17 00:00:00 2001 From: Newell Zhu Date: Sun, 15 May 2016 11:53:54 +0800 Subject: [PATCH 5/5] change better method call --- .../src/main/resources/rails5/routes.mustache | 18 +- .../server/petstore/rails5/config/routes.rb | 170 +++--------------- 2 files changed, 23 insertions(+), 165 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/rails5/routes.mustache b/modules/swagger-codegen/src/main/resources/rails5/routes.mustache index e6b95be33a4..6ebc0d4965d 100644 --- a/modules/swagger-codegen/src/main/resources/rails5/routes.mustache +++ b/modules/swagger-codegen/src/main/resources/rails5/routes.mustache @@ -2,28 +2,14 @@ Rails.application.routes.draw do def add_swagger_route http_method, path, opts = {} full_path = path.gsub(/{(.*?)}/, ':\1') - action = - (opts[:isRestfulIndex] && :index) || - (opts[:isRestfulShow] && :show) || - (opts[:isRestfulCreate] && :create) || - (opts[:isRestfulUpdate] && :update) || - (opts[:isRestfulDestroy] && :destroy) || - opts[:nickname] - - match full_path, to: "#{opts.fetch(:classVarName)}##{action}", via: http_method + match full_path, to: "#{opts.fetch(:controller_name)}##{opts[:action_name]}", via: http_method end {{#apiInfo}} {{#apis}} {{#operations}} {{#operation}} - add_swagger_route '{{httpMethod}}', '{{basePathWithoutHost}}{{path}}', - classVarName: '{{classVarName}}', nickname: '{{nickname}}', - isRestfulIndex: {{#isRestfulIndex}}true{{/isRestfulIndex}}{{^isRestfulIndex}}false{{/isRestfulIndex}}, - isRestfulCreate: {{#isRestfulCreate}}true{{/isRestfulCreate}}{{^isRestfulCreate}}false{{/isRestfulCreate}}, - isRestfulUpdate: {{#isRestfulUpdate}}true{{/isRestfulUpdate}}{{^isRestfulUpdate}}false{{/isRestfulUpdate}}, - isRestfulShow: {{#isRestfulShow}}true{{/isRestfulShow}}{{^isRestfulShow}}false{{/isRestfulShow}}, - isRestfulDestroy: {{#isRestfulDestroy}}true{{/isRestfulDestroy}}{{^isRestfulDestroy}}false{{/isRestfulDestroy}} + add_swagger_route '{{httpMethod}}', '{{basePathWithoutHost}}{{path}}', controller_name: '{{classVarName}}', action_name: {{#isRestfulIndex}}'index'{{/isRestfulIndex}}{{#isRestfulCreate}}'create'{{/isRestfulCreate}}{{#isRestfulUpdate}}'update'{{/isRestfulUpdate}}{{#isRestfulShow}}'show'{{/isRestfulShow}}{{#isRestfulDestroy}}'destroy'{{/isRestfulDestroy}}{{^isRestful}}'{{nickname}}'{{/isRestful}} {{/operation}} {{/operations}} {{/apis}} diff --git a/samples/server/petstore/rails5/config/routes.rb b/samples/server/petstore/rails5/config/routes.rb index 502140c332b..de0b1f61035 100644 --- a/samples/server/petstore/rails5/config/routes.rb +++ b/samples/server/petstore/rails5/config/routes.rb @@ -2,155 +2,27 @@ Rails.application.routes.draw do def add_swagger_route http_method, path, opts = {} full_path = path.gsub(/{(.*?)}/, ':\1') - action = - (opts[:isRestfulIndex] && :index) || - (opts[:isRestfulShow] && :show) || - (opts[:isRestfulCreate] && :create) || - (opts[:isRestfulUpdate] && :update) || - (opts[:isRestfulDestroy] && :destroy) || - opts[:nickname] - - match full_path, to: "#{opts.fetch(:classVarName)}##{action}", via: http_method + match full_path, to: "#{opts.fetch(:controller_name)}##{opts[:action_name]}", via: http_method end - add_swagger_route 'POST', '/v2/pet', - classVarName: 'pet', nickname: 'add_pet', - isRestfulIndex: false, - isRestfulCreate: true, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: false - add_swagger_route 'DELETE', '/v2/pet/{petId}', - classVarName: 'pet', nickname: 'delete_pet', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: true - add_swagger_route 'GET', '/v2/pet/findByStatus', - classVarName: 'pet', nickname: 'find_pets_by_status', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: false - add_swagger_route 'GET', '/v2/pet/findByTags', - classVarName: 'pet', nickname: 'find_pets_by_tags', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: false - add_swagger_route 'GET', '/v2/pet/{petId}', - classVarName: 'pet', nickname: 'get_pet_by_id', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: true, - isRestfulDestroy: false - add_swagger_route 'PUT', '/v2/pet', - classVarName: 'pet', nickname: 'update_pet', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: false - add_swagger_route 'POST', '/v2/pet/{petId}', - classVarName: 'pet', nickname: 'update_pet_with_form', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: false - add_swagger_route 'POST', '/v2/pet/{petId}/uploadImage', - classVarName: 'pet', nickname: 'upload_file', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: false - add_swagger_route 'DELETE', '/v2/store/order/{orderId}', - classVarName: 'store', nickname: 'delete_order', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: false - add_swagger_route 'GET', '/v2/store/inventory', - classVarName: 'store', nickname: 'get_inventory', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: false - add_swagger_route 'GET', '/v2/store/order/{orderId}', - classVarName: 'store', nickname: 'get_order_by_id', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: false - add_swagger_route 'POST', '/v2/store/order', - classVarName: 'store', nickname: 'place_order', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: false - add_swagger_route 'POST', '/v2/user', - classVarName: 'user', nickname: 'create_user', - isRestfulIndex: false, - isRestfulCreate: true, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: false - add_swagger_route 'POST', '/v2/user/createWithArray', - classVarName: 'user', nickname: 'create_users_with_array_input', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: false - add_swagger_route 'POST', '/v2/user/createWithList', - classVarName: 'user', nickname: 'create_users_with_list_input', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: false - add_swagger_route 'DELETE', '/v2/user/{username}', - classVarName: 'user', nickname: 'delete_user', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: true - add_swagger_route 'GET', '/v2/user/{username}', - classVarName: 'user', nickname: 'get_user_by_name', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: true, - isRestfulDestroy: false - add_swagger_route 'GET', '/v2/user/login', - classVarName: 'user', nickname: 'login_user', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: false - add_swagger_route 'GET', '/v2/user/logout', - classVarName: 'user', nickname: 'logout_user', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: false, - isRestfulShow: false, - isRestfulDestroy: false - add_swagger_route 'PUT', '/v2/user/{username}', - classVarName: 'user', nickname: 'update_user', - isRestfulIndex: false, - isRestfulCreate: false, - isRestfulUpdate: true, - isRestfulShow: false, - isRestfulDestroy: false + add_swagger_route 'POST', '/v2/pet', controller_name: 'pet', action_name: 'create' + add_swagger_route 'DELETE', '/v2/pet/{petId}', controller_name: 'pet', action_name: 'destroy' + add_swagger_route 'GET', '/v2/pet/findByStatus', controller_name: 'pet', action_name: 'find_pets_by_status' + add_swagger_route 'GET', '/v2/pet/findByTags', controller_name: 'pet', action_name: 'find_pets_by_tags' + add_swagger_route 'GET', '/v2/pet/{petId}', controller_name: 'pet', action_name: 'show' + add_swagger_route 'PUT', '/v2/pet', controller_name: 'pet', action_name: 'update_pet' + add_swagger_route 'POST', '/v2/pet/{petId}', controller_name: 'pet', action_name: 'update_pet_with_form' + add_swagger_route 'POST', '/v2/pet/{petId}/uploadImage', controller_name: 'pet', action_name: 'upload_file' + add_swagger_route 'DELETE', '/v2/store/order/{orderId}', controller_name: 'store', action_name: 'delete_order' + add_swagger_route 'GET', '/v2/store/inventory', controller_name: 'store', action_name: 'get_inventory' + add_swagger_route 'GET', '/v2/store/order/{orderId}', controller_name: 'store', action_name: 'get_order_by_id' + add_swagger_route 'POST', '/v2/store/order', controller_name: 'store', action_name: 'place_order' + add_swagger_route 'POST', '/v2/user', controller_name: 'user', action_name: 'create' + add_swagger_route 'POST', '/v2/user/createWithArray', controller_name: 'user', action_name: 'create_users_with_array_input' + add_swagger_route 'POST', '/v2/user/createWithList', controller_name: 'user', action_name: 'create_users_with_list_input' + add_swagger_route 'DELETE', '/v2/user/{username}', controller_name: 'user', action_name: 'destroy' + add_swagger_route 'GET', '/v2/user/{username}', controller_name: 'user', action_name: 'show' + add_swagger_route 'GET', '/v2/user/login', controller_name: 'user', action_name: 'login_user' + add_swagger_route 'GET', '/v2/user/logout', controller_name: 'user', action_name: 'logout_user' + add_swagger_route 'PUT', '/v2/user/{username}', controller_name: 'user', action_name: 'update' end