Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed Jan 14, 2025
1 parent ed90d82 commit df89265
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 5 deletions.
51 changes: 49 additions & 2 deletions packages/parsers/src/openrpc/1.x/MethodConverter.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
? [
Expand Down
90 changes: 87 additions & 3 deletions packages/parsers/src/openrpc/__test__/__snapshots__/petstore.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"endpoints": {
"list_pets": {
"id": "list_pets",
"displayName": "list_pets",
"displayName": "List all pets",
"method": "POST",
"path": [
{
Expand All @@ -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,
Expand All @@ -115,7 +140,7 @@
},
"create_pet": {
"id": "create_pet",
"displayName": "create_pet",
"displayName": "Create a pet",
"method": "POST",
"path": [
{
Expand All @@ -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,
Expand All @@ -147,7 +209,7 @@
},
"get_pet": {
"id": "get_pet",
"displayName": "get_pet",
"displayName": "Info for a specific pet",
"method": "POST",
"path": [
{
Expand All @@ -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,
Expand Down

0 comments on commit df89265

Please sign in to comment.