Skip to content

Commit

Permalink
fix(openrpc): respect tags and name in openrpc (#2040)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Jan 18, 2025
1 parent 4da2e74 commit 8bc22b0
Show file tree
Hide file tree
Showing 6 changed files with 1,764 additions and 543 deletions.
3 changes: 0 additions & 3 deletions packages/fdr-sdk/src/navigation/NodeCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ export class NodeCollector {
this.orphanedNodes.push(existing.node);
this.#setNode(node.slug, node, parents);
} else {
if (FernNavigation.isPage(existing.node)) {
console.warn(`Duplicate slug found: ${node.slug}`, node.title);
}
this.orphanedNodes.push(node);
}
}
Expand Down
44 changes: 39 additions & 5 deletions packages/parsers/src/openrpc/1.x/MethodConverter.node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { isNonNullish } from "@fern-api/ui-core-utils";
import { MethodObject } from "@open-rpc/meta-schema";
import { camelCase } from "es-toolkit";
import { UnreachableCaseError } from "ts-essentials";
import { FernRegistry } from "../../client/generated";
import { generateExampleForJsonSchema } from "../../examples/generateExampleForJsonSchema";
Expand All @@ -13,6 +12,27 @@ import {
import { resolveContentDescriptorObject } from "../utils/resolveContentDescriptorObject";
import { resolveExample } from "../utils/resolveExample";
import { resolveExamplePairingOrReference } from "../utils/resolveExamplePairing";
import { resolveTag } from "../utils/resolveTags";

const API_KEY_PATH_PARAMETER: FernRegistry.api.latest.ObjectProperty = {
key: FernRegistry.PropertyKey("apiKey"),
description: undefined,
availability: undefined,
valueShape: {
type: "alias",
value: {
type: "primitive",
value: {
type: "string",
format: undefined,
regex: undefined,
minLength: undefined,
maxLength: undefined,
default: undefined,
},
},
},
};

export class MethodConverterNode extends BaseOpenrpcConverterNode<
MethodObject,
Expand Down Expand Up @@ -204,11 +224,13 @@ export class MethodConverterNode extends BaseOpenrpcConverterNode<
// This is a basic implementation that needs to be expanded
return {
id: FernRegistry.EndpointId(this.input.name),
displayName: camelCase(this.input.name),
displayName: this.input.name,
method: "POST",
path: [{ type: "literal", value: "" }],
path: [
{ type: "pathParameter", value: FernRegistry.PropertyKey("apiKey") },
],
auth: undefined,
pathParameters: [],
pathParameters: [API_KEY_PATH_PARAMETER],
queryParameters: [],
requests: request != null ? [request] : undefined,
responses:
Expand All @@ -229,7 +251,8 @@ export class MethodConverterNode extends BaseOpenrpcConverterNode<
requestHeaders: [],
responseHeaders: [],
snippetTemplates: undefined,
namespace: [],
// use the first tag as the namespace
namespace: this.getNamespace(),
};
} catch (_error) {
this.context.errors.error({
Expand All @@ -240,6 +263,17 @@ export class MethodConverterNode extends BaseOpenrpcConverterNode<
}
}

private getNamespace(): FernRegistry.api.v1.SubpackageId[] | undefined {
if (this.method.tags?.[0] == null) {
return undefined;
}
const resolvedTag = resolveTag(this.method.tags[0], this.context.openrpc);
if (resolvedTag?.name == null) {
return undefined;
}
return [FernRegistry.api.v1.SubpackageId(resolvedTag.name)];
}

private convertToHttpResponse(
shape:
| FernRegistry.api.latest.TypeShape
Expand Down
Loading

0 comments on commit 8bc22b0

Please sign in to comment.