Skip to content

Commit

Permalink
(feature): Importer brings in Websocket Channels from AsyncAPI (#3037)
Browse files Browse the repository at this point in the history
* asyncapi channel creation

* persist channel

* (feature): spec importer handles creatinga async api channels

* add channel converter to openapi-ir-to-fern

* add messages

* channel schemas properly come through

* fix lint
  • Loading branch information
dsinghvi authored Feb 22, 2024
1 parent a0a9069 commit 4ff0032
Show file tree
Hide file tree
Showing 118 changed files with 1,449 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function generateOpenAPIIrForWorkspaces({
return;
}

const openAPIIr = getOpenAPIIRFromOpenAPIWorkspace(workspace, context);
const openAPIIr = await getOpenAPIIRFromOpenAPIWorkspace(workspace, context);

const irOutputFilePath = path.resolve(irFilepath);
const openApiIrJson = await serialization.OpenApiIntermediateRepresentation.jsonOrThrow(openAPIIr, {
Expand Down
16 changes: 16 additions & 0 deletions packages/cli/openapi-ir-sdk/fern/definition/finalIr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ types:
hasEndpointsMarkedInternal: boolean
endpoints: list<Endpoint>
webhooks: list<Webhook>
channel: list<WebsocketChannel>
schemas: map<commons.SchemaId, Schema>
errors: map<commons.StatusCode, HttpError>
variables: map<string, PrimitiveSchema>
Expand Down Expand Up @@ -53,6 +54,21 @@ types:
docs: |
Populated as ${operationId}Payload
payload: Schema

WebsocketChannel:
extends: commons.WithDescription
properties:
path: string
groupName: list<commons.SdkGroupName>
summary: optional<string>
handshake: WebsocketHandshake
publish: optional<Schema>
subscribe: optional<Schema>

WebsocketHandshake:
properties:
queryParameters: list<QueryParameter>
headers: list<Header>

WebhookHttpMethod:
enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface OpenApiIntermediateRepresentation {
hasEndpointsMarkedInternal: boolean;
endpoints: FernOpenapiIr.Endpoint[];
webhooks: FernOpenapiIr.Webhook[];
channel: FernOpenapiIr.WebsocketChannel[];
schemas: Record<FernOpenapiIr.SchemaId, FernOpenapiIr.Schema>;
errors: Record<FernOpenapiIr.StatusCode, FernOpenapiIr.HttpError>;
variables: Record<string, FernOpenapiIr.PrimitiveSchema>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as FernOpenapiIr from "../../..";

export interface WebsocketChannel extends FernOpenapiIr.WithDescription {
path: string;
groupName: FernOpenapiIr.SdkGroupName[];
summary: string | undefined;
handshake: FernOpenapiIr.WebsocketHandshake;
publish: FernOpenapiIr.Schema | undefined;
subscribe: FernOpenapiIr.Schema | undefined;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as FernOpenapiIr from "../../..";

export interface WebsocketHandshake {
queryParameters: FernOpenapiIr.QueryParameter[];
headers: FernOpenapiIr.Header[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export * from "./GlobalHeader";
export * from "./Tags";
export * from "./HttpError";
export * from "./Webhook";
export * from "./WebsocketChannel";
export * from "./WebsocketHandshake";
export * from "./WebhookHttpMethod";
export * from "./EndpointAvailability";
export * from "./Endpoint";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export const OpenApiIntermediateRepresentation: core.serialization.ObjectSchema<
hasEndpointsMarkedInternal: core.serialization.boolean(),
endpoints: core.serialization.list(core.serialization.lazyObject(async () => (await import("../../..")).Endpoint)),
webhooks: core.serialization.list(core.serialization.lazyObject(async () => (await import("../../..")).Webhook)),
channel: core.serialization.list(
core.serialization.lazyObject(async () => (await import("../../..")).WebsocketChannel)
),
schemas: core.serialization.record(
core.serialization.lazy(async () => (await import("../../..")).SchemaId),
core.serialization.lazy(async () => (await import("../../..")).Schema)
Expand Down Expand Up @@ -50,6 +53,7 @@ export declare namespace OpenApiIntermediateRepresentation {
hasEndpointsMarkedInternal: boolean;
endpoints: serializers.Endpoint.Raw[];
webhooks: serializers.Webhook.Raw[];
channel: serializers.WebsocketChannel.Raw[];
schemas: Record<serializers.SchemaId.Raw, serializers.Schema.Raw>;
errors: Record<serializers.StatusCode.Raw, serializers.HttpError.Raw>;
variables: Record<string, serializers.PrimitiveSchema.Raw>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as serializers from "../../..";
import * as FernOpenapiIr from "../../../../api";
import * as core from "../../../../core";

export const WebsocketChannel: core.serialization.ObjectSchema<
serializers.WebsocketChannel.Raw,
FernOpenapiIr.WebsocketChannel
> = core.serialization
.objectWithoutOptionalProperties({
path: core.serialization.string(),
groupName: core.serialization.list(
core.serialization.lazy(async () => (await import("../../..")).SdkGroupName)
),
summary: core.serialization.string().optional(),
handshake: core.serialization.lazyObject(async () => (await import("../../..")).WebsocketHandshake),
publish: core.serialization.lazy(async () => (await import("../../..")).Schema).optional(),
subscribe: core.serialization.lazy(async () => (await import("../../..")).Schema).optional(),
})
.extend(core.serialization.lazyObject(async () => (await import("../../..")).WithDescription));

export declare namespace WebsocketChannel {
interface Raw extends serializers.WithDescription.Raw {
path: string;
groupName: serializers.SdkGroupName.Raw[];
summary?: string | null;
handshake: serializers.WebsocketHandshake.Raw;
publish?: serializers.Schema.Raw | null;
subscribe?: serializers.Schema.Raw | null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as serializers from "../../..";
import * as FernOpenapiIr from "../../../../api";
import * as core from "../../../../core";

export const WebsocketHandshake: core.serialization.ObjectSchema<
serializers.WebsocketHandshake.Raw,
FernOpenapiIr.WebsocketHandshake
> = core.serialization.objectWithoutOptionalProperties({
queryParameters: core.serialization.list(
core.serialization.lazyObject(async () => (await import("../../..")).QueryParameter)
),
headers: core.serialization.list(core.serialization.lazyObject(async () => (await import("../../..")).Header)),
});

export declare namespace WebsocketHandshake {
interface Raw {
queryParameters: serializers.QueryParameter.Raw[];
headers: serializers.Header.Raw[];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export * from "./GlobalHeader";
export * from "./Tags";
export * from "./HttpError";
export * from "./Webhook";
export * from "./WebsocketChannel";
export * from "./WebsocketHandshake";
export * from "./WebhookHttpMethod";
export * from "./EndpointAvailability";
export * from "./Endpoint";
Expand Down
30 changes: 30 additions & 0 deletions packages/cli/openapi-ir-to-fern/src/FernDefnitionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export interface FernDefinitionBuilder {

addWebhook(file: RelativeFilePath, { name, schema }: { name: string; schema: RawSchemas.WebhookSchema }): void;

addChannel(file: RelativeFilePath, { channel }: { channel: RawSchemas.WebSocketChannelSchema }): void;

addChannelMessage(
file: RelativeFilePath,
{ messageId, message }: { messageId: string; message: RawSchemas.WebSocketChannelMessageSchema }
): void;

setServiceInfo(file: RelativeFilePath, { displayName, docs }: { displayName?: string; docs?: string }): void;

build(): FernDefinition;
Expand Down Expand Up @@ -72,6 +79,7 @@ export class FernDefinitionBuilderImpl implements FernDefinitionBuilder {
this.rootApiFile["display-name"] = ir.title;
}
}

setServiceInfo(
file: RelativeFilePath,
{ displayName, docs }: { displayName?: string | undefined; docs?: string | undefined }
Expand Down Expand Up @@ -220,6 +228,28 @@ export class FernDefinitionBuilderImpl implements FernDefinitionBuilder {
fernFile.webhooks[name] = schema;
}

public addChannel(file: RelativeFilePath, { channel }: { channel: RawSchemas.WebSocketChannelSchema }): void {
const fernFile = this.getOrCreateFile(file);
fernFile.channel = channel;
}

public addChannelMessage(
file: RelativeFilePath,
{ messageId, message }: { messageId: string; message: RawSchemas.WebSocketChannelMessageSchema }
): void {
const fernFile = this.getOrCreateFile(file);
if (fernFile.channel == null) {
fernFile.channel = {
path: "",
auth: false
};
}
if (fernFile.channel.messages == null) {
fernFile.channel.messages = {};
}
fernFile.channel.messages[messageId] = message;
}

public build(): FernDefinition {
if (this.modifyBasePaths) {
const basePath = getSharedEnvironmentBasePath(this.rootApiFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ describe("Fern Definition Builder", () => {
variables: {},
nonRequestReferencedSchemas: new Set(),
securitySchemes: {},
globalHeaders: []
globalHeaders: [],
channel: []
},
true
);
Expand Down
Loading

0 comments on commit 4ff0032

Please sign in to comment.