Skip to content
Open
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
8 changes: 8 additions & 0 deletions bin/configs/rust-reqwest-nullable-enum-query-params.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
generatorName: rust
outputDir: samples/client/others/rust/reqwest/nullable-enum-query-params
library: reqwest
inputSpec: modules/openapi-generator/src/test/resources/3_1/rust/nullable-enum-query-params.yaml
templateDir: modules/openapi-generator/src/main/resources/rust
additionalProperties:
supportAsync: true
packageName: nullable-enum-query-params-reqwest
Original file line number Diff line number Diff line change
Expand Up @@ -774,19 +774,18 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
boolean useAsyncFileStream = false;
List<CodegenOperation> operations = objectMap.getOperation();
for (CodegenOperation operation : operations) {
if (operation.pathParams != null && operation.pathParams.size() > 0) {

// For types with `isAnyType` we assume it's a `serde_json::Value` type.
// However for path, query, and headers it's unlikely to be JSON so we default to `String`.
// Note that we keep the default `serde_json::Value` for body parameters.
for (var param : operation.allParams) {
if (param.isAnyType && (param.isPathParam || param.isQueryParam || param.isHeaderParam)) {
param.dataType = "String";
param.isPrimitiveType = true;
param.isString = true;
}
// For types with `isAnyType` we assume it's a `serde_json::Value` type.
// However for path, query, and headers it's unlikely to be JSON so we default to `String`.
// Note that we keep the default `serde_json::Value` for body parameters.
for (var param : operation.allParams) {
if (param.isAnyType && (param.isPathParam || param.isQueryParam || param.isHeaderParam)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: JSON-content query parameters with an unconstrained schema now become Option<&str> rather than Option<serde_json::Value> when the operation has no path params. Preserve serde_json::Value for queryIsJsonMimeType parameters so callers can still supply and serialize arbitrary JSON values.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java, line 781:

<comment>JSON-content query parameters with an unconstrained schema now become `Option<&str>` rather than `Option<serde_json::Value>` when the operation has no path params. Preserve `serde_json::Value` for `queryIsJsonMimeType` parameters so callers can still supply and serialize arbitrary JSON values.</comment>

<file context>
@@ -774,19 +774,18 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
+            // However for path, query, and headers it's unlikely to be JSON so we default to `String`.
+            // Note that we keep the default `serde_json::Value` for body parameters.
+            for (var param : operation.allParams) {
+                if (param.isAnyType && (param.isPathParam || param.isQueryParam || param.isHeaderParam)) {
+                    param.dataType = "String";
+                    param.isPrimitiveType = true;
</file context>
Suggested change
if (param.isAnyType && (param.isPathParam || param.isQueryParam || param.isHeaderParam)) {
if (param.isAnyType && !param.queryIsJsonMimeType && (param.isPathParam || param.isQueryParam || param.isHeaderParam)) {

param.dataType = "String";
param.isPrimitiveType = true;
param.isString = true;
}
}

if (operation.pathParams != null && operation.pathParams.size() > 0) {
for (var pathParam : operation.pathParams) {
if (!pathParam.baseName.contains("-")) {
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
openapi: 3.1.0
info:
title: Nullable Enum Query Parameter Test
description: >-
Test spec for enum query parameters whose schema is not a bare $ref, as
emitted by FastAPI and other 3.1 producers. The same operation is defined
with and without a path parameter, because the two used to be generated
differently.
version: 1.0.0
paths:
/widgets/summary:
get:
operationId: getWidgetSummary
summary: Get a widget summary
parameters:
- name: kind
in: query
description: Kind filter, expressed as an anyOf with null
required: false
schema:
anyOf:
- $ref: '#/components/schemas/WidgetKind'
- type: 'null'
title: Kind
- name: sort
in: query
description: Sort order, expressed as a $ref with sibling keywords
required: false
schema:
$ref: '#/components/schemas/SortDirection'
title: Sort
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/WidgetSummary'
/widgets/{widget_id}/summary:
get:
operationId: getWidgetSummaryById
summary: Get a widget summary for a single widget
parameters:
- name: widget_id
in: path
required: true
schema:
type: string
- name: kind
in: query
description: Kind filter, expressed as an anyOf with null
required: false
schema:
anyOf:
- $ref: '#/components/schemas/WidgetKind'
- type: 'null'
title: Kind
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/WidgetSummary'
components:
schemas:
WidgetKind:
type: string
description: Widget kind
enum:
- basic
- premium
SortDirection:
type: string
description: Sort direction options
enum:
- asc
- desc
WidgetSummary:
type: object
properties:
kind:
$ref: '#/components/schemas/WidgetKind'
total:
type: integer
required:
- kind
- total
11 changes: 11 additions & 0 deletions samples/client/others/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target/
**/*.rs.bk
Cargo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.gitignore
.openapi-generator-ignore
.travis.yml
Cargo.toml
README.md
docs/DefaultApi.md
docs/SortDirection.md
docs/WidgetKind.md
docs/WidgetSummary.md
git_push.sh
src/apis/configuration.rs
src/apis/default_api.rs
src/apis/mod.rs
src/lib.rs
src/models/mod.rs
src/models/sort_direction.rs
src/models/widget_kind.rs
src/models/widget_summary.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.25.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: rust
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "nullable-enum-query-params-reqwest"
version = "1.0.0"
authors = ["OpenAPI Generator team and contributors"]
description = "Test spec for enum query parameters whose schema is not a bare $ref, as emitted by FastAPI and other 3.1 producers. The same operation is defined with and without a path parameter, because the two used to be generated differently."
# Override this license by providing a License Object in the OpenAPI.
license = "Unlicense"
edition = "2021"

[dependencies]
serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0"
serde_repr = "^0.1"
url = "^2.5"
reqwest = { version = "^0.13", default-features = false, features = ["json", "multipart", "query", "form"] }

[features]
default = ["native-tls"]
native-tls = ["reqwest/native-tls"]
rustls = ["reqwest/rustls"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Rust API client for nullable-enum-query-params-reqwest

Test spec for enum query parameters whose schema is not a bare $ref, as emitted by FastAPI and other 3.1 producers. The same operation is defined with and without a path parameter, because the two used to be generated differently.


## Overview

This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client.

- API version: 1.0.0
- Package version: 1.0.0
- Generator version: 7.25.0-SNAPSHOT
- Build package: `org.openapitools.codegen.languages.RustClientCodegen`

## Installation

Put the package under your project folder in a directory named `nullable-enum-query-params-reqwest` and add the following to `Cargo.toml` under `[dependencies]`:

```
nullable-enum-query-params-reqwest = { path = "./nullable-enum-query-params-reqwest" }
```

## Documentation for API Endpoints

All URIs are relative to *http://localhost*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*DefaultApi* | [**get_widget_summary**](docs/DefaultApi.md#get_widget_summary) | **GET** /widgets/summary | Get a widget summary
*DefaultApi* | [**get_widget_summary_by_id**](docs/DefaultApi.md#get_widget_summary_by_id) | **GET** /widgets/{widget_id}/summary | Get a widget summary for a single widget


## Documentation For Models

- [SortDirection](docs/SortDirection.md)
- [WidgetKind](docs/WidgetKind.md)
- [WidgetSummary](docs/WidgetSummary.md)


To get access to the crate's generated documentation, use:

```
cargo doc --open
```

## Author



Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# \DefaultApi

All URIs are relative to *http://localhost*

Method | HTTP request | Description
------------- | ------------- | -------------
[**get_widget_summary**](DefaultApi.md#get_widget_summary) | **GET** /widgets/summary | Get a widget summary
[**get_widget_summary_by_id**](DefaultApi.md#get_widget_summary_by_id) | **GET** /widgets/{widget_id}/summary | Get a widget summary for a single widget



## get_widget_summary

> models::WidgetSummary get_widget_summary(kind, sort)
Get a widget summary

### Parameters


Name | Type | Description | Required | Notes
------------- | ------------- | ------------- | ------------- | -------------
**kind** | Option<**String**> | Kind filter, expressed as an anyOf with null | |
**sort** | Option<**String**> | Sort order, expressed as a $ref with sibling keywords | |

### Return type

[**models::WidgetSummary**](WidgetSummary.md)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/json

[[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)


## get_widget_summary_by_id

> models::WidgetSummary get_widget_summary_by_id(widget_id, kind)
Get a widget summary for a single widget

### Parameters


Name | Type | Description | Required | Notes
------------- | ------------- | ------------- | ------------- | -------------
**widget_id** | **String** | | [required] |
**kind** | Option<**String**> | Kind filter, expressed as an anyOf with null | |

### Return type

[**models::WidgetSummary**](WidgetSummary.md)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/json

[[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)

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SortDirection

## Enum Variants

| Name | Value |
|---- | -----|
| Asc | asc |
| Desc | desc |


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


Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# WidgetKind

## Enum Variants

| Name | Value |
|---- | -----|
| Basic | basic |
| Premium | premium |


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


Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# WidgetSummary

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**kind** | [**models::WidgetKind**](WidgetKind.md) | |
**total** | **i32** | |

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


Loading
Loading