Skip to content
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

fix(openrpc): set subpackages in fdr latest #2041

Merged
merged 2 commits into from
Jan 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/parsers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fern-api/docs-parsers",
"version": "0.0.40",
"version": "0.0.41",
"repository": {
"type": "git",
"url": "https://github.com/fern-api/fern-platform.git",
32 changes: 2 additions & 30 deletions packages/parsers/src/openapi/3.1/OpenApiDocumentConverter.node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { camelCase } from "es-toolkit";
import { OpenAPIV3_1 } from "openapi-types";
import { v4 } from "uuid";
import { FernRegistry } from "../../client/generated";
import { computeSubpackages } from "../../utils/computeSubpackages";
import {
BaseOpenApiV3_1ConverterNode,
BaseOpenApiV3_1ConverterNodeConstructorArgs,
@@ -146,35 +146,7 @@ export class OpenApiDocumentConverterNode extends BaseOpenApiV3_1ConverterNode<
const subpackages: Record<
FernRegistry.api.v1.SubpackageId,
FernRegistry.api.latest.SubpackageMetadata
> = {};
if (endpoints != null) {
Object.values(endpoints).forEach((endpoint) =>
endpoint.namespace?.forEach((subpackage) => {
const qualifiedPath: string[] = [];
subpackages[FernRegistry.api.v1.SubpackageId(camelCase(subpackage))] =
{
id: FernRegistry.api.v1.SubpackageId(camelCase(subpackage)),
name: [...qualifiedPath, subpackage].join("/"),
displayName: subpackage,
};
qualifiedPath.push(subpackage);
})
);
}
if (webhookEndpoints != null) {
Object.values(webhookEndpoints).forEach((webhook) =>
webhook.namespace?.forEach((subpackage) => {
const qualifiedPath: string[] = [];
subpackages[FernRegistry.api.v1.SubpackageId(camelCase(subpackage))] =
{
id: FernRegistry.api.v1.SubpackageId(camelCase(subpackage)),
name: [...qualifiedPath, subpackage].join("/"),
displayName: subpackage,
};
qualifiedPath.push(subpackage);
})
);
}
> = computeSubpackages({ endpoints, webhookEndpoints });

const types = this.components?.convert();

Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import { FernRegistry } from "../../client/generated";
import { ServerObjectConverterNode } from "../../openapi";
import { ComponentsConverterNode } from "../../openapi/3.1/schemas/ComponentsConverter.node";
import { coalesceServers } from "../../openapi/utils/3.1/coalesceServers";
import { computeSubpackages } from "../../utils/computeSubpackages";
import {
BaseOpenrpcConverterNode,
BaseOpenrpcConverterNodeConstructorArgs,
@@ -72,25 +73,27 @@ export class OpenrpcDocumentConverterNode extends BaseOpenrpcConverterNode<
const apiDefinitionId = v4();
const types = this.components?.convert();

console.log(this.methods?.length);

const methods = this.methods
?.map((method) => {
return method.convert();
})
.filter(isNonNullish);

const endpoints = Object.fromEntries(
methods?.map((method) => [method.id, method]) ?? []
);

const subpackages = computeSubpackages({ endpoints });

return {
id: FernRegistry.ApiDefinitionId(apiDefinitionId),
types: Object.fromEntries(
Object.entries(types ?? {}).map(([id, type]) => [id, type])
),
endpoints: Object.fromEntries(
methods?.map((method) => [method.id, method]) ?? []
),
endpoints,
websockets: {},
webhooks: {},
subpackages: {},
subpackages,
auths: {},
globalHeaders: [],
};
Original file line number Diff line number Diff line change
@@ -419,7 +419,13 @@
},
"websockets": {},
"webhooks": {},
"subpackages": {},
"subpackages": {
"pets": {
"id": "pets",
"name": "pets",
"displayName": "pets"
}
},
"auths": {},
"globalHeaders": []
}
58 changes: 58 additions & 0 deletions packages/parsers/src/utils/computeSubpackages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { camelCase } from "es-toolkit";
import { FernRegistry } from "../client/generated";

export declare namespace ComputeSubpackages {
interface Args {
endpoints?: Record<
FernRegistry.EndpointId,
FernRegistry.api.latest.EndpointDefinition
>;
webhookEndpoints?: Record<
FernRegistry.EndpointId,
FernRegistry.api.latest.WebhookDefinition
>;
}
}

export function computeSubpackages({
endpoints,
webhookEndpoints,
}: ComputeSubpackages.Args): Record<
FernRegistry.api.v1.SubpackageId,
FernRegistry.api.latest.SubpackageMetadata
> {
const subpackages: Record<
FernRegistry.api.v1.SubpackageId,
FernRegistry.api.latest.SubpackageMetadata
> = {};

if (endpoints != null) {
Object.values(endpoints).forEach((endpoint) =>
endpoint.namespace?.forEach((subpackage) => {
const qualifiedPath: string[] = [];
subpackages[FernRegistry.api.v1.SubpackageId(camelCase(subpackage))] = {
id: FernRegistry.api.v1.SubpackageId(camelCase(subpackage)),
name: [...qualifiedPath, subpackage].join("/"),
displayName: subpackage,
};
qualifiedPath.push(subpackage);
})
);
}

if (webhookEndpoints != null) {
Object.values(webhookEndpoints).forEach((webhook) =>
webhook.namespace?.forEach((subpackage) => {
const qualifiedPath: string[] = [];
subpackages[FernRegistry.api.v1.SubpackageId(camelCase(subpackage))] = {
id: FernRegistry.api.v1.SubpackageId(camelCase(subpackage)),
name: [...qualifiedPath, subpackage].join("/"),
displayName: subpackage,
};
qualifiedPath.push(subpackage);
})
);
}

return subpackages;
}
Loading