Skip to content

Commit ac70f60

Browse files
committed
Merge remote-tracking branch 'upstream/master' into sttp4-client-oneof
2 parents 1e3be60 + c804b46 commit ac70f60

192 files changed

Lines changed: 3704 additions & 453 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/samples-groovy.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ jobs:
2020
matrix:
2121
sample:
2222
- samples/client/petstore/groovy
23+
services:
24+
petstore-api:
25+
image: swaggerapi/petstore
26+
ports:
27+
- 80:8080
28+
env:
29+
SWAGGER_HOST: http://petstore.swagger.io
30+
SWAGGER_BASE_PATH: /v2
2331
steps:
2432
- uses: actions/checkout@v5
2533
- uses: actions/setup-java@v5
@@ -41,6 +49,6 @@ jobs:
4149
gradle-version: ${{ env.GRADLE_VERSION }}
4250
build-root-directory: ${{ matrix.sample }}
4351
arguments: wrapper
44-
- name: Build
52+
- name: Build & Test
4553
working-directory: ${{ matrix.sample }}
46-
run: ./gradlew build -x test
54+
run: ./gradlew build

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ If you find OpenAPI Generator useful for work, please consider asking your compa
7575
[<img src="https://openapi-generator.tech/img/companies/unified_to.jpg" width="128" height="128">](https://unified.to/?utm_source=openapi-generator&utm_medium=sponsorship&utm_campaign=oss-sponsorship)
7676
[<img src="https://openapi-generator.tech/img/companies/savetwt.jpg" width="128" height="128">](https://savetwt.com/?utm_source=openapi-generator&utm_medium=sponsorship&utm_campaign=oss-sponsorship)
7777
[<img src="https://openapi-generator.tech/img/companies/serpapi.png" width="128" height="128">](https://serpapi.com/?utm_source=openapi-generator&utm_medium=sponsorship&utm_campaign=oss-sponsorship)
78+
[<img src="https://openapi-generator.tech/img/companies/socialwick.png" width="128" height="128">](https://socialwick.com/?utm_source=openapi-generator&utm_medium=sponsorship&utm_campaign=oss-sponsorship)
7879

7980
#### Thank you GoDaddy for sponsoring the domain names, Linode for sponsoring the VPS, Checkly for sponsoring the API monitoring and Gradle for sponsoring Develocity
8081

bin/configs/groovy.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
generatorName: groovy
22
outputDir: samples/client/petstore/groovy
3-
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/groovy/petstore.yaml
44
templateDir: modules/openapi-generator/src/main/resources/Groovy
55
additionalProperties:
6+
enumPropertyNaming: "original"
67
hideGenerationTimestamp: "true"

bin/utils/test_file_list.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ClientTest.java"
1111
sha256: 325fdd5d7e2c97790c0fb44f712ab7b2ba022d7e1a5b0056f47b07f342682b6d
1212
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java"
13-
sha256: 67941355a0a27ed9ff9318b1caa103e78b81b9aff61b594b18be5cd2bb9f6591
13+
sha256: b1b1d31e0df17f0b68cf2747a4a53879f12acb1bf2860e45385c679c1efe9894
1414
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/PetApiTest.java"
1515
sha256: 8b1b8f2a2ad00ccb090873a94a5f73e328b98317d2ec715f53bd7a1accb2a023
1616
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetTest.java"

docs/generators/typescript-axios.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2020
| ------ | ----------- | ------ | ------- |
2121
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
2222
|apiPackage|package for generated api classes| |null|
23-
|axiosVersion|Use this property to override the axios version in package.json| |^1.6.1|
23+
|axiosVersion|Use this property to override the axios version in package.json| |^1.13.5|
2424
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
2525
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
2626
|enumNameSuffix|Suffix that will be appended to all enum names.| |Enum|

modules/openapi-generator-mill-plugin/src/test/scala/org/openapitools/generator/mill/MillOpenapiModuleTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class MillOpenapiModuleTest extends Matchers {
9595
eval.apply(MillOpenapiModuleTestRoot.petstoreMicroprofile.compile)
9696
}
9797

98-
result shouldBe a[Right[_, _]]
98+
result shouldBe a[Right[?, ?]]
9999
}
100100

101101
@Test
@@ -104,6 +104,6 @@ class MillOpenapiModuleTest extends Matchers {
104104
// execute 'compile` task
105105
eval.apply(MillOpenapiModuleTestRoot.petstoreInvalid.compile)
106106
}
107-
result shouldBe a[Left[_, _]]
107+
result shouldBe a[Left[?, ?]]
108108
}
109109
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,13 @@ public Schema normalizeSchema(Schema schema, Set<Schema> visitedSchemas) {
803803
* @param schema Schema
804804
*/
805805
protected void normalizeReferenceSchema(Schema schema) {
806+
if (schema.getType() != null || schema.getTypes() != null && !schema.getTypes().isEmpty()) {
807+
// clears type(s) given that $ref is set
808+
schema.setType(null);
809+
schema.setTypes(null);
810+
LOGGER.warn("Type(s) cleared (set to null) given $ref is set to {}.", schema.get$ref());
811+
}
812+
806813
if (schema.getTitle() != null || schema.getDescription() != null
807814
|| schema.getNullable() != null || schema.getDefault() != null || schema.getDeprecated() != null
808815
|| schema.getMaximum() != null || schema.getMinimum() != null

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java

Lines changed: 131 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,65 @@
1717

1818
package org.openapitools.codegen.languages;
1919

20-
import io.swagger.v3.oas.models.OpenAPI;
21-
import io.swagger.v3.oas.models.media.Schema;
22-
import io.swagger.v3.oas.models.parameters.Parameter;
23-
import lombok.Getter;
24-
import lombok.Setter;
20+
import static org.openapitools.codegen.languages.AbstractTypeScriptClientCodegen.ParameterExpander.ParamStyle.form;
21+
import static org.openapitools.codegen.languages.AbstractTypeScriptClientCodegen.ParameterExpander.ParamStyle.simple;
22+
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
23+
import static org.openapitools.codegen.utils.StringUtils.camelize;
24+
import static org.openapitools.codegen.utils.StringUtils.underscore;
25+
26+
import java.io.File;
27+
import java.text.SimpleDateFormat;
28+
import java.util.ArrayList;
29+
import java.util.Arrays;
30+
import java.util.Collections;
31+
import java.util.Date;
32+
import java.util.EnumSet;
33+
import java.util.HashMap;
34+
import java.util.HashSet;
35+
import java.util.List;
36+
import java.util.Locale;
37+
import java.util.Map;
38+
import java.util.Set;
39+
import java.util.TreeSet;
40+
import java.util.function.BiPredicate;
41+
import java.util.function.Function;
42+
import java.util.regex.Pattern;
43+
import java.util.stream.Collectors;
44+
import java.util.stream.Stream;
45+
2546
import org.apache.commons.io.FilenameUtils;
2647
import org.apache.commons.lang3.StringUtils;
2748
import org.checkerframework.checker.nullness.qual.Nullable;
28-
import org.openapitools.codegen.*;
49+
import org.openapitools.codegen.CliOption;
50+
import org.openapitools.codegen.CodegenConfig;
51+
import org.openapitools.codegen.CodegenConstants;
2952
import org.openapitools.codegen.CodegenConstants.ENUM_PROPERTY_NAMING_TYPE;
3053
import org.openapitools.codegen.CodegenConstants.MODEL_PROPERTY_NAMING_TYPE;
3154
import org.openapitools.codegen.CodegenConstants.PARAM_NAMING_TYPE;
32-
import org.openapitools.codegen.meta.features.*;
55+
import org.openapitools.codegen.CodegenModel;
56+
import org.openapitools.codegen.CodegenOperation;
57+
import org.openapitools.codegen.CodegenParameter;
58+
import org.openapitools.codegen.CodegenProperty;
59+
import org.openapitools.codegen.CodegenType;
60+
import org.openapitools.codegen.DefaultCodegen;
61+
import org.openapitools.codegen.GeneratorLanguage;
62+
import org.openapitools.codegen.meta.features.ClientModificationFeature;
63+
import org.openapitools.codegen.meta.features.DocumentationFeature;
64+
import org.openapitools.codegen.meta.features.GlobalFeature;
65+
import org.openapitools.codegen.meta.features.SchemaSupportFeature;
66+
import org.openapitools.codegen.meta.features.SecurityFeature;
67+
import org.openapitools.codegen.meta.features.WireFormatFeature;
3368
import org.openapitools.codegen.model.ModelMap;
3469
import org.openapitools.codegen.model.ModelsMap;
3570
import org.openapitools.codegen.utils.ModelUtils;
3671
import org.slf4j.Logger;
3772
import org.slf4j.LoggerFactory;
3873

39-
import java.io.File;
40-
import java.text.SimpleDateFormat;
41-
import java.util.*;
42-
import java.util.function.BiPredicate;
43-
import java.util.function.Function;
44-
import java.util.regex.Pattern;
45-
import java.util.stream.Collectors;
46-
import java.util.stream.Stream;
47-
48-
import static org.openapitools.codegen.languages.AbstractTypeScriptClientCodegen.ParameterExpander.ParamStyle.form;
49-
import static org.openapitools.codegen.languages.AbstractTypeScriptClientCodegen.ParameterExpander.ParamStyle.simple;
50-
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
51-
import static org.openapitools.codegen.utils.StringUtils.camelize;
52-
import static org.openapitools.codegen.utils.StringUtils.underscore;
74+
import io.swagger.v3.oas.models.OpenAPI;
75+
import io.swagger.v3.oas.models.media.Schema;
76+
import io.swagger.v3.oas.models.parameters.Parameter;
77+
import lombok.Getter;
78+
import lombok.Setter;
5379

5480
public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen implements CodegenConfig {
5581

@@ -1023,22 +1049,104 @@ protected void addImport(CodegenModel m, String type) {
10231049
}
10241050
}
10251051

1052+
/**
1053+
* Override to fix the inner enum naming issue for maps/arrays of enums.
1054+
* <p>
1055+
* The parent implementation uses toEnumName(baseItem) which produces a generic name
1056+
* like "InnerEnum" based on the inner item's name. This override first calculates
1057+
* the correct property.enumName, then uses it in the datatypeWithEnum replacement.
1058+
* </p>
1059+
*
1060+
* @param property Codegen property
1061+
*/
1062+
@Override
1063+
protected void updateDataTypeWithEnumForArray(CodegenProperty property) {
1064+
CodegenProperty baseItem = property.items;
1065+
while (baseItem != null && (Boolean.TRUE.equals(baseItem.isMap)
1066+
|| Boolean.TRUE.equals(baseItem.isArray))) {
1067+
baseItem = baseItem.items;
1068+
}
1069+
1070+
if (baseItem != null) {
1071+
// First, set the property's enumName using the property itself (not the inner item)
1072+
// This ensures the correct enum name (e.g., "OptionsEnum") is used
1073+
// instead of the generic inner item name (e.g., "InnerEnum")
1074+
property.enumName = toEnumName(property);
1075+
1076+
// Now use property.enumName for datatypeWithEnum
1077+
property.datatypeWithEnum = property.datatypeWithEnum.replace(baseItem.baseType, property.enumName);
1078+
1079+
// set default value for variable with inner enum
1080+
if (property.defaultValue != null) {
1081+
property.defaultValue = property.defaultValue.replace(baseItem.baseType, property.enumName);
1082+
}
1083+
1084+
updateCodegenPropertyEnum(property);
1085+
}
1086+
}
1087+
1088+
/**
1089+
* Override to fix the inner enum naming issue for map properties.
1090+
* <p>
1091+
* The parent implementation uses {@code toEnumName(baseItem)} which produces "InnerEnum"
1092+
* for properties whose inner item has a generic name like "inner". We instead
1093+
* calculate the enumName from the property itself first, then use it in the replacement.
1094+
* </p>
1095+
*
1096+
* @param property Codegen property
1097+
*/
1098+
@Override
1099+
protected void updateDataTypeWithEnumForMap(CodegenProperty property) {
1100+
CodegenProperty baseItem = property.items;
1101+
while (baseItem != null && (Boolean.TRUE.equals(baseItem.isMap)
1102+
|| Boolean.TRUE.equals(baseItem.isArray))) {
1103+
baseItem = baseItem.items;
1104+
}
1105+
1106+
if (baseItem != null) {
1107+
// First, set the property's enumName using the property itself (not the inner item)
1108+
property.enumName = toEnumName(property);
1109+
1110+
// Replace only the LAST occurrence of baseType with enumName.
1111+
// In map types, the value type appears last (after the key type),
1112+
// so this approach is template-agnostic.
1113+
String datatypeWithEnum = property.datatypeWithEnum;
1114+
int lastIndex = datatypeWithEnum.lastIndexOf(baseItem.baseType);
1115+
if (lastIndex >= 0) {
1116+
property.datatypeWithEnum = datatypeWithEnum.substring(0, lastIndex)
1117+
+ property.enumName
1118+
+ datatypeWithEnum.substring(lastIndex + baseItem.baseType.length());
1119+
}
1120+
LOGGER.info("Updated datatypeWithEnum for map property '{}': {}", property.name, property.datatypeWithEnum);
1121+
1122+
// set default value for variable with inner enum
1123+
if (property.defaultValue != null) {
1124+
property.defaultValue = property.defaultValue.replace(baseItem.baseType, property.enumName);
1125+
}
1126+
1127+
updateCodegenPropertyEnum(property);
1128+
}
1129+
}
1130+
10261131
@Override
10271132
public ModelsMap postProcessModels(ModelsMap objs) {
10281133
// process enum in models
10291134
List<ModelMap> models = postProcessModelsEnum(objs).getModels();
10301135
for (ModelMap mo : models) {
10311136
CodegenModel cm = mo.getModel();
10321137
cm.imports = new TreeSet<>(cm.imports);
1138+
10331139
// name enum with model name, e.g. StatusEnum => Pet.StatusEnum
1140+
// This applies to both direct enum properties (isEnum) and properties containing
1141+
// inner enums (isInnerEnum) like maps or arrays of enums.
10341142
for (CodegenProperty var : cm.vars) {
1035-
if (Boolean.TRUE.equals(var.isEnum)) {
1143+
if (Boolean.TRUE.equals(var.isEnum) || Boolean.TRUE.equals(var.isInnerEnum)) {
10361144
var.datatypeWithEnum = var.datatypeWithEnum.replace(var.enumName, cm.classname + classEnumSeparator + var.enumName);
10371145
}
10381146
}
10391147
if (cm.parent != null) {
10401148
for (CodegenProperty var : cm.allVars) {
1041-
if (Boolean.TRUE.equals(var.isEnum)) {
1149+
if (Boolean.TRUE.equals(var.isEnum) || Boolean.TRUE.equals(var.isInnerEnum)) {
10421150
var.datatypeWithEnum = var.datatypeWithEnum
10431151
.replace(var.enumName, cm.classname + classEnumSeparator + var.enumName);
10441152
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege
5151
public static final String IMPORT_FILE_EXTENSION_SWITCH_DESC = "File extension to use with relative imports. Set it to '.js' or '.mjs' when using [ESM](https://nodejs.org/api/esm.html).";
5252
public static final String USE_SQUARE_BRACKETS_IN_ARRAY_NAMES = "useSquareBracketsInArrayNames";
5353
public static final String AXIOS_VERSION = "axiosVersion";
54-
public static final String DEFAULT_AXIOS_VERSION = "^1.6.1";
54+
public static final String DEFAULT_AXIOS_VERSION = "^1.13.5";
5555
public static final String WITH_AWSV4_SIGNATURE = "withAWSV4Signature";
5656

5757
@Getter @Setter

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Sc
383383

384384
@Override
385385
public ModelsMap postProcessModels(ModelsMap objs) {
386+
// postProcessModelsEnum applies inner enum fixes via the parent class override
386387
List<ModelMap> models = postProcessModelsEnum(objs).getModels();
387388

388389
// process enum and custom properties in models
@@ -800,7 +801,8 @@ private ExtendedCodegenModel processCodeGenModel(ExtendedCodegenModel cm) {
800801
for (CodegenProperty cpVar : cm.allVars) {
801802
ExtendedCodegenProperty var = (ExtendedCodegenProperty) cpVar;
802803

803-
if (Boolean.TRUE.equals(var.isEnum)) {
804+
// Handle both direct enum properties and inner enums (maps/arrays of enums)
805+
if (Boolean.TRUE.equals(var.isEnum) || Boolean.TRUE.equals(var.isInnerEnum)) {
804806
var.datatypeWithEnum = var.datatypeWithEnum
805807
.replace(var.enumName, cm.classname + var.enumName);
806808
}
@@ -845,7 +847,9 @@ private ExtendedCodegenModel processCodeGenModel(ExtendedCodegenModel cm) {
845847

846848
private boolean processCodegenProperty(ExtendedCodegenProperty var, String parentClassName, Object xEntityId) {
847849
// name enum with model name, e.g. StatusEnum => PetStatusEnum
848-
if (Boolean.TRUE.equals(var.isEnum)) {
850+
// This applies to both direct enum properties (isEnum) and properties containing
851+
// inner enums (isInnerEnum) like maps or arrays of enums.
852+
if (Boolean.TRUE.equals(var.isEnum) || Boolean.TRUE.equals(var.isInnerEnum)) {
849853
// behaviour for enum names is specific for Typescript Fetch, not using namespaces
850854
var.datatypeWithEnum = var.datatypeWithEnum.replace(var.enumName, parentClassName + var.enumName);
851855

@@ -1525,11 +1529,11 @@ public class ExtendedCodegenModel extends CodegenModel {
15251529
public Set<CodegenProperty> oneOfPrimitives = new HashSet<>();
15261530
@Getter @Setter
15271531
public CodegenDiscriminator.MappedModel selfReferencingDiscriminatorMapping;
1528-
1532+
15291533
public boolean isEntity; // Is a model containing an "id" property marked as isUniqueId
15301534
public String returnPassthrough;
15311535
public boolean hasReturnPassthroughVoid;
1532-
1536+
15331537
public boolean hasSelfReferencingDiscriminatorMapping(){
15341538
return selfReferencingDiscriminatorMapping != null;
15351539
}

0 commit comments

Comments
 (0)