From df89265a5b3e8f2b3a42676a76120d9662eaa1e9 Mon Sep 17 00:00:00 2001 From: dsinghvi Date: Mon, 13 Jan 2025 19:36:34 -0500 Subject: [PATCH] fix --- .../src/openrpc/1.x/MethodConverter.node.ts | 51 ++++++++++- .../__test__/__snapshots__/petstore.json | 90 ++++++++++++++++++- 2 files changed, 136 insertions(+), 5 deletions(-) diff --git a/packages/parsers/src/openrpc/1.x/MethodConverter.node.ts b/packages/parsers/src/openrpc/1.x/MethodConverter.node.ts index d154f995cb..82b63ae6b0 100644 --- a/packages/parsers/src/openrpc/1.x/MethodConverter.node.ts +++ b/packages/parsers/src/openrpc/1.x/MethodConverter.node.ts @@ -45,17 +45,64 @@ export class MethodConverterNode extends BaseOpenrpcConverterNode< }).convert() : undefined; + const resolvedParams = this.method.params + ?.map((param) => + resolveContentDescriptorObject(param, this.context.openrpc) + ) + .filter(isNonNullish); + + const requestParameters: FernRegistry.api.latest.ObjectProperty[] = + resolvedParams + ?.map((param): FernRegistry.api.latest.ObjectProperty | undefined => { + const schema = new SchemaConverterNode({ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + input: param.schema as any, + context: this.context, + accessPath: this.accessPath, + pathId: `params/${param.name}`, + }).convert(); + + if (!schema) return undefined; + + const valueShape = Array.isArray(schema) ? schema[0] : schema; + if (!valueShape) { + return undefined; + } + + return { + key: FernRegistry.PropertyKey(param.name), + valueShape, + description: param.description, + availability: undefined, + }; + }) + .filter(isNonNullish); + + const request: FernRegistry.api.latest.HttpRequest | undefined = + requestParameters.length > 0 + ? { + contentType: "application/json", + body: { + type: "object", + extends: [], + properties: requestParameters, + extraProperties: undefined, + }, + description: undefined, + } + : undefined; + // Convert method to HTTP endpoint // This is a basic implementation that needs to be expanded return { id: FernRegistry.EndpointId(this.input.name), - displayName: this.input.name, + displayName: this.input.summary ?? this.input.name, method: "POST", path: [{ type: "literal", value: "" }], auth: undefined, pathParameters: [], queryParameters: [], - requests: undefined, + requests: request != null ? [request] : undefined, responses: response != null ? [ diff --git a/packages/parsers/src/openrpc/__test__/__snapshots__/petstore.json b/packages/parsers/src/openrpc/__test__/__snapshots__/petstore.json index 7ebdc53030..5a2f75d424 100644 --- a/packages/parsers/src/openrpc/__test__/__snapshots__/petstore.json +++ b/packages/parsers/src/openrpc/__test__/__snapshots__/petstore.json @@ -83,7 +83,7 @@ "endpoints": { "list_pets": { "id": "list_pets", - "displayName": "list_pets", + "displayName": "List all pets", "method": "POST", "path": [ { @@ -93,6 +93,31 @@ ], "pathParameters": [], "queryParameters": [], + "requests": [ + { + "contentType": "application/json", + "body": { + "type": "object", + "extends": [], + "properties": [ + { + "key": "limit", + "valueShape": { + "type": "alias", + "value": { + "type": "primitive", + "value": { + "type": "integer", + "minimum": 1 + } + } + }, + "description": "How many items to return at one time (max 100)" + } + ] + } + } + ], "responses": [ { "statusCode": 200, @@ -115,7 +140,7 @@ }, "create_pet": { "id": "create_pet", - "displayName": "create_pet", + "displayName": "Create a pet", "method": "POST", "path": [ { @@ -125,6 +150,43 @@ ], "pathParameters": [], "queryParameters": [], + "requests": [ + { + "contentType": "application/json", + "body": { + "type": "object", + "extends": [], + "properties": [ + { + "key": "newPetName", + "valueShape": { + "type": "alias", + "value": { + "type": "primitive", + "value": { + "type": "string" + } + } + }, + "description": "Name of pet to create" + }, + { + "key": "newPetTag", + "valueShape": { + "type": "alias", + "value": { + "type": "primitive", + "value": { + "type": "string" + } + } + }, + "description": "Pet tag to create" + } + ] + } + } + ], "responses": [ { "statusCode": 200, @@ -147,7 +209,7 @@ }, "get_pet": { "id": "get_pet", - "displayName": "get_pet", + "displayName": "Info for a specific pet", "method": "POST", "path": [ { @@ -157,6 +219,28 @@ ], "pathParameters": [], "queryParameters": [], + "requests": [ + { + "contentType": "application/json", + "body": { + "type": "object", + "extends": [], + "properties": [ + { + "key": "petId", + "valueShape": { + "type": "alias", + "value": { + "type": "id", + "id": "PetId" + } + }, + "description": "The id of the pet to retrieve" + } + ] + } + } + ], "responses": [ { "statusCode": 200,