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

[Go] Fix "allOf" inherited model properties by embedding parent models #12683

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
4233d2a
Fixed enum values generation fo 'GraphQL NodeJS Express Server' gener…
antonio-petricca May 26, 2022
a39d86c
update graphql nodejs samples
wing328 May 26, 2022
54dca39
Add authentication for haskell-servant (#12470)
7omb May 26, 2022
5cce050
[OCaml] Code generation fixes (#12395)
MisterDA May 26, 2022
c6a4947
fix ocaml readme installation (#12477)
wing328 May 26, 2022
71ea659
[Java/Spring] Support Spring Boot 3 and Jakarta EE 9 (#12407)
cachescrubber May 26, 2022
c3a4914
update spring github workflow tests
wing328 May 26, 2022
c2eee6f
Use print() function in both Python 2 and Python 3 (#12467)
cclauss May 26, 2022
b6ef789
fix #11886 unhandled default enum case (#12344)
robbertvanwaveren May 26, 2022
e83f1ed
Graphql nodejs express server lists fixup (#12476)
antonio-petricca May 26, 2022
210b43a
update graphql nodejs samples
wing328 May 26, 2022
50958e2
Fixes #10568 (#12409)
taufik-rama May 26, 2022
fb1706b
[php-symfony] Allow non mandatory array value (#11618)
Cubid May 26, 2022
5307a8d
update samples
wing328 May 26, 2022
76eddeb
php-laravel, enum models, nullable and default values (#12480)
wing328 May 27, 2022
e823290
[PYTHON] GetItem not working for Client generated allOf model and bro…
the-akhil-nair May 28, 2022
078232a
[haskell-http-client] relax Aeson constraint to allow Aeson 1 (#12486)
jonschoning May 28, 2022
05d49d9
Add support for allOf in R client generator (#12487)
wing328 May 28, 2022
f0ea10f
Update R auto-generated doc (#12488)
wing328 May 29, 2022
4cfc32e
Kotlin-client: Pass OkHttpClient instance to the base class (ApiClien…
julienlavigne May 30, 2022
8919307
[typescript-angular] remove outdated angular samples (#12134)
mkusaka May 30, 2022
51f624e
typescript: fix status code (#12472)
ksvirkou-hubspot May 30, 2022
6f32206
[Typescript] Support text/html by ObjectSerializer.parse (#12459)
ksvirkou-hubspot May 30, 2022
129fd0a
[Typescript] update addImport method (fix oneOf) (#11689)
ksvirkou-hubspot May 30, 2022
88e2490
[Java/Spring] Fix of issue #12494: call to superclass method is done …
WeihmannDev Jun 1, 2022
bcc77d4
Fix for #12504: invalid elm code for paths containing UUIDs (#12506)
mawis Jun 1, 2022
41a2964
Add support for remote development with Gitpod (#12508)
joschi Jun 2, 2022
4d149e7
replace tabs with 4-space in SpringCodegenTest.java
wing328 Jun 2, 2022
fbc35a2
[BUG] Use https URL for Spring milestone repository (#12512)
welshm Jun 2, 2022
421b3be
[csharp-netcore] Add "WithHttpInfo" variant methods in api_doc (#12323)
prajon84 Jun 3, 2022
f043602
update samples
wing328 Jun 3, 2022
c1deedb
Add Gradle Enterprise logo (#12518)
sorin-florea Jun 3, 2022
45a3b15
[java][okhttp-gson] Fix NPE in the response header, junit5 issue in s…
wing328 Jun 4, 2022
fe8187b
[Kotlin][Client] replace java.nio.* to avoid crash on Android API 25 …
4brunu Jun 4, 2022
38018d8
Test PHP Symfony server sample in github action (#12533)
wing328 Jun 4, 2022
f30257d
Fix syntax error for $jsonDeserializationVisitor (#12521)
dmetzner Jun 4, 2022
aac39ea
fixing typo in InitOverrideFunction (#12528)
orange-buffalo Jun 4, 2022
ee9ba4a
update ts samples
wing328 Jun 4, 2022
5b44aaf
[Dart][Client] Support parsing DateTime (#12433)
kalymero Jun 4, 2022
0ec2bda
update build.gradle to work with junit5 (#12535)
wing328 Jun 5, 2022
53d66a8
add govery logo (#12537)
wing328 Jun 5, 2022
6869f3b
Skip generating operation examples when flag is set (#12539)
cyangle Jun 5, 2022
f52ee28
Fix NPE when generating examples for parameter (object) (#12538)
wing328 Jun 5, 2022
6cd2469
[R] add oneOf support (#12491)
wing328 Jun 5, 2022
ec6c4a4
[Feature] Handle optional operation responses (#12342)
Paul-Etienne Jun 5, 2022
c4db27f
Fixes #9923 - added recursion for nested objects (#12428)
0x7162 Jun 6, 2022
0296380
update html2 samples
wing328 Jun 6, 2022
c829567
add a link to blog post on api first
wing328 Jun 6, 2022
2c39835
[PHP] Replace @ character so we can use Hydra Jsonld models. (#12171)
warmwaterkruik Jun 6, 2022
daa95de
Use Arrays.equals and Arrays.hashCode by built-in array types (#12502)
JGRsystematic Jun 6, 2022
5bd3694
fix @implements annotations in PHP client (#11908)
IonBazan Jun 6, 2022
051ed53
Update spring generator documentation (#12298)
diasonti Jun 6, 2022
8f3dd48
update samples, docs
wing328 Jun 6, 2022
3b58720
[REQ] Add equals and hashcode to java-cxf pojo #12519 (#12520)
DevFlorian Jun 6, 2022
6948f15
update jaxrs cxf samples
wing328 Jun 6, 2022
5db8cd0
fix toJSON, add tests (#12541)
wing328 Jun 6, 2022
a339123
Fix typescript-fetch compatibility with noUncheckedIndexedAccess (#12…
javier-garcia-meteologica Jun 6, 2022
4fbe1e9
[R] add anyOf support (#12544)
wing328 Jun 7, 2022
8c0cb8b
ad fastly to user list (#12547)
wing328 Jun 7, 2022
5462681
Add milestone repository for Spring maven plugin (#12530)
welshm Jun 7, 2022
14aef2c
[R] Add validateJSON to oneOf, anyOf models (#12548)
wing328 Jun 7, 2022
45f430f
Fix problem when uploading file using form-data in jersey2 client (#1…
JFCote Jun 11, 2022
aeb40ab
[Go] Address Gosec vulnerabilities in Go client mustache template (#1…
gcatanese Jun 11, 2022
ee9b984
Add new option to customize inline model naming convention (#12562)
wing328 Jun 11, 2022
3bc4416
update go samples
wing328 Jun 11, 2022
c7107a1
throw exception when failed to refresh token (jersey3) (#12577)
wing328 Jun 12, 2022
0c18b2e
update jersey3 jackson-databind to 2.13.2.2 (#12579)
wing328 Jun 12, 2022
c259533
[java] Add useSingleRequestParameter support (#12580)
wing328 Jun 12, 2022
cdc2d92
[Java] fix bugs when property name, datatype are the same (#12581)
wing328 Jun 12, 2022
a7db213
Upgrade virtualan-plugin to 2.5.1 (#12429)
cachescrubber Jun 13, 2022
bf22f38
[C][Client] Support freeform object (#12557)
ityuhui Jun 13, 2022
3190084
Test JDK 17 in github workflow (#12583)
wing328 Jun 13, 2022
a00ae46
Fixes double serialization bug in python-experimental (#12561)
spacether Jun 13, 2022
ef583c5
[typescript-fetch] Fix ToJSON for non-descriminator oneOf constructs …
Nukesor Jun 13, 2022
6be94be
[ts-angular]: added ts-ignore directive to `addToHttpParams` to avoid…
marleypowell Jun 14, 2022
bd6617b
Better null check for encoding (#12597)
wing328 Jun 15, 2022
3ec1574
[JAVA][Feign] Remove camelCase naming for form parameters (#12587)
ledoyen Jun 15, 2022
01fdff0
update java samples
wing328 Jun 15, 2022
3143390
[java][okhttp-gson] Add streaming support in group parameters (#12601)
wing328 Jun 16, 2022
9485e3b
Update plugins.md (#12611)
xiao2shiqi Jun 16, 2022
8b77365
Fix cookies in parameters are always generated as required (#12599)
jorgerod Jun 16, 2022
bcb5f55
[C][Client] Set the default value for the null json (#12620)
ityuhui Jun 17, 2022
a01ed49
Update installation.md (#12621)
xiao2shiqi Jun 17, 2022
0140f84
Keep AST small when usign builder (#12610)
janisz Jun 17, 2022
c26ac3f
add documentations to r oneof, anyof (#12638)
wing328 Jun 19, 2022
7b108c2
handle wildcard sub content-type (#12469)
borsch Jun 19, 2022
decb96b
fix typescript node default enum (#12633)
GuyGitzMagen Jun 20, 2022
995f7ce
Fix bugs in camelcase lambda, add tests for pascalcase (#12639)
wing328 Jun 20, 2022
1440a68
[Java][Jersey/Native/okhttp] don't override x-implements (#12410)
borsch Jun 20, 2022
f29fdab
update constructor for r oneof, anyof objects (#12643)
wing328 Jun 21, 2022
1f7a495
update roxygen to newer version (#12652)
wing328 Jun 21, 2022
042f717
[R] escape item reserved words in model items (#12653)
wing328 Jun 21, 2022
f2cc3b8
fix roxygen warnings in oneof, anyof, api_client (#12654)
wing328 Jun 21, 2022
a599ae9
fix deserialization for r model with special item name (#12658)
wing328 Jun 22, 2022
012f908
add doc to api exception, response object in R client (#12659)
wing328 Jun 22, 2022
b1ea0f3
[swift5] Make it possible to opt out of JSONEncodable conformance (#1…
stjernegard Jun 22, 2022
75b883c
OkHttpClient - fix enum properties in requests (#12661)
Yartsev Jun 22, 2022
c38d825
[BUG] Issue 10792 Kotlin generator produces invalid code when allOf i…
etremblay Jun 22, 2022
45baa5e
update kotlin samples
wing328 Jun 23, 2022
7d768f2
[R] add error object type support (#12402)
wing328 Jun 23, 2022
c3970d7
update r model doc (#12676)
wing328 Jun 23, 2022
40d70f4
Add generation of embedded structs for inherited types
DouglasDwyer Jun 23, 2022
b9ba4a1
Pre PR commit
DouglasDwyer Jun 23, 2022
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
Prev Previous commit
Next Next commit
php-laravel, enum models, nullable and default values (#12480)
* + support for enum models & separating mustache templates for enums and generics
+ extract property 'type' and 'default value' from a #ref to an enum model
+ support for `PascalCase` naming convention for PHP generators
+ use a default value for known basic types when they are not nullable
+ use 'null' as default value for nullable types when they do not specify the default value
+ use defined constant path as enum default value when found

* + sample output update

* + change model fields to be public and acessible from outside

* + sample output update

Co-authored-by: Mostafa Aghajani <[email protected]>
  • Loading branch information
wing328 and aghajani authored May 27, 2022
commit 76eddeb7133fb5a549a077b907bce92da52278ec
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ public String toVarName(String name) {
// return the name in camelCase style
// phone_number => phoneNumber
name = camelize(name, true);
} else if ("PascalCase".equals(variableNamingConvention)) {
name = camelize(name, false);
} else { // default to snake case
// return the name in underscore style
// PhoneNumber => phone_number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
package org.openapitools.codegen.languages;

import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.meta.features.*;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.OperationMap;
import org.openapitools.codegen.model.OperationsMap;
import org.openapitools.codegen.utils.ModelUtils;

import io.swagger.v3.oas.models.media.Schema;

import java.io.File;
import java.util.*;
Expand Down Expand Up @@ -296,4 +300,96 @@ protected String toControllerName(String name) {

return camelize(name, false) + "Controller";
}

@Override
protected String getEnumDefaultValue(String defaultValue, String dataType) {
return defaultValue;
}

@Override
public CodegenProperty fromProperty(String name, Schema p) {
CodegenProperty property = super.fromProperty(name, p);
Schema referencedSchema = ModelUtils.getReferencedSchema(this.openAPI, p);

//Referenced enum case:
if (!property.isEnum && referencedSchema.getEnum() != null && !referencedSchema.getEnum().isEmpty()) {
property.dataType = this.getSchemaType(referencedSchema);
property.defaultValue = this.toDefaultValue(referencedSchema);
List<Object> _enum = referencedSchema.getEnum();

Map<String, Object> allowableValues = new HashMap<>();
allowableValues.put("values", _enum);
if (allowableValues.size() > 0) {
property.allowableValues = allowableValues;
}
}

return property;
}

@Override
public String toDefaultValue(Schema p) {
if (ModelUtils.isBooleanSchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
} else if (!Boolean.TRUE.equals(p.getNullable())) {
return "false";
}
} else if (ModelUtils.isDateSchema(p)) {
// TODO
} else if (ModelUtils.isDateTimeSchema(p)) {
// TODO
} else if (ModelUtils.isFileSchema(p)) {
// TODO
} else if (ModelUtils.isNumberSchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
} else if (!Boolean.TRUE.equals(p.getNullable())) {
return "0";
}
} else if (ModelUtils.isIntegerSchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
} else if (!Boolean.TRUE.equals(p.getNullable())) {
return "0";
}
} else if (ModelUtils.isStringSchema(p)) {
if (p.getDefault() != null) {
return "'" + p.getDefault() + "'";
} else if (!Boolean.TRUE.equals(p.getNullable())) {
return "\"\"";
}
} else if (ModelUtils.isArraySchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
} else if (!Boolean.TRUE.equals(p.getNullable())) {
return "[]";
}
}

return null;
}

@Override
public String toEnumDefaultValue(String value, String datatype) {
return datatype + "::" + value;
}

@Override
public String toEnumVarName(String value, String datatype) {
if (value.length() == 0) {
return super.toEnumVarName(value, datatype);
}

// number
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
String varName = "NUMBER_" + value;
varName = varName.replaceAll("-", "MINUS_");
varName = varName.replaceAll("\\+", "PLUS_");
varName = varName.replaceAll("\\.", "_DOT_");
return varName;
}

return super.toEnumVarName(value, datatype);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
<?php
{{#models}}{{#model}}/**
{{#models}}
{{#model}}
/**
* {{classname}}
*/
namespace {{modelPackage}};

/**
* {{classname}}
{{#description}}
* @description {{{.}}}
{{/description}}
*/
class {{classname}} {

{{#vars}}
/** @var {{{dataType}}} ${{name}} {{description}}*/
{{#deprecated}}
/** @deprecated */
{{/deprecated}}
private ${{name}};

{{/vars}}
}
{{/model}}{{/models}}
{{#isEnum}}{{>model_enum}}{{/isEnum}}{{^isEnum}}{{>model_generic}}{{/isEnum}}
{{/model}}
{{/models}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class {{classname}}
{
/**
* Possible values of this enum
*/
{{#allowableValues}}
{{#enumVars}}
const {{{name}}} = {{{value}}};

{{/enumVars}}
{{/allowableValues}}
/**
* Gets allowable values of the enum
* @return string[]
*/
public static function getAllowableEnumValues()
{
return [
{{#allowableValues}}
{{#enumVars}}
self::{{{name}}}{{^-last}},
{{/-last}}
{{/enumVars}}
{{/allowableValues}}

];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class {{classname}} {

{{#vars}}
/** @var {{{dataType}}}{{#isNullable}}|null{{/isNullable}} ${{name}} {{description}}*/
{{#deprecated}}
/** @deprecated */
{{/deprecated}}
public ${{name}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}{{#isNullable}} = null{{/isNullable}}{{/defaultValue}};

{{/vars}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
class AdditionalPropertiesClass {

/** @var array<string,string> $mapProperty */
private $mapProperty;
public $mapProperty;

/** @var array<string,array<string,string>> $mapOfMapProperty */
private $mapOfMapProperty;
public $mapOfMapProperty;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
class AllOfWithSingleRef {

/** @var string $username */
private $username;
public $username = "";

/** @var SingleRefType $singleRefType */
private $singleRefType;
/** @var SingleRefType|null $singleRefType */
public $singleRefType = null;

}
4 changes: 2 additions & 2 deletions samples/server/petstore/php-laravel/lib/app/Models/Animal.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
class Animal {

/** @var string $className */
private $className;
public $className = "";

/** @var string $color */
private $color;
public $color = 'red';

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
class ApiResponse {

/** @var int $code */
private $code;
public $code = 0;

/** @var string $type */
private $type;
public $type = "";

/** @var string $message */
private $message;
public $message = "";

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
class ArrayOfArrayOfNumberOnly {

/** @var float[][] $arrayArrayNumber */
private $arrayArrayNumber;
public $arrayArrayNumber = [];

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
class ArrayOfNumberOnly {

/** @var float[] $arrayNumber */
private $arrayNumber;
public $arrayNumber = [];

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
class ArrayTest {

/** @var string[] $arrayOfString */
private $arrayOfString;
public $arrayOfString = [];

/** @var int[][] $arrayArrayOfInteger */
private $arrayArrayOfInteger;
public $arrayArrayOfInteger = [];

/** @var \app\Models\ReadOnlyFirst[][] $arrayArrayOfModel */
private $arrayArrayOfModel;
public $arrayArrayOfModel = [];

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
class Capitalization {

/** @var string $smallCamel */
private $smallCamel;
public $smallCamel = "";

/** @var string $capitalCamel */
private $capitalCamel;
public $capitalCamel = "";

/** @var string $smallSnake */
private $smallSnake;
public $smallSnake = "";

/** @var string $capitalSnake */
private $capitalSnake;
public $capitalSnake = "";

/** @var string $sCAETHFlowPoints */
private $sCAETHFlowPoints;
public $sCAETHFlowPoints = "";

/** @var string $aTTNAME Name of the pet*/
private $aTTNAME;
public $aTTNAME = "";

}
6 changes: 3 additions & 3 deletions samples/server/petstore/php-laravel/lib/app/Models/Cat.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
class Cat {

/** @var string $className */
private $className;
public $className = "";

/** @var string $color */
private $color;
public $color = 'red';

/** @var bool $declawed */
private $declawed;
public $declawed = false;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
class CatAllOf {

/** @var bool $declawed */
private $declawed;
public $declawed = false;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
class Category {

/** @var int $id */
private $id;
public $id = 0;

/** @var string $name */
private $name;
public $name = 'default-name';

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

/**
* ClassModel
* @description Model for testing model with \"_class\" property
*/
class ClassModel {

/** @var string $class */
private $class;
public $class = "";

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
class Client {

/** @var string $client */
private $client;
public $client = "";

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
class DeprecatedObject {

/** @var string $name */
private $name;
public $name = "";

}
6 changes: 3 additions & 3 deletions samples/server/petstore/php-laravel/lib/app/Models/Dog.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
class Dog {

/** @var string $className */
private $className;
public $className = "";

/** @var string $color */
private $color;
public $color = 'red';

/** @var string $breed */
private $breed;
public $breed = "";

}
Loading