Generate validation zod schemas and types from openapi spec#599
Open
correct-horse-battery-bench wants to merge 15 commits intomasterfrom
Open
Conversation
…s not valid yet) use redocly and spectral for linting the openapi spec and json+api convention
…rily with type assertions in some cases)
…rVersions is defined but backend returns potentially undefined crackerVersions
…pi/expect the wrong schema
…nst-openapi-spec-or-write-them-by-hand # Conflicts: # src/app/core/_models/task.model.ts # src/app/users/edit-groups/edit-groups.component.spec.ts
Contributor
Author
|
Potential Improvements for the future
|
Contributor
Author
|
Should only be merged after the release so we have some time for testing locally to notice errors during validation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue: hashtopolis/server#2001
Currently only backend responses are validated as request outgoing validation needs a bit a refactoring how the calls are done. In addition, the pull request is already quite large therefore it makes sense to split this up.
Adds zod generated validation schemas and types using @hey-api/openapi-ts package and the zod plugin.
Currently strict mode is off which has some effect how types are inferred from zod but the solution will be to switch to strict mode at one point guaranteeing complete type safety within.
There are new scripts in package.json which generate the types from a running backend. Make sure that the correct backend branch is checked out to be sure that the openapi spec is correct (had to be adjusted somewhat on the branch).
As the openapi spec includes the json+api envelope and jsona parses them out and flattens attributes and includes relationships then the inferred zod type from the envelope will not correctly match the flattened object. Therefore a json-api types file has been added that maps the zod json+api type to the type that jsona actually returns. It also correctly adds included fields the the result type.
That the return type contains the correct relationship fields non optional could later be auto inferred when caling the client that does the request with certain included fields. Currently they can be passed manually so the J interfaces are matched in type.
Main Changes:
JAgent
JHashList
HealthCheckType
Was BRUTE_FORCE but api can return 0 and 3200 -> (md5 and bcrypt?)
JHealthCheck
JTask
Certain fields are made optional on the jtypes as they refer to relationships which may or may not be present as we do not know which includes have been sent in the request.