diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubySinatraServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubySinatraServerCodegen.java index 12f8f9a2a703..c81426eb0170 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubySinatraServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubySinatraServerCodegen.java @@ -87,6 +87,7 @@ public class RubySinatraServerCodegen extends AbstractRubyCodegen { supportingFiles.add(new SupportingFile("Gemfile", "", "Gemfile")); supportingFiles.add(new SupportingFile("README.md", "", "README.md")); supportingFiles.add(new SupportingFile("openapi.mustache", "", "openapi.yaml")); + supportingFiles.add(new SupportingFile("Dockerfile", "", "Dockerfile")); } @Override diff --git a/modules/openapi-generator/src/main/resources/ruby-sinatra-server/Dockerfile b/modules/openapi-generator/src/main/resources/ruby-sinatra-server/Dockerfile new file mode 100644 index 000000000000..41be83d48ece --- /dev/null +++ b/modules/openapi-generator/src/main/resources/ruby-sinatra-server/Dockerfile @@ -0,0 +1,32 @@ +## Build libraries +FROM ruby:3.0-alpine as rubydev + +## for thin or falcon +#RUN apk --no-cache add make g++ libc-dev +## for puma +#RUN apk --no-cache add make gcc libc-dev + +ADD . /app +WORKDIR /app + +RUN bundle config set path lib +RUN bundle install + +## Build Runtime image +FROM ruby:3.0-alpine + +RUN apk --no-cache add tzdata ## ca-certificates + +COPY --from=rubydev /app /app +WORKDIR /app + +ENV SINATRA_HOST 0.0.0.0 +ENV SINATRA_PORT 8080 +EXPOSE $SINATRA_PORT + +RUN addgroup sinatra +RUN adduser -S -G sinatra sinatra +USER sinatra +RUN bundle config set path lib + +CMD bundle exec rackup --host $SINATRA_HOST -p $SINATRA_PORT diff --git a/modules/openapi-generator/src/main/resources/ruby-sinatra-server/Gemfile b/modules/openapi-generator/src/main/resources/ruby-sinatra-server/Gemfile index be9c3168ea6f..90d7b0e3bcdc 100644 --- a/modules/openapi-generator/src/main/resources/ruby-sinatra-server/Gemfile +++ b/modules/openapi-generator/src/main/resources/ruby-sinatra-server/Gemfile @@ -1,4 +1,5 @@ source 'https://rubygems.org' +gem "webrick" gem "sinatra" -gem "sinatra-cross_origin" \ No newline at end of file +gem "sinatra-cross_origin" diff --git a/modules/openapi-generator/src/main/resources/ruby-sinatra-server/README.md b/modules/openapi-generator/src/main/resources/ruby-sinatra-server/README.md index bf132cb042a2..aecb705a1946 100644 --- a/modules/openapi-generator/src/main/resources/ruby-sinatra-server/README.md +++ b/modules/openapi-generator/src/main/resources/ruby-sinatra-server/README.md @@ -1,4 +1,4 @@ -# Swagger for Sinatra +# OpenAPI for Sinatra ## Overview This is a project to provide Swagger support inside the [Sinatra](http://www.sinatrarb.com/) framework. You can find @@ -6,24 +6,60 @@ out more about both the spec and the framework at http://swagger.io. For more i Wordnik's APIs, please visit http://developer.wordnik.com. ## Prerequisites -You need to install ruby 1.9.3 and the following gems: +As of ruby 3.0.0, the webrick web server library was removed. +You need to install a rack-supported web server, such as webrick and thin. + +The default Gemfile is as follows. +Update the name of the web server as your prefer. ``` -sinatra -sinatra-cross_origin +source 'https://rubygems.org' + +gem "webrick" +gem "sinatra" +gem "sinatra-cross_origin" ``` ## Getting started -This sample was generated with the [OpenAPI Generator](https://github.com/openapitools/openapi-generator) project. +To generate a ruby-sinatra server for petstore.yaml, please run the following: ``` -rackup -p 4567 config.ru +openapi-generator-cli generate \ + -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml \ + -g ruby-sinatra -o code ``` -In your [swagger ui](https://github.com/swagger-api/swagger-ui), put in the following URL: +To run the generated server, please run the following: ``` -http://localhost:4567/resources.json +cd code/ +bundle config set path lib +bundle install +bundle exec rackup -p 8080 +``` + +You can access the application by the following URL: + +``` +http://localhost:8080/v2/store/inventory +``` + +## Docker +If you want to use a web server other than webrick, you need to edit the generated Dockerfile to prepare the compiler and the make command. Please check the comment of the Dockerfile. + +To run the code on docker, you can use the Dockerfile as follows: + +### Build the docker image +The "container_name" can be changed for your preferences. + +``` +docker build . --tag "container_name" +``` + +### Run the docker image + +``` +docker run -it --rm -p 8080:8080 "container_name" ``` Voila!