diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java index 35a411d708ae..81068295053d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java @@ -69,6 +69,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg protected String interfaceNamePrefix = "", interfaceNameSuffix = "Interface"; protected String abstractNamePrefix = "Abstract", abstractNameSuffix = ""; protected String traitNamePrefix = "", traitNameSuffix = "Trait"; + protected boolean declareStrictTypes = false; private Map schemaKeyToModelNameCache = new HashMap<>(); @@ -285,6 +286,11 @@ public void processOpts() { // all PHP codegens requires Composer, it means that we need to exclude from SVN at least vendor folder supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore")); + // Add declareStrictTypes property to the additionalProperties + if (additionalProperties.containsKey("declareStrictTypes")) { + this.declareStrictTypes = Boolean.parseBoolean(additionalProperties.get("declareStrictTypes").toString()); + } + additionalProperties.put("declareStrictTypes", declareStrictTypes); } public String toSrcPath(final String packageName, final String basePath) { @@ -567,6 +573,14 @@ public String toInterfaceName(final String name) { public String toAbstractName(final String name) { return camelize(abstractNamePrefix + name + abstractNameSuffix); } + +@Override +public String getHelp() { + return "Generates a PHP client library." + "\n" + + "Options:\n" + + " - declareStrictTypes: boolean, set to true to add declare(strict_types=1); in generated PHP files."; +} + /** * Output the proper trait name (capitalized). diff --git a/modules/openapi-generator/src/main/resources/php/ApiException.mustache b/modules/openapi-generator/src/main/resources/php/ApiException.mustache index 285839e2ded7..46c78766fdf1 100644 --- a/modules/openapi-generator/src/main/resources/php/ApiException.mustache +++ b/modules/openapi-generator/src/main/resources/php/ApiException.mustache @@ -1,4 +1,6 @@