Skip to content

Commit bff9f50

Browse files
authored
Merge branch 'OpenAPITools:master' into master
2 parents 179288d + e1513f7 commit bff9f50

174 files changed

Lines changed: 906 additions & 569 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.

README.md

Lines changed: 42 additions & 39 deletions
Large diffs are not rendered by default.

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/Java/libraries/okhttp-gson/anyof_model.mustache

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
238238
/**
239239
* Set the instance that matches the anyOf child schema, check
240240
* the instance parameter is valid against the anyOf child schemas:
241-
* {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}
241+
* {{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}
242242
*
243243
* It could be an instance of the 'anyOf' schemas.
244244
*/
@@ -276,9 +276,9 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
276276

277277
/**
278278
* Get the actual instance, which can be the following:
279-
* {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}
279+
* {{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}
280280
*
281-
* @return The actual instance ({{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}})
281+
* @return The actual instance ({{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}})
282282
*/
283283
@SuppressWarnings("unchecked")
284284
@Override
@@ -290,11 +290,11 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
290290
{{#anyOf}}
291291
{{^vendorExtensions.x-duplicated-data-type-ignoring-erasure}}
292292
/**
293-
* Get the actual instance of `{{{dataType}}}`. If the actual instance is not `{{{dataType}}}`,
293+
* Get the actual instance of `{{dataType}}`. If the actual instance is not `{{dataType}}`,
294294
* the ClassCastException will be thrown.
295295
*
296-
* @return The actual instance of `{{{dataType}}}`
297-
* @throws ClassCastException if the instance is not `{{{dataType}}}`
296+
* @return The actual instance of `{{dataType}}`
297+
* @throws ClassCastException if the instance is not `{{dataType}}`
298298
*/
299299
public {{{dataType}}} get{{#sanitizeDataType}}{{{dataType}}}{{/sanitizeDataType}}() throws ClassCastException {
300300
return ({{{dataType}}})super.getActualInstance();

modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
316316
/**
317317
* Set the instance that matches the oneOf child schema, check
318318
* the instance parameter is valid against the oneOf child schemas:
319-
* {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}
319+
* {{#oneOf}}{{.}}{{^-last}}, {{/-last}}{{/oneOf}}
320320
*
321321
* It could be an instance of the 'oneOf' schemas.
322322
*/
@@ -354,9 +354,9 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
354354

355355
/**
356356
* Get the actual instance, which can be the following:
357-
* {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}
357+
* {{#oneOf}}{{.}}{{^-last}}, {{/-last}}{{/oneOf}}
358358
*
359-
* @return The actual instance ({{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}})
359+
* @return The actual instance ({{#oneOf}}{{.}}{{^-last}}, {{/-last}}{{/oneOf}})
360360
*/
361361
@SuppressWarnings("unchecked")
362362
@Override
@@ -368,12 +368,13 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
368368
{{#oneOf}}
369369
{{^vendorExtensions.x-duplicated-data-type-ignoring-erasure}}
370370
/**
371-
* Get the actual instance of `{{{dataType}}}`. If the actual instance is not `{{{dataType}}}`,
371+
* Get the actual instance of `{{dataType}}`. If the actual instance is not `{{dataType}}`,
372372
* the ClassCastException will be thrown.
373373
*
374-
* @return The actual instance of `{{{dataType}}}`
375-
* @throws ClassCastException if the instance is not `{{{dataType}}}`
374+
* @return The actual instance of `{{dataType}}`
375+
* @throws ClassCastException if the instance is not `{{dataType}}`
376376
*/
377+
@SuppressWarnings("unchecked")
377378
public {{{dataType}}} get{{#sanitizeDataType}}{{{dataType}}}{{/sanitizeDataType}}() throws ClassCastException {
378379
return ({{{dataType}}})super.getActualInstance();
379380
}

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
);

0 commit comments

Comments
 (0)