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

Client-side validation #111

Closed
zxjlm opened this issue Feb 9, 2022 · 6 comments
Closed

Client-side validation #111

zxjlm opened this issue Feb 9, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@zxjlm
Copy link

zxjlm commented Feb 9, 2022

I am now using this sdk to do some develop. But usually i get the APIResponseError error.

APIResponseError: body failed validation.

I plan to write a simple validator in my code, and I'm curious if this feature will be added in the future.

@ramnes
Copy link
Owner

ramnes commented Feb 9, 2022

Why not just let the API tell you the error?

Validating bodies would make the codebase much larger and harder to maintain; I really want to make sure it has a lot of benefits for users before going down this route.

@ramnes ramnes added the enhancement New feature or request label Feb 9, 2022
@ramnes ramnes changed the title Will validation functionality be added to the sdk in the future? Client-side validation Feb 9, 2022
@zxjlm
Copy link
Author

zxjlm commented Feb 10, 2022

Thanks for your response.

I am now writing a project that can convert books to notion type. and i got the error blow.

APIResponseError: body failed validation: body.children[0].bulleted_list_item.children[1].paragraph.children[0].bulleted_list_item.children should be not present

But i didn`t find the detail of validate rule in notion api page.

Is this data structure too deeply nested? so i want to get the rule notion used.

In addition to this, i think that local validation will benifit the unit test. The request made by UT is of no value to the notion server.

All of the above are personal opinions, if you think it is unnecessary, i will close this issue.

Finally, looking forward to your answer to question marked in bolded format.

@zxjlm
Copy link
Author

zxjlm commented Feb 10, 2022

Here is the data i used.

[
    {
        "type":"bulleted_list_item",
        "bulleted_list_item":{
            "text":[

            ],
            "children":[
                {
                    "type":"paragraph",
                    "paragraph":{
                        "text":[
                            {
                                "type":"text",
                                "text":{
                                    "content":"用户接口层",
                                    "link":null
                                }
                            }
                        ]
                    }
                },
                {
                    "type":"paragraph",
                    "paragraph":{
                        "text":[
                            {
                                "type":"text",
                                "text":{
                                    "content":"",
                                    "link":null
                                }
                            }
                        ],
                        "children":[
                            {
                                "type":"bulleted_list_item",
                                "bulleted_list_item":{
                                    "text":[
                                        {
                                            "type":"text",
                                            "text":{
                                                "content":"Assembler :将 CustomerDTO 转换为 CustomerEntity",
                                                "link":null
                                            }
                                        }
                                    ],
                                    "children":[

                                    ]
                                }
                            },
                            {
                                "type":"bulleted_list_item",
                                "bulleted_list_item":{
                                    "text":[
                                        {
                                            "type":"text",
                                            "text":{
                                                "content":"Dto:接收请求传入的数据 CustomerDTO",
                                                "link":null
                                            }
                                        }
                                    ],
                                    "children":[

                                    ]
                                }
                            },
                            {
                                "type":"bulleted_list_item",
                                "bulleted_list_item":{
                                    "text":[
                                        {
                                            "type":"text",
                                            "text":{
                                                "content":"Facade:调用应用层创建用户方法",
                                                "link":null
                                            }
                                        }
                                    ],
                                    "children":[

                                    ]
                                }
                            }
                        ]
                    }
                }
            ]
        }
    }
]

@ramnes
Copy link
Owner

ramnes commented Feb 10, 2022

I'm really not against the idea! I just think that:

  1. it would be a bit presumptuous to think that we could have a better validation than Notion's one on the client's side
  2. I really don't have enough bandwidth to maintain compatibility with their changes on such a fine grained level

Now, notion-sdk-js does seem to define the whole validation structures in their api-endpoints.ts file, so maybe we could use that with something like Js2Py, but that sounds quite experimental.

@zxjlm
Copy link
Author

zxjlm commented Feb 11, 2022

All validation occurs after the post\patch request has been sent. But I need a stateless validation.

So notion-sdk-js can achieve my goals. Js2Py is one way. Also I can edit the code and make a node.js micro-service to use notion`s rule to validate my data structure.

Thank you for helping me find the way to solve the problem ~

@zxjlm zxjlm closed this as completed Feb 11, 2022
@ramnes
Copy link
Owner

ramnes commented Feb 11, 2022

You're welcome! If you end up using Js2Py, please keep me updated as I would love to see if that can be achieved that way.

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

No branches or pull requests

2 participants