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

Forward schema warnings to diagnostics #174

Merged

Conversation

czechboy0
Copy link
Contributor

Motivation

OpenAPIKit emits warnings about parsed JSONSchema objects that could be helpful to adopters when debugging issues. Today, we are ignoring them.

Modifications

This PR forwards them into the diagnostics collector as warnings.

Result

When a schema is malformed in a way that OpenAPIKit still manages to parse it, but has issues, adopters will see these issues emitted as all other diagnostics we emit.

Test Plan

Added a unit test.

@czechboy0 czechboy0 merged commit d22ddfe into apple:main Aug 7, 2023
@czechboy0 czechboy0 deleted the hd-forward-schema-warnings-to-diagnostics branch August 7, 2023 18:21
@czechboy0 czechboy0 added the 🔨 semver/patch No public API change. label Aug 8, 2023
czechboy0 added a commit that referenced this pull request Aug 8, 2023
Stop treating schema warnings as errors

### Motivation

In #130, we introduced extra validation by calling into OpenAPIKit's `validate` method. (It's hidden behind a feature flag, but I've been testing with it enabled.)

It looks for structural issues, such as non-unique operation ids, which would result in us generating non-compiling code anyway, so the validation helps catch these early and emit descriptive errors that adopters can use to fix their doc.

However, the method also takes a parameter `strict`, which defaults to `true`, and when enabled, it turns warnings emitted during schema parsing into errors. This part is _too_ strict for us and was rejecting OpenAPI documents that were valid enough for our needs.

An example of a schema warning is a schema having `minItems: 1` on a non-array schema. While it's not technically correct, it also doesn't impede our understanding of the non-array schema, as we never actually check what the value of `minItems` is. That's why these are just warnings, not errors, so we should stop promoting them to fatal errors that block an adopter from generating code.

### Modifications

This PR flips the `strict` parameter to `false`. This doesn't make us miss out on these warnings, as recently (in #174), we started forwarding these schema warnings into generator diagnostics, so the adopter will see them still, and can address them on their own schedule.

### Result

Now documents with only schema warnings aren't rejected by the generator anymore.

### Test Plan

Added a unit test of the broken-out `validateDoc` function, ensures that a schema with warnings doesn't trip it up anymore.


Reviewed by: simonjbeaumont

Builds:
     ✔︎ pull request validation (5.8) - Build finished. 
     ✔︎ pull request validation (5.9) - Build finished. 
     ✔︎ pull request validation (docc test) - Build finished. 
     ✔︎ pull request validation (integration test) - Build finished. 
     ✔︎ pull request validation (nightly) - Build finished. 
     ✔︎ pull request validation (soundness) - Build finished. 

#178
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants