mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-06 10:35:25 +00:00
Fixes for php-ze-ph generator (#340)
* Fixes for ze-ph: - fixed gathering of required properties for query data model - fixed setting of internal vendor extensions for query data model detection - fixed small typo in generated README * Updated samples for ze-ph fixes
This commit is contained in:
parent
e45b3784f1
commit
d30fcbabba
@ -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)
|
||||
|
@ -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%
|
||||
|
@ -174,24 +174,30 @@ public class PhpZendExpressivePathHandlerServerCodegen extends AbstractPhpCodege
|
||||
continue;
|
||||
}
|
||||
|
||||
List<String> 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 @@ public class PhpZendExpressivePathHandlerServerCodegen extends AbstractPhpCodege
|
||||
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 @@ public class PhpZendExpressivePathHandlerServerCodegen extends AbstractPhpCodege
|
||||
if (property != null) {
|
||||
property.setName(queryParameter.getName());
|
||||
property.setDescription(queryParameter.getDescription());
|
||||
if (Boolean.TRUE.equals(queryParameter.getRequired())) {
|
||||
List<String> required = new ArrayList<String>();
|
||||
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) {
|
||||
|
@ -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:
|
||||
|
@ -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).
|
||||
|
Loading…
Reference in New Issue
Block a user