Skip to content

Commit

Permalink
couple papercuts
Browse files Browse the repository at this point in the history
  • Loading branch information
RohinBhargava committed Feb 14, 2025
1 parent 6a9e227 commit 42318ce
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
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.57",
"version": "0.0.58",
"repository": {
"type": "git",
"url": "https://github.com/fern-api/fern-platform.git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,15 @@ export class OpenApiDocumentConverterNode extends BaseOpenApiV3_1ConverterNode<

const { webhookEndpoints, endpoints } = this.paths?.convert() ?? {};

const webhooks = {
...(this.webhooks?.convert() ?? {}),
...(webhookEndpoints ?? {}),
};

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

const { types, auths } = this.components?.convert() ?? {};

Expand All @@ -139,10 +144,7 @@ export class OpenApiDocumentConverterNode extends BaseOpenApiV3_1ConverterNode<
endpoints: endpoints ?? {},
// Websockets are not implemented in OAS, but are in AsyncAPI
websockets: {},
webhooks: {
...(this.webhooks?.convert() ?? {}),
...(webhookEndpoints ?? {}),
},
webhooks,
types:
types != null
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export class ServerObjectConverterNode extends BaseOpenApiV3_1ConverterNode<
}

parse(): void {
this.url = this.input.url;
this.url =
Object.entries(this.input.variables ?? {}).reduce((url, [key, value]) => {
return url.replace(`{${key}}`, value.default);
}, this.input.url) ?? this.input.url;
this.serverName = new XFernServerNameConverterNode({
input: this.input,
context: this.context,
Expand All @@ -37,7 +40,6 @@ export class ServerObjectConverterNode extends BaseOpenApiV3_1ConverterNode<
}

return {
// TODO: url validation here
id: FernRegistry.EnvironmentId(serverName),
baseUrl: this.url,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,26 @@ describe("ServerObjectConverterNode", () => {
baseUrl: "https://api.example.com",
});
});

it("should replace variables in url", () => {
const input: OpenAPIV3_1.ServerObject = {
url: "https://api.example.com/{foo}/{bar}",
variables: {
foo: { default: "bar" },
bar: { default: "baz" },
},
};
const node = new ServerObjectConverterNode({
input,
context: mockContext,
accessPath: [],
pathId: "test",
});
const result = node.convert();
expect(result).toEqual({
id: FernRegistry.EnvironmentId("https://api.example.com/bar/baz"),
baseUrl: "https://api.example.com/bar/baz",
});
});
});
});

0 comments on commit 42318ce

Please sign in to comment.