Skip to content

Commit

Permalink
Add schema_version (#2331)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcwrobel committed Mar 6, 2023
1 parent 10cb582 commit b81a43f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
35 changes: 24 additions & 11 deletions _plugins/generate-api-v1.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
# This script creates API files for version 1 of the endoflife.date API.
#
# There are two kind of generated files :
# - all.json: contains endoflife metadata, such as the list of all the products and the product count.
# - <product>.json: contains a given product data (including releases data).
# There are multiples endpoints :
#
# - /api/v1/ - list all major endpoints (those not requiring a parameter)
# - /api/v1/products/ - list all products
# - /api/v1/products/<product>/ - get a single product details
# - /api/v1/products/<product>/latest - get details on the latest cycle for the given product
# - /api/v1/products/<product>/<cycle> - get details on the given cycle for the given product
# - /api/v1/categories/ - list categories used on endoflife.date
# - /api/v1/categories/<category> - list products having the given category
# - /api/v1/tags/ - list tags used on endoflife.date
# - /api/v1/tags/<tag> - list products having the given tag


require 'jekyll'

module ApiV1

VERSION = '1.0.0-b1'
MAJOR_VERSION = VERSION.split('.')[0]

STRIP_HTML_BLOCKS = Regexp.union(
/<script.*?<\/script>/m,
/<!--.*?-->/m,
Expand All @@ -29,7 +41,7 @@ class ApiGenerator < Jekyll::Generator
safe true
priority :lowest

TOPIC = "API v1:"
TOPIC = "API " + ApiV1::VERSION + ":"

def generate(site)
@site = site
Expand All @@ -53,9 +65,9 @@ def add_index_page(site)
site_url = site.config['url']
site.pages << JsonPage.new(site, '/', 'index', {
result: [
{ name: "products", uri: "#{site_url}/api/v1/products/" },
{ name: "categories", uri: "#{site_url}/api/v1/categories/" },
{ name: "tags", uri: "#{site_url}/api/v1/tags/" },
{ name: "products", uri: "#{site_url}/api/v#{ApiV1::MAJOR_VERSION}/products/" },
{ name: "categories", uri: "#{site_url}/api/v#{ApiV1::MAJOR_VERSION}/categories/" },
{ name: "tags", uri: "#{site_url}/api/v#{ApiV1::MAJOR_VERSION}/tags/" },
]
})
end
Expand Down Expand Up @@ -101,7 +113,7 @@ def add_all_categories_page(site, products)
.map { |product| product.data['category'] }
.uniq
.sort
.map { |category| { name: category, uri: "#{site.config['url']}/api/v1/categories/#{category}/" } }
.map { |category| { name: category, uri: "#{site.config['url']}/api/v#{ApiV1::MAJOR_VERSION}/categories/#{category}/" } }
})
end

Expand All @@ -123,7 +135,7 @@ def add_all_tags_page(site, products)
.flat_map { |product| product.data['tags'] }
.uniq
.sort
.map { |tag| { name: tag, uri: "#{site.config['url']}/api/v1/tags/#{tag}/" } }
.map { |tag| { name: tag, uri: "#{site.config['url']}/api/v#{ApiV1::MAJOR_VERSION}/tags/#{tag}/" } }
})
end

Expand All @@ -140,11 +152,12 @@ class JsonPage < Jekyll::Page
def initialize(site, path, name, data)
@site = site
@base = site.source
@dir = "api/v1#{path}"
@dir = "api/v#{ApiV1::MAJOR_VERSION}#{path}"
@name = "#{name}.json"
@data = {}
@data['layout'] = 'json'
@data['data'] = data
@data['data']['schema_version'] = ApiV1::VERSION

self.process(@name)
end
Expand All @@ -159,7 +172,7 @@ def initialize(site, path, name, products)
label: product.data['title'],
category: product.data['category'],
tags: product.data['tags'],
uri: "#{site.config['url']}/api/v1/products/#{product.data['id']}/",
uri: "#{site.config['url']}/api/v#{ApiV1::MAJOR_VERSION}/products/#{product.data['id']}/",
} }
})
end
Expand Down
16 changes: 16 additions & 0 deletions api_v1/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ components:
UriList:
type: object
properties:
schema_version:
type: string
description: Version of this schema.
example: 1.0.0
result:
type: array
items:
Expand Down Expand Up @@ -234,6 +238,10 @@ components:
ProductList:
type: object
properties:
schema_version:
type: string
description: Version of this schema.
example: 1.0.0
total:
type: integer
format: int32
Expand Down Expand Up @@ -265,6 +273,10 @@ components:
ProductCycle:
type: object
properties:
schema_version:
type: string
description: Version of this schema.
example: 1.0.0
name:
type: string
description: Name of the product cycle.
Expand Down Expand Up @@ -329,6 +341,10 @@ components:
Product:
type: object
properties:
schema_version:
type: string
description: Version of this schema.
example: 1.0.0
name:
type: string
description: Name of the product.
Expand Down

0 comments on commit b81a43f

Please sign in to comment.