-
Notifications
You must be signed in to change notification settings - Fork 8
feat(go): patch iaas/AreaID after generation to fix oneOf regex issue #277
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
Open
cgoetz-inovex
wants to merge
8
commits into
main
Choose a base branch
from
feat/STACKITSDK-226-post-process-patch-file
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a27ffa4
feat(go): patch iaas/AreaID after generation to fix oneOf regex issue
cgoetz-inovex 7956e39
feat(go): make file overrides configurable, add iaas overrides
cgoetz-inovex 41c2c03
Merge branch 'main' into feat/STACKITSDK-226-post-process-patch-file
cgoetz-inovex a9a6f6b
fix(ci): bump java version
cgoetz-inovex 6ea4534
feat(generator): rework custom generators, support java overrides
cgoetz-inovex ef502c2
fix(PostProcessFileReplace): don't use _ as lambda param
cgoetz-inovex d2eb282
Merge branch 'main' into feat/STACKITSDK-226-post-process-patch-file
cgoetz-inovex 6c88c66
fix(iaas): add overrides for VPCNetworkRanges
cgoetz-inovex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import org.openapitools.codegen.languages.JavaClientCodegen; | ||
| import shared.PostProcessFileReplace; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| public class JavaGenerator extends JavaClientCodegen { | ||
| private static PostProcessFileReplace postProcessFileReplace = new PostProcessFileReplace("overrides/java"); | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "JavaClientCodegen"; | ||
| } | ||
|
|
||
| public JavaGenerator(){ | ||
| super(); | ||
| System.out.println("=== Custom Java Generator initialized ==="); | ||
| } | ||
|
|
||
| @Override | ||
| public void postProcessFile(File file, String fileType) { | ||
| postProcessFileReplace.process(file); | ||
| super.postProcessFile(file, fileType); | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # Custom Generators | ||
|
|
||
| Customized templates are painful when updating the generator. Each template has to be compared with upstream and adapted | ||
| accordingly. | ||
|
|
||
| We use custom generators for introducing workarounds and fixes to not further customize our templates. | ||
|
|
||
| ## Structure | ||
|
|
||
| Custom generators live in this directory. For each language with a custom generator there should be a `<lang>Generator.java` | ||
| file. Each fix/workaround should live in its own class and be called from the `<lang>Generator.java` file. This allows | ||
| easy removal of such fixes, when they are no longer needed. | ||
|
|
||
| Fixes, applicable to multiple languages, should be implemented in the `shared` package. | ||
|
|
||
| We try to only use the JDK and no external libraries besides the `openapi-generator` itself to keep a simple build step. | ||
|
|
||
| ## How Custom Generators are executed | ||
|
|
||
| Each language with a custom generator, needs an adapted `<lang>.sh` script. Before building each service the custom | ||
| generator has to be built: | ||
|
|
||
| ```bash | ||
| # compile custom generator | ||
| cd ${ROOT_DIR} | ||
| mkdir -p custom | ||
| javac -cp "${GENERATOR_JAR_PATH}" -d custom $(find ./scripts/generators -type f -name '*.java' | grep -v overrides) | ||
| ``` | ||
|
|
||
| This compiles all java files into the `custom` directory. Here we also exclude java files in the `overrides` directory. | ||
| These are resources and should not be compiled in this step. | ||
|
|
||
| The generator call itself has to be adapted: | ||
|
|
||
| ```bash | ||
| java -Dlog.level="${GENERATOR_LOG_LEVEL}" -cp "custom:${GENERATOR_JAR_PATH}:scripts/generators" \ | ||
| org.openapitools.codegen.OpenAPIGenerator generate \ | ||
| --generator-name JavaGenerator \ | ||
| --enable-post-process-file \ | ||
| # more params | ||
| ``` | ||
|
|
||
| We have to: | ||
| - extend the classpath: `custom` makes the compiled custom generator available, `scripts/genrators` the `overrides` | ||
| resources | ||
| - the `generator-name` needs to be changed to the fully-qualified class name of the custom generator | ||
| - `enable-post-process-file` has to be activated to support `overrides` | ||
|
|
||
| ## Implemented Fixes | ||
|
|
||
| ### Go: Region Param Adjustment | ||
|
|
||
| - we use `RESOLVE_INLINE_ENUMS` | ||
| - this creates model classes for inline enums | ||
| - this leads to a lot of different types for region enums with the same options | ||
| - which makes the API hard to use | ||
| - we force a string parameter instead | ||
|
|
||
| ### Go/Java: Overrides | ||
|
|
||
| - there are some usages of `oneOf` schemas in our API specs, that are correct schema wise, but the generated code fails | ||
| - example: `{ "type": "cidrv4", "value": string }`, `{ "type": "cidrv6", "value": string }` both, have the same shape | ||
| - but they use different patterns for `value` | ||
| - some language generators do not apply the pattern when validating the `oneOf` and report a false positive violation | ||
| - fixing this upstream would be very involved | ||
| - we fix it by replacing after generating sources, by replacing files | ||
|
|
||
| How to configure an override: | ||
| - edit the `overrides.properties` file for the language in question | ||
| - to override a single file you need 3 properties: `<name>.path`, `<name>.replacementPath` and `<name>.hash` | ||
| - `<name>` has to be equal for all 3 properties | ||
| - `path` is used to match the generated file, which should be replaced | ||
| - `hash` is used to check that the generated file still has the same content as when the override was configured | ||
| - `replacementPath` specifies the file in resources, that should be used as replacement | ||
| - mark adjusted sections in the replacement file in resources with an `OVERRIDE:` comment |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| iaasV2ApiAreaId.path=iaas/v2api/model_area_id.go | ||
| iaasV2ApiAreaId.replacementPath=v2api_model_area_id.go | ||
| iaasV2ApiAreaId.hash=b7425456c4633b2e8c0a61e9ab3b579e | ||
|
|
||
| iaasV1ApiAreaId.path=iaas/v1api/model_area_id.go | ||
| iaasV1ApiAreaId.replacementPath=v1api_model_area_id.go | ||
| iaasV1ApiAreaId.hash=a9d72364fec0794cab3b51f3680de584 | ||
|
|
||
| iaasV2BetaApiAreaId.path="iaas/v2beta1api/model_area_id.go | ||
| iaasV2BetaApiAreaId.replacementPath=v2beta_model_area_id.go | ||
| iaasV2BetaApiAreaId.hash=bb5583419348ee95ebbde0b4133a36f0 | ||
Oops, something went wrong.
Oops, something went wrong.
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.
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.
quote in prefix. This prevents also that the file will be replaced