-
Notifications
You must be signed in to change notification settings - Fork 58
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
Validate generated JSON schemas #642
Comments
After re-reading your issue, I had to correct my previous post. So your request, is to detect invalid OpenAPI properties before it gets converted? Follow-up question:
|
I was thinking more of the latter as it should be quicker to implement, but the former would be ideal too perhaps as a separate feature. I would expect any tests the library generates to be valid, therefore the generated JSON schema injected by the library should be valid and, ideally, I should not have to worry about checking this. To address your follow up question: |
I understand your reasoning to leverage contract testing with JSON schema validation, so the schema should be valid. Typically, we see workflows, where the OpenAPI is validated using Spectral or Vacuum (or any other of the OSS OpenAPI linting tools), before it is handed over to Portman. Do you have a workflow for your OpenAPI specs with linting, filtering, ..., or just pass the raw OpenAPI file to Portman? @nicklloyd What do you think of this feature request? Technically it is straightforward, since AJV is already included in Portman, so we could throw a error when injecting the JSON schema validation. |
Yeah, I do think it's fair that you expect a valid OpenAPI spec before hand. In my case I am actually using Spectral to validate the spec before passing it to Portman, but perhaps they have an issue on their library because it does not raise any validation errors in this case. Anyway that's another issue. Here's some reproduction steps using a modified Swagger Petstore example:
Note that the
|
Thanks for all the info, I already spotted that 3.1.0 OpenAPI version, which might be a factor in the incorrect JSON schema used. I'll look into it in the next week and come back to you. |
Good spot. I just did a quick check with Thanks for your time! |
@harry-pledge-io We were able to find and fix the cause, and add a validation step during the conversion. REMARK: we did not stop the Portman conversion but added a warning and skipped the JSON schema check injection in the Postman collection. |
LGTM, thanks for looking into it! Is there a particular reason you prefer to warn in this case? I ask because I do the Portman conversion during a step in a CI pipeline and I would miss any instances of this warning unless I decide to manually look at each pipeline (or write some extra logic to look for warning logs in the pipeline). If you don't want to effect existing behaviour, then it would be ideal If there were a way to opt into fatal errors instead (perhaps with some kind of strict mode flag). |
The introduction of a "strict mode" could be useful, we are always cautious with the introduction of too many flags to handle edge cases. Out of curiosity, what else would you consider strict (fatal)? |
While we discuss the "strict mode", I can already share the news that we just released Portman 1.30.1, which contains the enhancements for the OpenAPI to JSON schema conversion, including the validation and alerting of the generated JSON schema. |
I'm not sure what all the current instances of warnings/errors are in Portman but I would say likely anything that's currently considered a warning/error but does not stop the process. Also anything that prevents Portman from outputting what is defined in the Portman config. |
@nicklloyd what is your opinion on the "strict" parameter, and which errors would you consider a hard exit of the conversion? |
Besides the "strict" discussion, did the last version of Portman solved the original issue? |
Hi there,
I wanted to bring up an issue I encountered with Portman that might be worth looking into.
In my OpenAPI spec, I had a field using
"types": ["object", "null"]
(note the use of"types"
instead of"type"
) along with"nullable": true
. Portman generated the contract tests successfully, but the resulting JSON schema was invalid.It might be helpful if Portman could catch this kind of inconsistency earlier in the process. For example, it could fail during the Postman collection generation with a clear JSON schema validation error. This change could make it easier for users to spot and fix these issues in their OpenAPI specs before they cause problems down the line.
I'm happy to provide more details or a specific example if that would be helpful. Thanks for considering this feedback!
The text was updated successfully, but these errors were encountered: