-
Notifications
You must be signed in to change notification settings - Fork 191
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
Generate client code from OpenAPI specification #366
Generate client code from OpenAPI specification #366
Conversation
@Xtansia do you have an examples of request / response models the generator produces? thank you! |
Sorry missed that, they look pretty close to what we have inherited (comparing to just template changes). |
@Xtansia this is amazing work! The generated client and req/res look very similar to the existing APIs.
|
love it, how can we move it closer to something we can merge? ++ stick a header on all generated files that say "this file is generated, don't edit" or something like that |
@dblock & @reta, I have added the warning header & refactored the transform logic to what I feel is a lot clearer. I've also managed to pull the few more complicated mustache "lambdas"/getters out to primarily templates, with some more minor code logic just to handle recursiveness. |
@Xtansia this is pretty cool, just from your perspective as implementor: how difficult it would be to keep OpenAPI and our own generator in sync (if it makes at all)? Specifically, I have in mind bugfixes and missing OpenAPI 3.1 features (the 3.1 support is still experimental and not fully implemented). As for a spec, I've found this outdated but pretty comprehensive snippet [1], I converted it to 3.x using Swagger Editor, we could try to use it meantime (for a sake to filling any implementation gaps), thanks [1] https://gist.github.com/rodripf/cd7a410b5ca7a91a1a4331d4ac7b1bcb |
e7a4fd5
to
f7cde43
Compare
9e93b3b
to
3d5f9c8
Compare
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
That's a fair point and I think in the long run it would make sense to have this in a separate repo. However at the moment it's not yet at a stable point where this makes sense to actively publish for others. The first primary goal is in getting part or all of the Java client being generated so this initial period of iteration and development is going to be inextricably tied to attempts to generate more operations and covering any missed edge cases etc. So I think it's reasonable for it to live here until it has stabilised somewhat as long as we aren't releasing it from here. |
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.
This is great!! The only comment I have (after a high level review) looking from previous comments is: if at all there is a chance for this generator to be moved out of this repo, could we make the generator classes restricted to use for consumers? Mostly no user would end up using them but if we move out public classes out of the repo, we might end up with breaking changes and a major version increment.
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.
Merge?
No objections, we are not going to backport it to |
Why not? Assuming we don't introduce breaking changes we should be able to swap manual authoring for a generator. Leaving this to @Xtansia. |
If we do, we need clearly document that this is new experimental module with all the limitations it has now - we do make releases from 2.x and the new module will be published |
I don't think I'm following, the generator is just a tool, the actual code of the client being released will not change. |
Correct, but will we release the tool as part of client release? |
I don't think so. Extracting the tool into something releasing on itself could make sense, but otherwise no. |
No objections, sounds good to me |
@reta I've removed the publish config from the build.gradle of the generator so it won't get published |
@Xtansia merge at will |
@dblock I'm happy for it to be merged if everyone else is, I can't do it myself as I'm not a maintainer |
Oh yeah? ;) Looking forward to that spec to be fully generated. |
@VachaShah I would think this should not be an issue as long as we aren't publishing the generator to maven etc. For someone to rely on the classes of the generator they'd need to be building from source. AFAIK Java doesn't have a good mechanism to restrict access to the classes in a useful way as they need to be |
* OpenAPI generator from scratch Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Write to files and generate object shapes Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Output response shapes and enum shapes Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Fix builder setters for enums Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Better handling of required fields Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Unify templates for ObjectShape/OperationRequest Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Simple http path expression Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate client class Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Cleanup Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate namespaces remote store client Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Add license header, improve http path builder, fix remote store spec Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Suppress checkstyle unused imports lint for generated code Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Centralize some naming Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Allow renaming operations Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Add generated warning header Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Refactor Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Less code more templates Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Simplify http path part Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Fixes Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Swap to swagger-parser Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Handle x-data-type & array response bodies Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Handle multiple http paths for same operation Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Improve type handling Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Tweak package name determination Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Handle additionalProperties on ErrorCause Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Simplify enum shape Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Change default number type Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate parameter-less operation method when no required fields Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Refactor to parse multi-file spec Signed-off-by: Thomas Farr <tsfarr@amazon.com> * spotlessApply Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Use spotless to format code Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Maintain spec location information Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Refactor model transformation and type mapper Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Match existing naming scheme Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Change OperationGroup matching logic to determine which to generate Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Better handle errors thrown by formatter Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Add typedef comment Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Support tagged union Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Add additional reserved keywords Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Improve parsing logic Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Add basic tests and implement proper argument parsing Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Improve tagged union generation and filter global query params Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Change enum naming style Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Handle Time type Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Handle deprecation Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Clear operations to generate Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Change usages of `<stream>.toList()` to `<stream>.collect(Collectors.toList())` Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Remove publishing from build.gradle Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Cleaning up Signed-off-by: Thomas Farr <tsfarr@amazon.com> * spotless Signed-off-by: Thomas Farr <tsfarr@amazon.com> --------- Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit bb995ec)
* Generate client code from OpenAPI specification (#366) * OpenAPI generator from scratch Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Write to files and generate object shapes Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Output response shapes and enum shapes Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Fix builder setters for enums Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Better handling of required fields Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Unify templates for ObjectShape/OperationRequest Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Simple http path expression Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate client class Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Cleanup Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate namespaces remote store client Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Add license header, improve http path builder, fix remote store spec Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Suppress checkstyle unused imports lint for generated code Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Centralize some naming Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Allow renaming operations Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Add generated warning header Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Refactor Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Less code more templates Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Simplify http path part Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Fixes Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Swap to swagger-parser Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Handle x-data-type & array response bodies Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Handle multiple http paths for same operation Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Improve type handling Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Tweak package name determination Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Handle additionalProperties on ErrorCause Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Simplify enum shape Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Change default number type Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate parameter-less operation method when no required fields Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Refactor to parse multi-file spec Signed-off-by: Thomas Farr <tsfarr@amazon.com> * spotlessApply Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Use spotless to format code Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Maintain spec location information Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Refactor model transformation and type mapper Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Match existing naming scheme Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Change OperationGroup matching logic to determine which to generate Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Better handle errors thrown by formatter Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Add typedef comment Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Support tagged union Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Add additional reserved keywords Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Improve parsing logic Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Add basic tests and implement proper argument parsing Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Improve tagged union generation and filter global query params Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Change enum naming style Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Handle Time type Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Handle deprecation Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Clear operations to generate Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Change usages of `<stream>.toList()` to `<stream>.collect(Collectors.toList())` Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Remove publishing from build.gradle Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Cleaning up Signed-off-by: Thomas Farr <tsfarr@amazon.com> * spotless Signed-off-by: Thomas Farr <tsfarr@amazon.com> --------- Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit bb995ec) * Bump commons-codec:commons-codec from 1.11.0 to 1.17.0 in java-codegen (#1023) Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit 13982b1) * Regenerate request/response for the `info` operation (#1026) * Tweak formatting rules used by codegen to allow reformatting javadoc Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Support codegen for request shapes that may be singleton Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate info operation shapes Signed-off-by: Thomas Farr <tsfarr@amazon.com> --------- Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit dea7e72) * Enforce & fix license headers (#1027) * Enforce license headers Signed-off-by: Thomas Farr <tsfarr@amazon.com> * spotlessApply Signed-off-by: Thomas Farr <tsfarr@amazon.com> --------- Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit 5d5c6b5) * Add `@Generated` annotation to generated classes (#1029) Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit 767c313) * Begin generating client implementations (#1052) * Tweak client generation to extend from existing classes Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Modify existing client classes to be abstract base classes Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Re-run generator Signed-off-by: Thomas Farr <tsfarr@amazon.com> * ./gradlew spotlessApply Signed-off-by: Thomas Farr <tsfarr@amazon.com> --------- Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit dbde609) * Bump org.junit:junit-bom from 5.10.2 to 5.10.3 (#1062) * Bump org.junit:junit-bom from 5.10.2 to 5.10.3 Bumps [org.junit:junit-bom](https://github.com/junit-team/junit5) from 5.10.2 to 5.10.3. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](junit-team/junit5@r5.10.2...r5.10.3) Signed-off-by: Thomas Farr <tsfarr@amazon.com> --- updated-dependencies: - dependency-name: org.junit:junit-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Update changelog Signed-off-by: dependabot[bot] <support@github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com> (cherry picked from commit af769c8) * Bump org.owasp.dependencycheck from 9.2.0 to 10.0.2 (#1069) * Bump org.owasp.dependencycheck from 9.2.0 to 10.0.2 Bumps org.owasp.dependencycheck from 9.2.0 to 10.0.2. Signed-off-by: Thomas Farr <tsfarr@amazon.com> --- updated-dependencies: - dependency-name: org.owasp.dependencycheck dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Update changelog Signed-off-by: dependabot[bot] <support@github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com> (cherry picked from commit 848be31) * Add workflow to auto-update codegen (#1065) Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit 0cf11db) * Fix handling of OpenAPI schemas with multiple types (#1102) Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit eff1ae1) * Regenerate dangling_indices namespace (#1124) * Rename genericArgs to typeParams Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Fix required path param handling Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Correctly generate AcknowledgedResponseBase Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate DeleteDanglingIndexRequest Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Correctly generate DeleteDanglingIndexResponse Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate import_dangling_index Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate ListDanglingIndicesRequest Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate ErrorCause Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate NodeStatistics Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate DanglingIndex Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate ListDanglingIndicesResponse Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate DanglingIndicesClient Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Fixes Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Changelog and Upgrading Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Fix javadoc Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Fix tests Signed-off-by: Thomas Farr <tsfarr@amazon.com> --------- Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit 324f90a) * Bump com.github.jk1.dependency-license-report from 2.8 to 2.9 (#1144) Bumps com.github.jk1.dependency-license-report from 2.8 to 2.9. Signed-off-by: Thomas Farr <tsfarr@amazon.com> --- updated-dependencies: - dependency-name: com.github.jk1.dependency-license-report dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> (cherry picked from commit 08e7e65) * Tweak codegen logic for formatting, documentation and handling of anyOf (#1152) * Re-generate code Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Improve builder doc comments Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Fix list/map isDefined serialize logic Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Add support for deprecated enums Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Improve isDefined logic Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Allow overriding request/response naming Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Support anyOf Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Update spec Signed-off-by: Thomas Farr <tsfarr@amazon.com> * spotlessApply Signed-off-by: Thomas Farr <tsfarr@amazon.com> --------- Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit 7b954af) * Generate the ml namespace (#1158) * Generate ml.register_model_group Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Start neural search sample Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Re-generate ShardStatistics Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Re-generate ShardFailure Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Re-generate Result Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Re-generate WriteResponseBase Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate ml.delete_model_group Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate ml.register_model Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Exclude legacy license from ml namespace Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate ml.get_task Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate ml.delete_task Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate ml.delete_model Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate ml.deploy_model Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate ml.undeploy_model Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Complete neural search sample Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate ml.get_model Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Add changelog entry Signed-off-by: Thomas Farr <tsfarr@amazon.com> * note Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Fix tests Signed-off-by: Thomas Farr <tsfarr@amazon.com> --------- Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit c6e61e1) * Invert abstractness of generated vs "handwritten" client classes (#1170) * Invert abstractness of generated vs "handwritten" client classes Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Address review comments Signed-off-by: Thomas Farr <tsfarr@amazon.com> --------- Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit 42e2928) * Temporarily disable code gen up-to-date check Signed-off-by: Thomas Farr <tsfarr@amazon.com> --------- Signed-off-by: Thomas Farr <tsfarr@amazon.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Description
As I mentioned in #284 (comment) this is a PoC creating a code generator that uses OpenAPI specs from scratch (ie. not based off openapi-generator). The code is not feature complete and not production ready.
Please direct general comments/discussion about the topic to the issue to keep things consolidated.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.