Skip to content

Commit

Permalink
feat!: introduce split definitions (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed May 16, 2022
1 parent 8b5b53f commit e5edd3a
Show file tree
Hide file tree
Showing 426 changed files with 29,035 additions and 12,126 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint-pr-title.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This action is centrally managed in https://github.com/asyncapi/.github/
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo
#This action is centrally managed in https://github.com/asyncapi/.github/
#Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo

name: Lint PR title

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
.nyc_output
.vscode
coverage
coverage
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
![npm](https://img.shields.io/npm/v/@asyncapi/specs?style=for-the-badge) ![npm](https://img.shields.io/npm/dt/@asyncapi/specs?style=for-the-badge)

> If you are currently using version 2, check out [migration guideline to version 3](./migrations/Migrate%20to%20version%203.md). You might be able to update it without any change.
# AsyncAPI

This package provides all the versions of the AsyncAPI schema.
This is a mono repository, which provides all the JSON Schema documents for validating AsyncAPI documents.

## Installation

Expand Down Expand Up @@ -45,7 +46,6 @@ const asyncapi = versions['1.1.0'];

// Do something with the schema.
```

### Go

Grab a specific AsyncAPI version:
Expand All @@ -62,4 +62,29 @@ func Do() {
// Do something with the schema
}

```
```

## Repository structure
This is the current project structure explained.
- [./definitions](./definitions) - contain all the individual schemas that will automatically be bundled together to provide the schemas in [./schemas](./schemas).
- [./tools/bundler](./tools/bundler) - is the tool that bundles all the individual schemas together.
- [./schemas](./schemas) - contain all automatically bundled and complete schemas for each AsyncAPI version. These schemas should **NOT** be manually changed as they are automatically generated. Any changes should be done in [./definitions](./definitions).

## Schema Bundling
Changes should not be done manually to the schemas in [./schemas](./schemas), but instead be done in their individual definitions located in [./definitions](./definitions).

These definitions are automatically bundled together on new releases through the npm script `prepublishOnly`, which ensures the project is build. This is where the [bundler](./tools/bundler) is called.

For example, for [2.2.0](./definitions/2.2.0), the [bundler](./tools/bundler/index.js) starts with the [asyncapi.json](definitions/2.2.0/asyncapi.json) file and recursively goes through all references (`$ref`) to create the [appropriate bundled version](./schemas/2.2.0.json).

### Creating a new version
To create a new version, simply run the following command:
```
npm run startNewVersion --new-version=x.x.x
```
Where `x.x.x` is the new version you want to create.

The manual process of creating a new version is to:
1. Duplicate the latest version (`y.y.y`) under definitions (so we have the correct base to make changes from).
2. Rename the folder to the new version (`x.x.x`).
3. Search and replace in the new duplicated folder for `y.y.y` and replace it with `x.x.x`.
36 changes: 36 additions & 0 deletions definitions/1.0.0/APIKeyHTTPSecurityScheme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"type": "object",
"required": [
"type",
"name",
"in"
],
"properties": {
"type": {
"type": "string",
"enum": [
"httpApiKey"
]
},
"name": {
"type": "string"
},
"in": {
"type": "string",
"enum": [
"header",
"query",
"cookie"
]
},
"description": {
"type": "string"
}
},
"patternProperties": {
"^x-": {}
},
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://asyncapi.com/definitions/1.0.0/APIKeyHTTPSecurityScheme.json"
}
33 changes: 33 additions & 0 deletions definitions/1.0.0/BearerHTTPSecurityScheme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"type": "object",
"required": [
"type",
"scheme"
],
"properties": {
"scheme": {
"type": "string",
"enum": [
"bearer"
]
},
"bearerFormat": {
"type": "string"
},
"type": {
"type": "string",
"enum": [
"http"
]
},
"description": {
"type": "string"
}
},
"patternProperties": {
"^x-": {}
},
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://asyncapi.com/definitions/1.0.0/BearerHTTPSecurityScheme.json"
}
15 changes: 15 additions & 0 deletions definitions/1.0.0/HTTPSecurityScheme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"oneOf": [
{
"$ref": "http://asyncapi.com/definitions/1.0.0/NonBearerHTTPSecurityScheme.json"
},
{
"$ref": "http://asyncapi.com/definitions/1.0.0/BearerHTTPSecurityScheme.json"
},
{
"$ref": "http://asyncapi.com/definitions/1.0.0/APIKeyHTTPSecurityScheme.json"
}
],
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://asyncapi.com/definitions/1.0.0/HTTPSecurityScheme.json"
}
38 changes: 38 additions & 0 deletions definitions/1.0.0/NonBearerHTTPSecurityScheme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"not": {
"type": "object",
"properties": {
"scheme": {
"type": "string",
"enum": [
"bearer"
]
}
}
},
"type": "object",
"required": [
"scheme",
"type"
],
"properties": {
"scheme": {
"type": "string"
},
"description": {
"type": "string"
},
"type": {
"type": "string",
"enum": [
"http"
]
}
},
"patternProperties": {
"^x-": {}
},
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://asyncapi.com/definitions/1.0.0/NonBearerHTTPSecurityScheme.json"
}
14 changes: 14 additions & 0 deletions definitions/1.0.0/Reference.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"type": "object",
"required": [
"$ref"
],
"properties": {
"$ref": {
"type": "string",
"format": "uri"
}
},
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://asyncapi.com/definitions/1.0.0/Reference.json"
}
11 changes: 11 additions & 0 deletions definitions/1.0.0/SecurityRequirement.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
},
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://asyncapi.com/definitions/1.0.0/SecurityRequirement.json"
}
24 changes: 24 additions & 0 deletions definitions/1.0.0/SecurityScheme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"oneOf": [
{
"$ref": "http://asyncapi.com/definitions/1.0.0/userPassword.json"
},
{
"$ref": "http://asyncapi.com/definitions/1.0.0/apiKey.json"
},
{
"$ref": "http://asyncapi.com/definitions/1.0.0/X509.json"
},
{
"$ref": "http://asyncapi.com/definitions/1.0.0/symmetricEncryption.json"
},
{
"$ref": "http://asyncapi.com/definitions/1.0.0/asymmetricEncryption.json"
},
{
"$ref": "http://asyncapi.com/definitions/1.0.0/HTTPSecurityScheme.json"
}
],
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://asyncapi.com/definitions/1.0.0/SecurityScheme.json"
}
23 changes: 23 additions & 0 deletions definitions/1.0.0/X509.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"X509"
]
},
"description": {
"type": "string"
}
},
"patternProperties": {
"^x-": {}
},
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://asyncapi.com/definitions/1.0.0/X509.json"
}
31 changes: 31 additions & 0 deletions definitions/1.0.0/apiKey.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"type": "object",
"required": [
"type",
"in"
],
"properties": {
"type": {
"type": "string",
"enum": [
"apiKey"
]
},
"in": {
"type": "string",
"enum": [
"user",
"password"
]
},
"description": {
"type": "string"
}
},
"patternProperties": {
"^x-": {}
},
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://asyncapi.com/definitions/1.0.0/apiKey.json"
}
23 changes: 23 additions & 0 deletions definitions/1.0.0/asymmetricEncryption.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"asymmetricEncryption"
]
},
"description": {
"type": "string"
}
},
"patternProperties": {
"^x-": {}
},
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://asyncapi.com/definitions/1.0.0/asymmetricEncryption.json"
}
64 changes: 64 additions & 0 deletions definitions/1.0.0/asyncapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"title": "AsyncAPI 1.0 schema.",
"id": "http://asyncapi.com/definitions/1.0.0/asyncapi.json",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"required": [
"asyncapi",
"info",
"topics"
],
"additionalProperties": false,
"patternProperties": {
"^x-": {
"$ref": "http://asyncapi.com/definitions/1.0.0/vendorExtension.json"
}
},
"properties": {
"asyncapi": {
"type": "string",
"enum": [
"1.0.0"
],
"description": "The AsyncAPI specification version of this document."
},
"info": {
"$ref": "http://asyncapi.com/definitions/1.0.0/info.json"
},
"baseTopic": {
"type": "string",
"pattern": "^[^/.]",
"description": "The base topic to the API. Example: 'hitch'.",
"default": ""
},
"servers": {
"type": "array",
"items": {
"$ref": "http://asyncapi.com/definitions/1.0.0/server.json"
},
"uniqueItems": true
},
"topics": {
"$ref": "http://asyncapi.com/definitions/1.0.0/topics.json"
},
"components": {
"$ref": "http://asyncapi.com/definitions/1.0.0/components.json"
},
"tags": {
"type": "array",
"items": {
"$ref": "http://asyncapi.com/definitions/1.0.0/tag.json"
},
"uniqueItems": true
},
"security": {
"type": "array",
"items": {
"$ref": "http://asyncapi.com/definitions/1.0.0/SecurityRequirement.json"
}
},
"externalDocs": {
"$ref": "http://asyncapi.com/definitions/1.0.0/externalDocs.json"
}
}
}
Loading

0 comments on commit e5edd3a

Please sign in to comment.