Skip to content

Commit

Permalink
Add identifiers in API response (#2595)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcwrobel committed Mar 3, 2023
1 parent 6d86bc2 commit 5456b69
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
11 changes: 7 additions & 4 deletions CHANGELOG_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ On 2023-03-02 endpoints were:
- "Product" (`/api/{product}.json`) : Get EoL dates of all cycles of a given product.
- "Cycle" (`/api/{product}/{cycle}.json`) : Details of a single release cycle of a given product.

## API v1 beta
## API v1.0.0-b1

### Summary

This is a major rework of the API with a lot of breaking changes. Compared the API v0, API v1:
API v1 is a major rework of the API v0 with a lot of breaking changes. Compared the API v0, API v1:

- is generated using a Jekyll Generator (see https://jekyllrb.com/docs/plugins/generators/),
- is versioned using the api/v1 prefix (#2066).
This will make it easier to implement non-backward-compatible changes in API,
- is versioned using the `api/v1` prefix, making it easier to implement non-backward-compatible
changes,
- feels more "Restful".

API v1 resolves : #394, #759, #905, #2062, #2066, #2078, #2160, #2331, #2431, #2595. It also reverts
#2425 due to incompatibilities in redirect rules.

The API v0 is still generated to give time to users to migrate to API v1.

### Changes in the "All products" endpoint
Expand Down
14 changes: 14 additions & 0 deletions _plugins/generate-api-v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ def initialize(site, path, name, products)
label: product.data['title'],
category: product.data['category'],
tags: product.data['tags'],
identifiers: [
product.data['identifiers']
.map { |identifier| {
type: identifier.keys.first,
id: identifier.values.first
}}
],
uri: "#{site.config['url']}/api/v#{ApiV1::MAJOR_VERSION}/products/#{product.data['id']}/",
} }
})
Expand All @@ -186,6 +193,13 @@ def initialize(site, product)
label: product.data['title'],
category: product.data['category'],
tags: product.data['tags'],
identifiers: [
product.data['identifiers']
.map { |identifier| {
type: identifier.keys.first,
id: identifier.values.first
}}
],
links: {
icon: product.data['iconUrl'],
html: "#{site.config['url']}/#{id}",
Expand Down
8 changes: 8 additions & 0 deletions _plugins/product-data-enricher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def enrich(page)
set_description(page)
set_icon_url(page)
set_tags(page)
set_identifiers(page)
set_overridden_columns_label(page)

page.data["releases"].each { |release| enrich_release(page, release) }
Expand Down Expand Up @@ -58,6 +59,13 @@ def set_tags(page)
page.data['tags'] = tags
end

# Set identifiers to empty if it's not present.
def set_identifiers(page)
if !page.data['identifiers']
page.data['identifiers'] = []
end
end

# Set properly the column presence/label if it was overridden.
def set_overridden_columns_label(page)
columnNames = [
Expand Down
22 changes: 22 additions & 0 deletions api_v1/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,18 @@ components:
description: URI
example: {{ site.url }}

Identifier:
type: object
properties:
name:
type: type
description: Type of the identifier (repology, purl...)
example: purl
id:
type: string
description: Identifier
example: pkg:docker/gerritcodereview/gerrit

UriList:
type: object
properties:
Expand Down Expand Up @@ -229,6 +241,11 @@ components:
description: Tags associated to the product
items:
type: string
identifiers:
type: array
description: Identifiers (purl, repology...) associated to the product
items:
$ref: '#/components/schemas/Identifier'
uri:
type: string
format: uri
Expand Down Expand Up @@ -362,6 +379,11 @@ components:
description: Tags associated to the productv
items:
type: string
identifiers:
type: array
description: Identifiers (purl, repology...) associated to the product
items:
$ref: '#/components/schemas/Identifier'
links:
type: array
description: API links (such as the Icon URL, the releasePolicyLink...).
Expand Down

0 comments on commit 5456b69

Please sign in to comment.