Skip to content
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

Merge master #2

Merged
merged 11 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
- 2020-08-25 - [OpenAPI Generator と TypeScript で型安全にフロントエンド開発をしている話](https://tech.smarthr.jp/entry/2020/08/25/135631) at [SmartHR Tech Blog](https://tech.smarthr.jp/)
- 2020-09-10 - [Introduction to OpenAPI with Instana](https://www.instana.com/blog/introduction-to-openapi-with-instana/) by [Cedric Ziel](https://www.instana.com/blog/author/cedricziel/) at [Instana Blog](https://www.instana.com/blog/)
- 2020-09-17 - [Generate PowerShellSDK using openapi-generator](https://medium.com/@ghufz.learn/generate-powershellsdk-using-openapi-generator-33b700891e33) by [Ghufran Zahidi](https://medium.com/@ghufz.learn)
- 2020-09-24 - [How to automate API code generation (OpenAPI/Swagger) and boost productivity - Tutorial with React Native featuring TypeScript](https://medium.com/@sceleski/how-to-automate-api-code-generation-openapi-swagger-and-boost-productivity-1176a0056d8a) by [Sanjin Celeski](https://medium.com/@sceleski)

## [6 - About Us](#table-of-contents)

Expand Down
1 change: 1 addition & 0 deletions bin/configs/python-experimental.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ inputSpec: modules/openapi-generator/src/test/resources/3_0/python-experimental/
templateDir: modules/openapi-generator/src/main/resources/python
additionalProperties:
packageName: petstore_api
recursionLimit: "1234"
9 changes: 9 additions & 0 deletions bin/configs/ruby-features-dynamic-servers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
generatorName: ruby
outputDir: samples/openapi3/client/features/dynamic-servers/ruby/
inputSpec: modules/openapi-generator/src/test/resources/3_0/features/dynamic-servers.yaml
templateDir: modules/openapi-generator/src/main/resources/ruby-client
additionalProperties:
gemVersion: 1.0.0
moduleName: DynamicServers
gemName: dynamic_servers
skipFormModel: "true"
1 change: 1 addition & 0 deletions docs/generators/python-experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sidebar_label: python-experimental
|packageUrl|python package URL.| |null|
|packageVersion|python package version.| |1.0.0|
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null|
|useNose|use the nose test framework| |false|

## IMPORT MAPPING
Expand Down
1 change: 1 addition & 0 deletions docs/generators/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sidebar_label: python
|packageUrl|python package URL.| |null|
|packageVersion|python package version.| |1.0.0|
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|useNose|use the nose test framework| |false|

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,19 +394,17 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
if (this.useOneOfInterfaces) {
// First, add newly created oneOf interfaces
for (CodegenModel cm : addOneOfInterfaces) {
Map<String, Object> modelValue = new HashMap<String, Object>() {{
putAll(additionalProperties());
put("model", cm);
}};
Map<String, Object> modelValue = new HashMap<>(additionalProperties());
modelValue.put("model", cm);

List<Object> modelsValue = Arrays.asList(modelValue);
List<Map<String, String>> importsValue = new ArrayList<Map<String, String>>();
Map<String, Object> objsValue = new HashMap<String, Object>() {{
put("models", modelsValue);
put("package", modelPackage());
put("imports", importsValue);
put("classname", cm.classname);
putAll(additionalProperties);
}};
Map<String, Object> objsValue = new HashMap<>();
objsValue.put("models", modelsValue);
objsValue.put("package", modelPackage());
objsValue.put("imports", importsValue);
objsValue.put("classname", cm.classname);
objsValue.putAll(additionalProperties);
objs.put(cm.name, objsValue);
}

Expand Down Expand Up @@ -2704,7 +2702,8 @@ private Discriminator recursiveGetDiscriminator(Schema sc, OpenAPI openAPI) {
if (foundDisc != null) {
return foundDisc;
}
if (!!this.getLegacyDiscriminatorBehavior()) {

if (this.getLegacyDiscriminatorBehavior()) {
return null;
}
Discriminator disc = new Discriminator();
Expand Down Expand Up @@ -2742,7 +2741,7 @@ private Discriminator recursiveGetDiscriminator(Schema sc, OpenAPI openAPI) {
throw new RuntimeException("The oneOf schemas have conflicting discriminator property names. " +
"oneOf schemas must have the same property name, but found " + String.join(", ", discriminatorsPropNames));
}
if ((hasDiscriminatorCnt + hasNullTypeCnt) == composedSchema.getOneOf().size() && discriminatorsPropNames.size() == 1) {
if (foundDisc != null && (hasDiscriminatorCnt + hasNullTypeCnt) == composedSchema.getOneOf().size() && discriminatorsPropNames.size() == 1) {
disc.setPropertyName(foundDisc.getPropertyName());
disc.setMapping(foundDisc.getMapping());
return disc;
Expand Down Expand Up @@ -2771,7 +2770,7 @@ private Discriminator recursiveGetDiscriminator(Schema sc, OpenAPI openAPI) {
throw new RuntimeException("The anyOf schemas have conflicting discriminator property names. " +
"anyOf schemas must have the same property name, but found " + String.join(", ", discriminatorsPropNames));
}
if ((hasDiscriminatorCnt + hasNullTypeCnt) == composedSchema.getAnyOf().size() && discriminatorsPropNames.size() == 1) {
if (foundDisc != null && (hasDiscriminatorCnt + hasNullTypeCnt) == composedSchema.getAnyOf().size() && discriminatorsPropNames.size() == 1) {
disc.setPropertyName(foundDisc.getPropertyName());
disc.setMapping(foundDisc.getMapping());
return disc;
Expand Down Expand Up @@ -2860,8 +2859,12 @@ protected List<MappedModel> getAllOfDescendants(String thisSchemaName, OpenAPI o
List<MappedModel> descendentSchemas = new ArrayList();
Map<String, Schema> schemas = ModelUtils.getSchemas(openAPI);
String currentSchemaName = thisSchemaName;
while (true) {
for (String childName : schemas.keySet()) {
Set<String> keys = schemas.keySet();

int count = 0;
// hack: avoid infinite loop on potential self-references in event our checks fail.
while (100000 > count++) {
for (String childName : keys) {
if (childName.equals(thisSchemaName)) {
continue;
}
Expand All @@ -2879,8 +2882,8 @@ protected List<MappedModel> getAllOfDescendants(String thisSchemaName, OpenAPI o
continue;
}
String parentName = ModelUtils.getSimpleRef(ref);
if (parentName.equals(currentSchemaName)) {
if (queue.contains(childName) || descendentSchemas.contains(childName)) {
if (parentName != null && parentName.equals(currentSchemaName)) {
if (queue.contains(childName) || descendentSchemas.stream().anyMatch(i -> childName.equals(i.getMappingName()))) {
throw new RuntimeException("Stack overflow hit when looking for " + thisSchemaName + " an infinite loop starting and ending at " + childName + " was seen");
}
queue.add(childName);
Expand Down Expand Up @@ -3600,7 +3603,10 @@ protected void handleMethodResponse(Operation operation,
op.hasReference = schemas != null && schemas.containsKey(op.returnBaseType);

// lookup discriminator
Schema schema = schemas.get(op.returnBaseType);
Schema schema = null;
if (schemas != null) {
schema = schemas.get(op.returnBaseType);
}
if (schema != null) {
CodegenModel cmod = fromModel(op.returnBaseType, schema);
op.discriminator = cmod.discriminator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
@Override
public void processOpts() {
super.processOpts();
boolean isLibrary = false;

if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_PROJECT_GUID)) {
setPackageGuid((String) additionalProperties.get(CodegenConstants.OPTIONAL_PROJECT_GUID));
Expand All @@ -191,10 +190,6 @@ public void processOpts() {

additionalProperties.put(PROJECT_SDK, projectSdk);

// TODO - should we be supporting a Giraffe class library?
if (isLibrary)
LOGGER.warn("Library flag not currently supported.");

String authFolder = sourceFolder + File.separator + "auth";
String implFolder = sourceFolder + File.separator + "impl";
String helperFolder = sourceFolder + File.separator + "helpers";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1274,9 +1274,11 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
if (dataType == null && cm.isArrayModel) { // isAlias + arrayModelType missing "datatype"
dataType = "[" + cm.arrayModelType + "]";
}
cm.vendorExtensions.put(VENDOR_EXTENSION_X_DATA_TYPE, dataType);
if (dataType.equals("Maybe A.Value")) {
cm.vendorExtensions.put(VENDOR_EXTENSION_X_IS_MAYBE_VALUE, true);
if (dataType != null) {
cm.vendorExtensions.put(VENDOR_EXTENSION_X_DATA_TYPE, dataType);
if (dataType.equals("Maybe A.Value")) {
cm.vendorExtensions.put(VENDOR_EXTENSION_X_IS_MAYBE_VALUE, true);
}
}
}
for (CodegenProperty var : cm.vars) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public String toString() {
return f;
});

private static final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000;
private static final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000L;

private static final long MIN_DATE;

Expand Down Expand Up @@ -551,10 +551,13 @@ private void appendRandomByte(StringBuilder buffer, CodegenOperation op, Codegen
short inclusiveMax = (short) (var == null || !var.exclusiveMaximum ? 1 : 0);
byte randomByte = (byte) (min + exclusiveMin + ((max + inclusiveMax - min - exclusiveMin) * Math.random()));

if (loadTestDataFromFile)
var.addTestData(randomByte);
else
if (loadTestDataFromFile) {
if (var != null) {
var.addTestData(randomByte);
}
} else {
buffer.append(String.format(Locale.getDefault(), "(byte)%0#2x", randomByte));
}
}
}

Expand All @@ -568,10 +571,13 @@ private void appendRandomChar(StringBuilder buffer, CodegenOperation op, Codegen
char inclusiveMax = (char) (var == null || !var.exclusiveMaximum ? 1 : 0);
char randomChar = (char) (min + exclusiveMin + ((max + inclusiveMax - min - exclusiveMin) * Math.random()));

if (loadTestDataFromFile)
var.addTestData(randomChar);
else
if (loadTestDataFromFile) {
if (var != null) {
var.addTestData(randomChar);
}
} else {
buffer.append(String.format(Locale.getDefault(), "'%c'", randomChar));
}
}
}

Expand Down Expand Up @@ -607,10 +613,10 @@ private void appendRandomDate(StringBuilder buffer, CodegenOperation op, Codegen
BigDecimal exclusiveMinLong = new BigDecimal(var != null && var.exclusiveMinimum ? 1 : 0);
BigDecimal inclusiveMaxLong = new BigDecimal(var == null || !var.exclusiveMaximum ? 1 : 0);
long randomDateLong = minLong.add(exclusiveMinLong).add(maxLong.add(inclusiveMaxLong).subtract(minLong)
.subtract(exclusiveMinLong).multiply(new BigDecimal(Math.random()))).longValue();
.subtract(exclusiveMinLong).multiply(BigDecimal.valueOf(Math.random()))).longValue();

// If it's just a date without a time, round downwards to the nearest day.
if ("date".equals(var.dataFormat))
if (var != null && "date".equals(var.dataFormat))
randomDateLong = (randomDateLong % MILLIS_PER_DAY) * MILLIS_PER_DAY;

// NOTE: By default Jackson serializes Date as long milliseconds since epoch date, but that conflicts with
Expand All @@ -635,19 +641,20 @@ private void appendRandomDate(StringBuilder buffer, CodegenOperation op, Codegen
private void appendRandomDouble(StringBuilder buffer, CodegenOperation op, CodegenVariable var) {
if (!appendRandomEnum(buffer, op, var)) {
// NOTE: use BigDecimal to hold double values, to avoid numeric overflow.
BigDecimal min = new BigDecimal(
var == null || var.minimum == null ? Long.MIN_VALUE : Double.parseDouble(var.minimum));
BigDecimal max = new BigDecimal(
var == null || var.maximum == null ? Long.MAX_VALUE : Double.parseDouble(var.maximum));
BigDecimal min = BigDecimal.valueOf(var == null || var.minimum == null ? Long.MIN_VALUE : Double.parseDouble(var.minimum));
BigDecimal max = BigDecimal.valueOf(var == null || var.maximum == null ? Long.MAX_VALUE : Double.parseDouble(var.maximum));
BigDecimal exclusiveMin = new BigDecimal(var != null && var.exclusiveMinimum ? 1 : 0);
BigDecimal inclusiveMax = new BigDecimal(var == null || !var.exclusiveMaximum ? 1 : 0);
BigDecimal randomBigDecimal = min.add(exclusiveMin).add(max.add(inclusiveMax).subtract(min)
.subtract(exclusiveMin).multiply(new BigDecimal(String.valueOf(Math.random()))));

if (loadTestDataFromFile)
var.addTestData(randomBigDecimal);
else
if (loadTestDataFromFile) {
if (var != null) {
var.addTestData(randomBigDecimal);
}
} else {
buffer.append(randomBigDecimal.toString()).append('D');
}
}
}

Expand Down Expand Up @@ -704,10 +711,13 @@ private void appendRandomFloat(StringBuilder buffer, CodegenOperation op, Codege
float randomFloat = (float) (min + exclusiveMin
+ ((max + inclusiveMax - min - exclusiveMin) * Math.random()));

if (loadTestDataFromFile)
var.addTestData(randomFloat);
else
if (loadTestDataFromFile) {
if (var != null) {
var.addTestData(randomFloat);
}
} else {
buffer.append(String.format(Locale.getDefault(), "%g", randomFloat)).append('F');
}
}
}

Expand All @@ -720,10 +730,13 @@ private void appendRandomInt(StringBuilder buffer, CodegenOperation op, CodegenV
long inclusiveMax = var == null || !var.exclusiveMaximum ? 1 : 0;
int randomInt = (int) (min + exclusiveMin + ((max + inclusiveMax - min - exclusiveMin) * Math.random()));

if (loadTestDataFromFile)
var.addTestData(randomInt);
else
if (loadTestDataFromFile) {
if (var != null) {
var.addTestData(randomInt);
}
} else {
buffer.append(randomInt);
}
}
}

Expand All @@ -737,13 +750,16 @@ private void appendRandomLong(StringBuilder buffer, CodegenOperation op, Codegen
BigDecimal exclusiveMin = new BigDecimal(var != null && var.exclusiveMinimum ? 1 : 0);
BigDecimal inclusiveMax = new BigDecimal(var == null || !var.exclusiveMaximum ? 1 : 0);
long randomLong = min.add(exclusiveMin).add(
max.add(inclusiveMax).subtract(min).subtract(exclusiveMin).multiply(new BigDecimal(Math.random())))
max.add(inclusiveMax).subtract(min).subtract(exclusiveMin).multiply(BigDecimal.valueOf(Math.random())))
.longValue();

if (loadTestDataFromFile)
var.addTestData(randomLong);
else
if (loadTestDataFromFile) {
if (var != null) {
var.addTestData(randomLong);
}
} else {
buffer.append(randomLong).append('L');
}
}
}

Expand All @@ -757,10 +773,13 @@ private void appendRandomShort(StringBuilder buffer, CodegenOperation op, Codege
short randomShort = (short) (min + exclusiveMin
+ ((max + inclusiveMax - min - exclusiveMin) * Math.random()));

if (loadTestDataFromFile)
var.addTestData(randomShort);
else
if (loadTestDataFromFile) {
if (var != null) {
var.addTestData(randomShort);
}
} else {
buffer.append(String.format(Locale.getDefault(), "(short)%d", randomShort));
}
}
}

Expand All @@ -769,7 +788,9 @@ private void appendRandomString(StringBuilder buffer, CodegenOperation op, Codeg
String randomString = generateRandomString(var);

if (loadTestDataFromFile) {
var.addTestData(randomString);
if (var != null) {
var.addTestData(randomString);
}
} else {
buffer.append('"').append(randomString).append('"');
}
Expand Down Expand Up @@ -1375,13 +1396,15 @@ public void processOpts() {
break;
}
}
supportingFiles.remove(supportingFile);
SupportingFile updated = new SupportingFile(
supportingFile.getTemplateFile(),
supportingFile.getFolder(),
"ApplicationContext-" + invokerPackage + ".xml"
);
supportingFiles.add(updated);
if (supportingFile != null) {
supportingFiles.remove(supportingFile);
SupportingFile updated = new SupportingFile(
supportingFile.getTemplateFile(),
supportingFile.getFolder(),
"ApplicationContext-" + invokerPackage + ".xml"
);
supportingFiles.add(updated);
}
}
}
}
Expand Down
Loading