Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 680c431

Browse files
RomanHotsiylornajaneSmoliyYtatomyr
authored
AsyncAPI linting support (#1127)
* chore: progress on asyncapi * chore: more progress * chore: enable assertions * Feat: Start adding protocol-specific channel bindings * Feat: flesh out components fields * Fix: remove link and x-code-sample, not supported for asyncapi * Feat: Add solace protocol support * chore: refactor channel/server bindings to define and add to collection * chore: re-order nodes to group by protocol * chore: re-order node listings to also group by protocol * feat: add topicConfiguration for Kafka and fix a typo * feat: rename ServerMap for clarity * feat: Add message bindings, remove incomplete protocols * fix: a few tests were failing after original refactoring * feat: add MessageTrait object * feat: Add operation bindings, export operation and message bindings * Feat: add a few rules for asyncapi, create channels-kebab-case * fix: Add messageBindings and operationBindings to components section * feat: Add no-channel-trailing-slash rule for asyncapi * fix: Update allowed/required list for httpAPIkey * chore: add tests for new AsyncAPI rules * Feat: Add sample asyncapi descriptions as tests * chore: generate snapshot.js for async-api tests * chore: fix some minor drift between main branch and this one after rebasing * docs: add a guide to linting AsyncAPI * fix: broken links in guide * chore: run prettier * chore: update test snapshot * chore: clean up comments and stray log message * docs: Update from review feedback, and add a health warning * Update packages/core/src/config/config-resolvers.ts Co-authored-by: Andrew Tatomyr <[email protected]> * fix: allow async2 as the only feature in custom plugins * chore: add tests and tweak error messages for document type detection * chore: fix tests and rename majorSpecVersion->getMajorSpecVersion * chore: run prettier * chore: Tidy and improve comments in main asyncapi types file * chore: remove outdated comment * fix: remove extraneous empty extends from guide and tests * docs: Add changeset for AsyncAPI feature * Update .changeset/quick-emus-punch.md Co-authored-by: Andrew Tatomyr <[email protected]> --------- Co-authored-by: Lorna Mitchell <[email protected]> Co-authored-by: SmoliyY <[email protected]> Co-authored-by: Lorna Jane Mitchell <[email protected]> Co-authored-by: Andrew Tatomyr <[email protected]>
1 parent b8bf007 commit 680c431

54 files changed

Lines changed: 5165 additions & 166 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/quick-emus-punch.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@redocly/openapi-core': minor
3+
'@redocly/cli': minor
4+
---
5+
6+
Added support for linting AsyncAPI v2 files, so that a wider range of API descriptions can use the Redocly linting workflow.

__tests__/lint-config/invalid-config-assertation-config-type/snapshot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`E2E lint-config test with option: { dirName: 'invalid-config-assertatio
44
55
[1] .redocly.yaml:8:17 at #/rules/assert~1path-item-mutually-required/where/0/subject/type
66
7-
\`type\` can be one of the following only: "any", "Root", "Tag", "TagList", "ExternalDocs", "Server", "ServerList", "ServerVariable", "ServerVariablesMap", "SecurityRequirement", "SecurityRequirementList", "Info", "Contact", "License", "Paths", "PathItem", "Parameter", "ParameterList", "Operation", "Callback", "CallbacksMap", "RequestBody", "MediaTypesMap", "MediaType", "Example", "ExamplesMap", "Encoding", "EncodingMap", "Header", "HeadersMap", "Responses", "Response", "Link", "LinksMap", "Schema", "Xml", "SchemaProperties", "DiscriminatorMapping", "Discriminator", "Components", "NamedSchemas", "NamedResponses", "NamedParameters", "NamedExamples", "NamedRequestBodies", "NamedHeaders", "NamedSecuritySchemes", "NamedLinks", "NamedCallbacks", "ImplicitFlow", "PasswordFlow", "ClientCredentials", "AuthorizationCode", "OAuth2Flows", "SecurityScheme", "XCodeSample", "XCodeSampleList", "WebhooksMap", "SpecExtension".
7+
\`type\` can be one of the following only: "any", "Root", "Tag", "TagList", "ExternalDocs", "Server", "ServerList", "ServerVariable", "ServerVariablesMap", "SecurityRequirement", "SecurityRequirementList", "Info", "Contact", "License", "Paths", "PathItem", "Parameter", "ParameterList", "Operation", "Callback", "CallbacksMap", "RequestBody", "MediaTypesMap", "MediaType", "Example", "ExamplesMap", "Encoding", "EncodingMap", "Header", "HeadersMap", "Responses", "Response", "Link", "LinksMap", "Schema", "Xml", "SchemaProperties", "DiscriminatorMapping", "Discriminator", "Components", "NamedSchemas", "NamedResponses", "NamedParameters", "NamedExamples", "NamedRequestBodies", "NamedHeaders", "NamedSecuritySchemes", "NamedLinks", "NamedCallbacks", "ImplicitFlow", "PasswordFlow", "ClientCredentials", "AuthorizationCode", "OAuth2Flows", "SecurityScheme", "XCodeSample", "XCodeSampleList", "WebhooksMap", "SpecExtension", "Message".
88
99
6 | where:
1010
7 | - subject:

__tests__/lint/async2/anyof.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
asyncapi: '2.6.0'
2+
info:
3+
title: AnyOf example
4+
version: '1.0.0'
5+
6+
channels:
7+
test:
8+
publish:
9+
message:
10+
$ref: '#/components/messages/testMessages'
11+
12+
components:
13+
messages:
14+
testMessages:
15+
payload:
16+
anyOf: # anyOf in payload schema
17+
- $ref: "#/components/schemas/objectWithKey"
18+
- $ref: "#/components/schemas/objectWithKey2"
19+
20+
schemas:
21+
objectWithKey:
22+
type: object
23+
properties:
24+
key:
25+
type: string
26+
additionalProperties: false
27+
objectWithKey2:
28+
type: object
29+
properties:
30+
key2:
31+
type: string
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
asyncapi: '2.6.0'
2+
info:
3+
title: Application Headers example
4+
version: '1.0.0'
5+
description: A cut of the Streetlights API to test application header changes supporting #112
6+
license:
7+
name: Apache 2.0
8+
url: https://www.apache.org/licenses/LICENSE-2.0
9+
10+
servers:
11+
production:
12+
url: test.mosquitto.org:{port}
13+
protocol: mqtt
14+
description: Test broker
15+
variables:
16+
port:
17+
description: Secure connection (TLS) is available through port 8883.
18+
default: '1883'
19+
enum:
20+
- '1883'
21+
- '8883'
22+
23+
defaultContentType: application/json
24+
25+
channels:
26+
smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured:
27+
parameters:
28+
streetlightId:
29+
$ref: '#/components/parameters/streetlightId'
30+
publish:
31+
summary: Inform about environmental lighting conditions of a particular streetlight.
32+
operationId: receiveLightMeasurement
33+
message:
34+
$ref: '#/components/messages/lightMeasured'
35+
36+
components:
37+
messages:
38+
lightMeasured:
39+
name: lightMeasured
40+
title: Light measured
41+
summary: Inform about environmental lighting conditions of a particular streetlight.
42+
correlationId:
43+
location: "$message.header#/MQMD/CorrelId"
44+
contentType: application/json
45+
headers:
46+
type: object
47+
properties:
48+
MQMD:
49+
type: object
50+
properties:
51+
CorrelId:
52+
type: string
53+
minLength: 24
54+
maxLength: 24
55+
format: binary
56+
applicationInstanceId:
57+
$ref: "#/components/schemas/applicationInstanceId"
58+
payload:
59+
$ref: "#/components/schemas/lightMeasuredPayload"
60+
61+
schemas:
62+
lightMeasuredPayload:
63+
type: object
64+
properties:
65+
lumens:
66+
type: integer
67+
minimum: 0
68+
description: Light intensity measured in lumens.
69+
sentAt:
70+
$ref: "#/components/schemas/sentAt"
71+
sentAt:
72+
type: string
73+
format: date-time
74+
description: Date and time when the message was sent.
75+
applicationInstanceId:
76+
description: Unique identifier for a given instance of the publishing application
77+
type: string
78+
79+
parameters:
80+
streetlightId:
81+
description: The ID of the streetlight.
82+
schema:
83+
type: string
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
asyncapi: '2.6.0'
2+
info:
3+
title: Correlation ID Example
4+
version: '1.0.0'
5+
description: A cut of the Streetlights API to test Correlation ID
6+
license:
7+
name: Apache 2.0
8+
url: https://www.apache.org/licenses/LICENSE-2.0
9+
10+
servers:
11+
production:
12+
url: test.mosquitto.org:{port}
13+
protocol: mqtt
14+
description: Test broker
15+
variables:
16+
port:
17+
description: Secure connection (TLS) is available through port 8883.
18+
default: '1883'
19+
enum:
20+
- '1883'
21+
- '8883'
22+
security:
23+
- apiKey: []
24+
- supportedOauthFlows:
25+
- streetlights:on
26+
- streetlights:off
27+
- streetlights:dim
28+
- openIdConnectWellKnown: []
29+
30+
defaultContentType: application/json
31+
32+
channels:
33+
smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured:
34+
parameters:
35+
streetlightId:
36+
$ref: '#/components/parameters/streetlightId'
37+
publish:
38+
summary: Inform about environmental lighting conditions of a particular streetlight.
39+
operationId: receiveLightMeasurement
40+
message:
41+
$ref: '#/components/messages/lightMeasured'
42+
43+
smartylighting/streetlights/1/0/action/{streetlightId}/dim:
44+
parameters:
45+
streetlightId:
46+
$ref: '#/components/parameters/streetlightId'
47+
subscribe:
48+
operationId: dimLight
49+
message:
50+
$ref: '#/components/messages/dimLight'
51+
52+
components:
53+
messages:
54+
lightMeasured:
55+
name: lightMeasured
56+
title: Light measured
57+
summary: Inform about environmental lighting conditions of a particular streetlight.
58+
correlationId:
59+
location: "$message.header#/MQMD/CorrelId"
60+
contentType: application/json
61+
payload:
62+
$ref: "#/components/schemas/lightMeasuredPayload"
63+
dimLight:
64+
name: dimLight
65+
title: Dim light
66+
summary: Command a particular streetlight to dim the lights.
67+
correlationId:
68+
$ref: "#/components/correlationIds/sentAtCorrelator"
69+
payload:
70+
$ref: "#/components/schemas/dimLightPayload"
71+
72+
schemas:
73+
lightMeasuredPayload:
74+
type: object
75+
properties:
76+
lumens:
77+
type: integer
78+
minimum: 0
79+
description: Light intensity measured in lumens.
80+
sentAt:
81+
$ref: "#/components/schemas/sentAt"
82+
dimLightPayload:
83+
type: object
84+
properties:
85+
percentage:
86+
type: integer
87+
description: Percentage to which the light should be dimmed to.
88+
minimum: 0
89+
maximum: 100
90+
sentAt:
91+
$ref: "#/components/schemas/sentAt"
92+
sentAt:
93+
type: string
94+
format: date-time
95+
description: Date and time when the message was sent.
96+
97+
parameters:
98+
streetlightId:
99+
description: The ID of the streetlight.
100+
schema:
101+
type: string
102+
103+
correlationIds:
104+
sentAtCorrelator:
105+
description: Data from message payload used as correlation ID
106+
location: $message.payload#/sentAt
107+
securitySchemes:
108+
apiKey:
109+
type: apiKey
110+
in: user
111+
description: Provide your API key as the user and leave the password empty.
112+
supportedOauthFlows:
113+
type: oauth2
114+
description: Flows to support OAuth 2.0
115+
flows:
116+
implicit:
117+
authorizationUrl: 'https://authserver.example/auth'
118+
scopes:
119+
'streetlights:on': Ability to switch lights on
120+
'streetlights:off': Ability to switch lights off
121+
'streetlights:dim': Ability to dim the lights
122+
password:
123+
tokenUrl: 'https://authserver.example/token'
124+
scopes:
125+
'streetlights:on': Ability to switch lights on
126+
'streetlights:off': Ability to switch lights off
127+
'streetlights:dim': Ability to dim the lights
128+
clientCredentials:
129+
tokenUrl: 'https://authserver.example/token'
130+
scopes:
131+
'streetlights:on': Ability to switch lights on
132+
'streetlights:off': Ability to switch lights off
133+
'streetlights:dim': Ability to dim the lights
134+
authorizationCode:
135+
authorizationUrl: 'https://authserver.example/auth'
136+
tokenUrl: 'https://authserver.example/token'
137+
refreshUrl: 'https://authserver.example/refresh'
138+
scopes:
139+
'streetlights:on': Ability to switch lights on
140+
'streetlights:off': Ability to switch lights off
141+
'streetlights:dim': Ability to dim the lights
142+
openIdConnectWellKnown:
143+
type: openIdConnect
144+
openIdConnectUrl: 'https://authserver.example/.well-known'

0 commit comments

Comments
 (0)