-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typescript-angular): add options to override angular deps + refa…
…ctor deps definition add tsVersion, rxjsVersion, ngPackagrVersion and zonejsVersion options to override default config if new version of Angular is available but not yet implemented in openapi-generator refactor Angular dependencies definition in separate readable yaml config file fix #20204
- Loading branch information
Thibaud SOWA
committed
Nov 29, 2024
1 parent
21d19fe
commit e2746e2
Showing
7 changed files
with
250 additions
and
118 deletions.
There are no files selected for viewing
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
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
69 changes: 69 additions & 0 deletions
69
modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/YamlConfigUtils.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.openapitools.codegen.utils; | ||
|
||
import org.yaml.snakeyaml.LoaderOptions; | ||
import org.yaml.snakeyaml.TypeDescription; | ||
import org.yaml.snakeyaml.Yaml; | ||
import org.yaml.snakeyaml.constructor.Constructor; | ||
import org.yaml.snakeyaml.introspector.BeanAccess; | ||
import org.yaml.snakeyaml.nodes.MappingNode; | ||
import org.yaml.snakeyaml.nodes.Node; | ||
import org.yaml.snakeyaml.nodes.Tag; | ||
|
||
import java.io.InputStream; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class YamlConfigUtils { | ||
|
||
/** | ||
* Load yaml config file as map | ||
* | ||
* @param configFile yaml config file to load | ||
* @param clazz class of object to map data | ||
* @param <T> type of config object to generate | ||
* @return config object generated | ||
*/ | ||
public static <T> Map<String, T> loadAsMap(String configFile, Class<T> clazz) { | ||
LoaderOptions loaderOptions = new LoaderOptions(); | ||
loaderOptions.setAllowDuplicateKeys(false); | ||
|
||
Yaml yaml = new Yaml(new MapConstructor(loaderOptions, clazz)); | ||
yaml.setBeanAccess(BeanAccess.FIELD); | ||
InputStream inputStream = YamlConfigUtils.class | ||
.getClassLoader() | ||
.getResourceAsStream(configFile); | ||
|
||
return yaml.load(inputStream); | ||
} | ||
|
||
private static class MapConstructor extends Constructor { | ||
private final TypeDescription itemType; | ||
|
||
public <T> MapConstructor(LoaderOptions loaderOptions, Class<T> clazz) { | ||
super(loaderOptions); | ||
this.rootTag = new Tag("root"); | ||
itemType = new TypeDescription(clazz); | ||
this.addTypeDescription(itemType); | ||
} | ||
|
||
@Override | ||
protected Object constructObject(Node node) { | ||
if ("root".equals(node.getTag().getValue()) && node instanceof MappingNode) { | ||
MappingNode mNode = (MappingNode) node; | ||
return mNode.getValue().stream().collect( | ||
Collectors.toMap( | ||
t -> super.constructObject(t.getKeyNode()), | ||
t -> { | ||
Node child = t.getValueNode(); | ||
child.setType(itemType.getType()); | ||
return super.constructObject(child); | ||
} | ||
) | ||
); | ||
|
||
} else { | ||
return super.constructObject(node); | ||
} | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...openapi-generator/src/main/resources/typescript-angular/angularDependenciesByVersion.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# For future versions... | ||
# Get typescript and rxjs version here: https://angular.dev/reference/versions | ||
# Get zone.js version here: https://github.com/angular/angular/blob/main/packages/core/package.json | ||
19.0.0: | ||
tsVersion: '>=5.5.0 <5.7.0' | ||
rxjsVersion: 7.4.0 | ||
ngPackagrVersion: 19.0.0 | ||
zonejsVersion: 0.15.0 | ||
18.1.0: | ||
tsVersion: '>=5.4.0 <5.6.0' | ||
rxjsVersion: 7.4.0 | ||
ngPackagrVersion: 18.1.0 | ||
zonejsVersion: 0.14.7 | ||
18.0.0: | ||
tsVersion: '>=5.4.0 <5.5.0' | ||
rxjsVersion: 7.4.0 | ||
ngPackagrVersion: 18.0.0 | ||
zonejsVersion: 0.14.7 | ||
17.0.0: | ||
tsVersion: '>=4.9.3 <5.3.0' | ||
rxjsVersion: 7.4.0 | ||
ngPackagrVersion: 17.0.3 | ||
zonejsVersion: 0.14.0 | ||
16.1.0: | ||
tsVersion: '>=4.9.3 <5.2.0' | ||
rxjsVersion: 7.4.0 | ||
ngPackagrVersion: 16.0.0 | ||
zonejsVersion: 0.13.0 | ||
16.0.0: | ||
tsVersion: '>=4.9.3 <5.1.0' | ||
rxjsVersion: 7.4.0 | ||
ngPackagrVersion: 16.0.0 | ||
zonejsVersion: 0.13.0 | ||
15.0.0: | ||
tsVersion: '>=4.8.2 <4.10.0' | ||
rxjsVersion: 7.5.5 | ||
ngPackagrVersion: 15.0.2 | ||
zonejsVersion: 0.11.5 | ||
14.0.0: | ||
tsVersion: '>=4.6.0 <=4.8.0' | ||
rxjsVersion: 7.5.5 | ||
ngPackagrVersion: 14.0.2 | ||
zonejsVersion: 0.11.5 | ||
tsickleVersion: 0.46.3 | ||
13.0.0: | ||
tsVersion: '>=4.4.2 <4.5.0' | ||
rxjsVersion: 7.4.0 | ||
ngPackagrVersion: 13.0.3 | ||
zonejsVersion: 0.11.4 | ||
tsickleVersion: 0.43.0 | ||
12.0.0: | ||
tsVersion: '>=4.3.0 <4.4.0' | ||
rxjsVersion: 6.6.0 | ||
ngPackagrVersion: 12.2.1 | ||
zonejsVersion: 0.11.4 | ||
tsickleVersion: 0.43.0 | ||
11.0.0: | ||
tsVersion: '>=4.0.0 <4.1.0' | ||
rxjsVersion: 6.6.0 | ||
ngPackagrVersion: 11.0.2 | ||
zonejsVersion: 0.11.3 | ||
tsickleVersion: 0.39.1 | ||
10.0.0: | ||
tsVersion: '>=3.9.2 <4.0.0' | ||
rxjsVersion: 6.6.0 | ||
ngPackagrVersion: 10.0.3 | ||
zonejsVersion: 0.10.2 | ||
tsickleVersion: 0.39.1 | ||
9.0.0: | ||
tsVersion: '>=3.6.0 <3.8.0' | ||
rxjsVersion: 6.5.3 | ||
ngPackagrVersion: 9.0.1 | ||
zonejsVersion: 0.10.2 | ||
tsickleVersion: 0.39.1 |
Oops, something went wrong.