diff --git a/README.md b/README.md index 40e3c296bb9d..4af1dbb26a15 100644 --- a/README.md +++ b/README.md @@ -500,6 +500,7 @@ OpenAPI Generator is a fork of [Swagger Codegen](https://github.com/swagger-api/ - [Akihito Nakano](https://github.com/ackintosh) - [Artem Ocheredko](https://github.com/galaxie) +- [Arthur Mogliev](https://github.com/Articus) - [Bartek Kryza](https://github.com/bkryza) - [Ben Wells](https://github.com/bvwells) - [Benjamin Gill](https://github.com/bjgill) diff --git a/bin/windows/ze-ph-petstore.bat b/bin/windows/ze-ph-petstore.bat index e9303185464a..7fe3854d65b4 100644 --- a/bin/windows/ze-ph-petstore.bat +++ b/bin/windows/ze-ph-petstore.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -l ze-ph -o samples\server\petstore\ze-ph +set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -l php-ze-ph -o samples\server\petstore\ze-ph java %JAVA_OPTS% -jar %executable% %ags% diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpZendExpressivePathHandlerServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpZendExpressivePathHandlerServerCodegen.java index c094ffaa8d0a..7ac4c894a2b3 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpZendExpressivePathHandlerServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpZendExpressivePathHandlerServerCodegen.java @@ -174,24 +174,30 @@ public void preprocessOpenAPI(OpenAPI openAPI) { continue; } + List requiredProperties = new ArrayList<>(); for (Parameter parameter : operation.getParameters()) { Schema schema = convertParameterToSchema(parameter); if (schema != null) { schemas.put(schema.getName(), schema); + if (Boolean.TRUE.equals(parameter.getRequired())) { + requiredProperties.add(schema.getName()); + } } } if (!schemas.isEmpty()) { - Schema model = new Schema(); + ObjectSchema model = new ObjectSchema(); String operationId = getOrGenerateOperationId(operation, pathname, method.name()); model.setDescription("Query parameters for " + operationId); model.setProperties(schemas); - model.addExtension(VEN_FROM_QUERY, Boolean.TRUE); + model.setRequired(requiredProperties); + //Add internal extension directly, because addExtension filters extension names + addInternalExtensionToSchema(model, VEN_FROM_QUERY, Boolean.TRUE); String definitionName = generateUniqueDefinitionName(operationId + "QueryData", openAPI); openAPI.getComponents().addSchemas(definitionName, model); String definitionModel = "\\" + modelPackage + "\\" + toModelName(definitionName); - operation.addExtension(VEN_QUERY_DATA_TYPE, definitionModel); - operation.addExtension(VEN_HAS_QUERY_DATA, Boolean.TRUE); + addInternalExtensionToOperation(operation, VEN_QUERY_DATA_TYPE, definitionModel); + addInternalExtensionToOperation(operation, VEN_HAS_QUERY_DATA, Boolean.TRUE); } } } @@ -214,7 +220,7 @@ protected Schema convertParameterToSchema(Parameter parameter) { if (collectionFormat == null) { collectionFormat = "csv"; } - arraySchema.addExtension(VEN_COLLECTION_FORMAT, collectionFormat); + addInternalExtensionToSchema(arraySchema, VEN_COLLECTION_FORMAT, collectionFormat); property = arraySchema; } else { // non-array e.g. string, integer switch (queryParameter.getSchema().getType()) { @@ -252,17 +258,28 @@ protected Schema convertParameterToSchema(Parameter parameter) { if (property != null) { property.setName(queryParameter.getName()); property.setDescription(queryParameter.getDescription()); - if (Boolean.TRUE.equals(queryParameter.getRequired())) { - List required = new ArrayList(); - required.add(queryParameter.getName()); - } - - property.addExtension(VEN_FROM_QUERY, Boolean.TRUE); + addInternalExtensionToSchema(property, VEN_FROM_QUERY, Boolean.TRUE); } } return property; } + protected void addInternalExtensionToSchema(Schema schema, String name, Object value) { + //Add internal extension directly, because addExtension filters extension names + if (schema.getExtensions() == null) { + schema.setExtensions(new HashMap<>()); + } + schema.getExtensions().put(name, value); + } + + protected void addInternalExtensionToOperation(Operation operation, String name, Object value) { + //Add internal extension directly, because addExtension filters extension names + if (operation.getExtensions() == null) { + operation.setExtensions(new HashMap<>()); + } + operation.getExtensions().put(name, value); + } + protected String generateUniqueDefinitionName(String name, OpenAPI openAPI) { String result = name; if (openAPI.getComponents().getSchemas() != null) { diff --git a/modules/openapi-generator/src/main/resources/ze-ph/README.md.mustache b/modules/openapi-generator/src/main/resources/ze-ph/README.md.mustache index 225642603e92..48a355ac7d2a 100644 --- a/modules/openapi-generator/src/main/resources/ze-ph/README.md.mustache +++ b/modules/openapi-generator/src/main/resources/ze-ph/README.md.mustache @@ -13,7 +13,7 @@ This server stub aims to provide light, yet comprehensive structure for your API All you have to do to start development is: - install dependencies via [Composer](https://getcomposer.org/) -- create cache folder: `mkdir -p ./data/cache/ZendCache` (you will need it later for configuration and metadata caches - check comments in `./application/conig.yml`) +- create cache folder: `mkdir -p ./data/cache/ZendCache` (you will need it later for configuration and metadata caches - check comments in `./application/config.yml`) - start PHP development server: `php -S 0.0.0.0:8080 -t ./public` (or any other SAPI you prefer, just make sure that you configure webroot to `./public` and rewrites to `./public/index.php`) After that you should be able to call all methods from your API spec. Most of the negative scenarios should be handled: diff --git a/samples/server/petstore/ze-ph/README.md b/samples/server/petstore/ze-ph/README.md index 90660da8e6ef..48a355ac7d2a 100644 --- a/samples/server/petstore/ze-ph/README.md +++ b/samples/server/petstore/ze-ph/README.md @@ -1,6 +1,6 @@ -# Swagger generated server +# OpenAPI generated server -Generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. +Generated by the [OpenAPI Generator](https://openapi-generator.tech) project. ## Overview This server stub aims to provide light, yet comprehensive structure for your API project using: @@ -13,7 +13,7 @@ This server stub aims to provide light, yet comprehensive structure for your API All you have to do to start development is: - install dependencies via [Composer](https://getcomposer.org/) -- create cache folder: `mkdir -p ./data/cache/ZendCache` (you will need it later for configuration and metadata caches - check comments in `./application/conig.yml`) +- create cache folder: `mkdir -p ./data/cache/ZendCache` (you will need it later for configuration and metadata caches - check comments in `./application/config.yml`) - start PHP development server: `php -S 0.0.0.0:8080 -t ./public` (or any other SAPI you prefer, just make sure that you configure webroot to `./public` and rewrites to `./public/index.php`) After that you should be able to call all methods from your API spec. Most of the negative scenarios should be handled: @@ -31,4 +31,4 @@ But for obvious reason you will not get any `200 OK`, only `500 Not implemented` - implement your handlers - the most tricky part :) ## Enjoy! -Hopefully this stub will reduce the amount of boilerplate code you have to write manually. If you have any suggestions or questions about `ze-ph` generator, feel free to create issue either in [Path Handler repository](https://github.com/Articus/PathHandler/issues) or in [Swagger Codegen repository](https://github.com/swagger-api/swagger-codegen/issues). +Hopefully this stub will reduce the amount of boilerplate code you have to write manually. If you have any suggestions or questions about `ze-ph` generator, feel free to create issue either in [Path Handler repository](https://github.com/Articus/PathHandler/issues) or in [OpenAPI Generator repository](https://openapi-generator.tech/issues).