Skip to content

Commit bc54c80

Browse files
committed
Merge remote-tracking branch 'source/master' into feature/fastapi-examples
2 parents 949744a + 6756caf commit bc54c80

140 files changed

Lines changed: 644 additions & 457 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.

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.slf4j.LoggerFactory;
3434

3535
import java.io.File;
36+
import java.math.BigDecimal;
3637
import java.util.*;
3738
import java.util.regex.Matcher;
3839
import java.util.regex.Pattern;
@@ -636,6 +637,48 @@ public String toDefaultValue(Schema p) {
636637
}
637638
}
638639

640+
// OAS 3.x: `default` may appear alongside `$ref` on the same schema (e.g. optional query param whose schema
641+
// references an enum model). That wrapper is often not classified as string/number here, but still carries
642+
// the default OpenAPI value — needed so Mustache can emit `query->get(..., <default>)` for php-symfony.
643+
if (p.getDefault() != null) {
644+
return defaultValueToPhpLiteral(p.getDefault());
645+
}
646+
647+
return null;
648+
}
649+
650+
/**
651+
* Converts a JSON Schema {@code default} value to a PHP expression suitable for templates (e.g. second argument to
652+
* {@code query->get}). Only safe scalar literals are supported; unknown types log a warning and yield {@code null}
653+
* so we do not emit broken PHP from {@code Object#toString()}.
654+
*/
655+
private String defaultValueToPhpLiteral(Object def) {
656+
if (def == null) {
657+
return null;
658+
}
659+
if (def instanceof String) {
660+
return "'" + escapeTextInSingleQuotes((String) def) + "'";
661+
}
662+
if (def instanceof Boolean) {
663+
return Boolean.TRUE.equals(def) ? "true" : "false";
664+
}
665+
if (def instanceof BigDecimal) {
666+
return ((BigDecimal) def).toPlainString();
667+
}
668+
if (def instanceof Number) {
669+
String s = def.toString();
670+
if (s.contains("Infinity") || s.contains("NaN")) {
671+
LOGGER.warn("Unsupported numeric default for PHP literal: {}", def);
672+
return null;
673+
}
674+
return s;
675+
}
676+
if (def instanceof Character) {
677+
return "'" + escapeTextInSingleQuotes(String.valueOf((Character) def)) + "'";
678+
}
679+
LOGGER.warn(
680+
"Cannot convert OpenAPI default of type {} to a PHP literal; omitting defaultValue",
681+
def.getClass().getName());
639682
return null;
640683
}
641684

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,11 @@ private String enumValuesToEnumTypeUnion(List<String> values, String dataType) {
772772
private String numericEnumValuesToEnumTypeUnion(List<Number> values) {
773773
List<String> stringValues = new ArrayList<>();
774774
for (Number value : values) {
775-
stringValues.add(value.toString());
775+
if (value == null) {
776+
LOGGER.warn("An enum value was null. See https://github.com/swagger-api/swagger-core/issues/4223");
777+
} else {
778+
stringValues.add(value.toString());
779+
}
776780
}
777781
return enumValuesToEnumTypeUnion(stringValues, "number");
778782
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,11 @@ private String enumValuesToEnumTypeUnion(List<String> values, String dataType) {
595595
private String numericEnumValuesToEnumTypeUnion(List<Number> values) {
596596
List<String> stringValues = new ArrayList<>();
597597
for (Number value : values) {
598-
stringValues.add(value.toString());
598+
if (value == null) {
599+
LOGGER.warn("An enum value was null. See https://github.com/swagger-api/swagger-core/issues/4223");
600+
} else {
601+
stringValues.add(value.toString());
602+
}
599603
}
600604
return enumValuesToEnumTypeUnion(stringValues, "number");
601605
}

modules/openapi-generator/src/main/resources/Javascript-Closure-Angular/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ goog.require('{{import}}');
6666
{{package}}.{{classname}}.prototype.{{nickname}} = function({{#allParams}}{{^required}}opt_{{/required}}{{paramName}}, {{/allParams}}opt_extraHttpRequestParams) {
6767
/** @const {string} */
6868
var path = this.basePath_ + '{{{path}}}'{{#pathParams}}
69-
.replace('{' + '{{baseName}}' + '}', String({{^required}}opt_{{/required}}{{paramName}})){{/pathParams}};
69+
.replace({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, String({{^required}}opt_{{/required}}{{paramName}})){{/pathParams}};
7070

7171
/** @type {!Object} */
7272
var queryParameters = {};

modules/openapi-generator/src/main/resources/Javascript-Closure-Angular/es6/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default class {{classname}} {
5656
method: '{{httpMethod}}',
5757
url: this.basePath + '{{{path}}}'
5858
{{#pathParams}}
59-
.replace('{' + '{{baseName}}' + '}', ':{{paramName}}')
59+
.replace({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, ':{{paramName}}')
6060
{{/pathParams}}
6161
}
6262
}

modules/openapi-generator/src/main/resources/Javascript-Flowtyped/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
8989
{{/required}}
9090
{{/allParams}}
9191
const localVarPath = `{{{path}}}`{{#pathParams}}
92-
.replace(`{${"{{baseName}}"}}`, encodeURIComponent(String({{paramName}}))){{/pathParams}};
92+
.replace({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, encodeURIComponent(String({{paramName}}))){{/pathParams}};
9393
const localVarUrlObj = url.parse(localVarPath, true);
9494
const localVarRequestOptions: RequestOptions = Object.assign({}, { method: '{{httpMethod}}' }, options);
9595
const localVarHeaderParameter = {};

modules/openapi-generator/src/main/resources/php-nextgen/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ use {{invokerPackage}}\ObjectSerializer;
718718
{{/collectionFormat}}
719719
if (${{paramName}} !== null) {
720720
$resourcePath = str_replace(
721-
'{' . '{{baseName}}' . '}',
721+
{{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>,
722722
ObjectSerializer::toPathValue(${{paramName}}{{#isEnumRef}}->value{{/isEnumRef}}),
723723
$resourcePath
724724
);

modules/openapi-generator/src/main/resources/php/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ use {{invokerPackage}}\ObjectSerializer;
640640
{{/collectionFormat}}
641641
if (${{paramName}} !== null) {
642642
$resourcePath = str_replace(
643-
'{' . '{{baseName}}' . '}',
643+
{{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>,
644644
ObjectSerializer::toPathValue(${{paramName}}),
645645
$resourcePath
646646
);

modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ use function sprintf;
598598
{{/collectionFormat}}
599599
if (${{paramName}} !== null) {
600600
$resourcePath = str_replace(
601-
'{' . '{{baseName}}' . '}',
601+
{{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>,
602602
ObjectSerializer::toPathValue(${{paramName}}),
603603
$resourcePath
604604
);

modules/openapi-generator/src/main/resources/ruby-client/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ module {{moduleName}}
170170
{{/hasValidation}}
171171
{{/allParams}}
172172
# resource path
173-
local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', CGI.escape({{paramName}}.to_s){{^strictSpecBehavior}}.gsub('%2F', '/'){{/strictSpecBehavior}}){{/pathParams}}
173+
local_var_path = '{{{path}}}'{{#pathParams}}.sub({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, CGI.escape({{paramName}}.to_s){{^strictSpecBehavior}}.gsub('%2F', '/'){{/strictSpecBehavior}}){{/pathParams}}
174174

175175
# query parameters
176176
query_params = opts[:query_params] || {}

0 commit comments

Comments
 (0)