-
Notifications
You must be signed in to change notification settings - Fork 677
feat(workspace-store): AsyncAPI support #7031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 239f1c5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 20 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Scalar Components Snapshot Test ResultsDetails
|
Scalar CDN Snapshot Diff ResultsDetails
Failed teststest-snapshots/snapshot.e2e.ts › Diff with CDN - Relative URL Example Important These tests detect visual differences between the current PR and the latest CDN build which means they may be affected by other changes in They can help determine if the changes in the PR are causing any unexpected visual regressions but may be less helpful in isolating the exact cause. For more details see the readme. |
92a9468 to
feecd65
Compare
085a006 to
2af1b96
Compare
This is okay. We just want to add support to the store. We don’t want to add the rendering yet. |
packages/workspace-store/src/schemas/asyncapi/v3.0/asyncapi-document.ts
Outdated
Show resolved
Hide resolved
packages/workspace-store/src/schemas/asyncapi/v3.0/correlation-id.ts
Outdated
Show resolved
Hide resolved
bd4af0c to
15a905d
Compare
31bc06c to
f593df7
Compare
…r documents - Updated the type guard function to combine checks for OpenAPI and Swagger documents, improving clarity and maintainability. - Refactored the `createWorkspaceStore` logic to utilize the new type guard, ensuring consistent document type detection. - Added documentation comments for better understanding of the type guard functions.
…onent - Enhanced the logic in the Content component to check if the document is an OpenAPI document before accessing its version property, preventing potential runtime errors. - Updated the rendering condition for traversed operations to ensure it only displays when a valid OpenAPI document is present, improving robustness and user experience.
- Corrected import paths for AsyncAPI document types in SearchButton, SearchModal, and useSearchIndex components to align with the new v3.0 schema organization. - This change enhances clarity and maintainability by ensuring consistent references to AsyncAPI documents across the codebase.
- Introduced a check for AsyncAPI documents in the useWorkspaceStoreEvents hook to prepare for future support. - Added TODO comments to indicate the need for implementing AsyncAPI functionality, enhancing clarity for upcoming development efforts.
- Changed 'publish' to 'send' for user signup events. - Updated 'subscribe' to 'receive' for user deletion events. - Adjusted related test assertions to reflect these changes.
…uments - Updated the condition for rendering the Models component to check if the document is a valid OpenAPI document, preventing potential rendering issues.
- Introduced support for multi-format schemas in the Models component. - Updated the rendering logic to include messages under channels in the AsyncAPI document. - Added new type guards and utility functions for better message ID generation and schema resolution. - Enhanced tests to cover new message handling scenarios, ensuring robust navigation structure for AsyncAPI documents.
…rom ClassicLayout component - Simplified the schema prop type in ClassicLayout.vue by removing MultiFormatSchemaObject, ensuring it only uses SchemaObject. - This change helps streamline the component's type definitions and improves clarity.
…n check - Fixed a typo in the title prop of the IntroductionCardItem component from "Authentication" to "Authpentication". - Updated the condition for rendering the Models component to ensure it only displays for valid OpenAPI documents, improving the component's reliability.
- Fixed a typo in the title prop from "Authpentication" to "Authentication" in the Content.vue file, ensuring accurate display of the authentication title.
13b3ed4 to
239f1c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: AsyncAPI Security Scheme Mutators Undefined
The securitySchemeMutators field is undefined for AsyncAPI documents, but its type doesn't reflect this. This can cause runtime errors when callers attempt to use mutator methods, like addSecurityScheme, on an AsyncAPI document.
packages/workspace-store/src/mutators/index.ts#L43-L48
scalar/packages/workspace-store/src/mutators/index.ts
Lines 43 to 48 in 239f1c5
| requestMutators: requestMutators(document), | |
| securitySchemeMutators: | |
| document && isOpenApiDocument(document) | |
| ? securitySchemeMutators(document?.components?.securitySchemes) | |
| : // TODO: AsyncAPI Security Schemes | |
| undefined, |
Bug: Binding Schema Accepts Invalid Protocol Combinations
The BindingBaseSchemaDefinition uses Type.Record with a union of all possible binding types, which means it accepts ANY string key with ANY of the binding values. This is incorrect for binding objects where specific protocol names should map to their corresponding binding types (e.g., "http" should only accept HttpOperationBinding, not KafkaServerBinding). The current implementation allows invalid combinations like { "http": AmqpChannelBinding } which violates the AsyncAPI specification where binding keys must match their protocol-specific values.
packages/workspace-store/src/schemas/asyncapi/v3.0/binding.ts#L42-L94
scalar/packages/workspace-store/src/schemas/asyncapi/v3.0/binding.ts
Lines 42 to 94 in 239f1c5
| */ | |
| const BindingBaseSchemaDefinition = Type.Record( | |
| Type.String(), | |
| Type.Union([ | |
| // AMQP | |
| AmqpChannelBindingRef, | |
| AmqpOperationBindingRef, | |
| AmqpMessageBindingRef, | |
| // HTTP | |
| HttpOperationBindingRef, | |
| HttpMessageBindingRef, | |
| // WebSocket | |
| WebSocketChannelBindingRef, | |
| // Kafka | |
| KafkaServerBindingRef, | |
| KafkaChannelBindingRef, | |
| KafkaOperationBindingRef, | |
| KafkaMessageBindingRef, | |
| // MQTT | |
| MqttServerBindingRef, | |
| MqttOperationBindingRef, | |
| MqttMessageBindingRef, | |
| // MQTT5 | |
| Mqtt5ServerBindingRef, | |
| // NATS | |
| NatsOperationBindingRef, | |
| // SNS | |
| SnsChannelBindingRef, | |
| SnsOperationBindingRef, | |
| // SQS | |
| SqsChannelBindingRef, | |
| SqsOperationBindingRef, | |
| // Google Pub/Sub | |
| GooglePubSubChannelBindingRef, | |
| GooglePubSubMessageBindingRef, | |
| // Anypoint MQ | |
| AnypointMqChannelBindingRef, | |
| AnypointMqMessageBindingRef, | |
| // IBM MQ | |
| IbmMqServerBindingRef, | |
| IbmMqChannelBindingRef, | |
| IbmMqMessageBindingRef, | |
| // JMS | |
| JmsServerBindingRef, | |
| JmsChannelBindingRef, | |
| JmsMessageBindingRef, | |
| // Pulsar | |
| PulsarServerBindingRef, | |
| PulsarChannelBindingRef, | |
| // Solace | |
| SolaceServerBindingRef, | |
| SolaceOperationBindingRef, | |
| ]), |
Bug: Schema Reference Redundancy
The schemas field in ComponentsObject allows a union of SchemaObjectRef and MultiFormatSchemaObjectRef with their references. However, the Type.Union includes both the direct refs and reference() wrappers for each type, creating redundancy. The reference() function already wraps refs, so reference(SchemaObjectRef) and reference(MultiFormatSchemaObjectRef) may create duplicate or conflicting schema definitions. This should likely just be Type.Union([SchemaObjectRef, MultiFormatSchemaObjectRef]) with a single reference() wrapper if needed.
packages/workspace-store/src/schemas/asyncapi/v3.0/components.ts#L53-L62
| schemas: Type.Optional( | |
| Type.Record( | |
| Type.String(), | |
| Type.Union([ | |
| SchemaObjectRef, | |
| MultiFormatSchemaObjectRef, | |
| reference(SchemaObjectRef), | |
| reference(MultiFormatSchemaObjectRef), | |
| ]), | |
| ), |
Bug: Duplicate AsyncAPI Operations Writing
The code writes AsyncAPI operations chunks twice in the same block. Lines 471-479 check if (operations) and write AsyncAPI operations chunks, but this is redundant since lines 460-469 already handle writing operations chunks. This means for AsyncAPI documents, operations will be written twice to the same location, potentially causing race conditions or wasted I/O operations. The second block (471-479) should likely have a different condition or be removed entirely since AsyncAPI operations are already handled by the first operations block.
packages/workspace-store/src/server.ts#L470-L479
scalar/packages/workspace-store/src/server.ts
Lines 470 to 479 in 239f1c5
| // Write the AsyncAPI operations chunks | |
| if (operations) { | |
| const operationPath = `${basePath}/chunks/${name}/operations` | |
| await fs.mkdir(operationPath, { recursive: true }) | |
| for (const [operationId, operation] of Object.entries(operations)) { | |
| await fs.writeFile(`${operationPath}/${operationId}.json`, JSON.stringify(operation)) | |
| } | |
| } |
| // | ((a: { action: string; channel: string }, b: { action: string; channel: string }) => number) | ||
|
|
||
| /** Function to generate unique IDs for markdown headings */ | ||
| getHeadingId: (heading: { depth: number; value: string; slug?: string }) => string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We’re transitioning to a new interface for ID generation.
The new design uses a single function that accepts an object containing a type discriminator and its associated context.
| if (document.operations) { | ||
| Object.entries(document.operations).forEach(([operationId, operation]) => { | ||
| // Handle ReferenceType - operation could be a $ref or the actual operation | ||
| const actualOperation = '$ref' in operation ? operation['$ref-value'] : operation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use the helper here called getResolvedRef
| export const MessagesObjectRef = Type.Ref(ASYNCAPI_REF_DEFINITIONS.MessagesObject) | ||
| export const TagsObjectRef = Type.Ref(ASYNCAPI_REF_DEFINITIONS.TagsObject) | ||
|
|
||
| // Legacy aliases for backward compatibility (will be removed in future versions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need this
| requestMutators: requestMutators(document), | ||
| securitySchemeMutators: securitySchemeMutators(document?.components?.securitySchemes), | ||
| securitySchemeMutators: | ||
| document && isOpenApiDocument(document) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of doing this we can create different mutators for async api and conditionally return mutators
| Object.entries(result.documents).map(([name, doc]) => [ | ||
| name, | ||
| createOverridesProxy(createMagicProxy(doc), result.overrides[name]), | ||
| createOverridesProxy(createMagicProxy(doc) as ApiDefinition, result.overrides[name]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of casting we need to update the Inmem worksapce schema
Tasks
Problem
Currently, we support OpenAPI documents, that's great. But what if someone wants to load an AsyncAPI document? 🤔 It seems so similar … so what if we add support for it?
Solution
This PR:
OpenApiDocument | AsyncApiDocumenttypes instead of justOpenApiDocumentOut of scope
Checklist
I've gone through the following:
pnpm changeset).Note
Add AsyncAPI 3.0 support to the workspace store (schemas, navigation, server/client), gate OpenAPI-only UI/search paths, and update tests/docs.
AsyncApiDocument3.0 schema set and navigation types; addisOpenApiDocument/isAsyncApiDocumenttype guards; support mixedApiDefinition.createAsyncApiNavigationwith channel/operation/message traversal.x-original-asyncapi-version), conditional navigation generation, config/override handling, and export/load logic.servers, clients, models) via type checks.OpenApiDocument | AsyncApiDocument; build search index only for OpenAPI.Written by Cursor Bugbot for commit 239f1c5. This will update automatically on new commits. Configure here.