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

better error message for list of different type #210

Open
XiaosongWen opened this issue Feb 6, 2023 · 2 comments
Open

better error message for list of different type #210

XiaosongWen opened this issue Feb 6, 2023 · 2 comments

Comments

@XiaosongWen
Copy link

My use case I have two type type of target_discovery (http and ping), each of them have different schema, my code is:

target_discovery: list(include('resourcePingProvider'), include('resourceHttpProvider'))

resourcePingProvider:
  resourceProvider: str(equals="ping")
  probeMetadata: include('probeMetadata')
  ...

resourceHttpProvider:
  resourceProvider: str(equals="http")
  url: ...

Basically, it is checking the value of each resourceProvider field. However, if I input "xxxx", it gave me blow error messages, it contains other redundant infos.

target_discovery.0.resourceProvider: XXXX does not equal ping
target_discovery.0.probeMetadata: Unexpected element
... ...
target_discovery.0.resourceProvider: XXXX does not equal http
target_discovery.0.url: Required field missing
... ... 

Is there a way that it only return something like XXXX does not equal ping or http?

@nbaju1
Copy link

nbaju1 commented Feb 15, 2023

You could look into generalizing the resourceProvider schema to handle both types and do:

target_discovery: list(include('resourceProvider'))

resourceProvider:
  resourceProviderType: enum("ping", "http")
  ...

Or you could create a custom constraint that replaces equals which outputs your desired error message.

@XiaosongWen
Copy link
Author

@nbaju1 Thanks for your advice. Since different Provider have very different schema, first approach probably wont work. I will try your second suggestion

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