Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary,
isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isPassword, isFreeFormObject, isAnyType, isShort, isUnboundedInteger;
public boolean isArray, isMap;
/**
* If a query parameter should be serialized as json
*/
public boolean queryIsJsonMimeType;
/**
* datatype is the generic inner parameter of a std::optional for C++, or Optional (Java)
*/
Expand Down Expand Up @@ -265,6 +269,7 @@ public CodegenParameter copy() {
output.isAnyType = this.isAnyType;
output.isArray = this.isArray;
output.isMap = this.isMap;
output.queryIsJsonMimeType = this.queryIsJsonMimeType;
output.isOptional = this.isOptional;
output.isExplode = this.isExplode;
output.style = this.style;
Expand All @@ -289,7 +294,7 @@ public int hashCode() {
isFormStyle, isSpaceDelimited, isPipeDelimited,
jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal,
isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isPassword,
isFreeFormObject, isAnyType, isArray, isMap, isOptional, isFile, isEnum, isEnumRef, _enum, allowableValues,
isFreeFormObject, isAnyType, isArray, isMap, queryIsJsonMimeType, isOptional, isFile, isEnum, isEnumRef, _enum, allowableValues,
items, mostInnerItems, additionalProperties, vars, requiredVars, vendorExtensions, hasValidation,
getMaxProperties(), getMinProperties(), isNullable, isDeprecated, required, getMaximum(),
getExclusiveMaximum(), getMinimum(), getExclusiveMinimum(), getMaxLength(), getMinLength(),
Expand Down Expand Up @@ -339,6 +344,7 @@ public boolean equals(Object o) {
isAnyType == that.isAnyType &&
isArray == that.isArray &&
isMap == that.isMap &&
queryIsJsonMimeType == that.queryIsJsonMimeType &&
isOptional == that.isOptional &&
isFile == that.isFile &&
isEnum == that.isEnum &&
Expand Down Expand Up @@ -479,6 +485,7 @@ public String toString() {
sb.append(", isAnyType=").append(isAnyType);
sb.append(", isArray=").append(isArray);
sb.append(", isMap=").append(isMap);
sb.append(", queryIsJsonMimeType=").append(queryIsJsonMimeType);
sb.append(", isOptional=").append(isOptional);
sb.append(", isFile=").append(isFile);
sb.append(", isEnum=").append(isEnum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5359,6 +5359,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
if (parameter instanceof QueryParameter || "query".equalsIgnoreCase(parameter.getIn())) {
codegenParameter.isQueryParam = true;
codegenParameter.isAllowEmptyValue = parameter.getAllowEmptyValue() != null && parameter.getAllowEmptyValue();
codegenParameter.queryIsJsonMimeType = isJsonMimeType(codegenParameter.contentType);
} else if (parameter instanceof PathParameter || "path".equalsIgnoreCase(parameter.getIn())) {
codegenParameter.required = true;
codegenParameter.isPathParam = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5006,4 +5006,15 @@ public void testSingleRequestParameter_hasSingleParamTrue() {
// When & Then
assertThat(codegenOperation.getHasSingleParam()).isTrue();
}

@Test
public void testQueryIsJsonMimeType() {
DefaultCodegen codegen = new DefaultCodegen();
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/echo_api.yaml");
codegen.setOpenAPI(openAPI);
String path = "/query/style_jsonSerialization/object";
CodegenOperation codegenOperation = codegen.fromOperation(path, "GET", openAPI.getPaths().get(path).getGet(), null);

assertTrue(codegenOperation.queryParams.stream().allMatch(p -> p.queryIsJsonMimeType));
}
}
29 changes: 29 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/echo_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,35 @@ paths:
text/plain:
schema:
type: string
/query/style_jsonSerialization/object:
get:
tags:
- query
summary: Test query parameter(s)
description: Test query parameter(s)
operationId: test/query/style_jsonSerialization/object
parameters:
- in: query
name: json_serialized_object_ref_string_query
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
- in: query
name: json_serialized_object_array_ref_string_query
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
responses:
'200':
description: Successful operation
content:
text/plain:
schema:
type: string
# body parameter tests
/body/application/octetstream/binary:
post:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Class | Method | HTTP request | Description
*QueryApi* | [**TestQueryStyleFormExplodeTrueArrayString**](docs/QueryApi.md#testquerystyleformexplodetruearraystring) | **GET** /query/style_form/explode_true/array_string | Test query parameter(s)
*QueryApi* | [**TestQueryStyleFormExplodeTrueObject**](docs/QueryApi.md#testquerystyleformexplodetrueobject) | **GET** /query/style_form/explode_true/object | Test query parameter(s)
*QueryApi* | [**TestQueryStyleFormExplodeTrueObjectAllOf**](docs/QueryApi.md#testquerystyleformexplodetrueobjectallof) | **GET** /query/style_form/explode_true/object/allOf | Test query parameter(s)
*QueryApi* | [**TestQueryStyleJsonSerializationObject**](docs/QueryApi.md#testquerystylejsonserializationobject) | **GET** /query/style_jsonSerialization/object | Test query parameter(s)


<a id="documentation-for-models"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,37 @@ paths:
summary: Test query parameter(s)
tags:
- query
/query/style_jsonSerialization/object:
get:
description: Test query parameter(s)
operationId: test/query/style_jsonSerialization/object
parameters:
- content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
in: query
name: json_serialized_object_ref_string_query
required: false
- content:
application/json:
schema:
items:
$ref: "#/components/schemas/Pet"
type: array
in: query
name: json_serialized_object_array_ref_string_query
required: false
responses:
"200":
content:
text/plain:
schema:
type: string
description: Successful operation
summary: Test query parameter(s)
tags:
- query
/body/application/octetstream/binary:
post:
description: Test body parameter(s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ All URIs are relative to *http://localhost:3000*
| [**TestQueryStyleFormExplodeTrueArrayString**](QueryApi.md#testquerystyleformexplodetruearraystring) | **GET** /query/style_form/explode_true/array_string | Test query parameter(s) |
| [**TestQueryStyleFormExplodeTrueObject**](QueryApi.md#testquerystyleformexplodetrueobject) | **GET** /query/style_form/explode_true/object | Test query parameter(s) |
| [**TestQueryStyleFormExplodeTrueObjectAllOf**](QueryApi.md#testquerystyleformexplodetrueobjectallof) | **GET** /query/style_form/explode_true/object/allOf | Test query parameter(s) |
| [**TestQueryStyleJsonSerializationObject**](QueryApi.md#testquerystylejsonserializationobject) | **GET** /query/style_jsonSerialization/object | Test query parameter(s) |

<a id="testenumrefstring"></a>
# **TestEnumRefString**
Expand Down Expand Up @@ -935,3 +936,96 @@ No authorization required

[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

<a id="testquerystylejsonserializationobject"></a>
# **TestQueryStyleJsonSerializationObject**
> string TestQueryStyleJsonSerializationObject (Pet? jsonSerializedObjectRefStringQuery = null, List<Pet>? jsonSerializedObjectArrayRefStringQuery = null)

Test query parameter(s)

Test query parameter(s)

### Example
```csharp
using System.Collections.Generic;
using System.Diagnostics;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;

namespace Example
{
public class TestQueryStyleJsonSerializationObjectExample
{
public static void Main()
{
Configuration config = new Configuration();
config.BasePath = "http://localhost:3000";
var apiInstance = new QueryApi(config);
var jsonSerializedObjectRefStringQuery = new Pet?(); // Pet? | (optional)
var jsonSerializedObjectArrayRefStringQuery = new List<Pet>?(); // List<Pet>? | (optional)

try
{
// Test query parameter(s)
string result = apiInstance.TestQueryStyleJsonSerializationObject(jsonSerializedObjectRefStringQuery, jsonSerializedObjectArrayRefStringQuery);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling QueryApi.TestQueryStyleJsonSerializationObject: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
}
```

#### Using the TestQueryStyleJsonSerializationObjectWithHttpInfo variant
This returns an ApiResponse object which contains the response data, status code and headers.

```csharp
try
{
// Test query parameter(s)
ApiResponse<string> response = apiInstance.TestQueryStyleJsonSerializationObjectWithHttpInfo(jsonSerializedObjectRefStringQuery, jsonSerializedObjectArrayRefStringQuery);
Debug.Write("Status Code: " + response.StatusCode);
Debug.Write("Response Headers: " + response.Headers);
Debug.Write("Response Body: " + response.Data);
}
catch (ApiException e)
{
Debug.Print("Exception when calling QueryApi.TestQueryStyleJsonSerializationObjectWithHttpInfo: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
```

### Parameters

| Name | Type | Description | Notes |
|------|------|-------------|-------|
| **jsonSerializedObjectRefStringQuery** | [**Pet?**](Pet?.md) | | [optional] |
| **jsonSerializedObjectArrayRefStringQuery** | [**List&lt;Pet&gt;?**](Pet.md) | | [optional] |

### Return type

**string**

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: text/plain


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Successful operation | - |

[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

Loading
Loading