Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation de l'API avec Swagger et rswag #2157

Merged
merged 12 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ gem "rails-i18n"
gem "rbnacl", "~> 7.1"
gem "redis", "~> 5.1"
gem "roo", "~> 2"
gem "rswag", "~> 2"
gem "sanitize"
gem "sassc-rails"
gem "skylight"
Expand All @@ -86,6 +87,7 @@ gem "unsplash"
group :development, :test do
gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
gem "figaro"
gem "rspec-rails"
gem "vcr"
gem "webmock"
end
Expand Down
65 changes: 50 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,17 @@ GEM
autoprefixer-rails (10.4.19.0)
execjs (~> 2)
aws-eventstream (1.3.0)
aws-partitions (1.970.0)
aws-sdk-core (3.202.2)
aws-partitions (1.971.0)
aws-sdk-core (3.203.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.9)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.88.0)
aws-sdk-core (~> 3, >= 3.201.0)
aws-sdk-kms (1.89.0)
aws-sdk-core (~> 3, >= 3.203.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.159.0)
aws-sdk-core (~> 3, >= 3.201.0)
aws-sdk-s3 (1.160.0)
aws-sdk-core (~> 3, >= 3.203.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.5)
aws-sigv4 (1.9.1)
Expand Down Expand Up @@ -210,6 +210,7 @@ GEM
warden (~> 1.2.3)
devise-i18n (1.12.1)
devise (>= 4.9.0)
diff-lcs (1.5.1)
docile (1.4.1)
domain_name (0.6.20240107)
drb (2.2.1)
Expand Down Expand Up @@ -336,6 +337,8 @@ GEM
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.7.2)
json-schema (4.3.1)
addressable (>= 2.8)
jwt (2.8.2)
base64
kamifusen (1.12.0)
Expand Down Expand Up @@ -399,7 +402,7 @@ GEM
nesty (1.0.2)
net-http (0.4.1)
uri
net-imap (0.4.15)
net-imap (0.4.16)
date
net-protocol
net-pop (0.1.2)
Expand Down Expand Up @@ -443,7 +446,7 @@ GEM
orm_adapter (0.5.0)
pexels (0.5.0)
requests (~> 1.0.2)
pg (1.5.7)
pg (1.5.8)
pg_query (5.1.0)
google-protobuf (>= 3.22.3)
pghero (3.6.0)
Expand Down Expand Up @@ -517,19 +520,50 @@ GEM
redis-client (0.22.2)
connection_pool
regexp_parser (2.9.2)
reline (0.5.9)
reline (0.5.10)
io-console (~> 0.5)
requests (1.0.2)
require_all (3.0.0)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.3.6)
strscan
rexml (3.3.7)
roo (2.10.1)
nokogiri (~> 1)
rubyzip (>= 1.3.0, < 3.0.0)
rotp (6.3.0)
rspec-core (3.13.1)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (7.0.1)
actionpack (>= 7.0)
activesupport (>= 7.0)
railties (>= 7.0)
rspec-core (~> 3.13)
rspec-expectations (~> 3.13)
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rswag (2.14.0)
rswag-api (= 2.14.0)
rswag-specs (= 2.14.0)
rswag-ui (= 2.14.0)
rswag-api (2.14.0)
activesupport (>= 5.2, < 8.0)
railties (>= 5.2, < 8.0)
rswag-specs (2.14.0)
activesupport (>= 5.2, < 8.0)
json-schema (>= 2.2, < 5.0)
railties (>= 5.2, < 8.0)
rspec-core (>= 2.14)
rswag-ui (2.14.0)
actionpack (>= 5.2, < 8.0)
railties (>= 5.2, < 8.0)
ruby-saml (1.16.0)
nokogiri (>= 1.13.10)
rexml
Expand Down Expand Up @@ -575,7 +609,7 @@ GEM
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
skylight (6.0.4)
activesupport (>= 5.2.0)
Expand All @@ -591,7 +625,6 @@ GEM
activesupport (>= 6.1)
sprockets (>= 3.0.0)
stringio (3.1.1)
strscan (3.1.0)
sugar-high (0.7.3)
sweetloader (0.1.6)
activesupport (>= 3.0.1)
Expand All @@ -600,14 +633,14 @@ GEM
unicode-display_width (>= 1.1.1, < 3)
thor (1.3.2)
tilt (2.4.0)
time (0.3.0)
time (0.4.0)
date
timeout (0.4.1)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
tzinfo-data (1.2024.1)
tzinfo-data (1.2024.2)
tzinfo (>= 1.0.0)
unaccent (0.4.0)
unicode-display_width (2.5.0)
Expand Down Expand Up @@ -715,6 +748,8 @@ DEPENDENCIES
rbnacl (~> 7.1)
redis (~> 5.1)
roo (~> 2)
rspec-rails
rswag (~> 2)
sanitize
sassc-rails
selenium-webdriver
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/api/osuny/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
class Api::Osuny::ApplicationController < Api::ApplicationController
skip_before_action :verify_authenticity_token
Dismissed Show dismissed Hide dismissed
before_action :verify_app_token

protected

def verify_app_token
@app = current_university.apps.find_by(token: request.headers['X-Osuny-Token'])
raise_403_unless @app
end

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ class Api::Osuny::Communication::Websites::ApplicationController < Api::Osuny::A

protected

def website
@website ||= current_university.websites.find params[:website_id]
def websites
@websites ||= current_university.websites
end

def website
@website ||= websites.find params[:website_id]
end
end
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
class Api::Osuny::Communication::Websites::EventsController < Api::Osuny::Communication::Websites::ApplicationController
skip_before_action :verify_authenticity_token, only: :import
before_action :verify_app_token, only: :import

# TODO create
def import
importer = Importers::Api::Osuny::Communication::Website::Agenda::Event
importer.new university: current_university,
website: website,
params: params[:event]
render json: :ok
end

end
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class Api::Osuny::Communication::Websites::PagesController < Api::Osuny::Communication::Websites::ApplicationController
skip_before_action :verify_authenticity_token, only: :import
before_action :verify_app_token, only: :import

# TODO create
def import
Importers::Api::Osuny::Communication::Website::Page.new university: current_university,
website: website,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
class Api::Osuny::Communication::Websites::PostsController < Api::Osuny::Communication::Websites::ApplicationController
skip_before_action :verify_authenticity_token, only: :import
before_action :verify_app_token, only: :import
before_action :load_post, only: [:create, :update]

def import
Importers::Api::Osuny::Communication::Website::Post.new university: current_university,
website: website,
params: params[:post]
render json: :ok
def index
@posts = website.posts.published
end

def show
@post = website.posts.find params[:id]
end

def create
@post.assign_attributes post_params
if @post.save
render json: @post
else
render json: @post.errors
end
end

def update
if @post.update post_params
render json: @post
else
render json: @post.errors
end
end

# def import
# Importers::Api::Osuny::Communication::Website::Post.new university: current_university,
# website: website,
# params: params[:post]
# render json: :ok
# end

protected

def load_post
@migration_identifier = params[:post][:migration_identifier]
SebouChu marked this conversation as resolved.
Show resolved Hide resolved
@language = Language.find_by(iso_code: params[:post][:locale])
SebouChu marked this conversation as resolved.
Show resolved Hide resolved
@post = website.posts.where(
migration_identifier: @migration_identifier,
language: @language
).first_or_initialize
end

def post_params
params.require(:post)
.permit(
:title, :summary, :published
).merge(
university_id: current_university.id,
communication_website_id: website.id
)
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class Api::Osuny::Communication::WebsitesController < Api::Osuny::ApplicationController

class Api::Osuny::Communication::WebsitesController < Api::Osuny::Communication::Websites::ApplicationController
def index
@websites = current_university.communication_websites.in_production
@websites = websites.ordered
end

def show
@website = websites.find params[:id]
end
end
14 changes: 8 additions & 6 deletions app/controllers/api/osuny/server/websites_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
class Api::Osuny::Server::WebsitesController < Api::Osuny::ApplicationController
skip_before_action :verify_authenticity_token, only: [:theme_released]
skip_before_action :verify_app_token
before_action :verify_autoupdate_theme_key

def theme_released
if params[:secret_key].present? && params[:secret_key] == ENV['OSUNY_API_AUTOUPDATE_THEME_KEY']
Communication::Website.autoupdate_websites
else
render_forbidden
end
Communication::Website.autoupdate_websites
end

def verify_autoupdate_theme_key
render_forbidden if params[:secret_key].blank?
render_forbidden if params[:secret_key] != ENV['OSUNY_API_AUTOUPDATE_THEME_KEY']
end
end
6 changes: 5 additions & 1 deletion app/controllers/api/osuny_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
class Api::OsunyController < Api::ApplicationController
class Api::OsunyController < Api::Osuny::ApplicationController
def redirect_to_v1
redirect_to '/api/osuny/v1'
end

def index
end
end
10 changes: 5 additions & 5 deletions app/views/api/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
<div class="col-lg-6 mb-5">
<h2>Osuny</h2>
<p>
L'API Osuny permet d'interagir avec une instance.
L'implémentation est très rudimentaire, n'hésitez pas à ouvrir <a href="https://github.com/noesya/osuny/issues" target="_blank" rel="noreferrer">une issue sur Github</a> pour signaler un manque.
L'API Osuny v1 permet d'interagir avec une instance.
L'implémentation est incomplète, n'hésitez pas à ouvrir <a href="https://github.com/osunyorg/admin/issues" target="_blank" rel="noreferrer">une issue sur Github</a> pour signaler un manque.
</p>
<%= link_to 'API', api_osuny_path, class: 'btn btn-primary' %>
<%= link_to 'Documentation', '/api/docs', class: 'btn btn-primary' %>
</div>
<div class="col-lg-6 mb-5">
<h2>LHÉO</h2>
<p>
LHÉO est le <a href="http://lheo.gouv.fr/" target="_blank" rel="noreferrer">Langage Harmonisé d'Échange d'informations sur l'Offre de formation.</a>.
LHÉO est le <a href="http://lheo.gouv.fr/" target="_blank" rel="noreferrer">Langage Harmonisé d'Échange d'informations sur l'Offre de formation</a>.
L'API Osuny LHÉO met à disposition toute l'offre de formation à ce format.
L'implémentation est incomplète, n'hésitez pas à ouvrir <a href="https://github.com/noesya/osuny/issues" target="_blank" rel="noreferrer">une issue sur Github</a> pour signaler un manque.
L'implémentation est incomplète, n'hésitez pas à ouvrir <a href="https://github.com/osunyorg/admin/issues" target="_blank" rel="noreferrer">une issue sur Github</a> pour signaler un manque.
</p>
<%= link_to 'API', api_lheo_path, class: 'btn btn-primary' %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
json.array! @websites.each do |website|
json.name website.name
json.url website.url
json.extract! website, :id, :name, :url
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
json.array! @posts.each do |post|
json.id post.id
json.title post.title
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
json.extract! @post, :id, :title, :published, :published_at, :pinned, :featured_image_alt, :featured_image_credit, :meta_description, :slug, :summary, :migration_identifier, :created_at, :updated_at
json.migration do
json.identifier @post.migration_identifier
end if @post.migration_identifier
json.author do
json.id @post.author.id
json.name @post.author.to_s
end if @post.author.present?
20 changes: 20 additions & 0 deletions app/views/api/osuny/communication/websites/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
json.extract! @website, :name, :url
json.deuxfleurs do
json.hosting @website.deuxfleurs_hosting
json.identifier @website.deuxfleurs_identifier
end
json.features do
json.agenda @website.feature_agenda
json.portfolio @website.feature_portfolio
json.posts @website.feature_posts
end
json.git do
json.branch @website.git_branch
json.endpoint @website.git_endpoint
json.provider @website.git_provider
end
json.showcase do
json.present @website.in_showcase
json.highlighted @website.highlighted_in_showcase
json.tags @website.showcase_tags
end
Loading
Loading