Skip to content

Commit

Permalink
feat: add extensions support (#506)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukasz Gornicki <[email protected]>%0ACo-authored-by: derberg <[email protected]>
  • Loading branch information
sambhavgupta0705 and derberg authored Apr 18, 2024
1 parent 9507aff commit a0975d9
Show file tree
Hide file tree
Showing 9 changed files with 555 additions and 263 deletions.
1 change: 1 addition & 0 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sonar.exclusions=tools/**/*
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ This is the current project structure explained:
- [./examples](./examples) - contain most individual definition examples that will automatically be bundled together to provide example for each definition in 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).
- [./extensions](./extensions) - contains all the schemas of the extensions that will automatically be bundled to provide informations about extensions.


## Schema Bundling

Expand Down Expand Up @@ -210,7 +212,16 @@ Whenever you make changes in AsyncAPI JSON Schema, you should always manually ve
```yaml
# yaml-language-server: $schema=YOUR-PROJECTS-DIRECTORY/spec-json-schemas/schemas/2.6.0-without-$id.json
```

## Extensions

Extensions are a way to [extend AsyncAPI specification](https://www.asyncapi.com/docs/concepts/asyncapi-document/extending-specification) with fields that are not yet defined inside the specification. To add JSON schema of the extension in this repository, you need to first make sure it is added to the [extension-catalog](https://github.com/asyncapi/extensions-catalog) repository.
### How to add schema of the extension

1. All the extensions must be present in [./extensions](./extensions) folder.
2. A proper folder structure must be followed to add the extensions.
3. A new folder just as [x extension](./extensions/x) must be added with proper `versioning` and `schema file`.
4. All the schemas must be added in a file named `schema.json` just as one is defined for [x extension](./extensions/x/0.1.0/schema.json).

5. Extension schema should not be referenced directly in the definition of the object it extends. For example if you add an extension for `info`, your extension's schema should not be referenced from `info.json` but [infoExtensions.json](./definitions/3.0.0/infoExtensions.json). If the object that you extend doesn't have a corresponding `*Extensions.json` file, you need to create one.

118 changes: 61 additions & 57 deletions definitions/3.0.0/info.json
Original file line number Diff line number Diff line change
@@ -1,66 +1,70 @@
{
"type": "object",
"description": "The object provides metadata about the API. The metadata can be used by the clients if needed.",
"required": [
"version",
"title"
],
"additionalProperties": false,
"patternProperties": {
"^x-[\\w\\d\\.\\x2d_]+$": {
"$ref": "http://asyncapi.com/definitions/3.0.0/specificationExtension.json"
}
},
"properties": {
"title": {
"type": "string",
"description": "A unique and precise title of the API."
},
"version": {
"type": "string",
"description": "A semantic version number of the API."
},
"description": {
"type": "string",
"description": "A longer description of the API. Should be different from the title. CommonMark is allowed."
},
"termsOfService": {
"type": "string",
"description": "A URL to the Terms of Service for the API. MUST be in the format of a URL.",
"format": "uri"
},
"contact": {
"$ref": "http://asyncapi.com/definitions/3.0.0/contact.json"
},
"license": {
"$ref": "http://asyncapi.com/definitions/3.0.0/license.json"
},
"tags": {
"type": "array",
"description": "A list of tags for application API documentation control. Tags can be used for logical grouping of applications.",
"items": {
"oneOf": [
{
"$ref": "http://asyncapi.com/definitions/3.0.0/Reference.json"
},
{
"$ref": "http://asyncapi.com/definitions/3.0.0/tag.json"
}
]
"allOf": [
{
"type": "object",
"required": ["version", "title"],
"additionalProperties": false,
"patternProperties": {
"^x-[\\w\\d\\.\\x2d_]+$": {
"$ref": "http://asyncapi.com/definitions/3.0.0/specificationExtension.json"
}
},
"uniqueItems": true
},
"externalDocs": {
"oneOf": [
{
"$ref": "http://asyncapi.com/definitions/3.0.0/Reference.json"
"properties": {
"title": {
"type": "string",
"description": "A unique and precise title of the API."
},
{
"$ref": "http://asyncapi.com/definitions/3.0.0/externalDocs.json"
"version": {
"type": "string",
"description": "A semantic version number of the API."
},
"description": {
"type": "string",
"description": "A longer description of the API. Should be different from the title. CommonMark is allowed."
},
"termsOfService": {
"type": "string",
"description": "A URL to the Terms of Service for the API. MUST be in the format of a URL.",
"format": "uri"
},
"contact": {
"$ref": "http://asyncapi.com/definitions/3.0.0/contact.json"
},
"license": {
"$ref": "http://asyncapi.com/definitions/3.0.0/license.json"
},
"tags": {
"type": "array",
"description": "A list of tags for application API documentation control. Tags can be used for logical grouping of applications.",
"items": {
"oneOf": [
{
"$ref": "http://asyncapi.com/definitions/3.0.0/Reference.json"
},
{
"$ref": "http://asyncapi.com/definitions/3.0.0/tag.json"
}
]
},
"uniqueItems": true
},
"externalDocs": {
"oneOf": [
{
"$ref": "http://asyncapi.com/definitions/3.0.0/Reference.json"
},
{
"$ref": "http://asyncapi.com/definitions/3.0.0/externalDocs.json"
}
]
}
]
}
},
{
"$ref": "http://asyncapi.com/definitions/3.0.0/infoExtensions.json"
}
},
],
"example": {
"$ref": "http://asyncapi.com/examples/3.0.0/info.json"
},
Expand Down
11 changes: 11 additions & 0 deletions definitions/3.0.0/infoExtensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "object",
"description": "The object that lists all the extensions of Info",
"properties": {
"x-x":{
"$ref": "http://asyncapi.com/extensions/x/0.1.0/schema.json"
}
},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://asyncapi.com/definitions/3.0.0/infoExtensions.json"
}
10 changes: 10 additions & 0 deletions extensions/x/0.1.0/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": "string",
"description": "This extension allows you to provide the Twitter username of the account representing the team/company of the API.",
"example": [
"sambhavgupta75",
"AsyncAPISpec"
],
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://asyncapi.com/extensions/x/0.1.0/schema.json"
}
138 changes: 81 additions & 57 deletions schemas/3.0.0-without-$id.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,68 +50,75 @@
"additionalItems": true
},
"info": {
"type": "object",
"description": "The object provides metadata about the API. The metadata can be used by the clients if needed.",
"required": [
"version",
"title"
],
"additionalProperties": false,
"patternProperties": {
"^x-[\\w\\d\\.\\x2d_]+$": {
"$ref": "#/definitions/specificationExtension"
}
},
"properties": {
"title": {
"type": "string",
"description": "A unique and precise title of the API."
},
"version": {
"type": "string",
"description": "A semantic version number of the API."
},
"description": {
"type": "string",
"description": "A longer description of the API. Should be different from the title. CommonMark is allowed."
},
"termsOfService": {
"type": "string",
"description": "A URL to the Terms of Service for the API. MUST be in the format of a URL.",
"format": "uri"
},
"contact": {
"$ref": "#/definitions/contact"
},
"license": {
"$ref": "#/definitions/license"
},
"tags": {
"type": "array",
"description": "A list of tags for application API documentation control. Tags can be used for logical grouping of applications.",
"items": {
"oneOf": [
{
"$ref": "#/definitions/Reference"
},
{
"$ref": "#/definitions/tag"
}
]
"allOf": [
{
"type": "object",
"required": [
"version",
"title"
],
"additionalProperties": false,
"patternProperties": {
"^x-[\\w\\d\\.\\x2d_]+$": {
"$ref": "#/definitions/specificationExtension"
}
},
"uniqueItems": true
},
"externalDocs": {
"oneOf": [
{
"$ref": "#/definitions/Reference"
"properties": {
"title": {
"type": "string",
"description": "A unique and precise title of the API."
},
{
"$ref": "#/definitions/externalDocs"
"version": {
"type": "string",
"description": "A semantic version number of the API."
},
"description": {
"type": "string",
"description": "A longer description of the API. Should be different from the title. CommonMark is allowed."
},
"termsOfService": {
"type": "string",
"description": "A URL to the Terms of Service for the API. MUST be in the format of a URL.",
"format": "uri"
},
"contact": {
"$ref": "#/definitions/contact"
},
"license": {
"$ref": "#/definitions/license"
},
"tags": {
"type": "array",
"description": "A list of tags for application API documentation control. Tags can be used for logical grouping of applications.",
"items": {
"oneOf": [
{
"$ref": "#/definitions/Reference"
},
{
"$ref": "#/definitions/tag"
}
]
},
"uniqueItems": true
},
"externalDocs": {
"oneOf": [
{
"$ref": "#/definitions/Reference"
},
{
"$ref": "#/definitions/externalDocs"
}
]
}
]
}
},
{
"$ref": "#/definitions/infoExtensions"
}
},
],
"examples": [
{
"title": "AsyncAPI Sample App",
Expand Down Expand Up @@ -292,6 +299,23 @@
}
]
},
"infoExtensions": {
"type": "object",
"description": "The object that lists all the extensions of Info",
"properties": {
"x-x": {
"$ref": "#/definitions/extensions-x-0.1.0-schema"
}
}
},
"extensions-x-0.1.0-schema": {
"type": "string",
"description": "This extension allows you to provide the Twitter username of the account representing the team/company of the API.",
"example": [
"sambhavgupta75",
"AsyncAPISpec"
]
},
"servers": {
"description": "An object representing multiple servers.",
"type": "object",
Expand Down
Loading

0 comments on commit a0975d9

Please sign in to comment.