Skip to content

Commit

Permalink
Merge branch 'master' into java_add_lombok_model
Browse files Browse the repository at this point in the history
  • Loading branch information
dabdirb committed Jan 24, 2024
2 parents b98a449 + f31164b commit bafad1b
Show file tree
Hide file tree
Showing 264 changed files with 15,710 additions and 5,302 deletions.
1 change: 1 addition & 0 deletions .github/workflows/samples-kotlin-client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
- samples/client/petstore/kotlin-jvm-spring-2-webclient
- samples/client/petstore/kotlin-jvm-spring-3-webclient
- samples/client/petstore/kotlin-jvm-spring-3-restclient
- samples/client/echo_api/kotlin-jvm-spring-3-restclient
- samples/client/petstore/kotlin-spring-cloud
- samples/client/petstore/kotlin-name-parameter-mappings
- samples/client/others/kotlin-jvm-okhttp-parameter-tests
Expand Down
3 changes: 3 additions & 0 deletions CI/circle_parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ if [ "$NODE_INDEX" = "1" ]; then
echo "Running node $NODE_INDEX ..."
java -version

sudo apt-get -y install cpanminus

(cd samples/client/petstore/perl && /bin/bash ./test.bash)
(cd samples/client/petstore/ruby && mvn integration-test)
(cd samples/client/petstore/ruby-faraday && mvn integration-test)
(cd samples/client/petstore/ruby-httpx && mvn integration-test)
Expand Down
9 changes: 9 additions & 0 deletions bin/configs/kotlin-jvm-spring-3-restclient-echo-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
generatorName: kotlin
outputDir: samples/client/echo_api/kotlin-jvm-spring-3-restclient
library: jvm-spring-restclient
inputSpec: modules/openapi-generator/src/test/resources/3_0/kotlin/echo_api.yaml
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
additionalProperties:
enumUnknownDefaultCase: true
serializationLibrary: jackson
useSpringBoot3: true
2 changes: 1 addition & 1 deletion bin/configs/perl.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
generatorName: perl
outputDir: samples/client/petstore/perl
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
inputSpec: modules/openapi-generator/src/test/resources/3_0/perl/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/perl
additionalProperties:
hideGenerationTimestamp: "true"
Expand Down
2 changes: 1 addition & 1 deletion bin/utils/test_file_list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ClientTest.java"
sha256: db505f7801fef62c13a08a8e9ca1fc4c5c947ab46b46f12943139d353feacf17
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java"
sha256: 6db714e9744c150c8982c3cb18e4f37a9c1ecd8f72f6d58943986e781ab4a344
sha256: 7b9514ac0b3730685590d6ef273b2c2a1fb72d968529c2423a139ee9b0b92a65
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/PetApiTest.java"
sha256: 0d64cdc11809a7b5b952ccdad2bd91bd0045b3894d6fabf3e368fa0be12b8217
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetTest.java"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ default void setTypeProperties(Schema p) {
setIsFreeFormObject(true);
// TODO: remove below later after updating generators to properly use isFreeFormObject
setIsMap(true);
} else if (ModelUtils.isMapSchema(p)) {
setIsMap(true);
} else if (ModelUtils.isTypeObjectSchema(p)) {
setIsMap(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -851,13 +851,21 @@ private void flattenProperties(OpenAPI openAPI, Map<String, Schema> properties,
} else {
LOGGER.debug("Schema not yet handled in model resolver: {}", inner);
}
} else if (ModelUtils.isComposedSchema(property)) { // oneOf, anyOf, etc
String propertyModelName = resolveModelName(property.getTitle(), path + "_" + key);
gatherInlineModels(property, propertyModelName);
propertyModelName = addSchemas(propertyModelName, property);
Schema schema = new Schema().$ref(propertyModelName);
schema.setRequired(property.getRequired());
propsToUpdate.put(key, schema);
} else if (ModelUtils.isComposedSchema(property)) { // oneOf, anyOf, allOf etc
if (property.getAllOf() != null && property.getAllOf().size() == 1 // allOf with a single item
&& (property.getOneOf() == null || property.getOneOf().isEmpty()) // not oneOf
&& (property.getAnyOf() == null || property.getAnyOf().isEmpty()) // not anyOf
&& (property.getProperties() == null || property.getProperties().isEmpty())) { // no property
// don't do anything if it's allOf with a single item
LOGGER.debug("allOf with a single item (which can be handled by default codegen) skipped by inline model resolver: {}", property);
} else {
String propertyModelName = resolveModelName(property.getTitle(), path + "_" + key);
gatherInlineModels(property, propertyModelName);
propertyModelName = addSchemas(propertyModelName, property);
Schema schema = new Schema().$ref(propertyModelName);
schema.setRequired(property.getRequired());
propsToUpdate.put(key, schema);
}
} else {
LOGGER.debug("Schema not yet handled in model resolver: {}", property);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ private void processJvmSpringWebClientLibrary(final String infrastructureFolder)

private void processJvmSpringRestClientLibrary(final String infrastructureFolder) {
if (additionalProperties.getOrDefault(USE_SPRING_BOOT3, false).equals(false)) {
throw new RuntimeException("This library muse use spring boot 3. Try adding '--additional-properties useSpringBoot3=true' to your command.");
throw new RuntimeException("This library must use Spring Boot 3. Try adding '--additional-properties useSpringBoot3=true' to your command.");
}

proccessJvmSpring(infrastructureFolder);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -66,7 +68,7 @@ public ScalaHttp4sServerCodegen() {
supportsMultipleInheritance = true;
supportsInheritance = true;
supportsMixins = true;
addOneOfInterfaceImports =true;
addOneOfInterfaceImports = true;


setReservedWordsLowerCase(
Expand Down Expand Up @@ -141,7 +143,6 @@ public ScalaHttp4sServerCodegen() {
additionalProperties.put("licenseUrl", "http://apache.org/licenses/LICENSE-2.0.html");



languageSpecificPrimitives = new HashSet<>(
Arrays.asList(
"String",
Expand Down Expand Up @@ -197,6 +198,7 @@ public ScalaHttp4sServerCodegen() {
}

private final static Map<String, String> locationStatusToResponse = new HashMap<>();

static {
locationStatusToResponse.put("300", "MultipleChoices");
locationStatusToResponse.put("301", "MovedPermanently");
Expand All @@ -207,16 +209,19 @@ public ScalaHttp4sServerCodegen() {
}

private final static Map<String, String> wwwAuthStatusToResponse = new HashMap<>();

static {
wwwAuthStatusToResponse.put("401", "Unauthorized");
}

private final static Map<String, String> allowStatusToResponse = new HashMap<>();

static {
allowStatusToResponse.put("405", "MethodNotAllowed");
}

private final static Map<String, String> proxyAuthStatusToResponse = new HashMap<>();

static {
proxyAuthStatusToResponse.put("407", "ProxyAuthenticationRequired");
}
Expand Down Expand Up @@ -314,7 +319,7 @@ public void processOpts() {

apiTemplateFiles.put("api.mustache", ".scala");

if (!additionalProperties.containsKey(EXCLUDE_SBT) && !Boolean.parseBoolean((String)additionalProperties.get(EXCLUDE_SBT))) {
if (!additionalProperties.containsKey(EXCLUDE_SBT) && !Boolean.parseBoolean((String) additionalProperties.get(EXCLUDE_SBT))) {
supportingFiles.add(new SupportingFile("build.sbt", "", "build.sbt"));
supportingFiles.add(new SupportingFile("build.properties", "project", "build.properties"));
}
Expand All @@ -328,18 +333,18 @@ public Map<String, String> inlineSchemaOption() {

@Override
public boolean isEnablePostProcessFile() {
return true;
return true;
}

@Override
public void postProcessFile(File file, String fileType) {
System.out.println("postprocess " + file.toString());
LOGGER.debug("postprocess " + file.toString());
super.postProcessFile(file, fileType);
}

@Override
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
Map<String, ModelsMap> modelsMap = super.postProcessAllModels(objs);
Map<String, ModelsMap> modelsMap = super.postProcessAllModels(objs);

for (ModelsMap mm : modelsMap.values()) {
for (ModelMap model : mm.getModels()) {
Expand Down Expand Up @@ -367,7 +372,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)

// add refined constraints

for (CodegenProperty prop: cModel.vars) {
for (CodegenProperty prop : cModel.vars) {
Set<String> imports = new TreeSet<>();

prop.getVendorExtensions().putAll(refineProp(prop, imports));
Expand All @@ -389,8 +394,8 @@ private Map<String, Object> makeRefiined(Set<String> imports, String dataType, A

vendorExtensions.put("x-type", "Refined[" + dataType + ", " + refinedRgt + "]");
vendorExtensions.put("x-refined-lft", dataType);
vendorExtensions.put("x-refined-rgt", refinedRgt);
vendorExtensions.put("x-refined", true);
vendorExtensions.put("x-refined-rgt", refinedRgt);
vendorExtensions.put("x-refined", true);
} else {
vendorExtensions.put("x-type", dataType);
}
Expand All @@ -407,8 +412,8 @@ private Map<String, Object> refineProp(IJsonSchemaValidationProperties prop, Set
ArrayList<String> refined = new ArrayList<>();

if (prop.getMinLength() != null) {
refined.add("MinSize[" + prop.getMinLength() + "]");
imports.add("MinSize");
refined.add("MinSize[" + prop.getMinLength() + "]");
imports.add("MinSize");
}
if (prop.getMaxLength() != null) {
refined.add("MaxSize[" + prop.getMaxLength() + "]");
Expand Down Expand Up @@ -485,7 +490,7 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj

List<ModelMap> models = (List<ModelMap>) bundle.get("models");
TreeSet<String> allImports = new TreeSet<>();
for (ModelMap mm: models) {
for (ModelMap mm : models) {
for (String nextImport : mm.getModel().imports) {
String mapping = importMapping().get(nextImport);
if (mapping != null && !defaultIncludes().contains(mapping)) {
Expand All @@ -504,9 +509,9 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj

ApiInfoMap apiInfoMap = (ApiInfoMap) bundle.get("apiInfo");
Map<String, List<String>> authToOperationMap = new TreeMap<>();
for (OperationsMap op: apiInfoMap.getApis()) {
for (OperationsMap op : apiInfoMap.getApis()) {
List<HashMap<String, Object>> opsByAuth = (List<HashMap<String, Object>>) op.get("operationsByAuth");
for (HashMap<String, Object> auth: opsByAuth) {
for (HashMap<String, Object> auth : opsByAuth) {
String autName = (String) auth.get("auth");
String classname = (String) op.get("classname");
List<String> classnames = authToOperationMap.computeIfAbsent(autName, k -> new ArrayList<>());
Expand Down Expand Up @@ -549,7 +554,7 @@ public String escapeReservedWord(String name) {

@Override
public String apiFileFolder() {
return outputFolder + File.separator + apiFileFolderRelative() ;
return outputFolder + File.separator + apiFileFolderRelative();
}

private String apiFileFolderRelative() {
Expand Down Expand Up @@ -599,7 +604,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objsI, List<M
}

// decide wat methods do we need in responses:
for (CodegenResponse resp: op.responses) {
for (CodegenResponse resp : op.responses) {
if (resp.code.equals("0"))
resp.code = "200"; // 200 by default

Expand Down Expand Up @@ -649,11 +654,11 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objsI, List<M
}

if (op.authMethods != null) {
for (CodegenSecurity cs: op.authMethods) {
for (CodegenSecurity cs : op.authMethods) {
allAuth.add(cs.name);
}
List<Map<String, Object>> authDup = new ArrayList<>();
for (CodegenSecurity authMeth: op.authMethods) {
for (CodegenSecurity authMeth : op.authMethods) {
Map<String, Object> vals = new HashMap<>();
vals.put("authName", authMeth.name);
vals.put("operation", op);
Expand Down Expand Up @@ -781,7 +786,7 @@ private void generateScalaPath(CodegenOperation op) {
op.imports.addAll(imports);
}

private String cpToPathParameter(CodegenParameter cp, Set<String> imports, Map<String, Object> vendorExtensions) {
private String cpToPathParameter(CodegenParameter cp, Set<String> imports, Map<String, Object> vendorExtensions) {
// don't support containers and arrays yet, reset to string
if (cp.isContainer || cp.isArray) {
cp.setDataType("String");
Expand Down Expand Up @@ -809,20 +814,20 @@ private void generateQueryParameters(CodegenOperation op) {
String queryString = "";

for (CodegenParameter cp : op.queryParams) {
if (queryString.isEmpty()) {
queryString = queryString + " :? ";
} else {
queryString = queryString + " +& ";
}
if (queryString.isEmpty()) {
queryString = queryString + " :? ";
} else {
queryString = queryString + " +& ";
}

queryString = queryString + cpToQueryParameter(cp, imports, cp.vendorExtensions);
queryString = queryString + cpToQueryParameter(cp, imports, cp.vendorExtensions);
}

op.vendorExtensions.put("x-codegen-query", queryString);
op.imports.addAll(imports);
}

private String cpToQueryParameter(CodegenParameter cp, Set<String> imports, Map<String, Object> vendorExtensions) {
private String cpToQueryParameter(CodegenParameter cp, Set<String> imports, Map<String, Object> vendorExtensions) {
// don't support containers and arrays yet, reset to string
if (cp.isContainer && !cp.isArray) {
cp.setDataType("String");
Expand All @@ -848,5 +853,7 @@ public void postProcess() {
}

@Override
public GeneratorLanguage generatorLanguage() { return GeneratorLanguage.SCALA; }
public GeneratorLanguage generatorLanguage() {
return GeneratorLanguage.SCALA;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,16 @@ public static String getSimpleRef(String ref) {
* @return true if the specified schema is an Object schema.
*/
public static boolean isTypeObjectSchema(Schema schema) {
return SchemaTypeUtil.OBJECT_TYPE.equals(schema.getType());
if (schema instanceof JsonSchema) { // 3.1 spec
if (schema.getTypes() != null && schema.getTypes().size() == 1) {
return SchemaTypeUtil.OBJECT_TYPE.equals(schema.getTypes().iterator().next());
} else {
// null type or multiple types, e.g. [string, integer]
return false;
}
} else { // 3.0.x or 2.0 spec
return SchemaTypeUtil.OBJECT_TYPE.equals(schema.getType());
}
}

/**
Expand Down Expand Up @@ -567,9 +576,14 @@ public static boolean isMapSchema(Schema schema) {
return false;
}

return (schema instanceof MapSchema) ||
(schema.getAdditionalProperties() instanceof Schema) ||
(schema.getAdditionalProperties() instanceof Boolean && (Boolean) schema.getAdditionalProperties());
if (schema instanceof JsonSchema) { // 3.1 spec
return ((schema.getAdditionalProperties() instanceof JsonSchema) ||
(schema.getAdditionalProperties() instanceof Boolean && (Boolean) schema.getAdditionalProperties()));
} else { // 3.0 or 2.x spec
return (schema instanceof MapSchema) ||
(schema.getAdditionalProperties() instanceof Schema) ||
(schema.getAdditionalProperties() instanceof Boolean && (Boolean) schema.getAdditionalProperties());
}
}

/**
Expand Down Expand Up @@ -790,6 +804,31 @@ public static boolean isFreeFormObject(Schema schema) {
return false;
}

if (schema instanceof JsonSchema) { // 3.1 spec
if (isComposedSchema(schema)) { // composed schema, e.g. allOf, oneOf, anyOf
return false;
}

if (schema.getProperties() != null && !schema.getProperties().isEmpty()) { // has properties
return false;
}

if (schema.getAdditionalProperties() instanceof Boolean && (Boolean) schema.getAdditionalProperties()) {
return true;
} else if (schema.getAdditionalProperties() instanceof JsonSchema) {
return true;
} else if (schema.getTypes() != null) {
if (schema.getTypes().size() == 1) { // types = [object]
return SchemaTypeUtil.OBJECT_TYPE.equals(schema.getTypes().iterator().next());
} else { // has more than 1 type, e.g. types = [integer, string]
return false;
}
}

return false;
}

// 3.0.x spec or 2.x spec
// not free-form if allOf, anyOf, oneOf is not empty
if (isComposedSchema(schema)) {
List<Schema> interfaces = ModelUtils.getInterfaces(schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class ApiClient {
url = apiBasePath + path;
}

url = url.replace(/\{([\w-\.]+)\}/g, (fullMatch, key) => {
url = url.replace(/\{([\w-\.#]+)\}/g, (fullMatch, key) => {
var value;
if (pathParams.hasOwnProperty(key)) {
value = this.paramToString(pathParams[key]);
Expand Down
Loading

0 comments on commit bafad1b

Please sign in to comment.