Skip to content

Commit 4598f8c

Browse files
committed
Added no chrono test case
1 parent f549147 commit 4598f8c

77 files changed

Lines changed: 4231 additions & 11 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
generatorName: rust
2+
outputDir: samples/client/petstore/rust/reqwest/petstore-no-chrono
3+
library: reqwest
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/rust
6+
additionalProperties:
7+
supportAsync: false
8+
useChrono: false
9+
packageName: petstore-reqwest-no-chrono
10+
enumNameMappings:
11+
delivered: shipped

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
5555
@Setter(AccessLevel.PRIVATE) private boolean supportMiddleware = false;
5656
@Setter(AccessLevel.PRIVATE) private boolean useSerdePathToError = false;
5757
@Setter(AccessLevel.PRIVATE) private boolean supportTokenSource = false;
58+
private boolean useChrono = true;
5859
private boolean supportMultipleResponses = false;
5960
private boolean withAWSV4Signature = false;
6061
@Setter private boolean preferUnsignedInt = false;
@@ -74,6 +75,7 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
7475
public static final String SUPPORT_MIDDLEWARE = "supportMiddleware";
7576
public static final String USE_SERDE_PATH_TO_ERROR = "useSerdePathToError";
7677
public static final String SUPPORT_TOKEN_SOURCE = "supportTokenSource";
78+
public static final String USE_CHRONO = "useChrono";
7779
public static final String SUPPORT_MULTIPLE_RESPONSES = "supportMultipleResponses";
7880
public static final String PREFER_UNSIGNED_INT = "preferUnsignedInt";
7981
public static final String BEST_FIT_INT = "bestFitInt";
@@ -94,7 +96,7 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
9496
private boolean hasUUIDs = false;
9597
// The API has at least one Chrono type.
9698
// If the API does not contain any Dates or DateTimes we do not need to depend on the `chrono` crate
97-
private boolean hasChronoTypes = false;
99+
private boolean usesChronoTypes = false;
98100

99101
@Override
100102
public CodegenType getTag() {
@@ -186,8 +188,10 @@ public RustClientCodegen() {
186188
typeMapping.put("map", "std::collections::HashMap");
187189
typeMapping.put("UUID", "uuid::Uuid");
188190
typeMapping.put("URI", "String");
191+
// Temporarily set the default to chrono. Then when `processOpts` is called it will update to not use chrono if specified
189192
typeMapping.put("date", "chrono::NaiveDate");
190193
typeMapping.put("DateTime", "chrono::NaiveDateTime");
194+
191195
typeMapping.put("password", "String");
192196
typeMapping.put("decimal", "String");
193197

@@ -220,6 +224,8 @@ public RustClientCodegen() {
220224
.defaultValue(Boolean.FALSE.toString()));
221225
cliOptions.add(new CliOption(SUPPORT_TOKEN_SOURCE, "If set, add support for google-cloud-token. This option is for 'reqwest' and 'reqwest-trait' library only and requires the 'supportAsync' option", SchemaTypeUtil.BOOLEAN_TYPE)
222226
.defaultValue(Boolean.FALSE.toString()));
227+
cliOptions.add(new CliOption(USE_CHRONO, "If set, use chrono to represent date time objects (`chrono::NaiveDate` for `date` and `chrono::NaiveDateTime` for `date-time`)", SchemaTypeUtil.BOOLEAN_TYPE)
228+
.defaultValue(Boolean.TRUE.toString()));
223229
cliOptions.add(new CliOption(SUPPORT_MULTIPLE_RESPONSES, "If set, return type wraps an enum of all possible 2xx schemas. This option is for 'reqwest' and 'reqwest-trait' library only", SchemaTypeUtil.BOOLEAN_TYPE)
224230
.defaultValue(Boolean.FALSE.toString()));
225231
cliOptions.add(new CliOption(CodegenConstants.ENUM_NAME_SUFFIX, CodegenConstants.ENUM_NAME_SUFFIX_DESC).defaultValue(this.enumSuffix));
@@ -467,6 +473,11 @@ public void processOpts() {
467473
}
468474
writePropertyBack(SUPPORT_TOKEN_SOURCE, getSupportTokenSource());
469475

476+
if (additionalProperties.containsKey(USE_CHRONO)) {
477+
this.setUseChrono(convertPropertyToBoolean(USE_CHRONO));
478+
}
479+
writePropertyBack(USE_CHRONO, isUseChrono());
480+
470481
if (additionalProperties.containsKey(SUPPORT_MULTIPLE_RESPONSES)) {
471482
this.setSupportMultipleReturns(convertPropertyToBoolean(SUPPORT_MULTIPLE_RESPONSES));
472483
}
@@ -784,11 +795,13 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
784795
}
785796
}
786797
// Check for Chrono Types
787-
for (CodegenParameter param : operation.allParams) {
788-
if (!hasChronoTypes && (param.isDate || param.isDateTime)) {
789-
LOGGER.debug("Found Chrono Type in operation Parameter: {}", param.paramName);
790-
hasChronoTypes = true;
791-
break;
798+
if(isUseChrono()){
799+
for (CodegenParameter param : operation.allParams) {
800+
if (!usesChronoTypes && (param.isDate || param.isDateTime)) {
801+
LOGGER.debug("Found Chrono Type in operation Parameter: {}", param.paramName);
802+
usesChronoTypes = true;
803+
break;
804+
}
792805
}
793806
}
794807

@@ -893,19 +906,19 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
893906
}
894907
}
895908

896-
if (!hasChronoTypes) {
909+
if (isUseChrono() && !usesChronoTypes) {
897910
for (var map : allModels) {
898911
CodegenModel m = map.getModel();
899912
if (m.getIsDate() || hasChronoTypeInProperties(m.vars)) {
900-
hasChronoTypes = true;
913+
usesChronoTypes = true;
901914
LOGGER.debug("Found Chrono Type in model: {}", m.name);
902915
break;
903916
}
904917
}
905918
}
906919

907920
this.additionalProperties.put("hasUUIDs", hasUUIDs);
908-
this.additionalProperties.put("hasChronoTypes", hasChronoTypes);
921+
this.additionalProperties.put("usesChronoTypes", isUseChrono() && usesChronoTypes);
909922
return objs;
910923
}
911924

@@ -980,4 +993,20 @@ public static <K, V> boolean hasDuplicateValues(Map<K, V> map) {
980993
Set<V> uniqueValues = new HashSet<>(map.values());
981994
return uniqueValues.size() < map.size();
982995
}
996+
997+
998+
private boolean isUseChrono() {
999+
return useChrono;
1000+
}
1001+
1002+
private void setUseChrono(boolean useChrono) {
1003+
this.useChrono = useChrono;
1004+
if(isUseChrono()){
1005+
typeMapping.put("date", "chrono::NaiveDate");
1006+
typeMapping.put("DateTime", "chrono::NaiveDateTime");
1007+
}else{
1008+
typeMapping.put("date", "String");
1009+
typeMapping.put("DateTime", "String");
1010+
}
1011+
}
9831012
}

modules/openapi-generator/src/main/resources/rust/Cargo.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ url = "^2.5"
4545
{{#hasUUIDs}}
4646
uuid = { version = "^1.8", features = ["serde", "v4"] }
4747
{{/hasUUIDs}}
48-
{{#hasChronoTypes}}
48+
{{#usesChronoTypes}}
4949
chrono = { version = "^0.4", features = ["serde"] }
50-
{{/hasChronoTypes}}
50+
{{/usesChronoTypes}}
5151
{{#hyper}}
5252
{{#hyper0x}}
5353
hyper = { version = "~0.14", features = ["full"] }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target/
2+
**/*.rs.bk
3+
Cargo.lock
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
.gitignore
2+
.travis.yml
3+
Cargo.toml
4+
README.md
5+
docs/ActionContainer.md
6+
docs/AnyTypeTest.md
7+
docs/ApiResponse.md
8+
docs/ArrayItemRefTest.md
9+
docs/Baz.md
10+
docs/Category.md
11+
docs/EnumArrayTesting.md
12+
docs/FakeApi.md
13+
docs/ModelWithInlineEnum.md
14+
docs/ModelWithInlineEnumMetadata.md
15+
docs/NullableArray.md
16+
docs/NumericEnumTesting.md
17+
docs/OptionalTesting.md
18+
docs/Order.md
19+
docs/Page.md
20+
docs/Person.md
21+
docs/Pet.md
22+
docs/PetApi.md
23+
docs/PropertyTest.md
24+
docs/Ref.md
25+
docs/Return.md
26+
docs/StoreApi.md
27+
docs/Tag.md
28+
docs/TestAllOfWithMultiMetadataOnly.md
29+
docs/TestingApi.md
30+
docs/TypeTesting.md
31+
docs/UniqueItemArrayTesting.md
32+
docs/User.md
33+
docs/UserApi.md
34+
docs/Vehicle.md
35+
docs/WithInnerOneOf.md
36+
git_push.sh
37+
src/apis/configuration.rs
38+
src/apis/fake_api.rs
39+
src/apis/mod.rs
40+
src/apis/pet_api.rs
41+
src/apis/store_api.rs
42+
src/apis/testing_api.rs
43+
src/apis/user_api.rs
44+
src/lib.rs
45+
src/models/action_container.rs
46+
src/models/any_type_test.rs
47+
src/models/api_response.rs
48+
src/models/array_item_ref_test.rs
49+
src/models/baz.rs
50+
src/models/category.rs
51+
src/models/enum_array_testing.rs
52+
src/models/mod.rs
53+
src/models/model_ref.rs
54+
src/models/model_return.rs
55+
src/models/model_with_inline_enum.rs
56+
src/models/model_with_inline_enum_metadata.rs
57+
src/models/nullable_array.rs
58+
src/models/numeric_enum_testing.rs
59+
src/models/optional_testing.rs
60+
src/models/order.rs
61+
src/models/page.rs
62+
src/models/person.rs
63+
src/models/pet.rs
64+
src/models/property_test.rs
65+
src/models/tag.rs
66+
src/models/test_all_of_with_multi_metadata_only.rs
67+
src/models/type_testing.rs
68+
src/models/unique_item_array_testing.rs
69+
src/models/user.rs
70+
src/models/vehicle.rs
71+
src/models/with_inner_one_of.rs
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.22.0-SNAPSHOT
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: rust
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "petstore-reqwest-no-chrono"
3+
version = "1.0.0"
4+
authors = ["OpenAPI Generator team and contributors"]
5+
description = "This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters."
6+
license = "Apache-2.0"
7+
edition = "2021"
8+
9+
[dependencies]
10+
serde = { version = "^1.0", features = ["derive"] }
11+
serde_with = { version = "^3.8", default-features = false, features = ["base64", "std", "macros"] }
12+
serde_json = "^1.0"
13+
serde_repr = "^0.1"
14+
url = "^2.5"
15+
uuid = { version = "^1.8", features = ["serde", "v4"] }
16+
reqwest = { version = "^0.13", default-features = false, features = ["json", "blocking", "multipart", "query", "form"] }
17+
18+
[features]
19+
default = ["native-tls"]
20+
native-tls = ["reqwest/native-tls"]
21+
rustls = ["reqwest/rustls"]
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Rust API client for petstore-reqwest-no-chrono
2+
3+
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
4+
5+
6+
## Overview
7+
8+
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.
9+
10+
- API version: 1.0.0
11+
- Package version: 1.0.0
12+
- Generator version: 7.22.0-SNAPSHOT
13+
- Build package: `org.openapitools.codegen.languages.RustClientCodegen`
14+
15+
## Installation
16+
17+
Put the package under your project folder in a directory named `petstore-reqwest-no-chrono` and add the following to `Cargo.toml` under `[dependencies]`:
18+
19+
```
20+
petstore-reqwest-no-chrono = { path = "./petstore-reqwest-no-chrono" }
21+
```
22+
23+
## Documentation for API Endpoints
24+
25+
All URIs are relative to *http://localhost/v2*
26+
27+
Class | Method | HTTP request | Description
28+
------------ | ------------- | ------------- | -------------
29+
*FakeApi* | [**test_nullable_required_param**](docs/FakeApi.md#test_nullable_required_param) | **GET** /fake/user/{user_name} | To test nullable required parameters
30+
*PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store
31+
*PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **DELETE** /pet/{petId} | Deletes a pet
32+
*PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **GET** /pet/findByStatus | Finds Pets by status
33+
*PetApi* | [**find_pets_by_tags**](docs/PetApi.md#find_pets_by_tags) | **GET** /pet/findByTags | Finds Pets by tags
34+
*PetApi* | [**get_pet_by_id**](docs/PetApi.md#get_pet_by_id) | **GET** /pet/{petId} | Find pet by ID
35+
*PetApi* | [**pets_explode_post**](docs/PetApi.md#pets_explode_post) | **POST** /pets/explode | List all pets
36+
*PetApi* | [**pets_post**](docs/PetApi.md#pets_post) | **POST** /pets | List all pets
37+
*PetApi* | [**update_pet**](docs/PetApi.md#update_pet) | **PUT** /pet | Update an existing pet
38+
*PetApi* | [**update_pet_with_form**](docs/PetApi.md#update_pet_with_form) | **POST** /pet/{petId} | Updates a pet in the store with form data
39+
*PetApi* | [**upload_file**](docs/PetApi.md#upload_file) | **POST** /pet/{petId}/uploadImage | uploads an image
40+
*StoreApi* | [**delete_order**](docs/StoreApi.md#delete_order) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
41+
*StoreApi* | [**get_inventory**](docs/StoreApi.md#get_inventory) | **GET** /store/inventory | Returns pet inventories by status
42+
*StoreApi* | [**get_order_by_id**](docs/StoreApi.md#get_order_by_id) | **GET** /store/order/{orderId} | Find purchase order by ID
43+
*StoreApi* | [**place_order**](docs/StoreApi.md#place_order) | **POST** /store/order | Place an order for a pet
44+
*TestingApi* | [**tests_all_of_with_one_model_get**](docs/TestingApi.md#tests_all_of_with_one_model_get) | **GET** /tests/allOfWithOneModel | Test for allOf with a single option. (One of the issues in #20500)
45+
*TestingApi* | [**tests_file_response_get**](docs/TestingApi.md#tests_file_response_get) | **GET** /tests/fileResponse | Returns an image file
46+
*TestingApi* | [**tests_inline_enum_boxing_get**](docs/TestingApi.md#tests_inline_enum_boxing_get) | **GET** /tests/inlineEnumBoxing | Get model with inline enums
47+
*TestingApi* | [**tests_inline_enum_boxing_post**](docs/TestingApi.md#tests_inline_enum_boxing_post) | **POST** /tests/inlineEnumBoxing | Test for inline enum fields not being boxed in model constructors
48+
*TestingApi* | [**tests_type_testing_get**](docs/TestingApi.md#tests_type_testing_get) | **GET** /tests/typeTesting | Route to test the TypeTesting schema
49+
*UserApi* | [**create_user**](docs/UserApi.md#create_user) | **POST** /user | Create user
50+
*UserApi* | [**create_users_with_array_input**](docs/UserApi.md#create_users_with_array_input) | **POST** /user/createWithArray | Creates list of users with given input array
51+
*UserApi* | [**create_users_with_list_input**](docs/UserApi.md#create_users_with_list_input) | **POST** /user/createWithList | Creates list of users with given input array
52+
*UserApi* | [**delete_user**](docs/UserApi.md#delete_user) | **DELETE** /user/{username} | Delete user
53+
*UserApi* | [**get_user_by_name**](docs/UserApi.md#get_user_by_name) | **GET** /user/{username} | Get user by user name
54+
*UserApi* | [**login_user**](docs/UserApi.md#login_user) | **GET** /user/login | Logs user into the system
55+
*UserApi* | [**logout_user**](docs/UserApi.md#logout_user) | **GET** /user/logout | Logs out current logged in user session
56+
*UserApi* | [**update_user**](docs/UserApi.md#update_user) | **PUT** /user/{username} | Updated user
57+
58+
59+
## Documentation For Models
60+
61+
- [ActionContainer](docs/ActionContainer.md)
62+
- [AnyTypeTest](docs/AnyTypeTest.md)
63+
- [ApiResponse](docs/ApiResponse.md)
64+
- [ArrayItemRefTest](docs/ArrayItemRefTest.md)
65+
- [Baz](docs/Baz.md)
66+
- [Category](docs/Category.md)
67+
- [EnumArrayTesting](docs/EnumArrayTesting.md)
68+
- [ModelWithInlineEnum](docs/ModelWithInlineEnum.md)
69+
- [ModelWithInlineEnumMetadata](docs/ModelWithInlineEnumMetadata.md)
70+
- [NullableArray](docs/NullableArray.md)
71+
- [NumericEnumTesting](docs/NumericEnumTesting.md)
72+
- [OptionalTesting](docs/OptionalTesting.md)
73+
- [Order](docs/Order.md)
74+
- [Page](docs/Page.md)
75+
- [Person](docs/Person.md)
76+
- [Pet](docs/Pet.md)
77+
- [PropertyTest](docs/PropertyTest.md)
78+
- [Ref](docs/Ref.md)
79+
- [Return](docs/Return.md)
80+
- [Tag](docs/Tag.md)
81+
- [TestAllOfWithMultiMetadataOnly](docs/TestAllOfWithMultiMetadataOnly.md)
82+
- [TypeTesting](docs/TypeTesting.md)
83+
- [UniqueItemArrayTesting](docs/UniqueItemArrayTesting.md)
84+
- [User](docs/User.md)
85+
- [Vehicle](docs/Vehicle.md)
86+
- [WithInnerOneOf](docs/WithInnerOneOf.md)
87+
88+
89+
To get access to the crate's generated documentation, use:
90+
91+
```
92+
cargo doc --open
93+
```
94+
95+
## Author
96+
97+
98+

0 commit comments

Comments
 (0)