Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions .spectral-required.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ rules:
functionOptions:
match: ^[a-z0-9]+(-[a-z0-9]+)*$

entur-info-metadata-devExtensions:
documentationUrl: "https://github.com/entur/api-guidelines/blob/main/guidelines.md#244-development-only-openapi-extensions"
severity: error
given: $.info.x-entur-metadata.devExtensions
then:
function: schema
functionOptions:
schema:
type: array
items:
type: string
pattern: ^x-.*$

# -------------------------------------------------------------------------
# 2.5 Lifecycle
# -------------------------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions .spectral.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,19 @@ rules:
functionOptions:
match: ^[a-z0-9]+(-[a-z0-9]+)*$

entur-info-metadata-devExtensions:
documentationUrl: "https://github.com/entur/api-guidelines/blob/main/guidelines.md#244-development-only-openapi-extensions"
severity: error
given: $.info.x-entur-metadata.devExtensions
then:
function: schema
functionOptions:
schema:
type: array
items:
type: string
pattern: ^x-.*$

# -------------------------------------------------------------------------
# 2.5 Lifecycle
# -------------------------------------------------------------------------
Expand Down
43 changes: 37 additions & 6 deletions guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,13 @@ If you need to explain the required permissions in more detail, you can declare
### 2.4 Entur Metadata
All OpenAPI specifications published to Enturs developer portal must declare a block `x-entur-metadata` in the `info` section of the specification.

Field name|Type |Description
----------|--------|-----------
id |`string`|**REQUIRED**. Unique id for this specification. [Read more](#241-identifying-a-specification).
audience |`string`|**REQUIRED**. Who this specification is targeted to. Must be one of `"open"`, `"partner"`, `"internal"`, `"private"`
owner |`string`|**REQUIRED**. The Entur team responsible for this specification. [Read more](#242-specification-owner).
parentId |`string`|Id of the parent specification, used when merging. [Read more](#243-merging-specifications).
Field name |Type |Description
--------------|----------|-----------
id |`string` |**REQUIRED**. Unique id for this specification. [Read more](#241-identifying-a-specification).
audience |`string` |**REQUIRED**. Who this specification is targeted to. Must be one of `"open"`, `"partner"`, `"internal"`, `"private"`
owner |`string` |**REQUIRED**. The Entur team responsible for this specification. [Read more](#242-specification-owner).
parentId |`string` |Id of the parent specification, used when merging. [Read more](#243-merging-specifications).
devExtensions |[`string`]|OpenAPI extensions in the specification that are used for development, but that should not be visible to consumers of the API.

Example:
```json
Expand Down Expand Up @@ -229,6 +230,7 @@ There are some limitations when merging specifications:

<details>
<summary>Example</summary>

For example, say you have three microservices, `alpha`, `beta` and `gamma`:

Microservice `alpha` publishes the specification:
Expand Down Expand Up @@ -270,6 +272,35 @@ Microservice `gamma` publishes the specification:
Here, only 1 specification will be shown on the Developer Portal, which is a combination of `alpha`, `beta` and `gamma`. Since `alpha` is the parent specification, the combined specification will use `alpha` as the base, so fields like `info.title` will be picked from there.
</details>

#### 2.4.4 Development-only OpenAPI extensions
Sometimes there may be a need for adding OpenAPI extensions to a specification that are only meant for the development process, for example for generating server interfaces with [OpenAPIGenerator](https://openapi-generator.tech/docs/generators/kotlin-spring#supported-vendor-extensions). These extensions are only relevant for the team creating the API, not for consumers. To hide extensions like these from the OpenAPI specification that is served from the Developer Portal, use the field `x-entur-metadata.devExtensions`.

<details>
<summary>Example</summary>

The extension `x-kotlin-implements` will be stripped before the specification is published to the Developer Portal.

```json
{
"info": {
"x-entur-metadata": {
...,
"devExtensions": ["x-kotlin-implements"]
}
},
"components": {
"schemas": {
"Item": {
"type": "object",
"x-kotlin-implements": ["com.example.Item"],
...
}
}
}
}
```
</details>


### 2.5 Lifecycle
All APIs, and endpoints within an API, follow a lifecycle with different stages that have different properties. The following sections describe a standardized way to declare an API's lifecycle status in its specification. Following this standard has several benefits:
Expand Down
3 changes: 2 additions & 1 deletion specs/reference-spec-with-errors.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"openapi": "3.1.0",
"info": {
"title": "Items API",

Check warning on line 4 in specs/reference-spec-with-errors.json

View workflow job for this annotation

GitHub Actions / lint-reference-spec-with-errors

entur-info-title-no-api

"version": "1.0.0",
"description": "A long and descriptive description",
"termsOfService": "https://developer.entur.org/terms-of-service",
Expand All @@ -10,9 +10,10 @@
"url": "https://entur.no",
"email": "support@entur.no"
},
"x-entur-metadata": {
"owner": "team-Api",

Check failure on line 14 in specs/reference-spec-with-errors.json

View workflow job for this annotation

GitHub Actions / lint-reference-spec-with-errors

entur-info-metadata-owner-valid

"team-Api" must match the pattern "^team-[a-z0-9]+(-[a-z0-9]+)*$" Documentation: https://github.com/entur/api-guidelines/blob/main/guidelines.md#242-specification-owner
"audience": "public"
"audience": "public",

Check failure on line 15 in specs/reference-spec-with-errors.json

View workflow job for this annotation

GitHub Actions / lint-reference-spec-with-errors

entur-info-metadata-audience-valid

"public" must be equal to one of the allowed values: "open", "partner", "internal", "private" Documentation: https://github.com/entur/api-guidelines/blob/main/guidelines.md#24-entur-metadata
"devExtensions": ["kotlin-implements"]

Check failure on line 16 in specs/reference-spec-with-errors.json

View workflow job for this annotation

GitHub Actions / lint-reference-spec-with-errors

entur-info-metadata-devExtensions

Check failure on line 16 in specs/reference-spec-with-errors.json

View workflow job for this annotation

GitHub Actions / lint-reference-spec-with-errors

entur-info-metadata-id

The OpenAPI info section MUST include "x-entur-metadata.id". Documentation: https://github.com/entur/api-guidelines/blob/main/guidelines.md#241-identifying-a-specification
}
},

Expand Down Expand Up @@ -61,7 +62,7 @@
"properties": {
"id": {
"type": "string",
"example": 100

Check failure on line 65 in specs/reference-spec-with-errors.json

View workflow job for this annotation

GitHub Actions / lint-reference-spec-with-errors

oas3-valid-schema-example

"example" property type must be string Documentation: https://meta.stoplight.io/docs/spectral/docs/reference/openapi-rules.md#oas3-valid-schema-example
},
"name": {
"type": "string",
Expand All @@ -69,7 +70,7 @@
}
},
"example": {
"id": 100,

Check failure on line 73 in specs/reference-spec-with-errors.json

View workflow job for this annotation

GitHub Actions / lint-reference-spec-with-errors

oas3-valid-schema-example

"id" property type must be string Documentation: https://meta.stoplight.io/docs/spectral/docs/reference/openapi-rules.md#oas3-valid-schema-example
"name": "Item 100"
}
},
Expand Down Expand Up @@ -160,8 +161,8 @@
}
},
"x-entur-permissions": {
"description": 10,

Check failure on line 164 in specs/reference-spec-with-errors.json

View workflow job for this annotation

GitHub Actions / lint-reference-spec-with-errors

entur-permissions

"value": {"and": ["items:les"]}

Check failure on line 165 in specs/reference-spec-with-errors.json

View workflow job for this annotation

GitHub Actions / lint-reference-spec-with-errors

entur-permissions

}
},
"post": {
Expand Down Expand Up @@ -196,11 +197,11 @@
}
},
"x-entur-permissions": {
"bar": "something",

Check failure on line 200 in specs/reference-spec-with-errors.json

View workflow job for this annotation

GitHub Actions / lint-reference-spec-with-errors

entur-permissions

"description": "You need access to read organisations, and create items.",
"value": {
"all": [
"organisations:le",

Check failure on line 204 in specs/reference-spec-with-errors.json

View workflow job for this annotation

GitHub Actions / lint-reference-spec-with-errors

entur-permissions

{
"any": [
"items:oppret",
Expand All @@ -222,7 +223,7 @@
"tags": [
"Items"
],
"deprecated": true,

Check notice on line 226 in specs/reference-spec-with-errors.json

View workflow job for this annotation

GitHub Actions / lint-reference-spec-with-errors

entur-sunset-operation

"x-sunset" should be defined when "deprecated" is true Documentation: https://github.com/entur/api-guidelines/blob/main/guidelines.md#254-deprecation
"summary": "Get an item",
"description": "Get an item with given id.",
"operationId": "getItem",
Expand Down
3 changes: 2 additions & 1 deletion specs/reference-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"x-entur-metadata": {
"id": "items",
"owner": "team-api",
"audience": "partner"
"audience": "partner",
"devExtensions": ["x-kotlin-implements"]
}
},

Expand Down
Loading