-
Notifications
You must be signed in to change notification settings - Fork 127
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
Types extension #55
Types extension #55
Conversation
Co-Authored-By: Adam Altman <adam@rebilly.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few comments
src/typesExtention/index.js
Outdated
|
||
for (let i = 0; i < alteredFields.length; i++) { | ||
const pathToDefaultType = `${__dirname}/../types/${extension.properties[alteredFields[i]]}.js`; | ||
let alteredType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can assign the value directly on this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
class parameterAllOf { | ||
constructor(config) { | ||
this.config = { ...config }; | ||
switch (this.config.level) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need every custom rule to add this code? Maybe we can provide some base class with this behaviour handled. Also, where is this level used later? Is it propagated down the visitor invocations?
Also, I thing we should export constants for those 1, 2, 3, 4 numbers :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to make custom rules completely 0-dependency. We can just inherit from AbstractVisitor class and don't do this manually
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, numbers are in constants elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I think 0-dep makes sense. Maybe, instead we can just keep string values and adjust other related code to accept them instead of/ additionally to number values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, yes, that might work fine
|
||
OpenAPIParameter() { | ||
return { | ||
onEnter: (node, _, ctx, unresolved, traverseTools) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how to add an error from this validator? Could you add an example of validating the description field to be a string (using some custom code)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now we allow types (re)definition, not so much custom validators. we can (not sure if already) load additional rules (with are the same syntax/structure) as our own ones and run them on types we want
This PR introduces a concept of extending and redefining types and rules.
Description
From this version, user can add custom fields into default objects in all levels, which will then validate using either existing validators (for existing types, either with custom rules, created by user).
To extend or define a type, user should create a file and pass it as a
typeExtension
parameter in the config. It should follow such pattern (quite similar to usual reducers):Here, user adds field
allOf
toParameter
type.null
value in theproperties
object is allowed and means that given property is a leaf in the type-tree.To extend ruleset user can create another file and set it as
customRules
param of config with such contents:User should provide configuration file
.openapi-cli.yaml
in the root of the definition directory.