-
-
Notifications
You must be signed in to change notification settings - Fork 331
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
orval/core - generating factory method for schema interfaces #1334
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ export const generateInterface = ({ | |
} else { | ||
model += `export type ${name} = ${scalar.value};\n`; | ||
} | ||
model += `export function create${name}(): ${name} ${scalar.factoryMethodValue}\n`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You will add this in the model file here. It's a bit weird no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah... was thinking whether it should be in separate file or not. I've decided to leave it with model. Anyone who has imported a model, can either instantiate it through "new", or right away call a factory method - which increases the chances that random dev will learn about it and use it. People are lazy and do not read the code - especially the one that's generated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Factory methods are just noise for people who don't need them, so I'd like to be able to choose whether to generate them with a property. And by making it a property, people who want to use it will be aware that it will be generated. Therefore, you will be able to notice it even if you separate the file like |
||
|
||
// Filter out imports that refer to the type defined in current file (OpenAPI recursive schema definitions) | ||
const externalModulesImportsOnly = scalar.imports.filter( | ||
|
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.
Since
create
exists in the http status, I want to change the function name to thenew
prefix to avoid confusion.