Publish DFC endpoints as JSON

This commit is contained in:
Maikel Linke
2025-09-29 16:31:46 +10:00
parent 404c07a590
commit 9460d17417
4 changed files with 18 additions and 5 deletions

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
class WellKnownController < ApplicationController
layout nil
def dfc
base = "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/scopes.rdf#"
render json: {
"#{base}ReadEnterprise" => "/api/dfc/enterprises/",
"#{base}ReadProducts" => "/api/dfc/supplied_products/",
}
end
end

View File

@@ -29,6 +29,9 @@ Openfoodnetwork::Application.routes.draw do
get '/orders/:id/token/:token' => 'spree/orders#show', :as => :token_order get '/orders/:id/token/:token' => 'spree/orders#show', :as => :token_order
get '/payments/:id/authorize' => 'payments#redirect_to_authorize', as: "authorize_payment" get '/payments/:id/authorize' => 'payments#redirect_to_authorize', as: "authorize_payment"
# Well known paths
get "/.well-known/dfc/", to: "well_known#dfc"
resource :cart, controller: "cart" do resource :cart, controller: "cart" do
post :populate post :populate
end end

View File

@@ -1,4 +0,0 @@
{
"https://github.com/datafoodconsortium/taxonomies/releases/latest/download/scopes.rdf#ReadEnterprise": "/api/dfc/enterprises/",
"https://github.com/datafoodconsortium/taxonomies/releases/latest/download/scopes.rdf#ReadProducts": "/api/dfc/supplied_products/",
}

View File

@@ -8,8 +8,9 @@ RSpec.describe "/.well-known/" do
get "/.well-known/dfc/" get "/.well-known/dfc/"
expect(response).to have_http_status :ok expect(response).to have_http_status :ok
expect(response.content_type).to eq "text/plain" # Should be JSON!
expect(response.body).to include "ReadEnterprise" expect(response.body).to include "ReadEnterprise"
expect(response.content_type).to eq "application/json; charset=utf-8"
expect(response.parsed_body.count).to eq 2
end end
end end
end end