-
-
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
[C++][Pistache] Generate API generalization interface #15279
Merged
wing328
merged 11 commits into
OpenAPITools:master
from
CTerasa-ep:cppPistacheAddApiBase
Apr 26, 2023
Merged
[C++][Pistache] Generate API generalization interface #15279
wing328
merged 11 commits into
OpenAPITools:master
from
CTerasa-ep:cppPistacheAddApiBase
Apr 26, 2023
Conversation
This file contains 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
4cbad14
to
ed0a9d8
Compare
Supporting files are set up in the CppPistacheServerCodegen() constructor as well as in processOpts(). Refactor the code and extract a method setupSupportingFiles().
Both branches of the if/else do the same steps. Refactor this out and invert logic.
Both branches of the if/else if do the similar steps and are dependent on the suffix. Make this obvious by introducing a new method injectImplInFilename(String result, String suffix).
We do not need the separatorChar index to inject the "Impl" string. Simply truncate the whole string. Also rename the parameter from 'result' to' filename'.
Pull out the post-processing for a single operation, and also pull out post-processing for parameters. Introduce boolean expressions for supported parsing per parameter, and consumption of JSON. Reorder code to make locality more explicit i.e. how consumeJSON and isParsingSupported is generated and used.
Functional matching like anyMatch() directly state what boolean value is searched. However, the Predicates deserve to heave names themselves.
Looking at the generated main-api-server.cpp code it gets obvious that the API classes are self similar with a similar interface. Only the construction and teh initialization is called in the main() function. Leverage this fact to create a generalization ApiBase. Introduce ApiBase as a pure virtual base class to the concrete API classes and declare init() as virtual. Pull the route member into the base class. With this change we could have a container hold all the ApiImpl objects later and call init() on all of them using a for_each loop.
Refactor the main-api-server template to use a vector for ApiImpl storage instead of separate objects. This leverages the previously added ApiBase generalization. We push all concrete ApiImpl objects into a vector and call init() on each of them.
Due to teh addition of ApiBase class update the generated sample.
wing328
reviewed
Apr 26, 2023
...api-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java
Show resolved
Hide resolved
wing328
reviewed
Apr 26, 2023
...api-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java
Outdated
Show resolved
Hide resolved
While writing the comment, I realized that the method name could be more precise. Thus rename injectImplInFilename to implFilenameFromApiFilename and add comment.
muttleyxd
approved these changes
Apr 26, 2023
C++ and template code looks good to me |
Great! Thank you for the feedback and your effort! |
sjoubert
added a commit
to sjoubert/openapi-generator
that referenced
this pull request
May 10, 2023
This is following OpenAPITools#15279 Marking those methods 'override' should avoid producing '-Winconsistent-missing-override' warnings or similar.
6 tasks
wing328
pushed a commit
that referenced
this pull request
May 16, 2023
This is following #15279 Marking those methods 'override' should avoid producing '-Winconsistent-missing-override' warnings or similar.
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.
The code generated for
main()
contains self-similar construction of, and calls to API implementation classes.Example:
This sceams for OO generalization.
We could then store all
*server
objects inside one vector of API implementations and callinit()
on all of them.This patch set refactors some Pistache generator code and introduces a base class for APIs called ApiBase and adds tehe above construction code.
Additionally do some refactoring work in the Pistache generator code, that leverage some functional
stream()
methods that may make some intentions more explicit.Technical Committee C++:
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
(6.3.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks)