forked from loafle/openapi-generator-original
Merge branch 'master' of github.com:OpenAPITools/openapi-generator into feature/typescript-angular-deep-object-query-params
This commit is contained in:
@@ -61,6 +61,8 @@ jobs:
|
||||
- samples/client/petstore/java/webclient-swagger2
|
||||
- samples/client/petstore/java/webclient-useSingleRequestParameter
|
||||
- samples/client/petstore/java/vertx
|
||||
- samples/client/petstore/java/vertx-no-nullable
|
||||
- samples/client/petstore/java/vertx-supportVertxFuture
|
||||
- samples/client/petstore/java/jersey2-java8-localdatetime
|
||||
- samples/client/petstore/java/google-api-client
|
||||
- samples/client/petstore/java/rest-assured
|
||||
|
||||
10
bin/configs/java-vertx-supportVertxFuture.yaml
Normal file
10
bin/configs/java-vertx-supportVertxFuture.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
generatorName: java
|
||||
outputDir: samples/client/petstore/java/vertx-supportVertxFuture
|
||||
library: vertx
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/Java
|
||||
additionalProperties:
|
||||
artifactId: petstore-vertx-supportvertxfuture
|
||||
hideGenerationTimestamp: "true"
|
||||
dateLibrary: java8
|
||||
supportVertxFuture: "true"
|
||||
@@ -10,6 +10,14 @@ additionalProperties:
|
||||
wrapComplexType: false
|
||||
supportMultipleResponses: false
|
||||
aggregateModelsName: data
|
||||
customOptionsApi: |
|
||||
option java_multiple_files = true;
|
||||
option java_package = "com.example.tutorial.protos.api";
|
||||
option java_outer_classname = "ExampleProtos";
|
||||
customOptionsModel: |
|
||||
option java_multiple_files = false;
|
||||
option java_package = "com.example.tutorial.protos.model";
|
||||
option java_outer_classname = "ExampleProtos";
|
||||
useSimplifiedEnumNames: true
|
||||
typeMappings:
|
||||
object: "google.protobuf.Struct"
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ClientTest.java"
|
||||
sha256: 325fdd5d7e2c97790c0fb44f712ab7b2ba022d7e1a5b0056f47b07f342682b6d
|
||||
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java"
|
||||
sha256: e673d9928c8eb848262d0116fe0d28db832e128671a810a7c966d06d90cb9b63
|
||||
sha256: 67941355a0a27ed9ff9318b1caa103e78b81b9aff61b594b18be5cd2bb9f6591
|
||||
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/PetApiTest.java"
|
||||
sha256: 8b1b8f2a2ad00ccb090873a94a5f73e328b98317d2ec715f53bd7a1accb2a023
|
||||
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetTest.java"
|
||||
@@ -55,6 +55,8 @@
|
||||
sha256: 45cdaba3d2adc212cd4f0184ad475419a95e2326254c2ef84175e210c922b2f3
|
||||
- filename: "samples/client/petstore/java/feign/src/test/java/org/openapitools/client/JacksonTest.java"
|
||||
sha256: 45cdaba3d2adc212cd4f0184ad475419a95e2326254c2ef84175e210c922b2f3
|
||||
- filename: "samples/client/petstore/java/restclient/src/test/java/org/openapitools/client/JacksonTest.java"
|
||||
sha256: 45cdaba3d2adc212cd4f0184ad475419a95e2326254c2ef84175e210c922b2f3
|
||||
# rust axum test files
|
||||
- filename: "samples/server/petstore/rust-axum/output/rust-axum-oneof/tests/oneof_with_discriminator.rs"
|
||||
sha256: 2d4f5a069fdcb3057bb078d5e75b3de63cd477b97725e457079df24bd2c30600
|
||||
|
||||
@@ -127,7 +127,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|x-class-extra-annotation|List of custom annotations to be added to model|MODEL|null
|
||||
|x-field-extra-annotation|List of custom annotations to be added to property|FIELD, OPERATION_PARAMETER|null
|
||||
|x-operation-extra-annotation|List of custom annotations to be added to operation|OPERATION|null
|
||||
|x-spring-paginated|Add org.springframework.data.domain.Pageable to controller method. Can be used to handle page & size query parameters|OPERATION|false
|
||||
|x-spring-paginated|Add `org.springframework.data.domain.Pageable` to controller method. Can be used to handle `page`, `size` and `sort` query parameters. If these query parameters are also specified in the operation spec, they will be removed from the controller method as their values can be obtained from the `Pageable` object.|OPERATION|false
|
||||
|x-version-param|Marker property that tells that this parameter would be used for endpoint versioning. Applicable for headers & query params. true/false|OPERATION_PARAMETER|null
|
||||
|x-pattern-message|Add this property whenever you need to customize the invalidation error message for the regex pattern of a variable|FIELD, OPERATION_PARAMETER|null
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|sourceFolder|source folder for generated code| |src/main/java|
|
||||
|supportStreaming|Support streaming endpoint (beta)| |false|
|
||||
|supportUrlQuery|Generate toUrlQueryString in POJO (default to true). Available on `native`, `apache-httpclient` libraries.| |false|
|
||||
|supportVertxFuture|Also generate api methods that return a vertx Future instead of taking a callback. Only `vertx` supports this option. Requires vertx 4 or greater.| |false|
|
||||
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
|
||||
|useAbstractionForFiles|Use alternative types instead of java.io.File to allow passing bytes without a file on disk. Available on resttemplate, webclient, restclient, libraries| |false|
|
||||
|useBeanValidation|Use BeanValidation API annotations| |false|
|
||||
|
||||
@@ -87,6 +87,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|sourceFolder|source folder for generated code| |src/main/java|
|
||||
|supportStreaming|Support streaming endpoint (beta)| |false|
|
||||
|supportUrlQuery|Generate toUrlQueryString in POJO (default to true). Available on `native`, `apache-httpclient` libraries.| |false|
|
||||
|supportVertxFuture|Also generate api methods that return a vertx Future instead of taking a callback. Only `vertx` supports this option. Requires vertx 4 or greater.| |false|
|
||||
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
|
||||
|useAbstractionForFiles|Use alternative types instead of java.io.File to allow passing bytes without a file on disk. Available on resttemplate, webclient, restclient, libraries| |false|
|
||||
|useBeanValidation|Use BeanValidation API annotations| |false|
|
||||
|
||||
@@ -20,6 +20,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
| ------ | ----------- | ------ | ------- |
|
||||
|addJsonNameAnnotation|Append "json_name" annotation to message field when the specification name differs from the protobuf field name| |false|
|
||||
|aggregateModelsName|Aggregated model filename. If set, all generated models will be combined into this single file.| |null|
|
||||
|customOptionsApi|Custom options for the api files.| |null|
|
||||
|customOptionsModel|Custom options for the model files.| |null|
|
||||
|numberedFieldNumberList|Field numbers in order.| |false|
|
||||
|startEnumsWithUnspecified|Introduces "UNSPECIFIED" as the first element of enumerations.| |false|
|
||||
|supportMultipleResponses|Support multiple responses| |true|
|
||||
|
||||
@@ -120,7 +120,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|x-class-extra-annotation|List of custom annotations to be added to model|MODEL|null
|
||||
|x-field-extra-annotation|List of custom annotations to be added to property|FIELD, OPERATION_PARAMETER|null
|
||||
|x-operation-extra-annotation|List of custom annotations to be added to operation|OPERATION|null
|
||||
|x-spring-paginated|Add org.springframework.data.domain.Pageable to controller method. Can be used to handle page & size query parameters|OPERATION|false
|
||||
|x-spring-paginated|Add `org.springframework.data.domain.Pageable` to controller method. Can be used to handle `page`, `size` and `sort` query parameters. If these query parameters are also specified in the operation spec, they will be removed from the controller method as their values can be obtained from the `Pageable` object.|OPERATION|false
|
||||
|x-version-param|Marker property that tells that this parameter would be used for endpoint versioning. Applicable for headers & query params. true/false|OPERATION_PARAMETER|null
|
||||
|x-pattern-message|Add this property whenever you need to customize the invalidation error message for the regex pattern of a variable|FIELD, OPERATION_PARAMETER|null
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
public enum VendorExtension {
|
||||
|
||||
X_IMPLEMENTS("x-implements", ExtensionLevel.MODEL, "Ability to specify interfaces that model must implements", "empty array"),
|
||||
X_SPRING_PAGINATED("x-spring-paginated", ExtensionLevel.OPERATION, "Add org.springframework.data.domain.Pageable to controller method. Can be used to handle page & size query parameters", "false"),
|
||||
X_SPRING_PAGINATED("x-spring-paginated", ExtensionLevel.OPERATION, "Add `org.springframework.data.domain.Pageable` to controller method. Can be used to handle `page`, `size` and `sort` query parameters. If these query parameters are also specified in the operation spec, they will be removed from the controller method as their values can be obtained from the `Pageable` object.", "false"),
|
||||
X_SPRING_PROVIDE_ARGS("x-spring-provide-args", ExtensionLevel.OPERATION, "Allows adding additional hidden parameters in the API specification to allow access to content such as header values or properties", "empty array"),
|
||||
X_DISCRIMINATOR_VALUE("x-discriminator-value", ExtensionLevel.MODEL, "Used with model inheritance to specify value for discriminator that identifies current model", ""),
|
||||
X_SETTER_EXTRA_ANNOTATION("x-setter-extra-annotation", ExtensionLevel.FIELD, "Custom annotation that can be specified over java setter for specific field", "When field is array & uniqueItems, then this extension is used to add `@JsonDeserialize(as = LinkedHashSet.class)` over setter, otherwise no value"),
|
||||
|
||||
@@ -958,8 +958,10 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co
|
||||
for (Map<String, Object> enumVars : (List<Map<String, Object>>) model.getAllowableValues().get("enumVars")) {
|
||||
if ((Boolean) enumVars.get("isString")) {
|
||||
model.vendorExtensions.putIfAbsent("x-py-enum-type", "str");
|
||||
// update `name`, e.g.
|
||||
enumVars.put("name", toEnumVariableName((String) enumVars.get("value"), "str"));
|
||||
// Do not overwrite the variable name if already set through x-enum-varnames
|
||||
if (model.vendorExtensions.get("x-enum-varnames") == null) {
|
||||
enumVars.put("name", toEnumVariableName((String) enumVars.get("value"), "str"));
|
||||
}
|
||||
} else {
|
||||
model.vendorExtensions.putIfAbsent("x-py-enum-type", "int");
|
||||
// Do not overwrite the variable name if already set through x-enum-varnames
|
||||
|
||||
@@ -570,7 +570,11 @@ public class ElixirClientCodegen extends DefaultCodegen {
|
||||
*/
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
if (ModelUtils.isAnyType(p)) {
|
||||
return "any()";
|
||||
} else if(ModelUtils.isFreeFormObject(p, null)) {
|
||||
return "%{optional(String.t) => any()}";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
Schema inner = ModelUtils.getSchemaItems(p);
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
@@ -856,6 +860,10 @@ public class ElixirClientCodegen extends DefaultCodegen {
|
||||
private void buildTypespec(CodegenParameter param, StringBuilder sb) {
|
||||
if (param.dataType == null) {
|
||||
sb.append("nil");
|
||||
} else if (param.isAnyType) {
|
||||
sb.append("any()");
|
||||
} else if(param.isFreeFormObject) {
|
||||
sb.append("%{optional(String.t) => any()}");
|
||||
} else if (param.isArray) {
|
||||
// list(<subtype>)
|
||||
sb.append("list(");
|
||||
@@ -875,6 +883,10 @@ public class ElixirClientCodegen extends DefaultCodegen {
|
||||
if (property == null) {
|
||||
LOGGER.error(
|
||||
"CodegenProperty cannot be null. Please report the issue to https://github.com/openapitools/openapi-generator with the spec");
|
||||
} else if (property.isAnyType) {
|
||||
sb.append("any()");
|
||||
} else if(property.isFreeFormObject) {
|
||||
sb.append("%{optional(String.t) => any()}");
|
||||
} else if (property.isArray) {
|
||||
sb.append("list(");
|
||||
buildTypespec(property.items, sb);
|
||||
|
||||
@@ -101,6 +101,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
public static final String WEBCLIENT_BLOCKING_OPERATIONS = "webclientBlockingOperations";
|
||||
public static final String USE_ENUM_CASE_INSENSITIVE = "useEnumCaseInsensitive";
|
||||
public static final String FAIL_ON_UNKNOWN_PROPERTIES = "failOnUnknownProperties";
|
||||
public static final String SUPPORT_VERTX_FUTURE = "supportVertxFuture";
|
||||
|
||||
public static final String SERIALIZATION_LIBRARY_GSON = "gson";
|
||||
public static final String SERIALIZATION_LIBRARY_JACKSON = "jackson";
|
||||
@@ -243,6 +244,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
cliOptions.add(CliOption.newBoolean(SUPPORT_URL_QUERY, "Generate toUrlQueryString in POJO (default to true). Available on `native`, `apache-httpclient` libraries."));
|
||||
cliOptions.add(CliOption.newBoolean(USE_ENUM_CASE_INSENSITIVE, "Use `equalsIgnoreCase` when String for enum comparison", useEnumCaseInsensitive));
|
||||
cliOptions.add(CliOption.newBoolean(FAIL_ON_UNKNOWN_PROPERTIES, "Fail Jackson de-serialization on unknown properties", this.failOnUnknownProperties));
|
||||
cliOptions.add(CliOption.newBoolean(SUPPORT_VERTX_FUTURE, "Also generate api methods that return a vertx Future instead of taking a callback. Only `vertx` supports this option. Requires vertx 4 or greater."));
|
||||
|
||||
supportedLibraries.put(JERSEY2, "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.17.1");
|
||||
supportedLibraries.put(JERSEY3, "HTTP client: Jersey client 3.1.1. JSON processing: Jackson 2.17.1");
|
||||
@@ -632,6 +634,13 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
} else if (libRestClient) {
|
||||
forceSerializationLibrary(SERIALIZATION_LIBRARY_JACKSON);
|
||||
applyJakartaPackage();
|
||||
|
||||
// Composed schemas can have the 'additionalProperties' keyword, as specified in JSON schema.
|
||||
// In principle, this should be enabled by default for all code generators. However due to limitations
|
||||
// in other code generators, support needs to be enabled on a case-by-case basis.
|
||||
// The flag below should be set for all Java libraries, but the templates need to be ported
|
||||
// one by one for each library.
|
||||
supportsAdditionalPropertiesWithComposedSchema = true;
|
||||
} else if (libVertx) {
|
||||
typeMapping.put("file", "AsyncFile");
|
||||
importMapping.put("AsyncFile", "io.vertx.core.file.AsyncFile");
|
||||
|
||||
@@ -117,6 +117,7 @@ public class PhpClientCodegen extends AbstractPhpCodegen {
|
||||
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache", toSrcPath(invokerPackage, srcBasePath), "ApiException.php"));
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache", toSrcPath(invokerPackage, srcBasePath), "Configuration.php"));
|
||||
supportingFiles.add(new SupportingFile("FormDataProcessor.mustache", toSrcPath(invokerPackage, srcBasePath), "FormDataProcessor.php"));
|
||||
supportingFiles.add(new SupportingFile("ObjectSerializer.mustache", toSrcPath(invokerPackage, srcBasePath), "ObjectSerializer.php"));
|
||||
supportingFiles.add(new SupportingFile("ModelInterface.mustache", toSrcPath(modelPackage, srcBasePath), "ModelInterface.php"));
|
||||
supportingFiles.add(new SupportingFile("HeaderSelector.mustache", toSrcPath(invokerPackage, srcBasePath), "HeaderSelector.php"));
|
||||
|
||||
@@ -121,6 +121,7 @@ public class PhpNextgenClientCodegen extends AbstractPhpCodegen {
|
||||
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache", toSrcPath(invokerPackage, srcBasePath), "ApiException.php"));
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache", toSrcPath(invokerPackage, srcBasePath), "Configuration.php"));
|
||||
supportingFiles.add(new SupportingFile("FormDataProcessor.mustache", toSrcPath(invokerPackage, srcBasePath), "FormDataProcessor.php"));
|
||||
supportingFiles.add(new SupportingFile("ObjectSerializer.mustache", toSrcPath(invokerPackage, srcBasePath), "ObjectSerializer.php"));
|
||||
supportingFiles.add(new SupportingFile("ModelInterface.mustache", toSrcPath(modelPackage, srcBasePath), "ModelInterface.php"));
|
||||
supportingFiles.add(new SupportingFile("HeaderSelector.mustache", toSrcPath(invokerPackage, srcBasePath), "HeaderSelector.php"));
|
||||
@@ -203,9 +204,11 @@ public class PhpNextgenClientCodegen extends AbstractPhpCodegen {
|
||||
}
|
||||
|
||||
if (phpReturnTypeOptions.isEmpty()) {
|
||||
operation.vendorExtensions.putIfAbsent("x-php-return-type-is-void", true);
|
||||
operation.vendorExtensions.putIfAbsent("x-php-return-type", "void");
|
||||
operation.vendorExtensions.putIfAbsent("x-php-doc-return-type", "void");
|
||||
} else {
|
||||
operation.vendorExtensions.putIfAbsent("x-php-return-type-is-void", false);
|
||||
operation.vendorExtensions.putIfAbsent("x-php-return-type", String.join("|", phpReturnTypeOptions));
|
||||
operation.vendorExtensions.putIfAbsent("x-php-doc-return-type", String.join("|", docReturnTypeOptions));
|
||||
}
|
||||
|
||||
@@ -70,6 +70,10 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
public static final String AGGREGATE_MODELS_NAME = "aggregateModelsName";
|
||||
|
||||
public static final String CUSTOM_OPTIONS_API = "customOptionsApi";
|
||||
|
||||
public static final String CUSTOM_OPTIONS_MODEL = "customOptionsModel";
|
||||
|
||||
public static final String SUPPORT_MULTIPLE_RESPONSES = "supportMultipleResponses";
|
||||
|
||||
private final Logger LOGGER = LoggerFactory.getLogger(ProtobufSchemaCodegen.class);
|
||||
@@ -78,6 +82,12 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
@Setter protected String aggregateModelsName = null;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Setter protected String customOptionsApi = null;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Setter protected String customOptionsModel = null;
|
||||
|
||||
private boolean numberedFieldNumberList = false;
|
||||
|
||||
private boolean startEnumsWithUnspecified = false;
|
||||
@@ -203,6 +213,8 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
addSwitch(USE_SIMPLIFIED_ENUM_NAMES, "Use a simple name for enums", useSimplifiedEnumNames);
|
||||
addSwitch(SUPPORT_MULTIPLE_RESPONSES, "Support multiple responses", supportMultipleResponses);
|
||||
addOption(AGGREGATE_MODELS_NAME, "Aggregated model filename. If set, all generated models will be combined into this single file.", null);
|
||||
addOption(CUSTOM_OPTIONS_API, "Custom options for the api files.", null);
|
||||
addOption(CUSTOM_OPTIONS_MODEL, "Custom options for the model files.", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -253,6 +265,14 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
this.setAggregateModelsName((String) additionalProperties.get(AGGREGATE_MODELS_NAME));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CUSTOM_OPTIONS_API)) {
|
||||
this.setCustomOptionsApi((String) additionalProperties.get(CUSTOM_OPTIONS_API));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CUSTOM_OPTIONS_MODEL)) {
|
||||
this.setCustomOptionsModel((String) additionalProperties.get(CUSTOM_OPTIONS_MODEL));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(this.SUPPORT_MULTIPLE_RESPONSES)) {
|
||||
this.supportMultipleResponses = convertPropertyToBooleanAndWriteBack(SUPPORT_MULTIPLE_RESPONSES);
|
||||
} else {
|
||||
|
||||
@@ -71,6 +71,7 @@ public class PythonFastAPIServerCodegen extends AbstractPythonCodegen {
|
||||
private static final int DEFAULT_SERVER_PORT = 8080;
|
||||
private static final String DEFAULT_PACKAGE_NAME = "openapi_server";
|
||||
private static final String DEFAULT_SOURCE_FOLDER = "src";
|
||||
private static final String DEFAULT_IMPL_FOLDER = "impl";
|
||||
private static final String DEFAULT_PACKAGE_VERSION = "1.0.0";
|
||||
|
||||
private String implPackage;
|
||||
@@ -109,7 +110,7 @@ public class PythonFastAPIServerCodegen extends AbstractPythonCodegen {
|
||||
additionalProperties.put("baseSuffix", BASE_CLASS_SUFFIX);
|
||||
additionalProperties.put(CodegenConstants.SOURCE_FOLDER, DEFAULT_SOURCE_FOLDER);
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, DEFAULT_PACKAGE_NAME);
|
||||
additionalProperties.put(CodegenConstants.FASTAPI_IMPLEMENTATION_PACKAGE, DEFAULT_PACKAGE_NAME.concat(".impl"));
|
||||
additionalProperties.put(CodegenConstants.FASTAPI_IMPLEMENTATION_PACKAGE, DEFAULT_IMPL_FOLDER);
|
||||
|
||||
languageSpecificPrimitives.add("List");
|
||||
languageSpecificPrimitives.add("Dict");
|
||||
@@ -124,7 +125,7 @@ public class PythonFastAPIServerCodegen extends AbstractPythonCodegen {
|
||||
apiPackage = "apis";
|
||||
modelPackage = "models";
|
||||
testPackage = "tests";
|
||||
implPackage = "impl";
|
||||
implPackage = DEFAULT_IMPL_FOLDER;
|
||||
apiTestTemplateFiles().put("api_test.mustache", ".py");
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "python package name (convention: snake_case).")
|
||||
@@ -153,10 +154,14 @@ public class PythonFastAPIServerCodegen extends AbstractPythonCodegen {
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.FASTAPI_IMPLEMENTATION_PACKAGE)) {
|
||||
this.implPackage = ((String) additionalProperties.get(CodegenConstants.FASTAPI_IMPLEMENTATION_PACKAGE));
|
||||
// Prefix templating value with the package name
|
||||
additionalProperties.put(CodegenConstants.FASTAPI_IMPLEMENTATION_PACKAGE,
|
||||
this.packageName + "." + this.implPackage);
|
||||
}
|
||||
|
||||
modelPackage = packageName + "." + modelPackage;
|
||||
apiPackage = packageName + "." + apiPackage;
|
||||
implPackage = packageName + "." + implPackage;
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("openapi.mustache", "", "openapi.yaml"));
|
||||
|
||||
@@ -605,9 +605,18 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
|
||||
additionalProperties.put("serdeWith", true);
|
||||
}
|
||||
|
||||
// Add a field for checking if a field is with optional or required in templates.
|
||||
// This is useful in Mustache templates as it's not possible to do OR logic between variables.
|
||||
property.vendorExtensions.put("isMandatory", !property.isNullable && property.required);
|
||||
|
||||
// If a property is a base64-encoded byte array, use `serde_with` for deserialization.
|
||||
if (property.isByteArray) {
|
||||
additionalProperties.put("serdeWith", true);
|
||||
// If a byte array is both nullable and not required we need to include our own
|
||||
// custom double option as serde_as does not work with serde_with's double_option.
|
||||
if (property.isNullable && !property.required) {
|
||||
additionalProperties.put("serdeAsDoubleOption", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -996,6 +996,8 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
* Add dynamic imports based on the parameters and vendor extensions of an operation.
|
||||
* The imports are expanded by the mustache {{import}} tag available to model and api
|
||||
* templates.
|
||||
*
|
||||
* #8315 Also handles removing 'size', 'page' and 'sort' query parameters if using 'x-spring-paginated'.
|
||||
*/
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||
@@ -1023,6 +1025,15 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
if (DocumentationProvider.SPRINGDOC.equals(getDocumentationProvider())) {
|
||||
codegenOperation.imports.add("ParameterObject");
|
||||
}
|
||||
|
||||
// #8315 Spring Data Web default query params recognized by Pageable
|
||||
List<String> defaultPageableQueryParams = new ArrayList<>(
|
||||
Arrays.asList("page", "size", "sort")
|
||||
);
|
||||
|
||||
// #8315 Remove matching Spring Data Web default query params if 'x-spring-paginated' with Pageable is used
|
||||
codegenOperation.queryParams.removeIf(param -> defaultPageableQueryParams.contains(param.baseName));
|
||||
codegenOperation.allParams.removeIf(param -> param.isQueryParam && defaultPageableQueryParams.contains(param.baseName));
|
||||
}
|
||||
if (codegenOperation.vendorExtensions.containsKey("x-spring-provide-args") && !provideArgsClassSet.isEmpty()) {
|
||||
codegenOperation.imports.addAll(provideArgsClassSet);
|
||||
|
||||
@@ -9,12 +9,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
{{#jackson}}
|
||||
{{#feign-okhttp}}
|
||||
import feign.okhttp.OkHttpClient;
|
||||
{{/feign-okhttp}}
|
||||
{{#feign-hc5}}
|
||||
import feign.hc5.ApacheHttp5Client;
|
||||
{{/feign-hc5}}
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
@@ -76,12 +70,6 @@ public class ApiClient {
|
||||
{{#jackson}}
|
||||
objectMapper = createObjectMapper();
|
||||
feignBuilder = Feign.builder()
|
||||
{{#feign-okhttp}}
|
||||
.client(new OkHttpClient())
|
||||
{{/feign-okhttp}}
|
||||
{{#feign-hc5}}
|
||||
.client(new ApacheHttp5Client())
|
||||
{{/feign-hc5}}
|
||||
.encoder(new FormEncoder(new JacksonEncoder(objectMapper)))
|
||||
.decoder(new ApiResponseDecoder(objectMapper))
|
||||
{{#hasOAuthMethods}}
|
||||
|
||||
@@ -694,6 +694,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
*/
|
||||
public ApiClient setDebugging(boolean debugging) {
|
||||
this.debugging = debugging;
|
||||
applyDebugSetting(this.clientConfig);
|
||||
// Rebuild HTTP Client according to the new "debugging" value.
|
||||
this.httpClient = buildHttpClient();
|
||||
return this;
|
||||
@@ -1232,6 +1233,27 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
// to support (constant) query string in `path`, e.g. "/posts?draft=1"
|
||||
WebTarget target = httpClient.target(targetURL);
|
||||
|
||||
// put all headers in one place
|
||||
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
|
||||
allHeaderParams.putAll(headerParams);
|
||||
|
||||
if (authNames != null) {
|
||||
// update different parameters (e.g. headers) for authentication
|
||||
updateParamsForAuth(
|
||||
authNames,
|
||||
queryParams,
|
||||
allHeaderParams,
|
||||
cookieParams,
|
||||
{{#hasHttpSignatureMethods}}
|
||||
serializeToString(body, formParams, contentType, isBodyNullable),
|
||||
{{/hasHttpSignatureMethods}}
|
||||
{{^hasHttpSignatureMethods}}
|
||||
null,
|
||||
{{/hasHttpSignatureMethods}}
|
||||
method,
|
||||
target.getUri());
|
||||
}
|
||||
|
||||
if (queryParams != null) {
|
||||
for (Pair queryParam : queryParams) {
|
||||
if (queryParam.getValue() != null) {
|
||||
@@ -1262,27 +1284,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
|
||||
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
|
||||
|
||||
// put all headers in one place
|
||||
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
|
||||
allHeaderParams.putAll(headerParams);
|
||||
|
||||
if (authNames != null) {
|
||||
// update different parameters (e.g. headers) for authentication
|
||||
updateParamsForAuth(
|
||||
authNames,
|
||||
queryParams,
|
||||
allHeaderParams,
|
||||
cookieParams,
|
||||
{{#hasHttpSignatureMethods}}
|
||||
serializeToString(body, formParams, contentType, isBodyNullable),
|
||||
{{/hasHttpSignatureMethods}}
|
||||
{{^hasHttpSignatureMethods}}
|
||||
null,
|
||||
{{/hasHttpSignatureMethods}}
|
||||
method,
|
||||
target.getUri());
|
||||
}
|
||||
|
||||
for (Entry<String, String> entry : allHeaderParams.entrySet()) {
|
||||
String value = entry.getValue();
|
||||
if (value != null) {
|
||||
@@ -1383,8 +1384,10 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
* @return Client
|
||||
*/
|
||||
protected Client buildHttpClient() {
|
||||
// recreate the client config to pickup changes
|
||||
clientConfig = getDefaultClientConfig();
|
||||
// Create ClientConfig if it has not been initialized yet
|
||||
if (clientConfig == null) {
|
||||
clientConfig = getDefaultClientConfig();
|
||||
}
|
||||
|
||||
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
|
||||
clientBuilder = clientBuilder.withConfig(clientConfig);
|
||||
@@ -1405,6 +1408,11 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
|
||||
// turn off compliance validation to be able to send payloads with DELETE calls
|
||||
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
|
||||
applyDebugSetting(clientConfig);
|
||||
return clientConfig;
|
||||
}
|
||||
|
||||
private void applyDebugSetting(ClientConfig clientConfig) {
|
||||
if (debugging) {
|
||||
clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024*50 /* Log payloads up to 50K */));
|
||||
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
|
||||
@@ -1414,8 +1422,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
// suppress warnings for payloads with DELETE calls:
|
||||
java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
|
||||
}
|
||||
|
||||
return clientConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1507,4 +1513,4 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -694,6 +694,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
*/
|
||||
public ApiClient setDebugging(boolean debugging) {
|
||||
this.debugging = debugging;
|
||||
applyDebugSetting(this.clientConfig);
|
||||
// Rebuild HTTP Client according to the new "debugging" value.
|
||||
this.httpClient = buildHttpClient();
|
||||
return this;
|
||||
@@ -1232,6 +1233,27 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
// to support (constant) query string in `path`, e.g. "/posts?draft=1"
|
||||
WebTarget target = httpClient.target(targetURL);
|
||||
|
||||
// put all headers in one place
|
||||
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
|
||||
allHeaderParams.putAll(headerParams);
|
||||
|
||||
if (authNames != null) {
|
||||
// update different parameters (e.g. headers) for authentication
|
||||
updateParamsForAuth(
|
||||
authNames,
|
||||
queryParams,
|
||||
allHeaderParams,
|
||||
cookieParams,
|
||||
{{#hasHttpSignatureMethods}}
|
||||
serializeToString(body, formParams, contentType, isBodyNullable),
|
||||
{{/hasHttpSignatureMethods}}
|
||||
{{^hasHttpSignatureMethods}}
|
||||
null,
|
||||
{{/hasHttpSignatureMethods}}
|
||||
method,
|
||||
target.getUri());
|
||||
}
|
||||
|
||||
if (queryParams != null) {
|
||||
for (Pair queryParam : queryParams) {
|
||||
if (queryParam.getValue() != null) {
|
||||
@@ -1262,27 +1284,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
|
||||
Entity<?> entity = serialize(body, formParams, contentType, isBodyNullable);
|
||||
|
||||
// put all headers in one place
|
||||
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
|
||||
allHeaderParams.putAll(headerParams);
|
||||
|
||||
if (authNames != null) {
|
||||
// update different parameters (e.g. headers) for authentication
|
||||
updateParamsForAuth(
|
||||
authNames,
|
||||
queryParams,
|
||||
allHeaderParams,
|
||||
cookieParams,
|
||||
{{#hasHttpSignatureMethods}}
|
||||
serializeToString(body, formParams, contentType, isBodyNullable),
|
||||
{{/hasHttpSignatureMethods}}
|
||||
{{^hasHttpSignatureMethods}}
|
||||
null,
|
||||
{{/hasHttpSignatureMethods}}
|
||||
method,
|
||||
target.getUri());
|
||||
}
|
||||
|
||||
for (Entry<String, String> entry : allHeaderParams.entrySet()) {
|
||||
String value = entry.getValue();
|
||||
if (value != null) {
|
||||
@@ -1383,8 +1384,10 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
* @return Client
|
||||
*/
|
||||
protected Client buildHttpClient() {
|
||||
// recreate the client config to pickup changes
|
||||
// Create ClientConfig if it has not been initialized yet
|
||||
if (clientConfig == null) {
|
||||
clientConfig = getDefaultClientConfig();
|
||||
}
|
||||
|
||||
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
|
||||
clientBuilder = clientBuilder.withConfig(clientConfig);
|
||||
@@ -1405,6 +1408,11 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
|
||||
// turn off compliance validation to be able to send payloads with DELETE calls
|
||||
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
|
||||
applyDebugSetting(clientConfig);
|
||||
return clientConfig;
|
||||
}
|
||||
|
||||
private void applyDebugSetting(ClientConfig clientConfig) {
|
||||
if (debugging) {
|
||||
clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024*50 /* Log payloads up to 50K */));
|
||||
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
|
||||
@@ -1414,8 +1422,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
// suppress warnings for payloads with DELETE calls:
|
||||
java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
|
||||
}
|
||||
|
||||
return clientConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1507,4 +1513,4 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1166,17 +1166,8 @@ public class ApiClient {
|
||||
return (T) downloadFileFromResponse(response);
|
||||
}
|
||||
|
||||
String respBody;
|
||||
try {
|
||||
if (response.body() != null)
|
||||
respBody = response.body().string();
|
||||
else
|
||||
respBody = null;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
|
||||
if (respBody == null || "".equals(respBody)) {
|
||||
ResponseBody respBody = response.body();
|
||||
if (respBody == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1185,17 +1176,25 @@ public class ApiClient {
|
||||
// ensuring a default content type
|
||||
contentType = "application/json";
|
||||
}
|
||||
if (isJsonMime(contentType)) {
|
||||
return JSON.deserialize(respBody, returnType);
|
||||
} else if (returnType.equals(String.class)) {
|
||||
// Expecting string, return the raw response body.
|
||||
return (T) respBody;
|
||||
} else {
|
||||
throw new ApiException(
|
||||
try {
|
||||
if (isJsonMime(contentType)) {
|
||||
return JSON.deserialize(respBody.byteStream(), returnType);
|
||||
} else if (returnType.equals(String.class)) {
|
||||
String respBodyString = respBody.string();
|
||||
if (respBodyString.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// Expecting string, return the raw response body.
|
||||
return (T) respBodyString;
|
||||
} else {
|
||||
throw new ApiException(
|
||||
"Content type \"" + contentType + "\" is not supported for type: " + returnType,
|
||||
response.code(),
|
||||
response.headers().toMultimap(),
|
||||
respBody);
|
||||
response.body().string());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,11 @@ import org.joda.time.format.ISODateTimeFormat;
|
||||
import okio.ByteString;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.ParsePosition;
|
||||
@@ -198,6 +201,28 @@ public class JSON {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize the given JSON InputStream to a Java object.
|
||||
*
|
||||
* @param <T> Type
|
||||
* @param inputStream The JSON InputStream
|
||||
* @param returnType The type to deserialize into
|
||||
* @return The deserialized Java object
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T deserialize(InputStream inputStream, Type returnType) throws IOException {
|
||||
try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
|
||||
if (isLenientOnJson) {
|
||||
// see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
|
||||
JsonReader jsonReader = new JsonReader(reader);
|
||||
jsonReader.setLenient(true);
|
||||
return gson.fromJson(jsonReader, returnType);
|
||||
} else {
|
||||
return gson.fromJson(reader, returnType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gson TypeAdapter for Byte Array type
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
{{#additionalPropertiesType}}
|
||||
/**
|
||||
* A container for additional, undeclared properties.
|
||||
* This is a holder for any undeclared properties as specified with
|
||||
* the 'additionalProperties' keyword in the OAS document.
|
||||
*/
|
||||
private Map<String, {{{.}}}> additionalProperties;
|
||||
|
||||
/**
|
||||
* Set the additional (undeclared) property with the specified name and value.
|
||||
* If the property does not already exist, create it otherwise replace it.
|
||||
* @param key the name of the property
|
||||
* @param value the value of the property
|
||||
* @return self reference
|
||||
*/
|
||||
@JsonAnySetter
|
||||
public {{classname}} putAdditionalProperty(String key, {{{.}}} value) {
|
||||
if (this.additionalProperties == null) {
|
||||
this.additionalProperties = new HashMap<String, {{{.}}}>();
|
||||
}
|
||||
this.additionalProperties.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the additional (undeclared) properties.
|
||||
* @return the additional (undeclared) properties
|
||||
*/
|
||||
@JsonAnyGetter
|
||||
public Map<String, {{{.}}}> getAdditionalProperties() {
|
||||
return additionalProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the additional (undeclared) property with the specified name.
|
||||
* @param key the name of the property
|
||||
* @return the additional (undeclared) property with the specified name
|
||||
*/
|
||||
public {{{.}}} getAdditionalProperty(String key) {
|
||||
if (this.additionalProperties == null) {
|
||||
return null;
|
||||
}
|
||||
return this.additionalProperties.get(key);
|
||||
}
|
||||
{{/additionalPropertiesType}}
|
||||
78
modules/openapi-generator/src/main/resources/Java/libraries/restclient/model.mustache
vendored
Normal file
78
modules/openapi-generator/src/main/resources/Java/libraries/restclient/model.mustache
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
package {{package}};
|
||||
|
||||
{{#useReflectionEqualsHashCode}}
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
{{/useReflectionEqualsHashCode}}
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{#additionalPropertiesType}}
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
{{/additionalPropertiesType}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
import java.util.Objects;
|
||||
import java.util.Arrays;
|
||||
{{#imports}}
|
||||
import {{import}};
|
||||
{{/imports}}
|
||||
{{#serializableModel}}
|
||||
import java.io.Serializable;
|
||||
{{/serializableModel}}
|
||||
{{#jackson}}
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
{{#withXml}}
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.*;
|
||||
{{/withXml}}
|
||||
{{#vendorExtensions.x-has-readonly-properties}}
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
{{/vendorExtensions.x-has-readonly-properties}}
|
||||
{{/jackson}}
|
||||
{{#withXml}}
|
||||
import {{javaxPackage}}.xml.bind.annotation.*;
|
||||
import {{javaxPackage}}.xml.bind.annotation.adapters.*;
|
||||
import io.github.threetenjaxb.core.*;
|
||||
{{/withXml}}
|
||||
{{#jsonb}}
|
||||
import java.lang.reflect.Type;
|
||||
import {{javaxPackage}}.json.bind.annotation.JsonbTypeDeserializer;
|
||||
import {{javaxPackage}}.json.bind.annotation.JsonbTypeSerializer;
|
||||
import {{javaxPackage}}.json.bind.serializer.DeserializationContext;
|
||||
import {{javaxPackage}}.json.bind.serializer.JsonbDeserializer;
|
||||
import {{javaxPackage}}.json.bind.serializer.JsonbSerializer;
|
||||
import {{javaxPackage}}.json.bind.serializer.SerializationContext;
|
||||
import {{javaxPackage}}.json.stream.JsonGenerator;
|
||||
import {{javaxPackage}}.json.stream.JsonParser;
|
||||
import {{javaxPackage}}.json.bind.annotation.JsonbProperty;
|
||||
{{#vendorExtensions.x-has-readonly-properties}}
|
||||
import {{javaxPackage}}.json.bind.annotation.JsonbCreator;
|
||||
{{/vendorExtensions.x-has-readonly-properties}}
|
||||
{{/jsonb}}
|
||||
{{#parcelableModel}}
|
||||
import android.os.Parcelable;
|
||||
import android.os.Parcel;
|
||||
{{/parcelableModel}}
|
||||
{{#useBeanValidation}}
|
||||
import {{javaxPackage}}.validation.constraints.*;
|
||||
import {{javaxPackage}}.validation.Valid;
|
||||
{{/useBeanValidation}}
|
||||
{{#performBeanValidation}}
|
||||
import org.hibernate.validator.constraints.*;
|
||||
{{/performBeanValidation}}
|
||||
{{#supportUrlQuery}}
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.StringJoiner;
|
||||
{{/supportUrlQuery}}
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{#vendorExtensions.x-is-one-of-interface}}{{>oneof_interface}}{{/vendorExtensions.x-is-one-of-interface}}{{^vendorExtensions.x-is-one-of-interface}}{{>pojo}}{{/vendorExtensions.x-is-one-of-interface}}{{/isEnum}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
620
modules/openapi-generator/src/main/resources/Java/libraries/restclient/pojo.mustache
vendored
Normal file
620
modules/openapi-generator/src/main/resources/Java/libraries/restclient/pojo.mustache
vendored
Normal file
@@ -0,0 +1,620 @@
|
||||
/**
|
||||
* {{description}}{{^description}}{{classname}}{{/description}}{{#isDeprecated}}
|
||||
* @deprecated{{/isDeprecated}}
|
||||
*/{{#isDeprecated}}
|
||||
@Deprecated{{/isDeprecated}}
|
||||
{{#swagger1AnnotationLibrary}}
|
||||
{{#description}}
|
||||
@ApiModel(description = "{{{.}}}")
|
||||
{{/description}}
|
||||
{{/swagger1AnnotationLibrary}}
|
||||
{{#swagger2AnnotationLibrary}}
|
||||
{{#description}}
|
||||
@Schema(description = "{{{.}}}")
|
||||
{{/description}}
|
||||
{{/swagger2AnnotationLibrary}}
|
||||
{{#jackson}}
|
||||
@JsonPropertyOrder({
|
||||
{{#vars}}
|
||||
{{classname}}.JSON_PROPERTY_{{nameInSnakeCase}}{{^-last}},{{/-last}}
|
||||
{{/vars}}
|
||||
})
|
||||
{{#isClassnameSanitized}}
|
||||
{{^hasDiscriminatorWithNonEmptyMapping}}
|
||||
@JsonTypeName("{{name}}")
|
||||
{{/hasDiscriminatorWithNonEmptyMapping}}
|
||||
{{/isClassnameSanitized}}
|
||||
{{/jackson}}
|
||||
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtensions.x-implements}}{{#-first}}implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{#-last}} {{/-last}}{{/vendorExtensions.x-implements}}{
|
||||
{{#serializableModel}}
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
{{/serializableModel}}
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
{{^isContainer}}
|
||||
{{>modelInnerEnum}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#mostInnerItems}}
|
||||
{{>modelInnerEnum}}
|
||||
{{/mostInnerItems}}
|
||||
{{/isContainer}}
|
||||
{{/isEnum}}
|
||||
{{#gson}}
|
||||
public static final String SERIALIZED_NAME_{{nameInSnakeCase}} = "{{baseName}}";
|
||||
{{/gson}}
|
||||
{{#jackson}}
|
||||
public static final String JSON_PROPERTY_{{nameInSnakeCase}} = "{{baseName}}";
|
||||
{{/jackson}}
|
||||
{{#withXml}}
|
||||
@Xml{{#isXmlAttribute}}Attribute{{/isXmlAttribute}}{{^isXmlAttribute}}Element{{/isXmlAttribute}}(name = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
|
||||
{{#isXmlWrapped}}
|
||||
@XmlElementWrapper(name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
|
||||
{{/isXmlWrapped}}
|
||||
{{^isXmlAttribute}}
|
||||
{{#isDateTime}}
|
||||
@XmlJavaTypeAdapter(OffsetDateTimeXmlAdapter.class)
|
||||
{{/isDateTime}}
|
||||
{{/isXmlAttribute}}
|
||||
{{/withXml}}
|
||||
{{#gson}}
|
||||
@SerializedName(SERIALIZED_NAME_{{nameInSnakeCase}})
|
||||
{{/gson}}
|
||||
{{>nullable_var_annotations}}
|
||||
{{#vendorExtensions.x-field-extra-annotation}}
|
||||
{{{vendorExtensions.x-field-extra-annotation}}}
|
||||
{{/vendorExtensions.x-field-extra-annotation}}
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{#isContainer}}
|
||||
{{#hasChildren}}protected{{/hasChildren}}{{^hasChildren}}private{{/hasChildren}} JsonNullable<{{{datatypeWithEnum}}}> {{name}} = JsonNullable.<{{{datatypeWithEnum}}}>undefined();
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
{{#hasChildren}}protected{{/hasChildren}}{{^hasChildren}}private{{/hasChildren}} JsonNullable<{{{datatypeWithEnum}}}> {{name}} = JsonNullable.<{{{datatypeWithEnum}}}>{{#defaultValue}}of({{{.}}}){{/defaultValue}}{{^defaultValue}}undefined(){{/defaultValue}};
|
||||
{{/isContainer}}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{#isContainer}}
|
||||
{{#hasChildren}}protected{{/hasChildren}}{{^hasChildren}}private{{/hasChildren}} {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
{{#hasChildren}}protected{{/hasChildren}}{{^hasChildren}}private{{/hasChildren}} {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
{{/isContainer}}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
|
||||
{{/vars}}
|
||||
public {{classname}}() {
|
||||
{{#parent}}
|
||||
{{#parcelableModel}}
|
||||
super();{{/parcelableModel}}
|
||||
{{/parent}}
|
||||
{{#gson}}
|
||||
{{#discriminator}}
|
||||
{{#discriminator.isEnum}}
|
||||
this.{{{discriminatorName}}} = this.getClass().getSimpleName();
|
||||
{{/discriminator.isEnum}}
|
||||
{{/discriminator}}
|
||||
{{/gson}}
|
||||
}
|
||||
{{#vendorExtensions.x-has-readonly-properties}}
|
||||
{{^withXml}}
|
||||
/**
|
||||
* Constructor with only readonly parameters{{#generateConstructorWithAllArgs}}{{^vendorExtensions.x-java-all-args-constructor}} and all parameters{{/vendorExtensions.x-java-all-args-constructor}}{{/generateConstructorWithAllArgs}}
|
||||
*/
|
||||
{{#jsonb}}@JsonbCreator{{/jsonb}}{{#jackson}}@JsonCreator{{/jackson}}
|
||||
public {{classname}}(
|
||||
{{#readOnlyVars}}
|
||||
{{#jsonb}}@JsonbProperty(value = "{{baseName}}"{{^required}}, nullable = true{{/required}}){{/jsonb}}{{#jackson}}@JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}}){{/jackson}} {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}
|
||||
{{/readOnlyVars}}
|
||||
) {
|
||||
this();
|
||||
{{#readOnlyVars}}
|
||||
this.{{name}} = {{#vendorExtensions.x-is-jackson-optional-nullable}}{{name}} == null ? JsonNullable.<{{{datatypeWithEnum}}}>undefined() : JsonNullable.of({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{name}}{{/vendorExtensions.x-is-jackson-optional-nullable}};
|
||||
{{/readOnlyVars}}
|
||||
}
|
||||
{{/withXml}}
|
||||
{{/vendorExtensions.x-has-readonly-properties}}
|
||||
{{#vendorExtensions.x-java-all-args-constructor}}
|
||||
|
||||
/**
|
||||
* Constructor with all args parameters
|
||||
*/
|
||||
public {{classname}}({{#vendorExtensions.x-java-all-args-constructor-vars}}{{#jsonb}}@JsonbProperty(value = "{{baseName}}"{{^required}}, nullable = true{{/required}}){{/jsonb}}{{#jackson}}@JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}}){{/jackson}} {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}{{/vendorExtensions.x-java-all-args-constructor-vars}}) {
|
||||
{{#parent}}
|
||||
super({{#parentVars}}{{name}}{{^-last}}, {{/-last}}{{/parentVars}});
|
||||
{{/parent}}
|
||||
{{#vars}}
|
||||
this.{{name}} = {{#vendorExtensions.x-is-jackson-optional-nullable}}{{name}} == null ? JsonNullable.<{{{datatypeWithEnum}}}>undefined() : JsonNullable.of({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{name}}{{/vendorExtensions.x-is-jackson-optional-nullable}};
|
||||
{{/vars}}
|
||||
}
|
||||
{{/vendorExtensions.x-java-all-args-constructor}}
|
||||
|
||||
{{#vars}}
|
||||
{{^isReadOnly}}
|
||||
public {{classname}} {{name}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{name}});{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}this.{{name}} = {{name}};{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
return this;
|
||||
}
|
||||
{{#isArray}}
|
||||
|
||||
public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
if (this.{{name}} == null || !this.{{name}}.isPresent()) {
|
||||
this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}});
|
||||
}
|
||||
try {
|
||||
this.{{name}}.get().add({{name}}Item);
|
||||
} catch (java.util.NoSuchElementException e) {
|
||||
// this can never happen, as we make sure above that the value is present
|
||||
}
|
||||
return this;
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
if (this.{{name}} == null) {
|
||||
this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}};
|
||||
}
|
||||
this.{{name}}.add({{name}}Item);
|
||||
return this;
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
}
|
||||
{{/isArray}}
|
||||
{{#isMap}}
|
||||
|
||||
public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
if (this.{{name}} == null || !this.{{name}}.isPresent()) {
|
||||
this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}});
|
||||
}
|
||||
try {
|
||||
this.{{name}}.get().put(key, {{name}}Item);
|
||||
} catch (java.util.NoSuchElementException e) {
|
||||
// this can never happen, as we make sure above that the value is present
|
||||
}
|
||||
return this;
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^required}}
|
||||
if (this.{{name}} == null) {
|
||||
this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}};
|
||||
}
|
||||
{{/required}}
|
||||
this.{{name}}.put(key, {{name}}Item);
|
||||
return this;
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
}
|
||||
{{/isMap}}
|
||||
|
||||
{{/isReadOnly}}
|
||||
/**
|
||||
{{#description}}
|
||||
* {{.}}
|
||||
{{/description}}
|
||||
{{^description}}
|
||||
* Get {{name}}
|
||||
{{/description}}
|
||||
{{#minimum}}
|
||||
* minimum: {{.}}
|
||||
{{/minimum}}
|
||||
{{#maximum}}
|
||||
* maximum: {{.}}
|
||||
{{/maximum}}
|
||||
* @return {{name}}
|
||||
{{#deprecated}}
|
||||
* @deprecated
|
||||
{{/deprecated}}
|
||||
*/
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
{{>nullable_var_annotations}}
|
||||
{{#jsonb}}
|
||||
@JsonbProperty("{{baseName}}")
|
||||
{{/jsonb}}
|
||||
{{#useBeanValidation}}
|
||||
{{>beanValidation}}
|
||||
{{/useBeanValidation}}
|
||||
{{#swagger1AnnotationLibrary}}
|
||||
@ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
{{/swagger1AnnotationLibrary}}
|
||||
{{#swagger2AnnotationLibrary}}
|
||||
@Schema({{#example}}example = "{{{.}}}", {{/example}}requiredMode = {{#required}}Schema.RequiredMode.REQUIRED{{/required}}{{^required}}Schema.RequiredMode.NOT_REQUIRED{{/required}}, description = "{{{description}}}")
|
||||
{{/swagger2AnnotationLibrary}}
|
||||
{{#vendorExtensions.x-extra-annotation}}
|
||||
{{{vendorExtensions.x-extra-annotation}}}
|
||||
{{/vendorExtensions.x-extra-annotation}}
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{!unannotated, Jackson would pick this up automatically and add it *in addition* to the _JsonNullable getter field}}
|
||||
@JsonIgnore
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}{{#jackson}}{{> jackson_annotations}}{{/jackson}}{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{#isReadOnly}}{{! A readonly attribute doesn't have setter => jackson will set null directly if explicitly returned by API, so make sure we have an empty JsonNullable}}
|
||||
if ({{name}} == null) {
|
||||
{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>{{#defaultValue}}of({{{.}}}){{/defaultValue}}{{^defaultValue}}undefined(){{/defaultValue}};
|
||||
}
|
||||
{{/isReadOnly}}
|
||||
return {{name}}.orElse(null);
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
return {{name}};
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
}
|
||||
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{> jackson_annotations}}
|
||||
public JsonNullable<{{{datatypeWithEnum}}}> {{getter}}_JsonNullable() {
|
||||
return {{name}};
|
||||
}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
@JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}})
|
||||
{{#isReadOnly}}private{{/isReadOnly}}{{^isReadOnly}}public{{/isReadOnly}} void {{setter}}_JsonNullable(JsonNullable<{{{datatypeWithEnum}}}> {{name}}) {
|
||||
{{! For getters/setters that have name differing from attribute name, we must include setter (albeit private) for jackson to be able to set the attribute}}
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
|
||||
{{^isReadOnly}}
|
||||
{{#vendorExtensions.x-setter-extra-annotation}} {{{vendorExtensions.x-setter-extra-annotation}}}
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{> jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}} public void {{setter}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{name}});
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{name}} = {{name}};
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
}
|
||||
{{/isReadOnly}}
|
||||
|
||||
{{/vars}}
|
||||
{{>libraries/restclient/additional_properties}}
|
||||
{{#parent}}
|
||||
{{#readWriteVars}}
|
||||
{{#isOverridden}}
|
||||
@Override
|
||||
public {{classname}} {{name}}({{>nullable_var_annotations}} {{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{setter}}(JsonNullable.<{{{datatypeWithEnum}}}>of({{name}}));
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{setter}}({{name}});
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
return this;
|
||||
}
|
||||
|
||||
{{/isOverridden}}
|
||||
{{/readWriteVars}}
|
||||
{{/parent}}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
{{#useReflectionEqualsHashCode}}
|
||||
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
|
||||
{{/useReflectionEqualsHashCode}}
|
||||
{{^useReflectionEqualsHashCode}}
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}{{#hasVars}}
|
||||
{{classname}} {{classVarName}} = ({{classname}}) o;
|
||||
return {{#vars}}{{#vendorExtensions.x-is-jackson-optional-nullable}}equalsNullable(this.{{name}}, {{classVarName}}.{{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{#isByteArray}}Arrays{{/isByteArray}}{{^isByteArray}}Objects{{/isByteArray}}.equals(this.{{name}}, {{classVarName}}.{{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^-last}} &&
|
||||
{{/-last}}{{/vars}}{{#additionalPropertiesType}} &&
|
||||
Objects.equals(this.additionalProperties, {{classVarName}}.additionalProperties){{/additionalPropertiesType}}{{#parent}} &&
|
||||
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
|
||||
return {{#parent}}super.equals(o){{/parent}}{{^parent}}true{{/parent}};{{/hasVars}}
|
||||
{{/useReflectionEqualsHashCode}}
|
||||
}{{#vendorExtensions.x-jackson-optional-nullable-helpers}}
|
||||
|
||||
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
|
||||
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
|
||||
}{{/vendorExtensions.x-jackson-optional-nullable-helpers}}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
{{#useReflectionEqualsHashCode}}
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
{{/useReflectionEqualsHashCode}}
|
||||
{{^useReflectionEqualsHashCode}}
|
||||
return Objects.hash({{#vars}}{{#vendorExtensions.x-is-jackson-optional-nullable}}hashCodeNullable({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{^isByteArray}}{{name}}{{/isByteArray}}{{#isByteArray}}Arrays.hashCode({{name}}){{/isByteArray}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{^-last}}, {{/-last}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}}{{#additionalPropertiesType}}, additionalProperties{{/additionalPropertiesType}});
|
||||
{{/useReflectionEqualsHashCode}}
|
||||
}{{#vendorExtensions.x-jackson-optional-nullable-helpers}}
|
||||
|
||||
private static <T> int hashCodeNullable(JsonNullable<T> a) {
|
||||
if (a == null) {
|
||||
return 1;
|
||||
}
|
||||
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
|
||||
}{{/vendorExtensions.x-jackson-optional-nullable-helpers}}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#parent}}
|
||||
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
|
||||
{{/parent}}
|
||||
{{#vars}}
|
||||
sb.append(" {{name}}: ").append({{#isPassword}}"*"{{/isPassword}}{{^isPassword}}toIndentedString({{name}}){{/isPassword}}).append("\n");
|
||||
{{/vars}}
|
||||
{{#additionalPropertiesType}}
|
||||
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
|
||||
{{/additionalPropertiesType}}
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private{{#jsonb}} static{{/jsonb}} String toIndentedString(Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
{{#supportUrlQuery}}
|
||||
|
||||
/**
|
||||
* Convert the instance into URL query string.
|
||||
*
|
||||
* @return URL query string
|
||||
*/
|
||||
public String toUrlQueryString() {
|
||||
return toUrlQueryString(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the instance into URL query string.
|
||||
*
|
||||
* @param prefix prefix of the query string
|
||||
* @return URL query string
|
||||
*/
|
||||
public String toUrlQueryString(String prefix) {
|
||||
String suffix = "";
|
||||
String containerSuffix = "";
|
||||
String containerPrefix = "";
|
||||
if (prefix == null) {
|
||||
// style=form, explode=true, e.g. /pet?name=cat&type=manx
|
||||
prefix = "";
|
||||
} else {
|
||||
// deepObject style e.g. /pet?id[name]=cat&id[type]=manx
|
||||
prefix = prefix + "[";
|
||||
suffix = "]";
|
||||
containerSuffix = "]";
|
||||
containerPrefix = "[";
|
||||
}
|
||||
|
||||
StringJoiner joiner = new StringJoiner("&");
|
||||
|
||||
{{#allVars}}
|
||||
// add `{{baseName}}` to the URL query string
|
||||
{{#isArray}}
|
||||
{{#items.isPrimitiveType}}
|
||||
{{#uniqueItems}}
|
||||
if ({{getter}}() != null) {
|
||||
int i = 0;
|
||||
for ({{{items.datatypeWithEnum}}} _item : {{getter}}()) {
|
||||
try {
|
||||
joiner.add(String.format("%s{{baseName}}%s%s=%s", prefix, suffix,
|
||||
"".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix),
|
||||
URLEncoder.encode(String.valueOf(_item), "UTF-8").replaceAll("\\+", "%20")));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Should never happen, UTF-8 is always supported
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
{{/uniqueItems}}
|
||||
{{^uniqueItems}}
|
||||
if ({{getter}}() != null) {
|
||||
for (int i = 0; i < {{getter}}().size(); i++) {
|
||||
try {
|
||||
joiner.add(String.format("%s{{baseName}}%s%s=%s", prefix, suffix,
|
||||
"".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix),
|
||||
URLEncoder.encode(String.valueOf({{getter}}().get(i)), "UTF-8").replaceAll("\\+", "%20")));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Should never happen, UTF-8 is always supported
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
{{/uniqueItems}}
|
||||
{{/items.isPrimitiveType}}
|
||||
{{^items.isPrimitiveType}}
|
||||
{{#items.isModel}}
|
||||
{{#uniqueItems}}
|
||||
if ({{getter}}() != null) {
|
||||
int i = 0;
|
||||
for ({{{items.dataType}}} _item : {{getter}}()) {
|
||||
if (_item != null) {
|
||||
joiner.add(_item.toUrlQueryString(String.format("%s{{baseName}}%s%s", prefix, suffix,
|
||||
"".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix))));
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
{{/uniqueItems}}
|
||||
{{^uniqueItems}}
|
||||
if ({{getter}}() != null) {
|
||||
for (int i = 0; i < {{getter}}().size(); i++) {
|
||||
if ({{getter}}().get(i) != null) {
|
||||
joiner.add({{getter}}().get(i).toUrlQueryString(String.format("%s{{baseName}}%s%s", prefix, suffix,
|
||||
"".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix))));
|
||||
}
|
||||
}
|
||||
}
|
||||
{{/uniqueItems}}
|
||||
{{/items.isModel}}
|
||||
{{^items.isModel}}
|
||||
{{#uniqueItems}}
|
||||
if ({{getter}}() != null) {
|
||||
int i = 0;
|
||||
for ({{{items.dataType}}} _item : {{getter}}()) {
|
||||
if (_item != null) {
|
||||
try {
|
||||
joiner.add(String.format("%s{{baseName}}%s%s=%s", prefix, suffix,
|
||||
"".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix),
|
||||
URLEncoder.encode(String.valueOf(_item), "UTF-8").replaceAll("\\+", "%20")));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Should never happen, UTF-8 is always supported
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
{{/uniqueItems}}
|
||||
{{^uniqueItems}}
|
||||
if ({{getter}}() != null) {
|
||||
for (int i = 0; i < {{getter}}().size(); i++) {
|
||||
if ({{getter}}().get(i) != null) {
|
||||
try {
|
||||
joiner.add(String.format("%s{{baseName}}%s%s=%s", prefix, suffix,
|
||||
"".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix),
|
||||
URLEncoder.encode(String.valueOf({{getter}}().get(i)), "UTF-8").replaceAll("\\+", "%20")));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Should never happen, UTF-8 is always supported
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
{{/uniqueItems}}
|
||||
{{/items.isModel}}
|
||||
{{/items.isPrimitiveType}}
|
||||
{{/isArray}}
|
||||
{{^isArray}}
|
||||
{{#isMap}}
|
||||
{{^items.isModel}}
|
||||
if ({{getter}}() != null) {
|
||||
for (String _key : {{getter}}().keySet()) {
|
||||
try {
|
||||
joiner.add(String.format("%s{{baseName}}%s%s=%s", prefix, suffix,
|
||||
"".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, _key, containerSuffix),
|
||||
{{getter}}().get(_key), URLEncoder.encode(String.valueOf({{getter}}().get(_key)), "UTF-8").replaceAll("\\+", "%20")));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Should never happen, UTF-8 is always supported
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
{{/items.isModel}}
|
||||
{{#items.isModel}}
|
||||
if ({{getter}}() != null) {
|
||||
for (String _key : {{getter}}().keySet()) {
|
||||
if ({{getter}}().get(_key) != null) {
|
||||
joiner.add({{getter}}().get(_key).toUrlQueryString(String.format("%s{{baseName}}%s%s", prefix, suffix,
|
||||
"".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, _key, containerSuffix))));
|
||||
}
|
||||
}
|
||||
}
|
||||
{{/items.isModel}}
|
||||
{{/isMap}}
|
||||
{{^isMap}}
|
||||
{{#isPrimitiveType}}
|
||||
if ({{getter}}() != null) {
|
||||
try {
|
||||
joiner.add(String.format("%s{{{baseName}}}%s=%s", prefix, suffix, URLEncoder.encode(String.valueOf({{{getter}}}()), "UTF-8").replaceAll("\\+", "%20")));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Should never happen, UTF-8 is always supported
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
{{#isModel}}
|
||||
if ({{getter}}() != null) {
|
||||
joiner.add({{getter}}().toUrlQueryString(prefix + "{{{baseName}}}" + suffix));
|
||||
}
|
||||
{{/isModel}}
|
||||
{{^isModel}}
|
||||
if ({{getter}}() != null) {
|
||||
try {
|
||||
joiner.add(String.format("%s{{{baseName}}}%s=%s", prefix, suffix, URLEncoder.encode(String.valueOf({{{getter}}}()), "UTF-8").replaceAll("\\+", "%20")));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Should never happen, UTF-8 is always supported
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
{{/isModel}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isMap}}
|
||||
{{/isArray}}
|
||||
|
||||
{{/allVars}}
|
||||
return joiner.toString();
|
||||
}
|
||||
{{/supportUrlQuery}}
|
||||
{{#parcelableModel}}
|
||||
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
{{#model}}
|
||||
{{#isArray}}
|
||||
out.writeList(this);
|
||||
{{/isArray}}
|
||||
{{^isArray}}
|
||||
{{#parent}}
|
||||
super.writeToParcel(out, flags);
|
||||
{{/parent}}
|
||||
{{#vars}}
|
||||
out.writeValue({{name}});
|
||||
{{/vars}}
|
||||
{{/isArray}}
|
||||
{{/model}}
|
||||
}
|
||||
|
||||
{{classname}}(Parcel in) {
|
||||
{{#isArray}}
|
||||
in.readTypedList(this, {{arrayModelType}}.CREATOR);
|
||||
{{/isArray}}
|
||||
{{^isArray}}
|
||||
{{#parent}}
|
||||
super(in);
|
||||
{{/parent}}
|
||||
{{#vars}}
|
||||
{{#isPrimitiveType}}
|
||||
{{name}} = ({{{datatypeWithEnum}}})in.readValue(null);
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
{{name}} = ({{{datatypeWithEnum}}})in.readValue({{complexType}}.class.getClassLoader());
|
||||
{{/isPrimitiveType}}
|
||||
{{/vars}}
|
||||
{{/isArray}}
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<{{classname}}> CREATOR = new Parcelable.Creator<{{classname}}>() {
|
||||
public {{classname}} createFromParcel(Parcel in) {
|
||||
{{#model}}
|
||||
{{#isArray}}
|
||||
{{classname}} result = new {{classname}}();
|
||||
result.addAll(in.readArrayList({{arrayModelType}}.class.getClassLoader()));
|
||||
return result;
|
||||
{{/isArray}}
|
||||
{{^isArray}}
|
||||
return new {{classname}}(in);
|
||||
{{/isArray}}
|
||||
{{/model}}
|
||||
}
|
||||
public {{classname}}[] newArray(int size) {
|
||||
return new {{classname}}[size];
|
||||
}
|
||||
};
|
||||
{{/parcelableModel}}
|
||||
{{#generateBuilders}}
|
||||
|
||||
{{>javaBuilder}}
|
||||
{{/generateBuilders}}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,10 @@ import {{invokerPackage}}.ApiClient;
|
||||
{{/imports}}
|
||||
import io.vertx.core.AsyncResult;
|
||||
import io.vertx.core.Handler;
|
||||
{{#supportVertxFuture}}
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.Promise;
|
||||
{{/supportVertxFuture}}
|
||||
import io.vertx.core.json.JsonObject;
|
||||
|
||||
import java.util.*;
|
||||
@@ -18,11 +22,33 @@ public interface {{classname}} {
|
||||
{{/isDeprecated}}
|
||||
void {{operationId}}({{#allParams}}{{>nullable_var_annotations}} {{{dataType}}} {{paramName}}, {{/allParams}}Handler<AsyncResult<{{{returnType}}}{{^returnType}}Void{{/returnType}}>> handler);
|
||||
|
||||
{{#supportVertxFuture}}
|
||||
{{#isDeprecated}}
|
||||
@Deprecated
|
||||
{{/isDeprecated}}
|
||||
default Future<{{{returnType}}}{{^returnType}}Void{{/returnType}}> {{operationId}}({{#allParams}}{{>nullable_var_annotations}} {{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}){
|
||||
Promise<{{{returnType}}}{{^returnType}}Void{{/returnType}}> promise = Promise.promise();
|
||||
{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}promise);
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
{{/supportVertxFuture}}
|
||||
{{#isDeprecated}}
|
||||
@Deprecated
|
||||
{{/isDeprecated}}
|
||||
void {{operationId}}({{#allParams}}{{>nullable_var_annotations}} {{{dataType}}} {{paramName}}, {{/allParams}}ApiClient.AuthInfo authInfo, Handler<AsyncResult<{{{returnType}}}{{^returnType}}Void{{/returnType}}>> handler);
|
||||
|
||||
{{#supportVertxFuture}}
|
||||
{{#isDeprecated}}
|
||||
@Deprecated
|
||||
{{/isDeprecated}}
|
||||
default Future<{{{returnType}}}{{^returnType}}Void{{/returnType}}> {{operationId}}({{#allParams}}{{>nullable_var_annotations}} {{{dataType}}} {{paramName}}, {{/allParams}}ApiClient.AuthInfo authInfo){
|
||||
Promise<{{{returnType}}}{{^returnType}}Void{{/returnType}}> promise = Promise.promise();
|
||||
{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}authInfo, promise);
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
{{/supportVertxFuture}}
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ ext {
|
||||
swagger_annotations_version = "1.5.21"
|
||||
jackson_version = "2.17.1"
|
||||
jackson_databind_version = "2.17.1"
|
||||
vertx_version = "3.5.2"
|
||||
vertx_version = "{{#supportVertxFuture}}4.0.0{{/supportVertxFuture}}{{^supportVertxFuture}}3.5.2{{/supportVertxFuture}}"
|
||||
junit_version = "5.10.3"
|
||||
{{#openApiNullable}}
|
||||
jackson_databind_nullable_version = "0.2.6"
|
||||
|
||||
@@ -299,7 +299,7 @@
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<vertx-version>3.5.2</vertx-version>
|
||||
<vertx-version>{{#supportVertxFuture}}4.0.0{{/supportVertxFuture}}{{^supportVertxFuture}}3.5.2{{/supportVertxFuture}}</vertx-version>
|
||||
{{#swagger1AnnotationLibrary}}
|
||||
<swagger-annotations-version>1.6.6</swagger-annotations-version>
|
||||
{{/swagger1AnnotationLibrary}}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class {{classname}} {
|
||||
@ApiResponses(value = { {{#responses}}
|
||||
@ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}},{{/-last}}{{/responses}} })
|
||||
public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}}, {{/-last}}{{/allParams}}) {
|
||||
return delegate.{{nickname}}({{#allParams}}{{#isFile}}{{#isMultipart}}{{paramName}}InputStream, {{paramName}}Detail{{/isMultipart}}{{^isMultipart}}{{paramName}}{{/isMultipart}}{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}}, {{/allParams}}securityContext);
|
||||
return delegate.{{nickname}}({{#allParams}}{{#isFile}}{{#isMultipart}}{{paramName}}Detail{{/isMultipart}}{{^isMultipart}}{{paramName}}{{/isMultipart}}{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}}, {{/allParams}}securityContext);
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{{#isFormParam}}{{^isFile}}{{#isMultipart}}@Multipart{{/isMultipart}}{{^isMultipart}}@FormParam{{/isMultipart}}(value = "{{baseName}}"{{^required}}{{#isMultipart}}, required = false{{/isMultipart}}{{/required}}) {{{dataType}}} {{paramName}}{{/isFile}}{{#isFile}} @Multipart(value = "{{baseName}}"{{^required}}, required = false{{/required}}) InputStream {{paramName}}InputStream, @Multipart(value = "{{baseName}}" {{^required}}, required = false{{/required}}) Attachment {{paramName}}Detail{{/isFile}}{{/isFormParam}}
|
||||
{{#isFormParam}}{{^isFile}}{{#isMultipart}}@Multipart{{/isMultipart}}{{^isMultipart}}@FormParam{{/isMultipart}}(value = "{{baseName}}"{{^required}}{{#isMultipart}}, required = false{{/isMultipart}}{{/required}}) {{{dataType}}} {{paramName}}{{/isFile}}{{#isFile}} @Multipart(value = "{{baseName}}" {{^required}}, required = false{{/required}}) Attachment {{paramName}}Detail{{/isFile}}{{/isFormParam}}
|
||||
@@ -1 +1 @@
|
||||
{{#isFormParam}}{{^isFile}}{{{dataType}}} {{paramName}}{{/isFile}}{{#isFile}}InputStream {{paramName}}InputStream, Attachment {{paramName}}Detail{{/isFile}}{{/isFormParam}}
|
||||
{{#isFormParam}}{{^isFile}}{{{dataType}}} {{paramName}}{{/isFile}}{{#isFile}}Attachment {{paramName}}Detail{{/isFile}}{{/isFormParam}}
|
||||
@@ -603,7 +603,7 @@ namespace {{packageName}}.Client
|
||||
|
||||
if (inputVariables.ContainsKey(variable.Key))
|
||||
{
|
||||
if (((List<string>)serverVariables["enum_values"]).Contains(inputVariables[variable.Key]))
|
||||
if (!serverVariables.ContainsKey("enum_values") || ((List<string>)serverVariables["enum_values"]).Contains(inputVariables[variable.Key]))
|
||||
{
|
||||
url = url.Replace("{" + variable.Key + "}", inputVariables[variable.Key]);
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ defmodule {{moduleName}}.Connection do
|
||||
of the function call, will be set as a bearer token in the
|
||||
`authorization` header.
|
||||
{{/hasOAuthMethods}}
|
||||
- `options`: a keyword list of OpenAPIPetstore.Connection.options.
|
||||
- `options`: a keyword list of {{moduleName}}.Connection.options.
|
||||
|
||||
### Returns
|
||||
|
||||
@@ -133,7 +133,7 @@ defmodule {{moduleName}}.Connection do
|
||||
that returns a bearer token.
|
||||
- `scopes_or_password`: a list of Strings represenging OAuth2 scopes, or
|
||||
a single string that is the password for the username provided.
|
||||
- `options`: a keyword list of OpenAPIPetstore.Connection.options.
|
||||
- `options`: a keyword list of {{moduleName}}.Connection.options.
|
||||
|
||||
### Returns
|
||||
|
||||
@@ -155,7 +155,7 @@ defmodule {{moduleName}}.Connection do
|
||||
of the function call, will be set as a bearer token in the
|
||||
`authorization` header.
|
||||
- `scopes`: a list of Strings represenging OAuth2 scopes.
|
||||
- `options`: a keyword list of OpenAPIPetstore.Connection.options.
|
||||
- `options`: a keyword list of {{moduleName}}.Connection.options.
|
||||
|
||||
### Returns
|
||||
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
# This file is automatically generated by OpenAPI Generator (https://github.com/openAPITools/openapi-generator).
|
||||
# To include other gradle properties as part of the code generation process, please use the `gradleProperties` option.
|
||||
#
|
||||
# Gradle properties reference: https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
|
||||
#
|
||||
android.useAndroidX=true
|
||||
{{#generateRoomModels}}
|
||||
android.enableJetifier=true
|
||||
{{/generateRoomModels}}
|
||||
{{#gradleProperties}}
|
||||
{{{.}}}
|
||||
{{/gradleProperties}}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{{#isHeaderParam}}{{#useBeanValidation}}{{>beanValidationCore}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}", `in` = ParameterIn.HEADER{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} @RequestHeader(value = "{{baseName}}", required = {{#required}}true{{/required}}{{^required}}false{{/required}}) {{{paramName}}}: {{>optionalDataType}}{{/isHeaderParam}}
|
||||
{{#isHeaderParam}}{{#useBeanValidation}}{{>beanValidationCore}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}", `in` = ParameterIn.HEADER{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} @RequestHeader(value = "{{baseName}}", required = {{#required}}true{{/required}}{{^required}}false{{/required}}{{#defaultValue}}, defaultValue = {{#isEnum}}"{{/isEnum}}{{{.}}}{{#isEnum}}"{{/isEnum}}{{/defaultValue}}) {{{paramName}}}: {{>optionalDataType}}{{/isHeaderParam}}
|
||||
227
modules/openapi-generator/src/main/resources/php-nextgen/FormDataProcessor.mustache
vendored
Normal file
227
modules/openapi-generator/src/main/resources/php-nextgen/FormDataProcessor.mustache
vendored
Normal file
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
/**
|
||||
* FormDataProcessor
|
||||
* PHP version 8.1
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://openapi-generator.tech
|
||||
*/
|
||||
|
||||
{{>partial_header}}
|
||||
/**
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace {{invokerPackage}};
|
||||
|
||||
use ArrayAccess;
|
||||
use DateTime;
|
||||
use GuzzleHttp\Psr7\Utils;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use SplFileObject;
|
||||
use {{modelPackage}}\ModelInterface;
|
||||
|
||||
class FormDataProcessor
|
||||
{
|
||||
/**
|
||||
* Tags whether payload passed to ::prepare() contains one or more
|
||||
* SplFileObject or stream values.
|
||||
*/
|
||||
public bool $has_file = false;
|
||||
|
||||
/**
|
||||
* Take value and turn it into an array suitable for inclusion in
|
||||
* the http body (form parameter). If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
*
|
||||
* @param array<string|bool|array|DateTime|ArrayAccess|SplFileObject> $values the value of the form parameter
|
||||
*
|
||||
* @return array [key => value] of formdata
|
||||
*/
|
||||
public function prepare(array $values): array
|
||||
{
|
||||
$this->has_file = false;
|
||||
$result = [];
|
||||
|
||||
foreach ($values as $k => $v) {
|
||||
if ($v === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[$k] = $this->makeFormSafe($v);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens a multi-level array of data and generates a single-level array
|
||||
* compatible with formdata - a single-level array where the keys use bracket
|
||||
* notation to signify nested data.
|
||||
*
|
||||
* credit: https://github.com/FranBar1966/FlatPHP
|
||||
*/
|
||||
public static function flatten(array $source, string $start = ''): array
|
||||
{
|
||||
$opt = [
|
||||
'prefix' => '[',
|
||||
'suffix' => ']',
|
||||
'suffix-end' => true,
|
||||
'prefix-list' => '[',
|
||||
'suffix-list' => ']',
|
||||
'suffix-list-end' => true,
|
||||
];
|
||||
|
||||
if ($start === '') {
|
||||
$currentPrefix = '';
|
||||
$currentSuffix = '';
|
||||
$currentSuffixEnd = false;
|
||||
} elseif (array_is_list($source)) {
|
||||
$currentPrefix = $opt['prefix-list'];
|
||||
$currentSuffix = $opt['suffix-list'];
|
||||
$currentSuffixEnd = $opt['suffix-list-end'];
|
||||
} else {
|
||||
$currentPrefix = $opt['prefix'];
|
||||
$currentSuffix = $opt['suffix'];
|
||||
$currentSuffixEnd = $opt['suffix-end'];
|
||||
}
|
||||
|
||||
$currentName = $start;
|
||||
$result = [];
|
||||
|
||||
foreach ($source as $key => $val) {
|
||||
$currentName .= $currentPrefix . $key;
|
||||
|
||||
if (is_array($val) && !empty($val)) {
|
||||
$currentName .= $currentSuffix;
|
||||
$result += self::flatten($val, $currentName);
|
||||
} else {
|
||||
if ($currentSuffixEnd) {
|
||||
$currentName .= $currentSuffix;
|
||||
}
|
||||
|
||||
$result[$currentName] = ObjectSerializer::toString($val);
|
||||
}
|
||||
|
||||
$currentName = $start;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* formdata must be limited to scalars or arrays of scalar values,
|
||||
* or a resource for a file upload. Here we iterate through all available
|
||||
* data and identify how to handle each scenario
|
||||
*
|
||||
* @param string|bool|array|DateTime|ArrayAccess|SplFileObject $value
|
||||
*/
|
||||
protected function makeFormSafe(mixed $value)
|
||||
{
|
||||
if ($value instanceof SplFileObject) {
|
||||
return $this->processFiles([$value])[0];
|
||||
}
|
||||
|
||||
if (is_resource($value)) {
|
||||
$this->has_file = true;
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ($value instanceof ModelInterface) {
|
||||
return $this->processModel($value);
|
||||
}
|
||||
|
||||
if (is_array($value) || is_object($value)) {
|
||||
$data = [];
|
||||
|
||||
foreach ($value as $k => $v) {
|
||||
$data[$k] = $this->makeFormSafe($v);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
return ObjectSerializer::toString($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* We are able to handle nested ModelInterface. We do not simply call
|
||||
* json_decode(json_encode()) because any given model may have binary data
|
||||
* or other data that cannot be serialized to a JSON string
|
||||
*/
|
||||
protected function processModel(ModelInterface $model): array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($model::openAPITypes() as $name => $type) {
|
||||
$value = $model->offsetGet($name);
|
||||
|
||||
if ($value === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str_contains($type, '\SplFileObject')) {
|
||||
$file = is_array($value) ? $value : [$value];
|
||||
$result[$name] = $this->processFiles($file);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($value instanceof ModelInterface) {
|
||||
$result[$name] = $this->processModel($value);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($value) || is_object($value)) {
|
||||
$result[$name] = $this->makeFormSafe($value);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[$name] = ObjectSerializer::toString($value);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle file data
|
||||
*/
|
||||
protected function processFiles(array $files): array
|
||||
{
|
||||
$this->has_file = true;
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach ($files as $i => $file) {
|
||||
if (is_array($file)) {
|
||||
$result[$i] = $this->processFiles($file);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($file instanceof StreamInterface) {
|
||||
$result[$i] = $file;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($file instanceof SplFileObject) {
|
||||
$result[$i] = $this->tryFopen($file);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function tryFopen(SplFileObject $file)
|
||||
{
|
||||
return Utils::tryFopen($file->getRealPath(), 'rb');
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
namespace {{invokerPackage}};
|
||||
|
||||
use ArrayAccess;
|
||||
use DateTimeInterface;
|
||||
use DateTime;
|
||||
use GuzzleHttp\Psr7\Utils;
|
||||
@@ -316,37 +315,6 @@ class ObjectSerializer
|
||||
return self::toString($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take value and turn it into an array suitable for inclusion in
|
||||
* the http body (form parameter). If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
*
|
||||
* @param string|bool|array|DateTime|ArrayAccess|\SplFileObject $value the value of the form parameter
|
||||
*
|
||||
* @return array [key => value] of formdata
|
||||
*/
|
||||
public static function toFormValue(
|
||||
string $key,
|
||||
string|bool|array|DateTime|ArrayAccess|\SplFileObject $value,
|
||||
): array {
|
||||
if ($value instanceof \SplFileObject) {
|
||||
return [$key => $value->getRealPath()];
|
||||
} elseif (is_array($value) || $value instanceof ArrayAccess) {
|
||||
$flattened = [];
|
||||
$result = [];
|
||||
|
||||
self::flattenArray(json_decode(json_encode($value), true), $flattened);
|
||||
|
||||
foreach ($flattened as $k => $v) {
|
||||
$result["{$key}{$k}"] = self::toString($v);
|
||||
}
|
||||
|
||||
return $result;
|
||||
} else {
|
||||
return [$key => self::toString($value)];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the parameter. If it's a string, pass through unchanged
|
||||
@@ -612,58 +580,4 @@ class ObjectSerializer
|
||||
|
||||
return $qs ? (string) substr($qs, 0, -1) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens an array of Model object and generates an array compatible
|
||||
* with formdata - a single-level array where the keys use bracket
|
||||
* notation to signify nested data.
|
||||
*
|
||||
* credit: https://github.com/FranBar1966/FlatPHP
|
||||
*/
|
||||
private static function flattenArray(
|
||||
ArrayAccess|array $source,
|
||||
array &$destination,
|
||||
string $start = '',
|
||||
) {
|
||||
$opt = [
|
||||
'prefix' => '[',
|
||||
'suffix' => ']',
|
||||
'suffix-end' => true,
|
||||
'prefix-list' => '[',
|
||||
'suffix-list' => ']',
|
||||
'suffix-list-end' => true,
|
||||
];
|
||||
|
||||
if (!is_array($source)) {
|
||||
$source = (array) $source;
|
||||
}
|
||||
|
||||
if (array_is_list($source)) {
|
||||
$currentPrefix = $opt['prefix-list'];
|
||||
$currentSuffix = $opt['suffix-list'];
|
||||
$currentSuffixEnd = $opt['suffix-list-end'];
|
||||
} else {
|
||||
$currentPrefix = $opt['prefix'];
|
||||
$currentSuffix = $opt['suffix'];
|
||||
$currentSuffixEnd = $opt['suffix-end'];
|
||||
}
|
||||
|
||||
$currentName = $start;
|
||||
|
||||
foreach ($source as $key => $val) {
|
||||
$currentName .= $currentPrefix.$key;
|
||||
|
||||
if (is_array($val) && !empty($val)) {
|
||||
$currentName .= "{$currentSuffix}";
|
||||
self::flattenArray($val, $destination, $currentName);
|
||||
} else {
|
||||
if ($currentSuffixEnd) {
|
||||
$currentName .= $currentSuffix;
|
||||
}
|
||||
$destination[$currentName] = self::toString($val);
|
||||
}
|
||||
|
||||
$currentName = $start;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ use Psr\Http\Message\ResponseInterface;
|
||||
use {{invokerPackage}}\ApiException;
|
||||
use {{invokerPackage}}\Configuration;
|
||||
use {{invokerPackage}}\HeaderSelector;
|
||||
use {{invokerPackage}}\FormDataProcessor;
|
||||
use {{invokerPackage}}\ObjectSerializer;
|
||||
|
||||
/**
|
||||
@@ -189,8 +190,8 @@ use {{invokerPackage}}\ObjectSerializer;
|
||||
{{/vendorExtensions.x-group-parameters}}
|
||||
): {{{vendorExtensions.x-php-return-type}}}
|
||||
{
|
||||
{{#returnType}}list($response) = {{/returnType}}$this->{{operationId}}WithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}, {{/allParams}}{{#servers}}{{#-first}}$hostIndex, $variables, {{/-first}}{{/servers}}$contentType{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}});{{#returnType}}
|
||||
return $response;{{/returnType}}
|
||||
{{^vendorExtensions.x-php-return-type-is-void}}list($response) = {{/vendorExtensions.x-php-return-type-is-void}}$this->{{operationId}}WithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}, {{/allParams}}{{#servers}}{{#-first}}$hostIndex, $variables, {{/-first}}{{/servers}}$contentType{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}});{{^vendorExtensions.x-php-return-type-is-void}}
|
||||
return $response;{{/vendorExtensions.x-php-return-type-is-void}}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -724,25 +725,19 @@ use {{invokerPackage}}\ObjectSerializer;
|
||||
{{/pathParams}}
|
||||
|
||||
{{#formParams}}
|
||||
{{#-first}}
|
||||
// form params
|
||||
if (${{paramName}} !== null) {
|
||||
{{#isFile}}
|
||||
$multipart = true;
|
||||
$formParams['{{baseName}}'] = [];
|
||||
$paramFiles = is_array(${{paramName}}) ? ${{paramName}} : [${{paramName}}];
|
||||
foreach ($paramFiles as $paramFile) {
|
||||
$formParams['{{baseName}}'][] = $paramFile instanceof \Psr\Http\Message\StreamInterface
|
||||
? $paramFile
|
||||
: \GuzzleHttp\Psr7\Utils::tryFopen(
|
||||
ObjectSerializer::toFormValue('{{baseName}}', $paramFile)['{{baseName}}'],
|
||||
'rb'
|
||||
);
|
||||
}
|
||||
{{/isFile}}
|
||||
{{^isFile}}
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('{{baseName}}', ${{paramName}}));
|
||||
{{/isFile}}
|
||||
}
|
||||
$formDataProcessor = new FormDataProcessor();
|
||||
|
||||
$formData = $formDataProcessor->prepare([
|
||||
{{/-first}}
|
||||
'{{paramName}}' => ${{paramName}},
|
||||
{{#-last}}
|
||||
]);
|
||||
|
||||
$formParams = $formDataProcessor->flatten($formData);
|
||||
$multipart = $formDataProcessor->has_file;
|
||||
{{/-last}}
|
||||
{{/formParams}}
|
||||
|
||||
$headers = $this->headerSelector->selectHeaders(
|
||||
|
||||
233
modules/openapi-generator/src/main/resources/php/FormDataProcessor.mustache
vendored
Normal file
233
modules/openapi-generator/src/main/resources/php/FormDataProcessor.mustache
vendored
Normal file
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
/**
|
||||
* FormDataProcessor
|
||||
* PHP version 7.4
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://openapi-generator.tech
|
||||
*/
|
||||
|
||||
{{>partial_header}}
|
||||
/**
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace {{invokerPackage}};
|
||||
|
||||
use ArrayAccess;
|
||||
use DateTime;
|
||||
use GuzzleHttp\Psr7\Utils;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use SplFileObject;
|
||||
use {{modelPackage}}\ModelInterface;
|
||||
|
||||
/**
|
||||
* FormDataProcessor Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://openapi-generator.tech
|
||||
*/
|
||||
class FormDataProcessor
|
||||
{
|
||||
/**
|
||||
* Tags whether payload passed to ::prepare() contains one or more
|
||||
* SplFileObject or stream values.
|
||||
*/
|
||||
public bool $has_file = false;
|
||||
|
||||
/**
|
||||
* Take value and turn it into an array suitable for inclusion in
|
||||
* the http body (form parameter). If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
*
|
||||
* @param array<string|bool|array|DateTime|ArrayAccess|SplFileObject> $values the value of the form parameter
|
||||
*
|
||||
* @return array [key => value] of formdata
|
||||
*/
|
||||
public function prepare(array $values): array
|
||||
{
|
||||
$this->has_file = false;
|
||||
$result = [];
|
||||
|
||||
foreach ($values as $k => $v) {
|
||||
if ($v === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[$k] = $this->makeFormSafe($v);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens a multi-level array of data and generates a single-level array
|
||||
* compatible with formdata - a single-level array where the keys use bracket
|
||||
* notation to signify nested data.
|
||||
*
|
||||
* credit: https://github.com/FranBar1966/FlatPHP
|
||||
*/
|
||||
public static function flatten(array $source, string $start = ''): array
|
||||
{
|
||||
$opt = [
|
||||
'prefix' => '[',
|
||||
'suffix' => ']',
|
||||
'suffix-end' => true,
|
||||
'prefix-list' => '[',
|
||||
'suffix-list' => ']',
|
||||
'suffix-list-end' => true,
|
||||
];
|
||||
|
||||
if ($start === '') {
|
||||
$currentPrefix = '';
|
||||
$currentSuffix = '';
|
||||
$currentSuffixEnd = false;
|
||||
} elseif (array_is_list($source)) {
|
||||
$currentPrefix = $opt['prefix-list'];
|
||||
$currentSuffix = $opt['suffix-list'];
|
||||
$currentSuffixEnd = $opt['suffix-list-end'];
|
||||
} else {
|
||||
$currentPrefix = $opt['prefix'];
|
||||
$currentSuffix = $opt['suffix'];
|
||||
$currentSuffixEnd = $opt['suffix-end'];
|
||||
}
|
||||
|
||||
$currentName = $start;
|
||||
$result = [];
|
||||
|
||||
foreach ($source as $key => $val) {
|
||||
$currentName .= $currentPrefix.$key;
|
||||
|
||||
if (is_array($val) && !empty($val)) {
|
||||
$currentName .= $currentSuffix;
|
||||
$result += self::flatten($val, $currentName);
|
||||
} else {
|
||||
if ($currentSuffixEnd) {
|
||||
$currentName .= $currentSuffix;
|
||||
}
|
||||
|
||||
$result[$currentName] = ObjectSerializer::toString($val);
|
||||
}
|
||||
|
||||
$currentName = $start;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* formdata must be limited to scalars or arrays of scalar values,
|
||||
* or a resource for a file upload. Here we iterate through all available
|
||||
* data and identify how to handle each scenario
|
||||
*/
|
||||
protected function makeFormSafe($value)
|
||||
{
|
||||
if ($value instanceof SplFileObject) {
|
||||
return $this->processFiles([$value])[0];
|
||||
}
|
||||
|
||||
if (is_resource($value)) {
|
||||
$this->has_file = true;
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ($value instanceof ModelInterface) {
|
||||
return $this->processModel($value);
|
||||
}
|
||||
|
||||
if (is_array($value) || (is_object($value) && !$value instanceof \DateTimeInterface)) {
|
||||
$data = [];
|
||||
|
||||
foreach ($value as $k => $v) {
|
||||
$data[$k] = $this->makeFormSafe($v);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
return ObjectSerializer::toString($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* We are able to handle nested ModelInterface. We do not simply call
|
||||
* json_decode(json_encode()) because any given model may have binary data
|
||||
* or other data that cannot be serialized to a JSON string
|
||||
*/
|
||||
protected function processModel(ModelInterface $model): array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($model::openAPITypes() as $name => $type) {
|
||||
$value = $model->offsetGet($name);
|
||||
|
||||
if ($value === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strpos($type, '\SplFileObject') !== false) {
|
||||
$file = is_array($value) ? $value : [$value];
|
||||
$result[$name] = $this->processFiles($file);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($value instanceof ModelInterface) {
|
||||
$result[$name] = $this->processModel($value);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($value) || is_object($value)) {
|
||||
$result[$name] = $this->makeFormSafe($value);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[$name] = ObjectSerializer::toString($value);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle file data
|
||||
*/
|
||||
protected function processFiles(array $files): array
|
||||
{
|
||||
$this->has_file = true;
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach ($files as $i => $file) {
|
||||
if (is_array($file)) {
|
||||
$result[$i] = $this->processFiles($file);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($file instanceof StreamInterface) {
|
||||
$result[$i] = $file;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($file instanceof SplFileObject) {
|
||||
$result[$i] = $this->tryFopen($file);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function tryFopen(SplFileObject $file)
|
||||
{
|
||||
return Utils::tryFopen($file->getRealPath(), 'rb');
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
namespace {{invokerPackage}};
|
||||
|
||||
use ArrayAccess;
|
||||
use GuzzleHttp\Psr7\Utils;
|
||||
use {{modelPackage}}\ModelInterface;
|
||||
|
||||
@@ -315,35 +314,6 @@ class ObjectSerializer
|
||||
return self::toString($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take value and turn it into an array suitable for inclusion in
|
||||
* the http body (form parameter). If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
*
|
||||
* @param string|bool|array|DateTime|ArrayAccess|\SplFileObject $value the value of the form parameter
|
||||
*
|
||||
* @return array [key => value] of formdata
|
||||
*/
|
||||
public static function toFormValue(string $key, $value)
|
||||
{
|
||||
if ($value instanceof \SplFileObject) {
|
||||
return [$key => $value->getRealPath()];
|
||||
} elseif (is_array($value) || $value instanceof ArrayAccess) {
|
||||
$flattened = [];
|
||||
$result = [];
|
||||
|
||||
self::flattenArray(json_decode(json_encode($value), true), $flattened);
|
||||
|
||||
foreach ($flattened as $k => $v) {
|
||||
$result["{$key}{$k}"] = self::toString($v);
|
||||
}
|
||||
|
||||
return $result;
|
||||
} else {
|
||||
return [$key => self::toString($value)];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the parameter. If it's a string, pass through unchanged
|
||||
@@ -617,81 +587,4 @@ class ObjectSerializer
|
||||
|
||||
return $qs ? (string) substr($qs, 0, -1) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens an array of Model object and generates an array compatible
|
||||
* with formdata - a single-level array where the keys use bracket
|
||||
* notation to signify nested data.
|
||||
*
|
||||
* @param \ArrayAccess|array $source
|
||||
*
|
||||
* credit: https://github.com/FranBar1966/FlatPHP
|
||||
*/
|
||||
private static function flattenArray(
|
||||
$source,
|
||||
array &$destination,
|
||||
string $start = ''
|
||||
) {
|
||||
$opt = [
|
||||
'prefix' => '[',
|
||||
'suffix' => ']',
|
||||
'suffix-end' => true,
|
||||
'prefix-list' => '[',
|
||||
'suffix-list' => ']',
|
||||
'suffix-list-end' => true,
|
||||
];
|
||||
|
||||
if (!is_array($source)) {
|
||||
$source = (array) $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* array_is_list only in PHP >= 8.1
|
||||
*
|
||||
* credit: https://www.php.net/manual/en/function.array-is-list.php#127044
|
||||
*/
|
||||
if (!function_exists('array_is_list')) {
|
||||
function array_is_list(array $array)
|
||||
{
|
||||
$i = -1;
|
||||
|
||||
foreach ($array as $k => $v) {
|
||||
++$i;
|
||||
if ($k !== $i) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_is_list($source)) {
|
||||
$currentPrefix = $opt['prefix-list'];
|
||||
$currentSuffix = $opt['suffix-list'];
|
||||
$currentSuffixEnd = $opt['suffix-list-end'];
|
||||
} else {
|
||||
$currentPrefix = $opt['prefix'];
|
||||
$currentSuffix = $opt['suffix'];
|
||||
$currentSuffixEnd = $opt['suffix-end'];
|
||||
}
|
||||
|
||||
$currentName = $start;
|
||||
|
||||
foreach ($source as $key => $val) {
|
||||
$currentName .= $currentPrefix.$key;
|
||||
|
||||
if (is_array($val) && !empty($val)) {
|
||||
$currentName .= "{$currentSuffix}";
|
||||
self::flattenArray($val, $destination, $currentName);
|
||||
} else {
|
||||
if ($currentSuffixEnd) {
|
||||
$currentName .= $currentSuffix;
|
||||
}
|
||||
$destination[$currentName] = self::toString($val);
|
||||
}
|
||||
|
||||
$currentName = $start;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use {{invokerPackage}}\ApiException;
|
||||
use {{invokerPackage}}\Configuration;
|
||||
use {{invokerPackage}}\FormDataProcessor;
|
||||
use {{invokerPackage}}\HeaderSelector;
|
||||
use {{invokerPackage}}\ObjectSerializer;
|
||||
|
||||
@@ -646,23 +647,19 @@ use {{invokerPackage}}\ObjectSerializer;
|
||||
{{/pathParams}}
|
||||
|
||||
{{#formParams}}
|
||||
{{#-first}}
|
||||
// form params
|
||||
if (${{paramName}} !== null) {
|
||||
{{#isFile}}
|
||||
$multipart = true;
|
||||
$formParams['{{baseName}}'] = [];
|
||||
$paramFiles = is_array(${{paramName}}) ? ${{paramName}} : [${{paramName}}];
|
||||
foreach ($paramFiles as $paramFile) {
|
||||
$formParams['{{baseName}}'][] = \GuzzleHttp\Psr7\Utils::tryFopen(
|
||||
ObjectSerializer::toFormValue('{{baseName}}', $paramFile)['{{baseName}}'],
|
||||
'rb'
|
||||
);
|
||||
}
|
||||
{{/isFile}}
|
||||
{{^isFile}}
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('{{baseName}}', ${{paramName}}));
|
||||
{{/isFile}}
|
||||
}
|
||||
$formDataProcessor = new FormDataProcessor();
|
||||
|
||||
$formData = $formDataProcessor->prepare([
|
||||
{{/-first}}
|
||||
'{{paramName}}' => ${{paramName}},
|
||||
{{#-last}}
|
||||
]);
|
||||
|
||||
$formParams = $formDataProcessor->flatten($formData);
|
||||
$multipart = $formDataProcessor->has_file;
|
||||
{{/-last}}
|
||||
{{/formParams}}
|
||||
|
||||
{{#isMultipart}}
|
||||
|
||||
@@ -34,6 +34,7 @@ use {{invokerPackage}}\ApiException;
|
||||
use {{invokerPackage}}\Configuration;
|
||||
use {{invokerPackage}}\DebugPlugin;
|
||||
use {{invokerPackage}}\HeaderSelector;
|
||||
use {{invokerPackage}}\FormDataProcessor;
|
||||
use {{invokerPackage}}\ObjectSerializer;
|
||||
use Psr\Http\Client\ClientExceptionInterface;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
@@ -605,23 +606,19 @@ use function sprintf;
|
||||
{{/pathParams}}
|
||||
|
||||
{{#formParams}}
|
||||
{{#-first}}
|
||||
// form params
|
||||
if (${{paramName}} !== null) {
|
||||
{{#isFile}}
|
||||
$multipart = true;
|
||||
$formParams['{{baseName}}'] = [];
|
||||
$paramFiles = is_array(${{paramName}}) ? ${{paramName}} : [${{paramName}}];
|
||||
foreach ($paramFiles as $paramFile) {
|
||||
$formParams['{{baseName}}'][] = \GuzzleHttp\Psr7\try_fopen(
|
||||
ObjectSerializer::toFormValue('{{baseName}}', $paramFile)['{{baseName}}'],
|
||||
'rb'
|
||||
);
|
||||
}
|
||||
{{/isFile}}
|
||||
{{^isFile}}
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('{{baseName}}', ${{paramName}}));
|
||||
{{/isFile}}
|
||||
}
|
||||
$formDataProcessor = new FormDataProcessor();
|
||||
|
||||
$formData = $formDataProcessor->prepare([
|
||||
{{/-first}}
|
||||
'{{paramName}}' => ${{paramName}},
|
||||
{{#-last}}
|
||||
]);
|
||||
|
||||
$formParams = $formDataProcessor->flatten($formData);
|
||||
$multipart = $formDataProcessor->has_file;
|
||||
{{/-last}}
|
||||
{{/formParams}}
|
||||
|
||||
$headers = $this->headerSelector->selectHeaders(
|
||||
|
||||
@@ -3,6 +3,9 @@ syntax = "proto3";
|
||||
|
||||
package {{#lambda.lowercase}}{{{packageName}}}.{{{apiPackage}}}.{{{classname}}};{{/lambda.lowercase}}
|
||||
|
||||
{{#customOptionsApi}}
|
||||
{{{.}}}
|
||||
{{/customOptionsApi}}
|
||||
import "google/protobuf/empty.proto";
|
||||
{{#imports}}
|
||||
{{#import}}
|
||||
|
||||
@@ -3,6 +3,9 @@ syntax = "proto3";
|
||||
|
||||
package {{#lambda.lowercase}}{{{packageName}}};{{/lambda.lowercase}}
|
||||
|
||||
{{#customOptionsModel}}
|
||||
{{{.}}}
|
||||
{{/customOptionsModel}}
|
||||
{{#imports}}
|
||||
{{#import}}
|
||||
import public "{{{.}}}.proto";
|
||||
|
||||
@@ -129,9 +129,9 @@ pub struct {{{classname}}} {
|
||||
/// {{{.}}}
|
||||
{{/description}}
|
||||
{{#isByteArray}}
|
||||
{{#required}}#[serde_as(as = "serde_with::base64::Base64")]{{/required}}{{^required}}#[serde_as(as = "Option<serde_with::base64::Base64>")]{{/required}}
|
||||
{{#vendorExtensions.isMandatory}}#[serde_as(as = "serde_with::base64::Base64")]{{/vendorExtensions.isMandatory}}{{^vendorExtensions.isMandatory}}#[serde_as(as = "{{^serdeAsDoubleOption}}Option{{/serdeAsDoubleOption}}{{#serdeAsDoubleOption}}super::DoubleOption{{/serdeAsDoubleOption}}<serde_with::base64::Base64>")]{{/vendorExtensions.isMandatory}}
|
||||
{{/isByteArray}}
|
||||
#[serde(rename = "{{{baseName}}}"{{^required}}{{#isNullable}}, default, with = "::serde_with::rust::double_option"{{/isNullable}}{{/required}}{{^required}}, skip_serializing_if = "Option::is_none"{{/required}}{{#required}}{{#isNullable}}, deserialize_with = "Option::deserialize"{{/isNullable}}{{/required}})]
|
||||
#[serde(rename = "{{{baseName}}}"{{^required}}{{#isNullable}}, default{{^isByteArray}}, with = "::serde_with::rust::double_option"{{/isByteArray}}{{/isNullable}}{{/required}}{{^required}}, skip_serializing_if = "Option::is_none"{{/required}}{{#required}}{{#isNullable}}, deserialize_with = "Option::deserialize"{{/isNullable}}{{/required}})]
|
||||
pub {{{name}}}: {{!
|
||||
### Option Start
|
||||
}}{{#isNullable}}Option<{{/isNullable}}{{^required}}Option<{{/required}}{{!
|
||||
|
||||
@@ -4,3 +4,42 @@ pub mod {{{classFilename}}};
|
||||
pub use self::{{{classFilename}}}::{{{classname}}};
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
{{#serdeAsDoubleOption}}
|
||||
use serde::{Deserialize, Deserializer, Serializer};
|
||||
use serde_with::{de::DeserializeAsWrap, ser::SerializeAsWrap, DeserializeAs, SerializeAs};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub(crate) struct DoubleOption<T>(PhantomData<T>);
|
||||
|
||||
impl<T, TAs> SerializeAs<Option<Option<T>>> for DoubleOption<TAs>
|
||||
where
|
||||
TAs: SerializeAs<T>,
|
||||
{
|
||||
fn serialize_as<S>(values: &Option<Option<T>>, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
match values {
|
||||
None => serializer.serialize_unit(),
|
||||
Some(None) => serializer.serialize_none(),
|
||||
Some(Some(v)) => serializer.serialize_some(&SerializeAsWrap::<T, TAs>::new(v)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, T, TAs> DeserializeAs<'de, Option<Option<T>>> for DoubleOption<TAs>
|
||||
where
|
||||
TAs: DeserializeAs<'de, T>,
|
||||
T: std::fmt::Debug,
|
||||
{
|
||||
fn deserialize_as<D>(deserializer: D) -> Result<Option<Option<T>>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
Ok(Some(
|
||||
DeserializeAsWrap::<Option<T>, Option<TAs>>::deserialize(deserializer)?
|
||||
.into_inner(),
|
||||
))
|
||||
}
|
||||
}
|
||||
{{/serdeAsDoubleOption}}
|
||||
@@ -56,7 +56,7 @@ object {{classname}} {
|
||||
given decoder{{classname}}: Decoder[{{classname}}] = Decoder.instance { c =>
|
||||
for {
|
||||
{{#vars}}
|
||||
{{name}} <- c.downField("{{baseName}}").as[{{^required}}Option[{{{dataType}}}]{{/required}}{{#required}}{{{dataType}}}{{/required}}]
|
||||
{{name}} <- {{#isEnumOrRef}}{{^required}}mapEmptyStringToNull(c.downField("{{baseName}}")){{/required}}{{#required}}c.downField("{{baseName}}"){{/required}}{{/isEnumOrRef}}{{^isEnumOrRef}}c.downField("{{baseName}}"){{/isEnumOrRef}}.as[{{^required}}Option[{{{dataType}}}]{{/required}}{{#required}}{{{dataType}}}{{/required}}]
|
||||
{{/vars}}
|
||||
} yield {{classname}}(
|
||||
{{#vars}}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{{>licenseInfo}}
|
||||
package {{packageName}}
|
||||
|
||||
import io.circe.{Decoder, Encoder, Json}
|
||||
import io.circe.{Decoder, Encoder, Json, ACursor}
|
||||
import java.time.{Instant, LocalDate, OffsetDateTime}
|
||||
import java.util.UUID
|
||||
|
||||
@@ -31,4 +31,7 @@ package object models {
|
||||
given encodeJson: Encoder[Json] =
|
||||
Encoder.encodeString.contramap[Json](_.toString)
|
||||
|
||||
def mapEmptyStringToNull(f: ACursor): ACursor =
|
||||
f.withFocus(json => if json.toString == "\"\"" then Json.Null else json)
|
||||
|
||||
}
|
||||
@@ -26,20 +26,4 @@ import Foundation
|
||||
return params
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func encodingParameters(forEncodableObject encodableObj: Any?, codableHelper: CodableHelper) -> [String: any Sendable]? {
|
||||
var params: [String: any Sendable]?
|
||||
|
||||
if let encodableObj = encodableObj {
|
||||
do {
|
||||
let data = try JSONSerialization.data(withJSONObject: encodableObj, options: .prettyPrinted)
|
||||
params = JSONDataEncoding.encodingParameters(jsonData: data)
|
||||
} catch {
|
||||
print(error.localizedDescription)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{dataType}}, Sendable, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}, QueryStringEncodable{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{/enumUnknownDefaultCase}} {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{dataType}}, Sendable, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}{{#useJsonEncodable}}, QueryStringEncodable{{/useJsonEncodable}}{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{/enumUnknownDefaultCase}} {
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
case {{{name}}} = {{{value}}}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{enumName}}: {{^isContainer}}{{dataType}}{{/isContainer}}{{#isContainer}}String{{/isContainer}}, Sendable, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{^isContainer}}{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}, QueryStringEncodable{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}{{/isContainer}}{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{#isContainer}}, CaseIterableDefaultsLast{{/isContainer}}{{/enumUnknownDefaultCase}} {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{enumName}}: {{^isContainer}}{{dataType}}{{/isContainer}}{{#isContainer}}String{{/isContainer}}, Sendable, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{^isContainer}}{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}{{#useJsonEncodable}}, QueryStringEncodable{{/useJsonEncodable}}{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}{{/isContainer}}{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{#isContainer}}, CaseIterableDefaultsLast{{/isContainer}}{{/enumUnknownDefaultCase}} {
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
case {{{name}}} = {{{value}}}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{^useClasses}}Sendable, {{/useClasses}}{{#useClasses}}{{#readonlyProperties}}Sendable, {{/readonlyProperties}}{{/useClasses}}{{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable, QueryStringEncodable{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}}{{/useVapor}} {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{^useClasses}}Sendable, {{/useClasses}}{{#useClasses}}{{#readonlyProperties}}Sendable, {{/readonlyProperties}}{{/useClasses}}{{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable{{#useJsonEncodable}}, QueryStringEncodable{{/useJsonEncodable}}{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}}{{/useVapor}} {
|
||||
{{#oneOf}}
|
||||
case type{{#transformArrayType}}{{.}}{{/transformArrayType}}({{.}})
|
||||
{{/oneOf}}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{{>licenseInfo}}
|
||||
import { HttpHeaders, HttpParams, HttpParameterCodec } from '@angular/common/http';
|
||||
import { CustomHttpParameterCodec } from './encoder';
|
||||
import { {{configurationClassName}} } from './configuration';
|
||||
|
||||
@@ -275,7 +275,8 @@ export class {{classname}} extends BaseService {
|
||||
|
||||
{{/isResponseFile}}
|
||||
let localVarPath = `{{{path}}}`;
|
||||
return this.httpClient.request{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}('{{httpMethod}}', `${this.configuration.basePath}${localVarPath}`,
|
||||
const { basePath, withCredentials } = this.configuration;
|
||||
return this.httpClient.request{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}('{{httpMethod}}', `${basePath}${localVarPath}`,
|
||||
{
|
||||
{{#httpContextInOptions}}
|
||||
context: localVarHttpContext,
|
||||
@@ -297,7 +298,7 @@ export class {{classname}} extends BaseService {
|
||||
{{^isResponseFile}}
|
||||
responseType: <any>responseType_,
|
||||
{{/isResponseFile}}
|
||||
withCredentials: this.configuration.withCredentials,
|
||||
...(withCredentials ? { withCredentials } : {}),
|
||||
headers: localVarHeaders,
|
||||
observe: observe,
|
||||
{{#httpTransferCacheInOptions}}
|
||||
|
||||
@@ -66,26 +66,30 @@ export class {{configurationClassName}} {
|
||||
*/
|
||||
credentials: {[ key: string ]: string | (() => string | undefined)};
|
||||
|
||||
constructor(configurationParameters: {{configurationParametersInterfaceName}} = {}) {
|
||||
this.apiKeys = configurationParameters.apiKeys;
|
||||
this.username = configurationParameters.username;
|
||||
this.password = configurationParameters.password;
|
||||
this.accessToken = configurationParameters.accessToken;
|
||||
this.basePath = configurationParameters.basePath;
|
||||
this.withCredentials = configurationParameters.withCredentials;
|
||||
this.encoder = configurationParameters.encoder;
|
||||
if (configurationParameters.encodeParam) {
|
||||
this.encodeParam = configurationParameters.encodeParam;
|
||||
constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder, password, username, withCredentials }: {{configurationParametersInterfaceName}} = {}) {
|
||||
if (apiKeys) {
|
||||
this.apiKeys = apiKeys;
|
||||
}
|
||||
else {
|
||||
this.encodeParam = param => this.defaultEncodeParam(param);
|
||||
if (username !== undefined) {
|
||||
this.username = username;
|
||||
}
|
||||
if (configurationParameters.credentials) {
|
||||
this.credentials = configurationParameters.credentials;
|
||||
if (password !== undefined) {
|
||||
this.password = password;
|
||||
}
|
||||
else {
|
||||
this.credentials = {};
|
||||
if (accessToken !== undefined) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
if (basePath !== undefined) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
if (withCredentials !== undefined) {
|
||||
this.withCredentials = withCredentials;
|
||||
}
|
||||
if (encoder) {
|
||||
this.encoder = encoder;
|
||||
}
|
||||
this.encodeParam = encodeParam ?? (param => this.defaultEncodeParam(param));
|
||||
this.credentials = credentials ?? {};
|
||||
{{#authMethods}}
|
||||
|
||||
// init default {{name}} credential
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
"module": "{{#supportsES6}}es6{{/supportsES6}}{{^supportsES6}}commonjs{{/supportsES6}}",
|
||||
"moduleResolution": "node",
|
||||
"removeComments": true,
|
||||
"strictNullChecks": true,
|
||||
"exactOptionalPropertyTypes": true,
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"noLib": false,
|
||||
|
||||
@@ -30,7 +30,7 @@ public class PythonFastapiCodegenTest {
|
||||
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
||||
files.forEach(File::deleteOnExit);
|
||||
|
||||
TestUtils.assertFileExists(Paths.get(output.getAbsolutePath(), "/src", IMPL_PKG, "__init__.py"));
|
||||
TestUtils.assertFileExists(Paths.get(output.getAbsolutePath(), "/src", "/nodesc", IMPL_PKG, "__init__.py"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -137,6 +137,31 @@ paths:
|
||||
items:
|
||||
type: string
|
||||
collectionFormat: csv
|
||||
- name: size
|
||||
in: header
|
||||
description: 'A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used.'
|
||||
required: false
|
||||
type: string
|
||||
- name: size
|
||||
in: query
|
||||
description: 'The number of items to return per page. Test QueryParam for issue #8315 - must be removed when x-spring-paginated:true is used.'
|
||||
required: true
|
||||
type: integer
|
||||
minimum: 1
|
||||
default: 20
|
||||
- name: page
|
||||
in: query
|
||||
description: 'The page to return, starting with page 0. Test QueryParam for issue #8315 - must be removed when x-spring-paginated:true is used.'
|
||||
required: true
|
||||
type: integer
|
||||
minimum: 0
|
||||
default: 0
|
||||
- name: sort
|
||||
in: query
|
||||
description: 'The sorting to apply to the Pageable object. Test QueryParam for issue #8315 - must be removed when x-spring-paginated:true is used.'
|
||||
required: true
|
||||
type: string
|
||||
default: id,asc
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
|
||||
@@ -133,6 +133,31 @@ paths:
|
||||
items:
|
||||
type: string
|
||||
collectionFormat: csv
|
||||
- name: size
|
||||
in: header
|
||||
description: 'A test HeaderParam for issue #8315 - must NOT be removed when x-spring-paginated:true is used.'
|
||||
required: false
|
||||
type: string
|
||||
- name: size
|
||||
in: query
|
||||
description: 'The number of items to return per page. Test QueryParam for issue #8315 - must be removed when x-spring-paginated:true is used.'
|
||||
required: true
|
||||
type: integer
|
||||
minimum: 1
|
||||
default: 20
|
||||
- name: page
|
||||
in: query
|
||||
description: 'The page to return, starting with page 0. Test QueryParam for issue #8315 - must be removed when x-spring-paginated:true is used.'
|
||||
required: true
|
||||
type: integer
|
||||
minimum: 0
|
||||
default: 0
|
||||
- name: sort
|
||||
in: query
|
||||
description: 'The sorting to apply to the Pageable object. Test QueryParam for issue #8315 - must be removed when x-spring-paginated:true is used.'
|
||||
required: true
|
||||
type: string
|
||||
default: id,asc
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
|
||||
@@ -1012,6 +1012,40 @@ paths:
|
||||
$ref: "#/components/schemas/FreeFormObject"
|
||||
description: request body
|
||||
required: true
|
||||
/fake/implicitFreeFormObject:
|
||||
post:
|
||||
tags:
|
||||
- fake
|
||||
summary: test free form object with implicit additionalProperties
|
||||
description: ""
|
||||
operationId: testImplicitFreeFormObject
|
||||
responses:
|
||||
"200":
|
||||
description: successful operation
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/ImplicitFreeFormObject"
|
||||
description: request body
|
||||
required: true
|
||||
/fake/anyTypeObject:
|
||||
post:
|
||||
tags:
|
||||
- fake
|
||||
summary: test any type object
|
||||
description: ""
|
||||
operationId: testAnyTypeObject
|
||||
responses:
|
||||
"200":
|
||||
description: successful operation
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/AnyTypeObject"
|
||||
description: request body
|
||||
required: true
|
||||
/fake/stringMap-reference:
|
||||
post:
|
||||
tags:
|
||||
@@ -1859,6 +1893,19 @@ components:
|
||||
type: object
|
||||
description: A schema consisting only of additional properties
|
||||
additionalProperties: true
|
||||
ImplicitFreeFormObject:
|
||||
type: object
|
||||
description: A schema consisting only of additional properties (implicit)
|
||||
AnyTypeObject:
|
||||
oneOf:
|
||||
- type: string
|
||||
- type: number
|
||||
- type: integer
|
||||
- type: boolean
|
||||
- type: object
|
||||
- type: array
|
||||
items: {}
|
||||
nullable: true
|
||||
MapOfString:
|
||||
type: object
|
||||
description: A schema consisting only of additional properties of type string
|
||||
|
||||
@@ -1444,6 +1444,51 @@ paths:
|
||||
description: Range of HTTP code 400-499
|
||||
requestBody:
|
||||
$ref: '#/components/requestBodies/Pet'
|
||||
"/error":
|
||||
get:
|
||||
summary: Will always generate an error
|
||||
operationId: error
|
||||
responses: &commonErrors
|
||||
"400":
|
||||
description: The supplied request was not valid
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
"404":
|
||||
description: Requested item was not found
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
"422":
|
||||
description: The input to the operation was not valid
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
"500":
|
||||
description: Internal server error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
"/fake/pet/{pet_id}":
|
||||
delete:
|
||||
operationId: fakeDeletePet
|
||||
tags:
|
||||
- fake
|
||||
parameters:
|
||||
- name: pet_id
|
||||
in: path
|
||||
required: true
|
||||
description: The id of the pet to retrieve
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
"204":
|
||||
description: "Returns 204 No Content on success."
|
||||
<<: *commonErrors
|
||||
servers:
|
||||
- url: 'http://{server}.swagger.io:{port}/v2'
|
||||
description: petstore server
|
||||
@@ -2230,3 +2275,18 @@ components:
|
||||
type: integer
|
||||
error:
|
||||
type: string
|
||||
|
||||
Error:
|
||||
title: Error
|
||||
description: "Returned when the server encounters an error, either in client input or internally"
|
||||
properties:
|
||||
error:
|
||||
type: string
|
||||
description: "A human readable error message"
|
||||
errors:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
description: "Optional array of multiple errors encountered during processing"
|
||||
required:
|
||||
- error
|
||||
|
||||
@@ -342,6 +342,40 @@ paths:
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PetWithFile'
|
||||
'/pet/{petId}/uploadImageFullFormDataNested':
|
||||
post:
|
||||
tags:
|
||||
- pet
|
||||
summary: uploads an image attached to a Pet object as formdata
|
||||
description: ''
|
||||
operationId: uploadImageFullFormDataNested
|
||||
parameters:
|
||||
- name: petId
|
||||
in: path
|
||||
description: ID of pet to update
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ApiResponse'
|
||||
security:
|
||||
- petstore_auth:
|
||||
- 'write:pets'
|
||||
- 'read:pets'
|
||||
requestBody:
|
||||
content:
|
||||
multipart/form-data:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
pet:
|
||||
$ref: '#/components/schemas/PetWithFile'
|
||||
/store/inventory:
|
||||
get:
|
||||
tags:
|
||||
|
||||
@@ -2102,35 +2102,6 @@ components:
|
||||
enum:
|
||||
- 1.1
|
||||
- -1.2
|
||||
enum_number_vendor_ext:
|
||||
type: integer
|
||||
format: int32
|
||||
enum:
|
||||
- 42
|
||||
- 18
|
||||
- 56
|
||||
x-enum-descriptions:
|
||||
- 'Description for 42'
|
||||
- 'Description for 18'
|
||||
- 'Description for 56'
|
||||
x-enum-varnames:
|
||||
- FortyTwo
|
||||
- Eigtheen
|
||||
- FiftySix
|
||||
enum_string_vendor_ext:
|
||||
type: string
|
||||
enum:
|
||||
- FOO
|
||||
- Bar
|
||||
- baz
|
||||
x-enum-descriptions:
|
||||
- 'Description for FOO'
|
||||
- 'Description for Bar'
|
||||
- 'Description for baz'
|
||||
x-enum-varnames:
|
||||
- FOOVar
|
||||
- BarVar
|
||||
- bazVar
|
||||
enum_string_single_member:
|
||||
type: string
|
||||
enum:
|
||||
@@ -2148,6 +2119,10 @@ components:
|
||||
$ref: '#/components/schemas/OuterEnumDefaultValue'
|
||||
outerEnumIntegerDefaultValue:
|
||||
$ref: '#/components/schemas/OuterEnumIntegerDefaultValue'
|
||||
enumNumberVendorExt:
|
||||
$ref: '#/components/schemas/EnumNumberVendorExt'
|
||||
enumStringVendorExt:
|
||||
$ref: '#/components/schemas/EnumStringVendorExt'
|
||||
AdditionalPropertiesClass:
|
||||
type: object
|
||||
properties:
|
||||
@@ -2339,6 +2314,35 @@ components:
|
||||
- 1
|
||||
- 2
|
||||
example: 2
|
||||
EnumNumberVendorExt:
|
||||
type: integer
|
||||
format: int32
|
||||
enum:
|
||||
- 42
|
||||
- 18
|
||||
- 56
|
||||
x-enum-descriptions:
|
||||
- 'Description for 42'
|
||||
- 'Description for 18'
|
||||
- 'Description for 56'
|
||||
x-enum-varnames:
|
||||
- FortyTwo
|
||||
- Eigtheen
|
||||
- FiftySix
|
||||
EnumStringVendorExt:
|
||||
type: string
|
||||
enum:
|
||||
- FOO
|
||||
- Bar
|
||||
- baz
|
||||
x-enum-descriptions:
|
||||
- 'Description for FOO'
|
||||
- 'Description for Bar'
|
||||
- 'Description for baz'
|
||||
x-enum-varnames:
|
||||
- FOO_XEnumVarname
|
||||
- BarVar_XEnumVarname
|
||||
- bazVar_XEnumVarname
|
||||
OuterEnumDefaultValue:
|
||||
type: string
|
||||
enum:
|
||||
|
||||
@@ -935,6 +935,10 @@ components:
|
||||
bytes:
|
||||
type: string
|
||||
format: byte
|
||||
nullableBytes: # Regression test for bug report in #20500
|
||||
type: string
|
||||
format: byte
|
||||
nullable: true
|
||||
decimal:
|
||||
type: string
|
||||
format: number
|
||||
|
||||
@@ -171,6 +171,38 @@ paths:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
- description: "A test HeaderParam for issue #8315 - must NOT be removed when\
|
||||
\ x-spring-paginated:true is used."
|
||||
in: header
|
||||
name: size
|
||||
schema:
|
||||
type: string
|
||||
- description: "The number of items to return per page. Test QueryParam for\
|
||||
\ issue #8315 - must be removed when x-spring-paginated:true is used."
|
||||
in: query
|
||||
name: size
|
||||
required: true
|
||||
schema:
|
||||
default: 20
|
||||
minimum: 1
|
||||
type: integer
|
||||
- description: "The page to return, starting with page 0. Test QueryParam for\
|
||||
\ issue #8315 - must be removed when x-spring-paginated:true is used."
|
||||
in: query
|
||||
name: page
|
||||
required: true
|
||||
schema:
|
||||
default: 0
|
||||
minimum: 0
|
||||
type: integer
|
||||
- description: "The sorting to apply to the Pageable object. Test QueryParam\
|
||||
\ for issue #8315 - must be removed when x-spring-paginated:true is used."
|
||||
in: query
|
||||
name: sort
|
||||
required: true
|
||||
schema:
|
||||
default: "id,asc"
|
||||
type: string
|
||||
responses:
|
||||
200:
|
||||
description: successful operation
|
||||
|
||||
@@ -136,6 +136,38 @@ paths:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
- description: "A test HeaderParam for issue #8315 - must NOT be removed when\
|
||||
\ x-spring-paginated:true is used."
|
||||
in: header
|
||||
name: size
|
||||
schema:
|
||||
type: string
|
||||
- description: "The number of items to return per page. Test QueryParam for\
|
||||
\ issue #8315 - must be removed when x-spring-paginated:true is used."
|
||||
in: query
|
||||
name: size
|
||||
required: true
|
||||
schema:
|
||||
default: 20
|
||||
minimum: 1
|
||||
type: integer
|
||||
- description: "The page to return, starting with page 0. Test QueryParam for\
|
||||
\ issue #8315 - must be removed when x-spring-paginated:true is used."
|
||||
in: query
|
||||
name: page
|
||||
required: true
|
||||
schema:
|
||||
default: 0
|
||||
minimum: 0
|
||||
type: integer
|
||||
- description: "The sorting to apply to the Pageable object. Test QueryParam\
|
||||
\ for issue #8315 - must be removed when x-spring-paginated:true is used."
|
||||
in: query
|
||||
name: sort
|
||||
required: true
|
||||
schema:
|
||||
default: "id,asc"
|
||||
type: string
|
||||
responses:
|
||||
200:
|
||||
description: successful operation
|
||||
|
||||
@@ -503,7 +503,7 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
if (inputVariables.ContainsKey(variable.Key))
|
||||
{
|
||||
if (((List<string>)serverVariables["enum_values"]).Contains(inputVariables[variable.Key]))
|
||||
if (!serverVariables.ContainsKey("enum_values") || ((List<string>)serverVariables["enum_values"]).Contains(inputVariables[variable.Key]))
|
||||
{
|
||||
url = url.Replace("{" + variable.Key + "}", inputVariables[variable.Key]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
# This file is automatically generated by OpenAPI Generator (https://github.com/openAPITools/openapi-generator).
|
||||
# To include other gradle properties as part of the code generation process, please use the `gradleProperties` option.
|
||||
#
|
||||
# Gradle properties reference: https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
|
||||
# For example, uncomment below to build for Android
|
||||
#target = android
|
||||
|
||||
@@ -1006,17 +1006,8 @@ public class ApiClient {
|
||||
return (T) downloadFileFromResponse(response);
|
||||
}
|
||||
|
||||
String respBody;
|
||||
try {
|
||||
if (response.body() != null)
|
||||
respBody = response.body().string();
|
||||
else
|
||||
respBody = null;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
|
||||
if (respBody == null || "".equals(respBody)) {
|
||||
ResponseBody respBody = response.body();
|
||||
if (respBody == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1025,17 +1016,25 @@ public class ApiClient {
|
||||
// ensuring a default content type
|
||||
contentType = "application/json";
|
||||
}
|
||||
if (isJsonMime(contentType)) {
|
||||
return JSON.deserialize(respBody, returnType);
|
||||
} else if (returnType.equals(String.class)) {
|
||||
// Expecting string, return the raw response body.
|
||||
return (T) respBody;
|
||||
} else {
|
||||
throw new ApiException(
|
||||
try {
|
||||
if (isJsonMime(contentType)) {
|
||||
return JSON.deserialize(respBody.byteStream(), returnType);
|
||||
} else if (returnType.equals(String.class)) {
|
||||
String respBodyString = respBody.string();
|
||||
if (respBodyString.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// Expecting string, return the raw response body.
|
||||
return (T) respBodyString;
|
||||
} else {
|
||||
throw new ApiException(
|
||||
"Content type \"" + contentType + "\" is not supported for type: " + returnType,
|
||||
response.code(),
|
||||
response.headers().toMultimap(),
|
||||
respBody);
|
||||
response.body().string());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,11 @@ import io.gsonfire.TypeSelector;
|
||||
import okio.ByteString;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.ParsePosition;
|
||||
@@ -164,6 +167,28 @@ public class JSON {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize the given JSON InputStream to a Java object.
|
||||
*
|
||||
* @param <T> Type
|
||||
* @param inputStream The JSON InputStream
|
||||
* @param returnType The type to deserialize into
|
||||
* @return The deserialized Java object
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T deserialize(InputStream inputStream, Type returnType) throws IOException {
|
||||
try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
|
||||
if (isLenientOnJson) {
|
||||
// see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
|
||||
JsonReader jsonReader = new JsonReader(reader);
|
||||
jsonReader.setLenient(true);
|
||||
return gson.fromJson(jsonReader, returnType);
|
||||
} else {
|
||||
return gson.fromJson(reader, returnType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gson TypeAdapter for Byte Array type
|
||||
*/
|
||||
|
||||
@@ -936,17 +936,8 @@ public class ApiClient {
|
||||
return (T) downloadFileFromResponse(response);
|
||||
}
|
||||
|
||||
String respBody;
|
||||
try {
|
||||
if (response.body() != null)
|
||||
respBody = response.body().string();
|
||||
else
|
||||
respBody = null;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
|
||||
if (respBody == null || "".equals(respBody)) {
|
||||
ResponseBody respBody = response.body();
|
||||
if (respBody == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -955,17 +946,25 @@ public class ApiClient {
|
||||
// ensuring a default content type
|
||||
contentType = "application/json";
|
||||
}
|
||||
if (isJsonMime(contentType)) {
|
||||
return JSON.deserialize(respBody, returnType);
|
||||
} else if (returnType.equals(String.class)) {
|
||||
// Expecting string, return the raw response body.
|
||||
return (T) respBody;
|
||||
} else {
|
||||
throw new ApiException(
|
||||
try {
|
||||
if (isJsonMime(contentType)) {
|
||||
return JSON.deserialize(respBody.byteStream(), returnType);
|
||||
} else if (returnType.equals(String.class)) {
|
||||
String respBodyString = respBody.string();
|
||||
if (respBodyString.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// Expecting string, return the raw response body.
|
||||
return (T) respBodyString;
|
||||
} else {
|
||||
throw new ApiException(
|
||||
"Content type \"" + contentType + "\" is not supported for type: " + returnType,
|
||||
response.code(),
|
||||
response.headers().toMultimap(),
|
||||
respBody);
|
||||
response.body().string());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,11 @@ import io.gsonfire.TypeSelector;
|
||||
import okio.ByteString;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.ParsePosition;
|
||||
@@ -168,6 +171,28 @@ public class JSON {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize the given JSON InputStream to a Java object.
|
||||
*
|
||||
* @param <T> Type
|
||||
* @param inputStream The JSON InputStream
|
||||
* @param returnType The type to deserialize into
|
||||
* @return The deserialized Java object
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T deserialize(InputStream inputStream, Type returnType) throws IOException {
|
||||
try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
|
||||
if (isLenientOnJson) {
|
||||
// see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
|
||||
JsonReader jsonReader = new JsonReader(reader);
|
||||
jsonReader.setLenient(true);
|
||||
return gson.fromJson(jsonReader, returnType);
|
||||
} else {
|
||||
return gson.fromJson(reader, returnType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gson TypeAdapter for Byte Array type
|
||||
*/
|
||||
|
||||
@@ -93,6 +93,7 @@ public class Bird {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -93,6 +93,7 @@ public class Category {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -129,6 +129,7 @@ public class DataQuery extends Query {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DataQuery id(@jakarta.annotation.Nullable Long id) {
|
||||
this.setId(id);
|
||||
|
||||
@@ -406,6 +406,7 @@ public class DefaultValue {
|
||||
this.stringNullable = JsonNullable.<String>of(stringNullable);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -126,6 +126,7 @@ public class NumberPropertiesOnly {
|
||||
this._double = _double;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -271,6 +271,7 @@ public class Pet {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -141,6 +141,7 @@ public class Query {
|
||||
this.outcomes = outcomes;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -93,6 +93,7 @@ public class Tag {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -64,6 +64,7 @@ public class TestFormObjectMultipartRequestMarker {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -154,6 +154,7 @@ public class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -75,6 +75,7 @@ public class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -32,6 +32,7 @@ src/Api/PathApi.php
|
||||
src/Api/QueryApi.php
|
||||
src/ApiException.php
|
||||
src/Configuration.php
|
||||
src/FormDataProcessor.php
|
||||
src/HeaderSelector.php
|
||||
src/Model/Bird.php
|
||||
src/Model/Category.php
|
||||
|
||||
@@ -41,6 +41,7 @@ use Psr\Http\Message\ResponseInterface;
|
||||
use OpenAPI\Client\ApiException;
|
||||
use OpenAPI\Client\Configuration;
|
||||
use OpenAPI\Client\HeaderSelector;
|
||||
use OpenAPI\Client\FormDataProcessor;
|
||||
use OpenAPI\Client\ObjectSerializer;
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,6 +41,7 @@ use Psr\Http\Message\ResponseInterface;
|
||||
use OpenAPI\Client\ApiException;
|
||||
use OpenAPI\Client\Configuration;
|
||||
use OpenAPI\Client\HeaderSelector;
|
||||
use OpenAPI\Client\FormDataProcessor;
|
||||
use OpenAPI\Client\ObjectSerializer;
|
||||
|
||||
/**
|
||||
@@ -899,19 +900,14 @@ class BodyApi
|
||||
|
||||
|
||||
// form params
|
||||
if ($files !== null) {
|
||||
$multipart = true;
|
||||
$formParams['files'] = [];
|
||||
$paramFiles = is_array($files) ? $files : [$files];
|
||||
foreach ($paramFiles as $paramFile) {
|
||||
$formParams['files'][] = $paramFile instanceof \Psr\Http\Message\StreamInterface
|
||||
? $paramFile
|
||||
: \GuzzleHttp\Psr7\Utils::tryFopen(
|
||||
ObjectSerializer::toFormValue('files', $paramFile)['files'],
|
||||
'rb'
|
||||
);
|
||||
}
|
||||
}
|
||||
$formDataProcessor = new FormDataProcessor();
|
||||
|
||||
$formData = $formDataProcessor->prepare([
|
||||
'files' => $files,
|
||||
]);
|
||||
|
||||
$formParams = $formDataProcessor->flatten($formData);
|
||||
$multipart = $formDataProcessor->has_file;
|
||||
|
||||
$headers = $this->headerSelector->selectHeaders(
|
||||
['text/plain', ],
|
||||
@@ -1179,19 +1175,14 @@ class BodyApi
|
||||
|
||||
|
||||
// form params
|
||||
if ($my_file !== null) {
|
||||
$multipart = true;
|
||||
$formParams['my-file'] = [];
|
||||
$paramFiles = is_array($my_file) ? $my_file : [$my_file];
|
||||
foreach ($paramFiles as $paramFile) {
|
||||
$formParams['my-file'][] = $paramFile instanceof \Psr\Http\Message\StreamInterface
|
||||
? $paramFile
|
||||
: \GuzzleHttp\Psr7\Utils::tryFopen(
|
||||
ObjectSerializer::toFormValue('my-file', $paramFile)['my-file'],
|
||||
'rb'
|
||||
);
|
||||
}
|
||||
}
|
||||
$formDataProcessor = new FormDataProcessor();
|
||||
|
||||
$formData = $formDataProcessor->prepare([
|
||||
'my_file' => $my_file,
|
||||
]);
|
||||
|
||||
$formParams = $formDataProcessor->flatten($formData);
|
||||
$multipart = $formDataProcessor->has_file;
|
||||
|
||||
$headers = $this->headerSelector->selectHeaders(
|
||||
['text/plain', ],
|
||||
|
||||
@@ -41,6 +41,7 @@ use Psr\Http\Message\ResponseInterface;
|
||||
use OpenAPI\Client\ApiException;
|
||||
use OpenAPI\Client\Configuration;
|
||||
use OpenAPI\Client\HeaderSelector;
|
||||
use OpenAPI\Client\FormDataProcessor;
|
||||
use OpenAPI\Client\ObjectSerializer;
|
||||
|
||||
/**
|
||||
@@ -366,17 +367,16 @@ class FormApi
|
||||
|
||||
|
||||
// form params
|
||||
if ($integer_form !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('integer_form', $integer_form));
|
||||
}
|
||||
// form params
|
||||
if ($boolean_form !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('boolean_form', $boolean_form));
|
||||
}
|
||||
// form params
|
||||
if ($string_form !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('string_form', $string_form));
|
||||
}
|
||||
$formDataProcessor = new FormDataProcessor();
|
||||
|
||||
$formData = $formDataProcessor->prepare([
|
||||
'integer_form' => $integer_form,
|
||||
'boolean_form' => $boolean_form,
|
||||
'string_form' => $string_form,
|
||||
]);
|
||||
|
||||
$formParams = $formDataProcessor->flatten($formData);
|
||||
$multipart = $formDataProcessor->has_file;
|
||||
|
||||
$headers = $this->headerSelector->selectHeaders(
|
||||
['text/plain', ],
|
||||
@@ -650,9 +650,14 @@ class FormApi
|
||||
|
||||
|
||||
// form params
|
||||
if ($marker !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('marker', $marker));
|
||||
}
|
||||
$formDataProcessor = new FormDataProcessor();
|
||||
|
||||
$formData = $formDataProcessor->prepare([
|
||||
'marker' => $marker,
|
||||
]);
|
||||
|
||||
$formParams = $formDataProcessor->flatten($formData);
|
||||
$multipart = $formDataProcessor->has_file;
|
||||
|
||||
$headers = $this->headerSelector->selectHeaders(
|
||||
['text/plain', ],
|
||||
@@ -975,29 +980,19 @@ class FormApi
|
||||
|
||||
|
||||
// form params
|
||||
if ($form1 !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('form1', $form1));
|
||||
}
|
||||
// form params
|
||||
if ($form2 !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('form2', $form2));
|
||||
}
|
||||
// form params
|
||||
if ($form3 !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('form3', $form3));
|
||||
}
|
||||
// form params
|
||||
if ($form4 !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('form4', $form4));
|
||||
}
|
||||
// form params
|
||||
if ($id !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('id', $id));
|
||||
}
|
||||
// form params
|
||||
if ($name !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('name', $name));
|
||||
}
|
||||
$formDataProcessor = new FormDataProcessor();
|
||||
|
||||
$formData = $formDataProcessor->prepare([
|
||||
'form1' => $form1,
|
||||
'form2' => $form2,
|
||||
'form3' => $form3,
|
||||
'form4' => $form4,
|
||||
'id' => $id,
|
||||
'name' => $name,
|
||||
]);
|
||||
|
||||
$formParams = $formDataProcessor->flatten($formData);
|
||||
$multipart = $formDataProcessor->has_file;
|
||||
|
||||
$headers = $this->headerSelector->selectHeaders(
|
||||
['text/plain', ],
|
||||
|
||||
@@ -41,6 +41,7 @@ use Psr\Http\Message\ResponseInterface;
|
||||
use OpenAPI\Client\ApiException;
|
||||
use OpenAPI\Client\Configuration;
|
||||
use OpenAPI\Client\HeaderSelector;
|
||||
use OpenAPI\Client\FormDataProcessor;
|
||||
use OpenAPI\Client\ObjectSerializer;
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,6 +41,7 @@ use Psr\Http\Message\ResponseInterface;
|
||||
use OpenAPI\Client\ApiException;
|
||||
use OpenAPI\Client\Configuration;
|
||||
use OpenAPI\Client\HeaderSelector;
|
||||
use OpenAPI\Client\FormDataProcessor;
|
||||
use OpenAPI\Client\ObjectSerializer;
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,6 +41,7 @@ use Psr\Http\Message\ResponseInterface;
|
||||
use OpenAPI\Client\ApiException;
|
||||
use OpenAPI\Client\Configuration;
|
||||
use OpenAPI\Client\HeaderSelector;
|
||||
use OpenAPI\Client\FormDataProcessor;
|
||||
use OpenAPI\Client\ObjectSerializer;
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
/**
|
||||
* FormDataProcessor
|
||||
* PHP version 8.1
|
||||
*
|
||||
* @category Class
|
||||
* @package OpenAPI\Client
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://openapi-generator.tech
|
||||
*/
|
||||
|
||||
/**
|
||||
* Echo Server API
|
||||
*
|
||||
* Echo Server API
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0
|
||||
* Contact: team@openapitools.org
|
||||
* @generated Generated by: https://openapi-generator.tech
|
||||
* Generator version: 7.13.0-SNAPSHOT
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace OpenAPI\Client;
|
||||
|
||||
use ArrayAccess;
|
||||
use DateTime;
|
||||
use GuzzleHttp\Psr7\Utils;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use SplFileObject;
|
||||
use OpenAPI\Client\Model\ModelInterface;
|
||||
|
||||
class FormDataProcessor
|
||||
{
|
||||
/**
|
||||
* Tags whether payload passed to ::prepare() contains one or more
|
||||
* SplFileObject or stream values.
|
||||
*/
|
||||
public bool $has_file = false;
|
||||
|
||||
/**
|
||||
* Take value and turn it into an array suitable for inclusion in
|
||||
* the http body (form parameter). If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
*
|
||||
* @param array<string|bool|array|DateTime|ArrayAccess|SplFileObject> $values the value of the form parameter
|
||||
*
|
||||
* @return array [key => value] of formdata
|
||||
*/
|
||||
public function prepare(array $values): array
|
||||
{
|
||||
$this->has_file = false;
|
||||
$result = [];
|
||||
|
||||
foreach ($values as $k => $v) {
|
||||
if ($v === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[$k] = $this->makeFormSafe($v);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens a multi-level array of data and generates a single-level array
|
||||
* compatible with formdata - a single-level array where the keys use bracket
|
||||
* notation to signify nested data.
|
||||
*
|
||||
* credit: https://github.com/FranBar1966/FlatPHP
|
||||
*/
|
||||
public static function flatten(array $source, string $start = ''): array
|
||||
{
|
||||
$opt = [
|
||||
'prefix' => '[',
|
||||
'suffix' => ']',
|
||||
'suffix-end' => true,
|
||||
'prefix-list' => '[',
|
||||
'suffix-list' => ']',
|
||||
'suffix-list-end' => true,
|
||||
];
|
||||
|
||||
if ($start === '') {
|
||||
$currentPrefix = '';
|
||||
$currentSuffix = '';
|
||||
$currentSuffixEnd = false;
|
||||
} elseif (array_is_list($source)) {
|
||||
$currentPrefix = $opt['prefix-list'];
|
||||
$currentSuffix = $opt['suffix-list'];
|
||||
$currentSuffixEnd = $opt['suffix-list-end'];
|
||||
} else {
|
||||
$currentPrefix = $opt['prefix'];
|
||||
$currentSuffix = $opt['suffix'];
|
||||
$currentSuffixEnd = $opt['suffix-end'];
|
||||
}
|
||||
|
||||
$currentName = $start;
|
||||
$result = [];
|
||||
|
||||
foreach ($source as $key => $val) {
|
||||
$currentName .= $currentPrefix . $key;
|
||||
|
||||
if (is_array($val) && !empty($val)) {
|
||||
$currentName .= $currentSuffix;
|
||||
$result += self::flatten($val, $currentName);
|
||||
} else {
|
||||
if ($currentSuffixEnd) {
|
||||
$currentName .= $currentSuffix;
|
||||
}
|
||||
|
||||
$result[$currentName] = ObjectSerializer::toString($val);
|
||||
}
|
||||
|
||||
$currentName = $start;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* formdata must be limited to scalars or arrays of scalar values,
|
||||
* or a resource for a file upload. Here we iterate through all available
|
||||
* data and identify how to handle each scenario
|
||||
*
|
||||
* @param string|bool|array|DateTime|ArrayAccess|SplFileObject $value
|
||||
*/
|
||||
protected function makeFormSafe(mixed $value)
|
||||
{
|
||||
if ($value instanceof SplFileObject) {
|
||||
return $this->processFiles([$value])[0];
|
||||
}
|
||||
|
||||
if (is_resource($value)) {
|
||||
$this->has_file = true;
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ($value instanceof ModelInterface) {
|
||||
return $this->processModel($value);
|
||||
}
|
||||
|
||||
if (is_array($value) || is_object($value)) {
|
||||
$data = [];
|
||||
|
||||
foreach ($value as $k => $v) {
|
||||
$data[$k] = $this->makeFormSafe($v);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
return ObjectSerializer::toString($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* We are able to handle nested ModelInterface. We do not simply call
|
||||
* json_decode(json_encode()) because any given model may have binary data
|
||||
* or other data that cannot be serialized to a JSON string
|
||||
*/
|
||||
protected function processModel(ModelInterface $model): array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($model::openAPITypes() as $name => $type) {
|
||||
$value = $model->offsetGet($name);
|
||||
|
||||
if ($value === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str_contains($type, '\SplFileObject')) {
|
||||
$file = is_array($value) ? $value : [$value];
|
||||
$result[$name] = $this->processFiles($file);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($value instanceof ModelInterface) {
|
||||
$result[$name] = $this->processModel($value);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($value) || is_object($value)) {
|
||||
$result[$name] = $this->makeFormSafe($value);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[$name] = ObjectSerializer::toString($value);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle file data
|
||||
*/
|
||||
protected function processFiles(array $files): array
|
||||
{
|
||||
$this->has_file = true;
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach ($files as $i => $file) {
|
||||
if (is_array($file)) {
|
||||
$result[$i] = $this->processFiles($file);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($file instanceof StreamInterface) {
|
||||
$result[$i] = $file;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($file instanceof SplFileObject) {
|
||||
$result[$i] = $this->tryFopen($file);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function tryFopen(SplFileObject $file)
|
||||
{
|
||||
return Utils::tryFopen($file->getRealPath(), 'rb');
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
namespace OpenAPI\Client;
|
||||
|
||||
use ArrayAccess;
|
||||
use DateTimeInterface;
|
||||
use DateTime;
|
||||
use GuzzleHttp\Psr7\Utils;
|
||||
@@ -326,37 +325,6 @@ class ObjectSerializer
|
||||
return self::toString($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take value and turn it into an array suitable for inclusion in
|
||||
* the http body (form parameter). If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
*
|
||||
* @param string|bool|array|DateTime|ArrayAccess|\SplFileObject $value the value of the form parameter
|
||||
*
|
||||
* @return array [key => value] of formdata
|
||||
*/
|
||||
public static function toFormValue(
|
||||
string $key,
|
||||
string|bool|array|DateTime|ArrayAccess|\SplFileObject $value,
|
||||
): array {
|
||||
if ($value instanceof \SplFileObject) {
|
||||
return [$key => $value->getRealPath()];
|
||||
} elseif (is_array($value) || $value instanceof ArrayAccess) {
|
||||
$flattened = [];
|
||||
$result = [];
|
||||
|
||||
self::flattenArray(json_decode(json_encode($value), true), $flattened);
|
||||
|
||||
foreach ($flattened as $k => $v) {
|
||||
$result["{$key}{$k}"] = self::toString($v);
|
||||
}
|
||||
|
||||
return $result;
|
||||
} else {
|
||||
return [$key => self::toString($value)];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the parameter. If it's a string, pass through unchanged
|
||||
@@ -622,58 +590,4 @@ class ObjectSerializer
|
||||
|
||||
return $qs ? (string) substr($qs, 0, -1) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens an array of Model object and generates an array compatible
|
||||
* with formdata - a single-level array where the keys use bracket
|
||||
* notation to signify nested data.
|
||||
*
|
||||
* credit: https://github.com/FranBar1966/FlatPHP
|
||||
*/
|
||||
private static function flattenArray(
|
||||
ArrayAccess|array $source,
|
||||
array &$destination,
|
||||
string $start = '',
|
||||
) {
|
||||
$opt = [
|
||||
'prefix' => '[',
|
||||
'suffix' => ']',
|
||||
'suffix-end' => true,
|
||||
'prefix-list' => '[',
|
||||
'suffix-list' => ']',
|
||||
'suffix-list-end' => true,
|
||||
];
|
||||
|
||||
if (!is_array($source)) {
|
||||
$source = (array) $source;
|
||||
}
|
||||
|
||||
if (array_is_list($source)) {
|
||||
$currentPrefix = $opt['prefix-list'];
|
||||
$currentSuffix = $opt['suffix-list'];
|
||||
$currentSuffixEnd = $opt['suffix-list-end'];
|
||||
} else {
|
||||
$currentPrefix = $opt['prefix'];
|
||||
$currentSuffix = $opt['suffix'];
|
||||
$currentSuffixEnd = $opt['suffix-end'];
|
||||
}
|
||||
|
||||
$currentName = $start;
|
||||
|
||||
foreach ($source as $key => $val) {
|
||||
$currentName .= $currentPrefix.$key;
|
||||
|
||||
if (is_array($val) && !empty($val)) {
|
||||
$currentName .= "{$currentSuffix}";
|
||||
self::flattenArray($val, $destination, $currentName);
|
||||
} else {
|
||||
if ($currentSuffixEnd) {
|
||||
$currentName .= $currentSuffix;
|
||||
}
|
||||
$destination[$currentName] = self::toString($val);
|
||||
}
|
||||
|
||||
$currentName = $start;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ src/Api/PathApi.php
|
||||
src/Api/QueryApi.php
|
||||
src/ApiException.php
|
||||
src/Configuration.php
|
||||
src/FormDataProcessor.php
|
||||
src/HeaderSelector.php
|
||||
src/Model/Bird.php
|
||||
src/Model/Category.php
|
||||
|
||||
@@ -41,6 +41,7 @@ use Psr\Http\Message\ResponseInterface;
|
||||
use OpenAPI\Client\ApiException;
|
||||
use OpenAPI\Client\Configuration;
|
||||
use OpenAPI\Client\HeaderSelector;
|
||||
use OpenAPI\Client\FormDataProcessor;
|
||||
use OpenAPI\Client\ObjectSerializer;
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,6 +41,7 @@ use Psr\Http\Message\ResponseInterface;
|
||||
use OpenAPI\Client\ApiException;
|
||||
use OpenAPI\Client\Configuration;
|
||||
use OpenAPI\Client\HeaderSelector;
|
||||
use OpenAPI\Client\FormDataProcessor;
|
||||
use OpenAPI\Client\ObjectSerializer;
|
||||
|
||||
/**
|
||||
@@ -899,19 +900,14 @@ class BodyApi
|
||||
|
||||
|
||||
// form params
|
||||
if ($files !== null) {
|
||||
$multipart = true;
|
||||
$formParams['files'] = [];
|
||||
$paramFiles = is_array($files) ? $files : [$files];
|
||||
foreach ($paramFiles as $paramFile) {
|
||||
$formParams['files'][] = $paramFile instanceof \Psr\Http\Message\StreamInterface
|
||||
? $paramFile
|
||||
: \GuzzleHttp\Psr7\Utils::tryFopen(
|
||||
ObjectSerializer::toFormValue('files', $paramFile)['files'],
|
||||
'rb'
|
||||
);
|
||||
}
|
||||
}
|
||||
$formDataProcessor = new FormDataProcessor();
|
||||
|
||||
$formData = $formDataProcessor->prepare([
|
||||
'files' => $files,
|
||||
]);
|
||||
|
||||
$formParams = $formDataProcessor->flatten($formData);
|
||||
$multipart = $formDataProcessor->has_file;
|
||||
|
||||
$headers = $this->headerSelector->selectHeaders(
|
||||
['text/plain', ],
|
||||
@@ -1179,19 +1175,14 @@ class BodyApi
|
||||
|
||||
|
||||
// form params
|
||||
if ($my_file !== null) {
|
||||
$multipart = true;
|
||||
$formParams['my-file'] = [];
|
||||
$paramFiles = is_array($my_file) ? $my_file : [$my_file];
|
||||
foreach ($paramFiles as $paramFile) {
|
||||
$formParams['my-file'][] = $paramFile instanceof \Psr\Http\Message\StreamInterface
|
||||
? $paramFile
|
||||
: \GuzzleHttp\Psr7\Utils::tryFopen(
|
||||
ObjectSerializer::toFormValue('my-file', $paramFile)['my-file'],
|
||||
'rb'
|
||||
);
|
||||
}
|
||||
}
|
||||
$formDataProcessor = new FormDataProcessor();
|
||||
|
||||
$formData = $formDataProcessor->prepare([
|
||||
'my_file' => $my_file,
|
||||
]);
|
||||
|
||||
$formParams = $formDataProcessor->flatten($formData);
|
||||
$multipart = $formDataProcessor->has_file;
|
||||
|
||||
$headers = $this->headerSelector->selectHeaders(
|
||||
['text/plain', ],
|
||||
|
||||
@@ -41,6 +41,7 @@ use Psr\Http\Message\ResponseInterface;
|
||||
use OpenAPI\Client\ApiException;
|
||||
use OpenAPI\Client\Configuration;
|
||||
use OpenAPI\Client\HeaderSelector;
|
||||
use OpenAPI\Client\FormDataProcessor;
|
||||
use OpenAPI\Client\ObjectSerializer;
|
||||
|
||||
/**
|
||||
@@ -366,17 +367,16 @@ class FormApi
|
||||
|
||||
|
||||
// form params
|
||||
if ($integer_form !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('integer_form', $integer_form));
|
||||
}
|
||||
// form params
|
||||
if ($boolean_form !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('boolean_form', $boolean_form));
|
||||
}
|
||||
// form params
|
||||
if ($string_form !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('string_form', $string_form));
|
||||
}
|
||||
$formDataProcessor = new FormDataProcessor();
|
||||
|
||||
$formData = $formDataProcessor->prepare([
|
||||
'integer_form' => $integer_form,
|
||||
'boolean_form' => $boolean_form,
|
||||
'string_form' => $string_form,
|
||||
]);
|
||||
|
||||
$formParams = $formDataProcessor->flatten($formData);
|
||||
$multipart = $formDataProcessor->has_file;
|
||||
|
||||
$headers = $this->headerSelector->selectHeaders(
|
||||
['text/plain', ],
|
||||
@@ -650,9 +650,14 @@ class FormApi
|
||||
|
||||
|
||||
// form params
|
||||
if ($marker !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('marker', $marker));
|
||||
}
|
||||
$formDataProcessor = new FormDataProcessor();
|
||||
|
||||
$formData = $formDataProcessor->prepare([
|
||||
'marker' => $marker,
|
||||
]);
|
||||
|
||||
$formParams = $formDataProcessor->flatten($formData);
|
||||
$multipart = $formDataProcessor->has_file;
|
||||
|
||||
$headers = $this->headerSelector->selectHeaders(
|
||||
['text/plain', ],
|
||||
@@ -975,29 +980,19 @@ class FormApi
|
||||
|
||||
|
||||
// form params
|
||||
if ($form1 !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('form1', $form1));
|
||||
}
|
||||
// form params
|
||||
if ($form2 !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('form2', $form2));
|
||||
}
|
||||
// form params
|
||||
if ($form3 !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('form3', $form3));
|
||||
}
|
||||
// form params
|
||||
if ($form4 !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('form4', $form4));
|
||||
}
|
||||
// form params
|
||||
if ($id !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('id', $id));
|
||||
}
|
||||
// form params
|
||||
if ($name !== null) {
|
||||
$formParams = array_merge($formParams, ObjectSerializer::toFormValue('name', $name));
|
||||
}
|
||||
$formDataProcessor = new FormDataProcessor();
|
||||
|
||||
$formData = $formDataProcessor->prepare([
|
||||
'form1' => $form1,
|
||||
'form2' => $form2,
|
||||
'form3' => $form3,
|
||||
'form4' => $form4,
|
||||
'id' => $id,
|
||||
'name' => $name,
|
||||
]);
|
||||
|
||||
$formParams = $formDataProcessor->flatten($formData);
|
||||
$multipart = $formDataProcessor->has_file;
|
||||
|
||||
$headers = $this->headerSelector->selectHeaders(
|
||||
['text/plain', ],
|
||||
|
||||
@@ -41,6 +41,7 @@ use Psr\Http\Message\ResponseInterface;
|
||||
use OpenAPI\Client\ApiException;
|
||||
use OpenAPI\Client\Configuration;
|
||||
use OpenAPI\Client\HeaderSelector;
|
||||
use OpenAPI\Client\FormDataProcessor;
|
||||
use OpenAPI\Client\ObjectSerializer;
|
||||
|
||||
/**
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user