-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Rewrite of TypeScript Generators #802
Comments
@TiFu I suggest to consider using RxJS / Observables. Maybe there is an easy way to make this configurable? |
What would be the use case for Observables in this case? What should be observable? |
@TiFu the return value of the api call. see e.g. https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/api/pet.service.ts#L70 the use case is that observables are the standard for http interaction in angular. Therefore in the template it should be easy to have a configuration option to either have a promise-based generator or an observable-based generator. |
I will think about that some more. It looks quite complicated to include Observables together with promises internally (especially observing the different options like One option is to simply wrap promises in Observables e.g.
I'm just not sure how this could be integrated into the current HTTPLibrary design. |
@TiFu it is very important to handle observables correctly and not only wrap promises, since promises can‘t be cancelled, while observables can, which is an essential feature. |
However it is possible to convert an observable into a promise. This should fit all needs. Therefore internally it should be buolt on observables |
Oh okay. I have an idea how to solve this issue.
This encapsulates all api logic in 1. and just defers making the request to the library specific code section. Does that make sense? |
After my fork is merged in I’ll be very keen to throw myself and time at this work. My company has run into many issues with the ng clients and node clients so I’m very motivated to help unify the generators. |
@Place1 Thanks! Let me know when you are ready/have time to look into it and I will give you a quick overview over the code base - you can already find it on the I have finished a basic prototype for ts-fetch today (still has a ton of todos/bugs/only basic features, but it outlines the direction I want to take for the other generators). As a next step, I will go through the other generators step by step and try to find the most common features in all generators and create issues for them. There's also a project for the ts-refactor, so I'll assign all relevant issues to this project. I will be away from tomorrow until Monday evening, so I won't be able to do much until then. CLI Arguments I currently use to generate the client:
|
Not sure if this has been brought up elsewhere, but one issue I'm having adopting the generated typescript client is the use of namespaces for enums. If the typescript generator is being overhauled could alternate code styles be considered? |
@acornett Do you know of any temporary workarounds for this or will I have to avoid using enums all-together? |
@acornett noted. Although I have no timeline for finishing the prototype of the overhaul at this time. |
@madshargreave I have not been able to dig into it enough to develop a work around. I will see about working on a more concrete proposal (or if my schedule really opens up maybe a pull request!) |
see also #1884 |
@TiFu generally the idea is good. However I would strongly disagree on making more abstractions (like HTTP library) on the generated files. Generated files should use directly the chosen HTTP library (e.g. fetch), using an abstraction will make the files more complex and less readable especially to those new to openapi-generator (which they shouldn't need to understand). The goal is, as long as they know fetch then they can read, use, and modify the generated code. |
@ceefour Thanks for the feedback. Unfortunately not using an abstraction for HTTP makes the generator code far more complex e.g. we would have to change how we create the requests (including header params, query params, ...) for every HTTP library and wherever we use it. This would lead to duplicated code on our site which is harder to maintain and prone to bugs. In the end, the goal would be for people to not have to modify the code directly, but make it extensible through middleware (like we plan on doing for HTTP - you can simply modify the HTTP Request and before its being parsed/send). Other opinions regarding @ceefour's feedback? @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) |
@TiFu is it possible to put the "library" on the generator instead. So parent generators can call implementation-specific "child" generators, keeping the overall project structure uniform. I'm afraid that by having a runtime library, while it does reduce generator complexity but overall complexity is the same, just moved from the generator to the runtime library. |
@TiFu I support your point that without runtime http abstraction (which is just a single layer and easy to understand) the complexity of the codegen cannot be decreased. Personally, I never have a look at the generated code in a project, since it does its job. |
I apologize if this is just a simple analogy not real code, I'm not familiar with how it works. Library on runtime, generates:
then the runtime handles most of the logic, generator is simple. Library on generator:
So in my view, both approaches have similar overall complexity, but the proportion is different. Note: I have to support that the current
I hope so too. Recently I got #1133 (echoed by #1873, #1577, #1446, #457) so I needed to patch the generated code as a workaround in the meantime before the generator is fixed. It's the "leaky abstraction" problem which is hard to avoid, but understandable. |
Thanks for the detailed explanations! Regarding your first comment: Regarding your second comment: |
Do you want to merge #6177 before we file the PR to merge the generator into |
Yes, agreed on the GET-body check. I have already removed it in my unpushed work for #6177. As for XHR binary response bodies: Your suggestion seems fine for the technical implementation. (Note for implementation: Use So we could:
It is also possible to add generator config options to select between these variants or to select whether the polyfills are needed, which would allow to better tailor the generated code to the users requirements, but would also make our mustach templates more complicated. I'm tempted to go with option 1 for now and later implement option 3, to reduce work and code overhead, but I also know that “later” will probably never happen then. What do you think? Feel free to merge into master before we finish #6177. I can easily change the PR target to master and there is already a change in master I would like to use. |
Yeah sounds good.
Alright. I'll file the PR and CC you as well as the technical committee and whoever else we need.
Where would we need polyfills? My understanding is that most up-to-date browsers support In node, we could use |
By polyfill I meant the fallback. Replacing missing functionality for some platforms with an alternative implementation. Node seems fine to me, I think |
But as long as that alternative implementation is supported by default, this wouldn't increase the code size because we don't have to include any additional dependency. Am I missing something? |
Maybe I'm just overthinking this and adding a few lines (calling |
Yeah, I think adding a couple lines for that should be fine - probably doesn't even make any noticeable difference after minifying the code. We could support disabling this and just not supporting IE (i.e. a flag) but to be honest I doubt anyone would use that because the difference is so small. |
Alright then let's go for that. Should not even be so hard to implement. I'll see what I can build tomorrow. |
Fixes a handful of issues identified in #802 (comment) List of changes * Clean: Remove redundant cliOption definition * Remove redundant directory structure in templates If we need to have different index.ts files for the different frameworks, we can mostly do that in the one mustache file. In the cases where that is not possible, we can still add a new override file later. * Use File.separator consistently * Only export selected api type * Simplify promise polyfill import The behaviour should be the same, according to the es6-promise docs. Previously tsc would report the error: > error TS2307: Cannot find module 'es6-promise'. * Import HttpFile in all models * Export server configurations * Use undefined as default body value The empty string is not interpreted as "no body" by the browser fetch api and thus leads to an exception during get requests * Improve codestyle: prefer guards to nesting * Remove verbose debug output This should not be commited, because every developer has very different requirements what debug information he needs to see. * Fix: Use cleaned model names for imports * Fix: do not call toString on undefined * Fix typo in doc comment * Introduce RequestBody type and remove method check
Can you tell me, what the use case for |
The original plan was to use it as the auth provider instead of I think I'll just remove it. |
This reminds me of this: Standards |
That is an apt observation, @mocsy. |
@bodograumann the gain is huge to have a common implementation and small specific implementations. It's just a matter of time when everyone want to switch to the shiny new version of generator(s). We have some bugs with current implementation (for example nulls for nullable fields are treated like undefined) and just can't await to get this rewrite done to contribute. |
@mocsy Constructive feedback is always appreciated ;-) @Bessonov :-) We are trying to get this merged as soon as possible - see #6341 . @bodograumann is also working on adding inversify support (#6489). Are you missing any specific features in the rewrite? Happy to have a look at implementing whatever's missing or guiding you in the right direction to contributing to the rewrite :) |
… jquery (#6341) * Added http module draft * Added generic enum * Modified http lib, added config & middleware definition to ts-fetch * Added model generation with imports * Added auth module * Added servers * Added sample for typescript client * WIP: Models & API * Updated auth * WIP: api modeling * Implemented RequestFactory and Processor completely * Implemented fetch client * Ignore dist folder in typescript client sample * Added middleware to fetch * Restructured TypeScript generator * Reverted: http library.send returns string again * Removed TODOs * Added pom.xml files to TypeScript PetStore client samples * Removed tabs from TypeScriptClientCodegen * Added ts client codegen to root pom.xml and travis * Added server variable configuration to ts-refactor * [TS-Refactor] Added tests for Object Serializer * Added simple test for PetApi * Fixed ObjectSerializer test * Added handling for different http status codes and test for deletePet * Removed tabs in TypeScriptClientCodegen * Removed tabs in DefaultCodegen * Additional tests for pet store api * Fixed file uploads * Made api call configuration separately settable * Use string union for enums * Remove tab * Restructured module layout * Use observables internally * Added promise based middleware * Made discriminator and attributeTypeMap readonly * Configure discriminator correctly * Set discriminator value automatically * Fixed date-time and date handling * Added comments & license info * Added comments * Ignore openapi-generator-cli/bin * Removed accidentally created generated code * Fixed compilation issues in TypeScriptClientCodegen * Added typescript to docs/generators * Updated docs * Added gitignore and git_push * Added jquery library * Added pom.xmls, fixed packagejsons and hopefully webppack * Removed tabs in TypeScriptClientCodegen * Fixed a couple issues with pom.xml * Ensured up to date * Fixed missing fetch definition in TS default tests * Updated typescript docs * Refactor typescript merge master (#4319) Merge master into ts-refactor * Typescript refactor: stub rxjs (#4424) * Remove unused supportsES6 field from codegen * Add a new switch for RXJS * Remove redundant npm dependency on rxjs4 types * Fix return type of PromiseMiddleware methods * Install webpack dependency to run jquery tests * Update form-data to 2.5 which includes typings * Add missing dependency on node typings * Fix test artifact name typo * Stub rxjs when it is not explicitly enabled * Typescript refactor: Platform select for browser and node (#4500) * Use string form of filename parameter This works for the form-data library and is also compatible with the browser FormData object. * Add new option to select platform node or browser When no platform is selected, a default is chosen by the framework option and likewise the file data type option is implied by the platform. * Remove redundant import of node dns module * Only use form-data library for node platform * Generate npm package from npmName option * Use method convertPropertyToBooleanAndWriteBack * Generate typescript samples with ensure-up-to-date * Removed tab from DefaultCodegen * Readded missing change * Mark typescript client codegen as experimental * Removed whitespace * [TS-Refactor] Top-level exports for fetch & jquery (#6138) * Added top-level exports * Updated generator README * Updated typescript generator docs * Allow browsers File type for files (#5521) * Allow passing file parameters as File objects * Add test for jquery upload * Use HttpFile object for node platform * Regenerate samples This is by far the most common use case. A `File` object already contains the name attribute. This commit allows that information to be used directly. When sending a `Blob`, in most browsers the `File` constructor can be used to assign a file name. In all other browsers the alternative is ```typescript Object.assign(data, { name: "foobar.txt" }); ``` That is why we explicitely pass the name as third parameter to `FormData.append`. This `Object.assign` method also works for `Buffer` objects in node. If one really does not want to touch the data object in the browser it is possible to define another reference to the data with ```typescript new Blob([data], { type: data.type }) ``` or in node via ```typescript Buffer.from(data) ``` * [TS-Refactor] Added options for npm version, repository, name and updated readme (#6139) * Added options for npm version, repository, name and updated readme * Removed `this` where not required * Updated typescript docs * Typescript refactor fixes (#6027) Fixes a handful of issues identified in #802 (comment) List of changes * Clean: Remove redundant cliOption definition * Remove redundant directory structure in templates If we need to have different index.ts files for the different frameworks, we can mostly do that in the one mustache file. In the cases where that is not possible, we can still add a new override file later. * Use File.separator consistently * Only export selected api type * Simplify promise polyfill import The behaviour should be the same, according to the es6-promise docs. Previously tsc would report the error: > error TS2307: Cannot find module 'es6-promise'. * Import HttpFile in all models * Export server configurations * Use undefined as default body value The empty string is not interpreted as "no body" by the browser fetch api and thus leads to an exception during get requests * Improve codestyle: prefer guards to nesting * Remove verbose debug output This should not be commited, because every developer has very different requirements what debug information he needs to see. * Fix: Use cleaned model names for imports * Fix: do not call toString on undefined * Fix typo in doc comment * Introduce RequestBody type and remove method check * Support media types other than json (#6177) List of changes: * Add */* as fallback to accept header * Use more sophisticated media type selection * Handle object stringify in ObjectSerializer * Parse response with ObejctSerializer * Fix: Correctly extract response headers in browser * Create HttpFile objects from responses * Handle binary responses * Clean up dependencies and replace isomorphic-fetch Instead of isomorphic-fetch, which is unmaintained, we directly use node-fetch and whatwg-fetch polyfills. * Updated versions in ts-default/jquery and ts docs * Replaced isSuccessCode with is2xx * [TypeScript-Refactor] Use OAIv3 spec and fix bugs in JQuery Blob download (#6416) * Change to OAIv3 spec for TS-Refactor * Moved samples to oaiv3 folder * Updated package-lock * Update pom to use OAIv3 paths for Typescript-refactor * Renamed ts-refactor samples & tests in pom.xmls * Fixed compile issues in ts-refactor jquery http test * Fixed bugs in blob handling of jquery * [Typescript] Support http bearer authentication with token provider (#6425) * Add http bearer security * Update typescript to 3.9 * Fix: Use Authorization header for basic and bearer * Allow asynchronous tokenProvider in bearer auth * Add TS-Rewrite-Jquery tests node_modules to travis caching * Remove NoAuthentication * Added file to generate TS samples on Windows * Exclude btoa in browser * Regen samples * Remove outdated ToDo comments * Document and optimize `getReturnType` in TSClientCodegen * Added option to generate objects for operation function arguments * Upgrade typescript docs * Updated generators * Updated samples * Updated docs * Readded pom.xml * [Typescript] Support InversifyJS (#6489) * Add config option to enable InversifyJS * Add pascal case lambda for mustache * Generate a class for each auth method * Add service identifiers and service binder helper * Split Configuration into interface and factory This way we don't need to import the factory everywhere to do typechecking. * Define minimal interface for ServerConfiguration * Add annotations for inversify when enabled * Always expose list of server configurations * Add samples and defalt tests for useInversify * Simplify sample generation script * Fix: Add object_params arg description to help * Fix: Properly enable inversify with bool property * Build tests in pom instead of prepublish Otherwise running `npm install`, when the build failed was impossible. * Update dependencies for inversify tests * Test basic api service resolution * Remove Promise and Observable prefix from exports * Fix, RxJS: Import Observable in object params api * Add ioc service identifier for object param api * Add hint about unimpeded development * Simplify api service binder syntax * Remove default tests for inversify * Add wrapper for easy promise based http libraries This wrapper allows defining and injecting http libraries that do not need to know anything about observables, especially when useRxJS is not enabled. I will employ this in the tests for InversifyJS. Not sure if we should also use this wrapper internally. * Add named injects for remaining auth parameters * Directly inject promise services without RxJS * Add tests for api service binder * Add convenience method to bind all api services * Fix: Rename inversify test artifact * Run bin/utils/copy-to-website.sh * Restore changes to CONTRIBUTING.md from PR #6489 Co-authored-by: Bodo Graumann <mail@bodograumann.de> Co-authored-by: Esteban Gehring <esteban.gehring@bithost.ch>
|
Also there is issue with json. |
… jquery (#6341) * Added http module draft * Added generic enum * Modified http lib, added config & middleware definition to ts-fetch * Added model generation with imports * Added auth module * Added servers * Added sample for typescript client * WIP: Models & API * Updated auth * WIP: api modeling * Implemented RequestFactory and Processor completely * Implemented fetch client * Ignore dist folder in typescript client sample * Added middleware to fetch * Restructured TypeScript generator * Reverted: http library.send returns string again * Removed TODOs * Added pom.xml files to TypeScript PetStore client samples * Removed tabs from TypeScriptClientCodegen * Added ts client codegen to root pom.xml and travis * Added server variable configuration to ts-refactor * [TS-Refactor] Added tests for Object Serializer * Added simple test for PetApi * Fixed ObjectSerializer test * Added handling for different http status codes and test for deletePet * Removed tabs in TypeScriptClientCodegen * Removed tabs in DefaultCodegen * Additional tests for pet store api * Fixed file uploads * Made api call configuration separately settable * Use string union for enums * Remove tab * Restructured module layout * Use observables internally * Added promise based middleware * Made discriminator and attributeTypeMap readonly * Configure discriminator correctly * Set discriminator value automatically * Fixed date-time and date handling * Added comments & license info * Added comments * Ignore openapi-generator-cli/bin * Removed accidentally created generated code * Fixed compilation issues in TypeScriptClientCodegen * Added typescript to docs/generators * Updated docs * Added gitignore and git_push * Added jquery library * Added pom.xmls, fixed packagejsons and hopefully webppack * Removed tabs in TypeScriptClientCodegen * Fixed a couple issues with pom.xml * Ensured up to date * Fixed missing fetch definition in TS default tests * Updated typescript docs * Refactor typescript merge master (#4319) Merge master into ts-refactor * Typescript refactor: stub rxjs (#4424) * Remove unused supportsES6 field from codegen * Add a new switch for RXJS * Remove redundant npm dependency on rxjs4 types * Fix return type of PromiseMiddleware methods * Install webpack dependency to run jquery tests * Update form-data to 2.5 which includes typings * Add missing dependency on node typings * Fix test artifact name typo * Stub rxjs when it is not explicitly enabled * Typescript refactor: Platform select for browser and node (#4500) * Use string form of filename parameter This works for the form-data library and is also compatible with the browser FormData object. * Add new option to select platform node or browser When no platform is selected, a default is chosen by the framework option and likewise the file data type option is implied by the platform. * Remove redundant import of node dns module * Only use form-data library for node platform * Generate npm package from npmName option * Use method convertPropertyToBooleanAndWriteBack * Generate typescript samples with ensure-up-to-date * Removed tab from DefaultCodegen * Readded missing change * Mark typescript client codegen as experimental * Removed whitespace * [TS-Refactor] Top-level exports for fetch & jquery (#6138) * Added top-level exports * Updated generator README * Updated typescript generator docs * Allow browsers File type for files (#5521) * Allow passing file parameters as File objects * Add test for jquery upload * Use HttpFile object for node platform * Regenerate samples This is by far the most common use case. A `File` object already contains the name attribute. This commit allows that information to be used directly. When sending a `Blob`, in most browsers the `File` constructor can be used to assign a file name. In all other browsers the alternative is ```typescript Object.assign(data, { name: "foobar.txt" }); ``` That is why we explicitely pass the name as third parameter to `FormData.append`. This `Object.assign` method also works for `Buffer` objects in node. If one really does not want to touch the data object in the browser it is possible to define another reference to the data with ```typescript new Blob([data], { type: data.type }) ``` or in node via ```typescript Buffer.from(data) ``` * [TS-Refactor] Added options for npm version, repository, name and updated readme (#6139) * Added options for npm version, repository, name and updated readme * Removed `this` where not required * Updated typescript docs * Typescript refactor fixes (#6027) Fixes a handful of issues identified in OpenAPITools/openapi-generator#802 (comment) List of changes * Clean: Remove redundant cliOption definition * Remove redundant directory structure in templates If we need to have different index.ts files for the different frameworks, we can mostly do that in the one mustache file. In the cases where that is not possible, we can still add a new override file later. * Use File.separator consistently * Only export selected api type * Simplify promise polyfill import The behaviour should be the same, according to the es6-promise docs. Previously tsc would report the error: > error TS2307: Cannot find module 'es6-promise'. * Import HttpFile in all models * Export server configurations * Use undefined as default body value The empty string is not interpreted as "no body" by the browser fetch api and thus leads to an exception during get requests * Improve codestyle: prefer guards to nesting * Remove verbose debug output This should not be commited, because every developer has very different requirements what debug information he needs to see. * Fix: Use cleaned model names for imports * Fix: do not call toString on undefined * Fix typo in doc comment * Introduce RequestBody type and remove method check * Support media types other than json (#6177) List of changes: * Add */* as fallback to accept header * Use more sophisticated media type selection * Handle object stringify in ObjectSerializer * Parse response with ObejctSerializer * Fix: Correctly extract response headers in browser * Create HttpFile objects from responses * Handle binary responses * Clean up dependencies and replace isomorphic-fetch Instead of isomorphic-fetch, which is unmaintained, we directly use node-fetch and whatwg-fetch polyfills. * Updated versions in ts-default/jquery and ts docs * Replaced isSuccessCode with is2xx * [TypeScript-Refactor] Use OAIv3 spec and fix bugs in JQuery Blob download (#6416) * Change to OAIv3 spec for TS-Refactor * Moved samples to oaiv3 folder * Updated package-lock * Update pom to use OAIv3 paths for Typescript-refactor * Renamed ts-refactor samples & tests in pom.xmls * Fixed compile issues in ts-refactor jquery http test * Fixed bugs in blob handling of jquery * [Typescript] Support http bearer authentication with token provider (#6425) * Add http bearer security * Update typescript to 3.9 * Fix: Use Authorization header for basic and bearer * Allow asynchronous tokenProvider in bearer auth * Add TS-Rewrite-Jquery tests node_modules to travis caching * Remove NoAuthentication * Added file to generate TS samples on Windows * Exclude btoa in browser * Regen samples * Remove outdated ToDo comments * Document and optimize `getReturnType` in TSClientCodegen * Added option to generate objects for operation function arguments * Upgrade typescript docs * Updated generators * Updated samples * Updated docs * Readded pom.xml * [Typescript] Support InversifyJS (#6489) * Add config option to enable InversifyJS * Add pascal case lambda for mustache * Generate a class for each auth method * Add service identifiers and service binder helper * Split Configuration into interface and factory This way we don't need to import the factory everywhere to do typechecking. * Define minimal interface for ServerConfiguration * Add annotations for inversify when enabled * Always expose list of server configurations * Add samples and defalt tests for useInversify * Simplify sample generation script * Fix: Add object_params arg description to help * Fix: Properly enable inversify with bool property * Build tests in pom instead of prepublish Otherwise running `npm install`, when the build failed was impossible. * Update dependencies for inversify tests * Test basic api service resolution * Remove Promise and Observable prefix from exports * Fix, RxJS: Import Observable in object params api * Add ioc service identifier for object param api * Add hint about unimpeded development * Simplify api service binder syntax * Remove default tests for inversify * Add wrapper for easy promise based http libraries This wrapper allows defining and injecting http libraries that do not need to know anything about observables, especially when useRxJS is not enabled. I will employ this in the tests for InversifyJS. Not sure if we should also use this wrapper internally. * Add named injects for remaining auth parameters * Directly inject promise services without RxJS * Add tests for api service binder * Add convenience method to bind all api services * Fix: Rename inversify test artifact * Run bin/utils/copy-to-website.sh * Restore changes to CONTRIBUTING.md from PR #6489 Co-authored-by: Bodo Graumann <mail@bodograumann.de> Co-authored-by: Esteban Gehring <esteban.gehring@bithost.ch>
* [TypeScript] Rewritten TypeScript client generator supporting fetch & jquery (#6341) * Added http module draft * Added generic enum * Modified http lib, added config & middleware definition to ts-fetch * Added model generation with imports * Added auth module * Added servers * Added sample for typescript client * WIP: Models & API * Updated auth * WIP: api modeling * Implemented RequestFactory and Processor completely * Implemented fetch client * Ignore dist folder in typescript client sample * Added middleware to fetch * Restructured TypeScript generator * Reverted: http library.send returns string again * Removed TODOs * Added pom.xml files to TypeScript PetStore client samples * Removed tabs from TypeScriptClientCodegen * Added ts client codegen to root pom.xml and travis * Added server variable configuration to ts-refactor * [TS-Refactor] Added tests for Object Serializer * Added simple test for PetApi * Fixed ObjectSerializer test * Added handling for different http status codes and test for deletePet * Removed tabs in TypeScriptClientCodegen * Removed tabs in DefaultCodegen * Additional tests for pet store api * Fixed file uploads * Made api call configuration separately settable * Use string union for enums * Remove tab * Restructured module layout * Use observables internally * Added promise based middleware * Made discriminator and attributeTypeMap readonly * Configure discriminator correctly * Set discriminator value automatically * Fixed date-time and date handling * Added comments & license info * Added comments * Ignore openapi-generator-cli/bin * Removed accidentally created generated code * Fixed compilation issues in TypeScriptClientCodegen * Added typescript to docs/generators * Updated docs * Added gitignore and git_push * Added jquery library * Added pom.xmls, fixed packagejsons and hopefully webppack * Removed tabs in TypeScriptClientCodegen * Fixed a couple issues with pom.xml * Ensured up to date * Fixed missing fetch definition in TS default tests * Updated typescript docs * Refactor typescript merge master (#4319) Merge master into ts-refactor * Typescript refactor: stub rxjs (#4424) * Remove unused supportsES6 field from codegen * Add a new switch for RXJS * Remove redundant npm dependency on rxjs4 types * Fix return type of PromiseMiddleware methods * Install webpack dependency to run jquery tests * Update form-data to 2.5 which includes typings * Add missing dependency on node typings * Fix test artifact name typo * Stub rxjs when it is not explicitly enabled * Typescript refactor: Platform select for browser and node (#4500) * Use string form of filename parameter This works for the form-data library and is also compatible with the browser FormData object. * Add new option to select platform node or browser When no platform is selected, a default is chosen by the framework option and likewise the file data type option is implied by the platform. * Remove redundant import of node dns module * Only use form-data library for node platform * Generate npm package from npmName option * Use method convertPropertyToBooleanAndWriteBack * Generate typescript samples with ensure-up-to-date * Removed tab from DefaultCodegen * Readded missing change * Mark typescript client codegen as experimental * Removed whitespace * [TS-Refactor] Top-level exports for fetch & jquery (#6138) * Added top-level exports * Updated generator README * Updated typescript generator docs * Allow browsers File type for files (#5521) * Allow passing file parameters as File objects * Add test for jquery upload * Use HttpFile object for node platform * Regenerate samples This is by far the most common use case. A `File` object already contains the name attribute. This commit allows that information to be used directly. When sending a `Blob`, in most browsers the `File` constructor can be used to assign a file name. In all other browsers the alternative is ```typescript Object.assign(data, { name: "foobar.txt" }); ``` That is why we explicitely pass the name as third parameter to `FormData.append`. This `Object.assign` method also works for `Buffer` objects in node. If one really does not want to touch the data object in the browser it is possible to define another reference to the data with ```typescript new Blob([data], { type: data.type }) ``` or in node via ```typescript Buffer.from(data) ``` * [TS-Refactor] Added options for npm version, repository, name and updated readme (#6139) * Added options for npm version, repository, name and updated readme * Removed `this` where not required * Updated typescript docs * Typescript refactor fixes (#6027) Fixes a handful of issues identified in OpenAPITools/openapi-generator#802 (comment) List of changes * Clean: Remove redundant cliOption definition * Remove redundant directory structure in templates If we need to have different index.ts files for the different frameworks, we can mostly do that in the one mustache file. In the cases where that is not possible, we can still add a new override file later. * Use File.separator consistently * Only export selected api type * Simplify promise polyfill import The behaviour should be the same, according to the es6-promise docs. Previously tsc would report the error: > error TS2307: Cannot find module 'es6-promise'. * Import HttpFile in all models * Export server configurations * Use undefined as default body value The empty string is not interpreted as "no body" by the browser fetch api and thus leads to an exception during get requests * Improve codestyle: prefer guards to nesting * Remove verbose debug output This should not be commited, because every developer has very different requirements what debug information he needs to see. * Fix: Use cleaned model names for imports * Fix: do not call toString on undefined * Fix typo in doc comment * Introduce RequestBody type and remove method check * Support media types other than json (#6177) List of changes: * Add */* as fallback to accept header * Use more sophisticated media type selection * Handle object stringify in ObjectSerializer * Parse response with ObejctSerializer * Fix: Correctly extract response headers in browser * Create HttpFile objects from responses * Handle binary responses * Clean up dependencies and replace isomorphic-fetch Instead of isomorphic-fetch, which is unmaintained, we directly use node-fetch and whatwg-fetch polyfills. * Updated versions in ts-default/jquery and ts docs * Replaced isSuccessCode with is2xx * [TypeScript-Refactor] Use OAIv3 spec and fix bugs in JQuery Blob download (#6416) * Change to OAIv3 spec for TS-Refactor * Moved samples to oaiv3 folder * Updated package-lock * Update pom to use OAIv3 paths for Typescript-refactor * Renamed ts-refactor samples & tests in pom.xmls * Fixed compile issues in ts-refactor jquery http test * Fixed bugs in blob handling of jquery * [Typescript] Support http bearer authentication with token provider (#6425) * Add http bearer security * Update typescript to 3.9 * Fix: Use Authorization header for basic and bearer * Allow asynchronous tokenProvider in bearer auth * Add TS-Rewrite-Jquery tests node_modules to travis caching * Remove NoAuthentication * Added file to generate TS samples on Windows * Exclude btoa in browser * Regen samples * Remove outdated ToDo comments * Document and optimize `getReturnType` in TSClientCodegen * Added option to generate objects for operation function arguments * Upgrade typescript docs * Updated generators * Updated samples * Updated docs * Readded pom.xml * [Typescript] Support InversifyJS (#6489) * Add config option to enable InversifyJS * Add pascal case lambda for mustache * Generate a class for each auth method * Add service identifiers and service binder helper * Split Configuration into interface and factory This way we don't need to import the factory everywhere to do typechecking. * Define minimal interface for ServerConfiguration * Add annotations for inversify when enabled * Always expose list of server configurations * Add samples and defalt tests for useInversify * Simplify sample generation script * Fix: Add object_params arg description to help * Fix: Properly enable inversify with bool property * Build tests in pom instead of prepublish Otherwise running `npm install`, when the build failed was impossible. * Update dependencies for inversify tests * Test basic api service resolution * Remove Promise and Observable prefix from exports * Fix, RxJS: Import Observable in object params api * Add ioc service identifier for object param api * Add hint about unimpeded development * Simplify api service binder syntax * Remove default tests for inversify * Add wrapper for easy promise based http libraries This wrapper allows defining and injecting http libraries that do not need to know anything about observables, especially when useRxJS is not enabled. I will employ this in the tests for InversifyJS. Not sure if we should also use this wrapper internally. * Add named injects for remaining auth parameters * Directly inject promise services without RxJS * Add tests for api service binder * Add convenience method to bind all api services * Fix: Rename inversify test artifact * Run bin/utils/copy-to-website.sh * Restore changes to CONTRIBUTING.md from PR #6489 Co-authored-by: Bodo Graumann <mail@bodograumann.de> Co-authored-by: Esteban Gehring <esteban.gehring@bithost.ch> * Add Deno support to typescript(experimental) generator (#6732) * add 'deno' to typescript platforms * add Deno support to typescript generator * add Deno support to typescript generator * add Deno support to typescript generator * add Deno support to typescript generator * add Deno support to typescript generator * add extensionForDeno property for typescript generator * add URLParse Deno wrapper for typescript generator * update deno version in .travis.yml * [typescript] Fix generation of enum models (#7529) This fixes #665 for the consolidated typescript generator. Original fix for typescript-node was in PR #2266, merged as 8417c5bed0e23764dc841816c2322cf7dc4e9b0d in version 4.1.0. * Unifies naming for isArray in Schema class properties (#7691) * Updates key java files * Adds all lingering isArray fixes * Adds two files * Reverts two cs files * Fixes lingering isListContainer + isArrayModel references * Some ensure up to date updates * Removes secondaryParam and hasMore (#7882) * Removes secondaryParam and hasMore * Fixes tests * Only uses bodyParam in groovy template * Allows install typescript client via npm from Git (#7878) * Allows install typescript client via npm from Git 'prepublishOnly' is run before the package is published. 'prepack' is run before the package is published and after installation local installation eg. via Git. * Update examples for Typescript * [typescript(experimental)] fix for Deno v1.6 (#8265) * fix for Deno 1.6 * update dependency version of Deno test code * replace tab with spaces, minor code format change (#8775) * Apply template-patches/typescript-custom-license-header.patch * Apply template-patches/typescript-star-imports.patch * Apply template-patches/typescript-date-serialization.patch * Apply template-patches/typescript-user-agent.patch * Apply template-patches/typescript-alias-from-function.patch * Apply template-patches/typescript-per-endpoint-servers.patch * Regenerate client from commit 7e667f1 of spec repo Co-authored-by: Tino Fuhrmann <TiFu@users.noreply.github.com> Co-authored-by: Bodo Graumann <mail@bodograumann.de> Co-authored-by: Esteban Gehring <esteban.gehring@bithost.ch> Co-authored-by: Tomofumi Chiba <tomofumi.chiba@gmail.com> Co-authored-by: Justin Black <spacether@users.noreply.github.com> Co-authored-by: Adam Dobrawy <ad-m@users.noreply.github.com> Co-authored-by: William Cheng <wing328hk@gmail.com> Co-authored-by: Thomas Hervé <thomas.herve@datadoghq.com> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
… jquery (#6341) * Added http module draft * Added generic enum * Modified http lib, added config & middleware definition to ts-fetch * Added model generation with imports * Added auth module * Added servers * Added sample for typescript client * WIP: Models & API * Updated auth * WIP: api modeling * Implemented RequestFactory and Processor completely * Implemented fetch client * Ignore dist folder in typescript client sample * Added middleware to fetch * Restructured TypeScript generator * Reverted: http library.send returns string again * Removed TODOs * Added pom.xml files to TypeScript PetStore client samples * Removed tabs from TypeScriptClientCodegen * Added ts client codegen to root pom.xml and travis * Added server variable configuration to ts-refactor * [TS-Refactor] Added tests for Object Serializer * Added simple test for PetApi * Fixed ObjectSerializer test * Added handling for different http status codes and test for deletePet * Removed tabs in TypeScriptClientCodegen * Removed tabs in DefaultCodegen * Additional tests for pet store api * Fixed file uploads * Made api call configuration separately settable * Use string union for enums * Remove tab * Restructured module layout * Use observables internally * Added promise based middleware * Made discriminator and attributeTypeMap readonly * Configure discriminator correctly * Set discriminator value automatically * Fixed date-time and date handling * Added comments & license info * Added comments * Ignore openapi-generator-cli/bin * Removed accidentally created generated code * Fixed compilation issues in TypeScriptClientCodegen * Added typescript to docs/generators * Updated docs * Added gitignore and git_push * Added jquery library * Added pom.xmls, fixed packagejsons and hopefully webppack * Removed tabs in TypeScriptClientCodegen * Fixed a couple issues with pom.xml * Ensured up to date * Fixed missing fetch definition in TS default tests * Updated typescript docs * Refactor typescript merge master (#4319) Merge master into ts-refactor * Typescript refactor: stub rxjs (#4424) * Remove unused supportsES6 field from codegen * Add a new switch for RXJS * Remove redundant npm dependency on rxjs4 types * Fix return type of PromiseMiddleware methods * Install webpack dependency to run jquery tests * Update form-data to 2.5 which includes typings * Add missing dependency on node typings * Fix test artifact name typo * Stub rxjs when it is not explicitly enabled * Typescript refactor: Platform select for browser and node (#4500) * Use string form of filename parameter This works for the form-data library and is also compatible with the browser FormData object. * Add new option to select platform node or browser When no platform is selected, a default is chosen by the framework option and likewise the file data type option is implied by the platform. * Remove redundant import of node dns module * Only use form-data library for node platform * Generate npm package from npmName option * Use method convertPropertyToBooleanAndWriteBack * Generate typescript samples with ensure-up-to-date * Removed tab from DefaultCodegen * Readded missing change * Mark typescript client codegen as experimental * Removed whitespace * [TS-Refactor] Top-level exports for fetch & jquery (#6138) * Added top-level exports * Updated generator README * Updated typescript generator docs * Allow browsers File type for files (#5521) * Allow passing file parameters as File objects * Add test for jquery upload * Use HttpFile object for node platform * Regenerate samples This is by far the most common use case. A `File` object already contains the name attribute. This commit allows that information to be used directly. When sending a `Blob`, in most browsers the `File` constructor can be used to assign a file name. In all other browsers the alternative is ```typescript Object.assign(data, { name: "foobar.txt" }); ``` That is why we explicitely pass the name as third parameter to `FormData.append`. This `Object.assign` method also works for `Buffer` objects in node. If one really does not want to touch the data object in the browser it is possible to define another reference to the data with ```typescript new Blob([data], { type: data.type }) ``` or in node via ```typescript Buffer.from(data) ``` * [TS-Refactor] Added options for npm version, repository, name and updated readme (#6139) * Added options for npm version, repository, name and updated readme * Removed `this` where not required * Updated typescript docs * Typescript refactor fixes (#6027) Fixes a handful of issues identified in OpenAPITools/openapi-generator#802 (comment) List of changes * Clean: Remove redundant cliOption definition * Remove redundant directory structure in templates If we need to have different index.ts files for the different frameworks, we can mostly do that in the one mustache file. In the cases where that is not possible, we can still add a new override file later. * Use File.separator consistently * Only export selected api type * Simplify promise polyfill import The behaviour should be the same, according to the es6-promise docs. Previously tsc would report the error: > error TS2307: Cannot find module 'es6-promise'. * Import HttpFile in all models * Export server configurations * Use undefined as default body value The empty string is not interpreted as "no body" by the browser fetch api and thus leads to an exception during get requests * Improve codestyle: prefer guards to nesting * Remove verbose debug output This should not be commited, because every developer has very different requirements what debug information he needs to see. * Fix: Use cleaned model names for imports * Fix: do not call toString on undefined * Fix typo in doc comment * Introduce RequestBody type and remove method check * Support media types other than json (#6177) List of changes: * Add */* as fallback to accept header * Use more sophisticated media type selection * Handle object stringify in ObjectSerializer * Parse response with ObejctSerializer * Fix: Correctly extract response headers in browser * Create HttpFile objects from responses * Handle binary responses * Clean up dependencies and replace isomorphic-fetch Instead of isomorphic-fetch, which is unmaintained, we directly use node-fetch and whatwg-fetch polyfills. * Updated versions in ts-default/jquery and ts docs * Replaced isSuccessCode with is2xx * [TypeScript-Refactor] Use OAIv3 spec and fix bugs in JQuery Blob download (#6416) * Change to OAIv3 spec for TS-Refactor * Moved samples to oaiv3 folder * Updated package-lock * Update pom to use OAIv3 paths for Typescript-refactor * Renamed ts-refactor samples & tests in pom.xmls * Fixed compile issues in ts-refactor jquery http test * Fixed bugs in blob handling of jquery * [Typescript] Support http bearer authentication with token provider (#6425) * Add http bearer security * Update typescript to 3.9 * Fix: Use Authorization header for basic and bearer * Allow asynchronous tokenProvider in bearer auth * Add TS-Rewrite-Jquery tests node_modules to travis caching * Remove NoAuthentication * Added file to generate TS samples on Windows * Exclude btoa in browser * Regen samples * Remove outdated ToDo comments * Document and optimize `getReturnType` in TSClientCodegen * Added option to generate objects for operation function arguments * Upgrade typescript docs * Updated generators * Updated samples * Updated docs * Readded pom.xml * [Typescript] Support InversifyJS (#6489) * Add config option to enable InversifyJS * Add pascal case lambda for mustache * Generate a class for each auth method * Add service identifiers and service binder helper * Split Configuration into interface and factory This way we don't need to import the factory everywhere to do typechecking. * Define minimal interface for ServerConfiguration * Add annotations for inversify when enabled * Always expose list of server configurations * Add samples and defalt tests for useInversify * Simplify sample generation script * Fix: Add object_params arg description to help * Fix: Properly enable inversify with bool property * Build tests in pom instead of prepublish Otherwise running `npm install`, when the build failed was impossible. * Update dependencies for inversify tests * Test basic api service resolution * Remove Promise and Observable prefix from exports * Fix, RxJS: Import Observable in object params api * Add ioc service identifier for object param api * Add hint about unimpeded development * Simplify api service binder syntax * Remove default tests for inversify * Add wrapper for easy promise based http libraries This wrapper allows defining and injecting http libraries that do not need to know anything about observables, especially when useRxJS is not enabled. I will employ this in the tests for InversifyJS. Not sure if we should also use this wrapper internally. * Add named injects for remaining auth parameters * Directly inject promise services without RxJS * Add tests for api service binder * Add convenience method to bind all api services * Fix: Rename inversify test artifact * Run bin/utils/copy-to-website.sh * Restore changes to CONTRIBUTING.md from PR #6489 Co-authored-by: Bodo Graumann <mail@bodograumann.de> Co-authored-by: Esteban Gehring <esteban.gehring@bithost.ch>
IMO it's critical that the generalized Typescript generator has a lot more explanation in its readme pertaining to what it is and whether or not people should use it. It's pretty confusing seeing "Typescript" and "Typescript-Fetch" right next to each other, with only this to distinguish them:
|
Hello, |
Motivation
We currently have 7 (!) different generators for TypeScript, which do not share common code. This makes introducing bug fixes to the TypeScript generator family very hard.
Goal
Create a general framework which can be used in any OOP language - unifying the generator structure and making the project easier to work with. At the beginning, I would like to look into merging the TypeScript generators into one and improve the architecture during the implementation.
Feedback
Tear the architecture apart! Focus on the bigger picture first (e.g. missing some important feature? something which is hard to implement with this architecture?) and then go into details (e.g. missing variables).
The TODOs in the text below mark parts which I did not think (enough) about yet. Feel free to fill in what's missing.
Architecture
Architecture (looks weird if I include it as an image. sorry!)
The key idea is to extract everything into its own component and hide it behind an interface. The key advantage of this architecture is
I'll go through the different components one by one and try to explain the idea.
HTTP Library
This part should be clear - hide the details of making a HTTP request behind an interface so that we can use different libraries without changing the API Client. To achieve this we create our own data structures for requests and responses.
TODO: Use promises/futures?
Authentication
Same idea as HTTP library.
I want to highlight one part: the authentication interface has a method
apply(Request r)
. This method applies the authentication scheme to the given request e.g. in the case of an API Key it would append the api key.TODO: OAuth work flow with this implementation?
Response Models & Param Models
TODO: Should this be separated or can response & param models be used interchangeably? i.e. param Pet can also be a response model? If yes these two components should be merged.
This component contains model classes for each parameter & response as well as a (object) serializer and deserializer for these models (e.g.
Array<JsonObject>
in the API response is transformed toArray<Pet>
by the ObjectDeserializer).Server
This component contains the different servers as defined in OAS.
TODO: handling of variables. I would propose to offer setters for each variable.
Variables are not yet supported in OpenAPITools. See #793
Config
See current implementation.
API Client
The API client coordinates all other components.
r
Server#apply(r)
Callbacks in OAS 3
TODO: create server, hide it behind an interface to make the library exchangeable and create one method for each callback endpoint.
Framework Specific Code
Anything framework specific goes here and acts as a proxy to
APIClient
.Technical Committee
@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01)
Project
William created a project for this issue: https://github.com/OpenAPITools/openapi-generator/projects/4
The text was updated successfully, but these errors were encountered: