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

Support "in": "body" parameter #3

Open
thnguyendn opened this issue Oct 29, 2021 · 9 comments
Open

Support "in": "body" parameter #3

thnguyendn opened this issue Oct 29, 2021 · 9 comments

Comments

@thnguyendn
Copy link

This is a bug report related to the generation of a node from a Swagger definition.

Description

I have the following Swagger definition 2.0 that I want to generate the node using nodebuilder by executing the following command : npm run generate

I generated successfully the node with this command,

However, I got the following error while I add the generated files in the following directory \packages\nodes-base\nodes{myDirectory} of the project n8n (see the following image) :

!image

Could you please review the tool nodebuilder, so that it can fix the generated error
Swagger_def.txt
?

Thank you in advance for your help

@ivov
Copy link
Owner

ivov commented Nov 2, 2021

Thank you for your report. The fixes will be merged soon - meanwhile here is the correct output.

Note that nodebuilder builds most of the node, but not yet all of it - it does not create the credentials file and the icon. You will also need to fill in the placeholders USERTASK in openApiRequestAllItems in GenericFunctions.ts.

@thnguyendn
Copy link
Author

Thank you for your quick reply. I will check and keep you informed

@thnguyendn
Copy link
Author

thnguyendn commented Nov 2, 2021

I have just checked the generated file. The generation process terminated well. And I can add the generated file as a custom node in the n8n project.

But, there is still a problem... When you look into the Swagger definition, you will have a "schema" block that has been predefined for query parameter and for response as follows

image

However, I cannot find the code generated for schema of query parameter and schema of response.

Does your generation tool take into account these pieces of information during its generation process ?

@thnguyendn
Copy link
Author

@ivov Do you have any idea about my question ?

@ivov
Copy link
Owner

ivov commented Nov 11, 2021

Dereferencing is supported. This works correctly for the sample Lichess spec and also for OpenCell. You can inspect the dereferenced spec at ./src/input/_deref.json after generation.

private parseSpec(serviceName: string) {
const source = path.join(openApiInputDir, serviceName);
const target = path.join(inputDir, "_deref.json");
execSync(
`node ${swagger} bundle --dereference ${source} --outfile ${target}`
);
return JSON.parse(fs.readFileSync(target).toString());
}

What is not supported is the "in": "body" parameter, as it had not come up in my own use cases. Will keep this issue open and support this in future, hopefully soon, as time allows.

type OperationParameter = {
in: "path" | "query" | "header";
name: string;
description?: string;
schema: PathQuerySchema;
required?: boolean;
example?: string;
$ref?: string; // from OpenAPI
};

@ivov ivov changed the title Cannot generate correctly a node from Swagger definition using nodebuilder Support "in": "body" parameter Nov 11, 2021
@thnguyendn
Copy link
Author

thnguyendn commented Nov 15, 2021

Hello @ivov , thank you very much for your reply.

I hope you can soon support "in": "body" parameter

@thnguyendn
Copy link
Author

Hello @ivov ,

I found the file _deref.json that has been generated by processing dereferencing. However, I do not know where to add this dereferenring file in n8n project so that n8n can take into consideration this file. Any idea ?

@ivov
Copy link
Owner

ivov commented Nov 15, 2021

Nodebuilder dereferences the spec (i.e. replaces its references at $ref with the actual params) into _deref.json and then parses that file into an n8n node. Therefore, _deref.json is an only intermediate output, not meant for the user. I mentioned it above to make clear that dereferencing is taken care of.

What remains to be done is enabling the parser to generate params for "in": "body", as it does for "path", "query" and "header".

@thnguyendn
Copy link
Author

Hi @ivov : Do you have good news about the implementation of the parser for parameter "in": "body"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants