-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
148 additions
and
768 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
samples/server/petstore/ruby-sinatra/.openapi-generator/FILES
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Dockerfile | ||
Gemfile | ||
README.md | ||
api/pet_api.rb | ||
api/store_api.rb | ||
api/user_api.rb | ||
config.ru | ||
lib/openapiing.rb | ||
my_app.rb | ||
openapi.yaml |
2 changes: 1 addition & 1 deletion
2
samples/server/petstore/ruby-sinatra/.openapi-generator/VERSION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
4.2.1-SNAPSHOT | ||
5.1.1-SNAPSHOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem "webrick" | ||
gem "sinatra" | ||
gem "sinatra-cross_origin" | ||
gem "sinatra-cross_origin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,65 @@ | ||
# 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 | ||
out more about both the spec and the framework at http://swagger.io. For more information about | ||
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: | ||
|
||
``` | ||
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 | ||
``` | ||
|
||
To run the generated server, please run the following: | ||
|
||
``` | ||
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. | ||
|
||
``` | ||
rackup -p 4567 config.ru | ||
docker build . --tag "container_name" | ||
``` | ||
|
||
In your [swagger ui](https://github.com/swagger-api/swagger-ui), put in the following URL: | ||
### Run the docker image | ||
|
||
``` | ||
http://localhost:4567/resources.json | ||
docker run -it --rm -p 8080:8080 "container_name" | ||
``` | ||
|
||
Voila! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.