Skip to content

Commit

Permalink
fix NPE in body parameter due to incorrect parameter/consume (OpenAPI…
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Jul 14, 2018
1 parent 35924e8 commit cd3c392
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ public void setParameterExampleValue(CodegenParameter codegenParameter) {
* Return the example value of the parameter.
*
* @param codegenParameter Codegen parameter
* @param parameter Parameter
* @param parameter Parameter
*/
public void setParameterExampleValue(CodegenParameter codegenParameter, Parameter parameter) {
if (parameter.getExample() != null) {
Expand All @@ -1120,7 +1120,7 @@ public void setParameterExampleValue(CodegenParameter codegenParameter, Paramete

if (parameter.getExamples() != null && !parameter.getExamples().isEmpty()) {
Example example = parameter.getExamples().values().iterator().next();
if(example.getValue() != null) {
if (example.getValue() != null) {
codegenParameter.example = example.getValue().toString();
return;
}
Expand All @@ -1139,7 +1139,7 @@ public void setParameterExampleValue(CodegenParameter codegenParameter, Paramete
* Return the example value of the parameter.
*
* @param codegenParameter Codegen parameter
* @param requestBody Request body
* @param requestBody Request body
*/
public void setParameterExampleValue(CodegenParameter codegenParameter, RequestBody requestBody) {
Content content = requestBody.getContent();
Expand All @@ -1157,7 +1157,7 @@ public void setParameterExampleValue(CodegenParameter codegenParameter, RequestB

if (mediaType.getExamples() != null && !mediaType.getExamples().isEmpty()) {
Example example = mediaType.getExamples().values().iterator().next();
if(example.getValue() != null) {
if (example.getValue() != null) {
codegenParameter.example = example.getValue().toString();
return;
}
Expand Down Expand Up @@ -1614,7 +1614,7 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al
m.isInteger = Boolean.TRUE;
}
}
if (ModelUtils.isStringSchema(schema)){
if (ModelUtils.isStringSchema(schema)) {
m.isString = Boolean.TRUE;
}

Expand Down Expand Up @@ -4373,15 +4373,32 @@ public CodegenParameter fromRequestBody(RequestBody body, Map<String, Schema> sc
if (schema.getAdditionalProperties() != null) {// http body is map
LOGGER.error("Map should be supported. Please report to openapi-generator github repo about the issue.");
} else if (codegenProperty != null) {
String codegenModelName, codegenModelDescription;

if (codegenModel != null) {
codegenModelName = codegenModel.classname;
codegenModelDescription = codegenModel.description;
} else {
LOGGER.warn("The following schema has undefined (null) baseType. " +
"It could be due to form parameter defined in OpenAPI v2 spec with incorrect consumes. " +
"A correct 'consumes' for form parameters should be " +
"'application/x-www-form-urlencoded' or 'multipart/form-data'");
LOGGER.warn("schema: " + schema);
LOGGER.warn("codegenModel is null. Default to UNKNOWN_BASE_TYPE");
codegenModelName = "UNKNOWN_BASE_TYPE";
codegenModelDescription = "UNKNOWN_DESCRIPTION";
}

if (StringUtils.isEmpty(bodyParameterName)) {
codegenParameter.baseName = codegenModel.classname;
codegenParameter.baseName = codegenModelName;
} else {
codegenParameter.baseName = bodyParameterName;
}

codegenParameter.paramName = toParamName(codegenParameter.baseName);
codegenParameter.baseType = codegenModel.classname;
codegenParameter.dataType = getTypeDeclaration(codegenModel.classname);
codegenParameter.description = codegenModel.description;
codegenParameter.baseType = codegenModelName;
codegenParameter.dataType = getTypeDeclaration(codegenModelName);
codegenParameter.description = codegenModelDescription;
imports.add(codegenParameter.baseType);

if (codegenProperty.complexType != null) {
Expand Down Expand Up @@ -4465,6 +4482,6 @@ public void generateYAMLSpecFile(Map<String, Object> objs) {
}

public boolean isDataTypeString(String dataType) {
return "String".equals(dataType);
return "String".equals(dataType);
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.0-SNAPSHOT
3.1.1-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ $apiInstance = new OpenAPI\Client\Api\FakeApi(
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client()
);
$unknown_base_type = new \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE(); // object |
$unknown_base_type = new \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE(); // \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE |

try {
$apiInstance->testCodeInjectEndRnNR($unknown_base_type);
Expand All @@ -74,7 +74,7 @@ try {

## Documentation for API Endpoints

All URIs are relative to *petstore.swagger.io *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r/v2 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r*
All URIs are relative to *http://petstore.swagger.io *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r/v2 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OpenAPI\Client\FakeApi

All URIs are relative to *petstore.swagger.io *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r/v2 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r*
All URIs are relative to *http://petstore.swagger.io *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r/v2 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r*

Method | HTTP request | Description
------------- | ------------- | -------------
Expand All @@ -22,7 +22,7 @@ $apiInstance = new OpenAPI\Client\Api\FakeApi(
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client()
);
$unknown_base_type = new \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE(); // object |
$unknown_base_type = new \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE(); // \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE |

try {
$apiInstance->testCodeInjectEndRnNR($unknown_base_type);
Expand All @@ -36,7 +36,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**unknown_base_type** | [**object**](../Model/UNKNOWN_BASE_TYPE.md)| | [optional]
**unknown_base_type** | [**\OpenAPI\Client\Model\UNKNOWN_BASE_TYPE**](../Model/UNKNOWN_BASE_TYPE.md)| | [optional]

### Return type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.0-SNAPSHOT
* OpenAPI Generator version: 3.1.1-SNAPSHOT
*/

/**
Expand Down Expand Up @@ -92,7 +92,7 @@ public function getConfig()
*
* To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
*
* @param object $unknown_base_type unknown_base_type (optional)
* @param \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE $unknown_base_type unknown_base_type (optional)
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
Expand All @@ -108,7 +108,7 @@ public function testCodeInjectEndRnNR($unknown_base_type = null)
*
* To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
*
* @param object $unknown_base_type (optional)
* @param \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE $unknown_base_type (optional)
*
* @throws \OpenAPI\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
Expand Down Expand Up @@ -160,7 +160,7 @@ public function testCodeInjectEndRnNRWithHttpInfo($unknown_base_type = null)
*
* To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
*
* @param object $unknown_base_type (optional)
* @param \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE $unknown_base_type (optional)
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
Expand All @@ -180,7 +180,7 @@ function ($response) {
*
* To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
*
* @param object $unknown_base_type (optional)
* @param \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE $unknown_base_type (optional)
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
Expand Down Expand Up @@ -216,7 +216,7 @@ function ($exception) {
/**
* Create request for operation 'testCodeInjectEndRnNR'
*
* @param object $unknown_base_type (optional)
* @param \OpenAPI\Client\Model\UNKNOWN_BASE_TYPE $unknown_base_type (optional)
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.0-SNAPSHOT
* OpenAPI Generator version: 3.1.1-SNAPSHOT
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.0-SNAPSHOT
* OpenAPI Generator version: 3.1.1-SNAPSHOT
*/

/**
Expand Down Expand Up @@ -81,7 +81,7 @@ class Configuration
*
* @var string
*/
protected $host = 'petstore.swagger.io *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r/v2 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r';
protected $host = 'http://petstore.swagger.io *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r/v2 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r';

/**
* User agent of the HTTP request, set to "OpenAPI-Generator/{version}/PHP" by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.0-SNAPSHOT
* OpenAPI Generator version: 3.1.1-SNAPSHOT
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.0-SNAPSHOT
* OpenAPI Generator version: 3.1.1-SNAPSHOT
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.0-SNAPSHOT
* OpenAPI Generator version: 3.1.1-SNAPSHOT
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.0-SNAPSHOT
* OpenAPI Generator version: 3.1.1-SNAPSHOT
*/

/**
Expand Down

0 comments on commit cd3c392

Please sign in to comment.