diff --git a/packages/cli/api-importers/openapi/openapi-ir-parser/src/asyncapi/sharedUtils.ts b/packages/cli/api-importers/openapi/openapi-ir-parser/src/asyncapi/sharedUtils.ts deleted file mode 100644 index 9f46461b6b6..00000000000 --- a/packages/cli/api-importers/openapi/openapi-ir-parser/src/asyncapi/sharedUtils.ts +++ /dev/null @@ -1,6 +0,0 @@ -export function transformToValidPath(path: string): string { - if (!path.startsWith("/")) { - return "/" + path; - } - return path; -} diff --git a/packages/cli/api-importers/openapi/openapi-ir-parser/src/asyncapi/v2/parseAsyncAPIV2.ts b/packages/cli/api-importers/openapi/openapi-ir-parser/src/asyncapi/v2/parseAsyncAPIV2.ts index 0339008e875..f79f268cd1c 100644 --- a/packages/cli/api-importers/openapi/openapi-ir-parser/src/asyncapi/v2/parseAsyncAPIV2.ts +++ b/packages/cli/api-importers/openapi/openapi-ir-parser/src/asyncapi/v2/parseAsyncAPIV2.ts @@ -25,7 +25,6 @@ import { FernAsyncAPIExtension } from "../fernExtensions"; import { WebsocketSessionExampleExtension, getFernExamples } from "../getFernExamples"; import { ParseAsyncAPIOptions } from "../options"; import { AsyncAPIIntermediateRepresentation } from "../parse"; -import { transformToValidPath } from "../sharedUtils"; import { AsyncAPIV2 } from "../v2"; import { AsyncAPIV2ParserContext } from "./AsyncAPIV2ParserContext"; import { ExampleWebsocketSessionFactory } from "./ExampleWebsocketSessionFactory"; @@ -250,7 +249,7 @@ export function parseAsyncAPIV2({ subscribe: subscribeSchema != null ? convertSchemaWithExampleToSchema(subscribeSchema) : subscribeSchema, summary: getExtension(channel, FernAsyncAPIExtension.FERN_DISPLAY_NAME), - path: transformToValidPath(channelPath), + path: channelPath, description: undefined, examples, source diff --git a/packages/cli/api-importers/openapi/openapi-ir-parser/src/asyncapi/v3/parseAsyncAPIV3.ts b/packages/cli/api-importers/openapi/openapi-ir-parser/src/asyncapi/v3/parseAsyncAPIV3.ts index ce96036fd81..c330af22b64 100644 --- a/packages/cli/api-importers/openapi/openapi-ir-parser/src/asyncapi/v3/parseAsyncAPIV3.ts +++ b/packages/cli/api-importers/openapi/openapi-ir-parser/src/asyncapi/v3/parseAsyncAPIV3.ts @@ -23,7 +23,6 @@ import { getSchemas } from "../../utils/getSchemas"; import { FernAsyncAPIExtension } from "../fernExtensions"; import { ParseAsyncAPIOptions } from "../options"; import { AsyncAPIIntermediateRepresentation } from "../parse"; -import { transformToValidPath } from "../sharedUtils"; import { AsyncAPIV3 } from "../v3"; import { AsyncAPIV3ParserContext } from "./AsyncAPIV3ParserContext"; @@ -141,7 +140,7 @@ export function parseAsyncAPIV3({ const queryParameters: QueryParameterWithExample[] = []; if (channel.parameters != null) { for (const [name, parameter] of Object.entries(channel.parameters)) { - const { type, path } = convertChannelParameterLocation(parameter.location); + const { type, parameterKey } = convertChannelParameterLocation(parameter.location); const parameterName = upperFirst(camelCase(channelPath)) + upperFirst(camelCase(name)); const parameterSchema = parameter.enum != null && Array.isArray(parameter.enum) @@ -165,13 +164,13 @@ export function parseAsyncAPIV3({ description: undefined, availability: undefined, generatedName: "", - title: undefined, + title: parameterName, groupName: undefined, nameOverride: undefined }); const parameterObject = { - name, + name: parameterKey, description: parameter.description, parameterNameOverride: undefined, schema: parameterSchema, @@ -227,7 +226,9 @@ export function parseAsyncAPIV3({ ? convertSchemaWithExampleToSchema(channelSchemas[channelPath].subscribe) : undefined, summary: getExtension(channel, FernAsyncAPIExtension.FERN_DISPLAY_NAME), - path: transformToValidPath(channelPath), + // TODO (Eden): This can be a LOT more complicated than this. See the link below for more details: + // https://www.asyncapi.com/docs/reference/specification/v3.0.0#channelObject + path: channel.address ?? transformToValidPath(channelPath), description: undefined, examples: [], source @@ -249,9 +250,12 @@ function getChannelPathFromOperation(operation: AsyncAPIV3.Operation): string { return operation.channel.$ref.substring(CHANNEL_REFERENCE_PREFIX.length); } -function convertChannelParameterLocation(location: string): { type: "header" | "path" | "payload"; path: string } { - const [messageType, path] = location.split("#/"); - if (messageType == null || path == null) { +function convertChannelParameterLocation(location: string): { + type: "header" | "path" | "payload"; + parameterKey: string; +} { + const [messageType, parameterKey] = location.split("#/"); + if (messageType == null || parameterKey == null) { throw new Error(`Invalid location format: ${location}`); } if (!messageType.startsWith(LOCATION_PREFIX)) { @@ -261,7 +265,14 @@ function convertChannelParameterLocation(location: string): { type: "header" | " if (type !== "header" && type !== "path" && type !== "payload") { throw new Error(`Invalid message type: ${type}. Must be one of: header, path, payload`); } - return { type, path }; + return { type, parameterKey }; +} + +function transformToValidPath(path: string): string { + if (!path.startsWith("/")) { + return "/" + path; + } + return path; } function buildEnumSchema({ diff --git a/packages/cli/cli/versions.yml b/packages/cli/cli/versions.yml index a63aba9c42d..66ebd1104b9 100644 --- a/packages/cli/cli/versions.yml +++ b/packages/cli/cli/versions.yml @@ -1,3 +1,10 @@ +- changelogEntry: + - summary: | + Correctly parse out channel address for v3 AsyncAPI specs. + type: fix + irVersion: 55 + version: 0.53.6 + - changelogEntry: - summary: | Support validation schemas in detailed Union types.