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

Recursion error when receiving Json object in the body #160

Closed
alexayalaa opened this issue Jan 9, 2024 · 12 comments
Closed

Recursion error when receiving Json object in the body #160

alexayalaa opened this issue Jan 9, 2024 · 12 comments

Comments

@alexayalaa
Copy link

alexayalaa commented Jan 9, 2024

It turns out that I have a problem with the openapi enforcer Middleware library, initially I am creating an instance to validate a series of openapi either version 2.0 or 3.0 it works correctly but when There is a very complex structure in the Body that generates a recursion error at the level of the internal object, for example:

{
    "data": [
        {
            "account": {
                "type": "SAVINGS_ACCOUNT",
                "number": "91200244139"
            }
        }
    ]
}

.... I send this structure and when I trace it it generates this when I print the incoming value:
{ data: [ { account: [Object] } ] }
does the type validation correctly but is not going deeper than object especially this part, [Object]... I would like to know if we can make a solution or if I am overlooking something or if a body recursion function is needed, I am very attentive to your response and thank you very much for your attention .

@Gi60s
Copy link
Owner

Gi60s commented Jan 9, 2024

Hello @alexayalaa and thank you for the issue. The library is set up for both nested and recursive objects and schemas. It is possible that there is a bug somewhere though.

To look more into this, will you please share with me the relevant parts of your OpenAPI schema definition file? Better yet, if you have a repo that I could look at to see your code that could help too.

Thank you for using the OpenAPI Enforcer library.

@alexayalaa
Copy link
Author

alexayalaa commented Jan 9, 2024 via email

@Gi60s
Copy link
Owner

Gi60s commented Jan 10, 2024

Will you please also share your openapi.yaml file and the method, path, and body of the request that you're sending into the system?

Thank you.

@Gi60s
Copy link
Owner

Gi60s commented Jan 10, 2024

I just saw that your response does include the body. Please share the openapi document. I might be able to figure out the rest.

@alexayalaa
Copy link
Author

alexayalaa commented Jan 10, 2024 via email

@Gi60s
Copy link
Owner

Gi60s commented Jan 11, 2024

I'm not seeing your yaml. I noticed that you are using email to reply to the comments instead of using the gitlab webpage where you posted the issue. Maybe try visiting the gitlab page where you posted the issue and adding the yaml there.

@alexayalaa
Copy link
Author

alexayalaa commented Jan 11, 2024 via email

@Gi60s
Copy link
Owner

Gi60s commented Jan 12, 2024

I don't know that I'm seeing the same error as you based on what you provided me. This is the error I see when making the request:

Request has one or more errors
  In body
    Invalid value
      at: data > 0 > account
        Did not validate against all schemas
          at: 0 > type
            Value "SAVINGS_ACCOUNT" did not meet enum requirements

When I change the request to use CUENTA_DE_AHORRO for the type it is successful. So here is a successful request:

POST localhost:3000/accounts/retrieve-basic
{
    "data": [
        {
            "account": {
            "type": "CUENTA_DE_AHORRO",
            "number": "91200244139"
            }
        }
    ]
}

@alexayalaa
Copy link
Author

alexayalaa commented Jan 12, 2024 via email

@Gi60s
Copy link
Owner

Gi60s commented Jan 12, 2024

Could you record a video demonstrating what you are seeing?

@alexayalaa
Copy link
Author

Hello James, thank you very much in advance for the help, since through github issues it only allows 10mb I decided to upload the video ( https://we.tl/t-tvgoTTP2Zu )on the same WeTranfer platform, the video I want to show you that the body arrives in the library and it validates almost everything except what it has inside [Object] in my case it is this { data: [ { account: [Object] } ] } it correctly generates the external validations but not the internal one in that case [Object], which prevents validating if the values ​​are being sent correct and it is not matching with the openapi.yaml since all the parameters are required, it is ignoring them.

@Gi60s
Copy link
Owner

Gi60s commented Jan 19, 2024

@alexayalaa Thanks for sending the video. I now understand what the issue is. What you're running into is simply the way that node logs objects to the console. This has nothing to do with the OpenAPI Enforcer.

The reason that some of your logs show the complete object instead of just { data: [ { account: [Object] } ] } is because you're converting those objects into a string prior to logging them to the console.

In node, objects that are logged to the console will be shortened automatically by node to improve log readability. If you want to see the entire object you'll need to stringify it first.

I've taken a screenshot of your code, highlighting the two spots where one is logged as a string and the other is logged as an object. I hope that answers your questions. Good luck and happy coding.

image

@Gi60s Gi60s closed this as completed Jan 19, 2024
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