Skip to content

Commit 65e74a3

Browse files
authored
[Rust] [Axum] Revert PR #18061 (#18354)
1 parent b4c315e commit 65e74a3

42 files changed

Lines changed: 162 additions & 281 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import org.openapitools.codegen.config.GlobalSettings;
5353
import org.openapitools.codegen.examples.ExampleGenerator;
5454
import org.openapitools.codegen.languages.PhpNextgenClientCodegen;
55-
import org.openapitools.codegen.languages.RustAxumServerCodegen;
5655
import org.openapitools.codegen.languages.RustServerCodegen;
5756
import org.openapitools.codegen.meta.FeatureSet;
5857
import org.openapitools.codegen.meta.GeneratorMetadata;
@@ -707,7 +706,7 @@ public Map<String, ModelsMap> updateAllModels(Map<String, ModelsMap> objs) {
707706
* Removes importToRemove from the imports of objs, if present.
708707
* This is useful to remove imports that are already present in operations-related template files, to avoid importing the same thing twice.
709708
*
710-
* @param objs imports will be removed from this objs' imports collection
709+
* @param objs imports will be removed from this objs' imports collection
711710
* @param importToRemove the import statement to be removed
712711
*/
713712
protected void removeImport(OperationsMap objs, String importToRemove) {
@@ -2302,7 +2301,7 @@ public String toDefaultParameterValue(Schema<?> schema) {
23022301
* Any non-null value will cause {{#defaultValue} check to pass.
23032302
*
23042303
* @param codegenProperty Codegen Property
2305-
* @param schema Parameter schema
2304+
* @param schema Parameter schema
23062305
* @return string presentation of the default value of the parameter
23072306
*/
23082307
public String toDefaultParameterValue(CodegenProperty codegenProperty, Schema<?> schema) {
@@ -2329,7 +2328,7 @@ public String toDefaultValueWithParam(String name, Schema schema) {
23292328
* Return null if you do NOT want a default value.
23302329
* Any non-null value will cause {{#defaultValue} check to pass.
23312330
*
2332-
* @param schema Property schema
2331+
* @param schema Property schema
23332332
* @param codegenProperty Codegen property
23342333
* @return string presentation of the default value of the property
23352334
*/
@@ -2372,7 +2371,6 @@ public String getSchemaType(Schema schema) {
23722371
}
23732372

23742373

2375-
23762374
protected Schema<?> getSchemaAdditionalProperties(Schema schema) {
23772375
Schema<?> inner = ModelUtils.getAdditionalProperties(schema);
23782376
if (inner == null) {
@@ -3009,6 +3007,7 @@ protected String toTestCaseName(String specTestCaseName) {
30093007
/**
30103008
* A method that allows generators to pre-process test example payloads
30113009
* This can be useful if one needs to change how values like null in string are represented
3010+
*
30123011
* @param data the test data payload
30133012
* @return the updated test data payload
30143013
*/
@@ -3019,6 +3018,7 @@ protected Object processTestExampleData(Object data) {
30193018
/**
30203019
* Processes any test cases if they exist in the components.x-test-examples vendor extensions
30213020
* If they exist then cast them to java class instances and return them back in a map
3021+
*
30223022
* @param refToTestCases the component schema name that the test cases are for
30233023
*/
30243024
private HashMap<String, SchemaTestCase> extractSchemaTestCases(String refToTestCases) {
@@ -3055,7 +3055,7 @@ private HashMap<String, SchemaTestCase> extractSchemaTestCases(String refToTestC
30553055
/**
30563056
* Sets the booleans that define the model's type
30573057
*
3058-
* @param model the model to update
3058+
* @param model the model to update
30593059
* @param schema the model's schema
30603060
*/
30613061
protected void updateModelForString(CodegenModel model, Schema schema) {
@@ -3313,7 +3313,6 @@ protected void setAddProps(Schema schema, IJsonSchemaValidationProperties proper
33133313
* @param sc The Schema that may contain the discriminator
33143314
* @param discPropName The String that is the discriminator propertyName in the schema
33153315
* @param visitedSchemas A set of visited schema names
3316-
*
33173316
*/
33183317
private CodegenProperty discriminatorFound(String composedSchemaName, Schema sc, String discPropName, Set<String> visitedSchemas) {
33193318
if (visitedSchemas.contains(composedSchemaName)) { // recursive schema definition found
@@ -3400,7 +3399,7 @@ private CodegenProperty discriminatorFound(String composedSchemaName, Schema sc,
34003399
/**
34013400
* Recursively look in Schema sc for the discriminator and return it
34023401
*
3403-
* @param sc The Schema that may contain the discriminator
3402+
* @param sc The Schema that may contain the discriminator
34043403
* @param visitedSchemas An array list of visited schemas
34053404
*/
34063405
private Discriminator recursiveGetDiscriminator(Schema sc, ArrayList<Schema> visitedSchemas) {
@@ -3620,9 +3619,9 @@ protected List<MappedModel> getAllOfDescendants(String thisSchemaName) {
36203619
Map<String, Object> vendorExtensions = cs.getExtensions();
36213620
String mappingName =
36223621
Optional.ofNullable(vendorExtensions)
3623-
.map(ve -> ve.get("x-discriminator-value"))
3624-
.map(discriminatorValue -> (String) discriminatorValue)
3625-
.orElse(currentSchemaName);
3622+
.map(ve -> ve.get("x-discriminator-value"))
3623+
.map(discriminatorValue -> (String) discriminatorValue)
3624+
.orElse(currentSchemaName);
36263625
MappedModel mm = new MappedModel(mappingName, toModelName(currentSchemaName), !mappingName.equals(currentSchemaName));
36273626
descendentSchemas.add(mm);
36283627
}
@@ -3649,11 +3648,11 @@ protected CodegenDiscriminator createDiscriminator(String schemaName, Schema sch
36493648
// the future..
36503649
String propertyType =
36513650
Optional.ofNullable(schema.getProperties())
3652-
.map(p -> (Schema<?>) p.get(discriminatorPropertyName))
3653-
.map(Schema::get$ref)
3654-
.map(ModelUtils::getSimpleRef)
3655-
.map(this::toModelName)
3656-
.orElseGet(() -> typeMapping.get("string"));
3651+
.map(p -> (Schema<?>) p.get(discriminatorPropertyName))
3652+
.map(Schema::get$ref)
3653+
.map(ModelUtils::getSimpleRef)
3654+
.map(this::toModelName)
3655+
.orElseGet(() -> typeMapping.get("string"));
36573656
discriminator.setPropertyType(propertyType);
36583657

36593658
// check to see if the discriminator property is an enum string
@@ -3944,8 +3943,8 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required) {
39443943
* This method was kept when required was added to the fromProperty signature
39453944
* to ensure that the change was non-breaking
39463945
*
3947-
* @param name name of the property
3948-
* @param p OAS property schema
3946+
* @param name name of the property
3947+
* @param p OAS property schema
39493948
* @return Codegen Property object
39503949
*/
39513950
public CodegenProperty fromProperty(String name, Schema p) {
@@ -3961,9 +3960,9 @@ public CodegenProperty fromProperty(String name, Schema p) {
39613960
* Any subsequent processing of the CodegenModel return value must be idempotent
39623961
* for a given (String name, Schema schema).
39633962
*
3964-
* @param name name of the property
3965-
* @param p OAS property schema
3966-
* @param required true if the property is required in the next higher object schema, false otherwise
3963+
* @param name name of the property
3964+
* @param p OAS property schema
3965+
* @param required true if the property is required in the next higher object schema, false otherwise
39673966
* @param schemaIsFromAdditionalProperties true if the property is a required property defined by additional properties schema
39683967
* If this is the actual additionalProperties schema not defining a required property, then
39693968
* the value should be false
@@ -4742,7 +4741,7 @@ public CodegenOperation fromOperation(String path,
47424741
if (contentType != null) {
47434742
contentType = contentType.toLowerCase(Locale.ROOT);
47444743
}
4745-
if (!(this instanceof RustAxumServerCodegen) && contentType != null &&
4744+
if (contentType != null &&
47464745
(contentType.startsWith("application/x-www-form-urlencoded") ||
47474746
contentType.startsWith("multipart"))) {
47484747
// process form parameters
@@ -5909,10 +5908,10 @@ protected void addImport(Set<String> importsToBeAddedTo, String type) {
59095908
/**
59105909
* Add the model name of the child schema in a composed schema to the set of imports
59115910
*
5912-
* @param composed composed schema
5911+
* @param composed composed schema
59135912
* @param childSchema composed schema
5914-
* @param model codegen model
5915-
* @param modelName model name
5913+
* @param model codegen model
5914+
* @param modelName model name
59165915
*/
59175916
protected void addImport(Schema composed, Schema childSchema, CodegenModel model, String modelName) {
59185917
if (composed == null || childSchema == null) {
@@ -6795,12 +6794,12 @@ protected List<Map<String, Object>> buildEnumVars(List<Object> values, String da
67956794
String enumValue = isDataTypeString(dataType)
67966795
? enumUnknownDefaultCaseName
67976796
: // This is a dummy value that attempts to avoid collisions with previously specified cases.
6798-
// Int.max / 192
6799-
// The number 192 that is used to calculate this random value, is the Swift Evolution proposal for frozen/non-frozen enums.
6800-
// [SE-0192](https://github.com/apple/swift-evolution/blob/master/proposals/0192-non-exhaustive-enums.md)
6801-
// Since this functionality was born in the Swift 5 generator and latter on broth to all generators
6802-
// https://github.com/OpenAPITools/openapi-generator/pull/11013
6803-
String.valueOf(11184809);
6797+
// Int.max / 192
6798+
// The number 192 that is used to calculate this random value, is the Swift Evolution proposal for frozen/non-frozen enums.
6799+
// [SE-0192](https://github.com/apple/swift-evolution/blob/master/proposals/0192-non-exhaustive-enums.md)
6800+
// Since this functionality was born in the Swift 5 generator and latter on broth to all generators
6801+
// https://github.com/OpenAPITools/openapi-generator/pull/11013
6802+
String.valueOf(11184809);
68046803

68056804
enumVar.put("name", toEnumVarName(enumName, dataType));
68066805
enumVar.put("value", toEnumValue(enumValue, dataType));
@@ -7984,6 +7983,7 @@ protected String getItemsName(Schema containingSchema, String containingSchemaNa
79847983
protected String getAdditionalPropertiesName() {
79857984
return "additional_properties";
79867985
}
7986+
79877987
private void addJsonSchemaForBodyRequestInCaseItsNotPresent(CodegenParameter codegenParameter, RequestBody body) {
79887988
if (codegenParameter.jsonSchema == null)
79897989
codegenParameter.jsonSchema = Json.pretty(body);
@@ -8250,8 +8250,8 @@ public void addOneOfNameExtension(Schema schema, String name) {
82508250
/**
82518251
* Add a given ComposedSchema as an interface model to be generated, assuming it has `oneOf` defined
82528252
*
8253-
* @param cs ComposedSchema object to create as interface model
8254-
* @param type name to use for the generated interface model
8253+
* @param cs ComposedSchema object to create as interface model
8254+
* @param type name to use for the generated interface model
82558255
*/
82568256
public void addOneOfInterfaceModel(Schema cs, String type) {
82578257
if (cs.getOneOf() == null) {
@@ -8441,7 +8441,7 @@ private List<CodegenProperty> getComposedProperties(List<Schema> xOfCollection,
84418441
// in other sub-schemas of allOf/anyOf/oneOf
84428442
cp.vendorExtensions.putIfAbsent("x-duplicated-data-type", true);
84438443
} else {
8444-
if(isTypeErasedGenerics()) {
8444+
if (isTypeErasedGenerics()) {
84458445
dataTypeSet.add(cp.baseType);
84468446
} else {
84478447
dataTypeSet.add(cp.dataType);
@@ -8472,10 +8472,14 @@ public List<VendorExtension> getSupportedVendorExtensions() {
84728472
}
84738473

84748474
@Override
8475-
public boolean getUseInlineModelResolver() { return true; }
8475+
public boolean getUseInlineModelResolver() {
8476+
return true;
8477+
}
84768478

84778479
@Override
8478-
public boolean getUseOpenapiNormalizer() { return true; }
8480+
public boolean getUseOpenapiNormalizer() {
8481+
return true;
8482+
}
84798483

84808484
@Override
84818485
public Set<String> getOpenapiGeneratorIgnoreList() {
@@ -8492,7 +8496,9 @@ public boolean isTypeErasedGenerics() {
84928496
And convert special characters like newline, tab, carriage return
84938497
Into strings that can be rendered in the language that the generator will output to
84948498
*/
8495-
protected String handleSpecialCharacters(String name) { return name; }
8499+
protected String handleSpecialCharacters(String name) {
8500+
return name;
8501+
}
84968502

84978503
/**
84988504
* Used to ensure that null or Schema is returned given an input Boolean/Schema/null

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ conversion = [
4242
async-trait = "0.1"
4343
axum = { version = "0.7" }
4444
axum-extra = { version = "0.9", features = ["cookie", "multipart"] }
45-
base64 = "0.21"
45+
base64 = "0.22"
4646
bytes = "1"
4747
chrono = { version = "0.4", features = ["serde"] }
4848
frunk = { version = "0.4", optional = true }
@@ -62,7 +62,7 @@ tokio = { version = "1", default-features = false, features = [
6262
] }
6363
tracing = { version = "0.1", features = ["attributes"] }
6464
uuid = { version = "1", features = ["serde"] }
65-
validator = { version = "0.16", features = ["derive"] }
65+
validator = { version = "0.18", features = ["derive"] }
6666

6767
[dev-dependencies]
6868
tracing-subscriber = "0.3"

modules/openapi-generator/src/main/resources/rust-axum/lib.mustache

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)]
2-
#![allow(unused_imports, unused_attributes)]
1+
#![allow(
2+
missing_docs,
3+
trivial_casts,
4+
unused_variables,
5+
unused_mut,
6+
unused_extern_crates,
7+
non_camel_case_types,
8+
unused_imports,
9+
unused_attributes
10+
)]
311
#![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)]
412

513
use async_trait::async_trait;

modules/openapi-generator/src/main/resources/rust-axum/models.mustache

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ use crate::{models, types::*};
3636
{{/maxLength}}
3737
{{#pattern}}
3838
{{^isByteArray}}
39-
regex = "RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}HeaderParams_{{{paramName}}}{{/lambda.uppercase}}",
39+
regex(path = *RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}HeaderParams_{{{paramName}}}{{/lambda.uppercase}}),
4040
{{/isByteArray}}
4141
{{#isByteArray}}
42-
custom ="validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}HeaderParams_{{{paramName}}}{{/lambda.lowercase}}"
42+
custom(function = "validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}HeaderParams_{{{paramName}}}{{/lambda.lowercase}}"),
4343
{{/isByteArray}}
4444
{{/pattern}}
4545
{{#maximum}}
@@ -128,10 +128,10 @@ use crate::{models, types::*};
128128
{{/maxLength}}
129129
{{#pattern}}
130130
{{^isByteArray}}
131-
regex = "RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}PathParams_{{{paramName}}}{{/lambda.uppercase}}",
131+
regex(path = *RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}PathParams_{{{paramName}}}{{/lambda.uppercase}}),
132132
{{/isByteArray}}
133133
{{#isByteArray}}
134-
custom ="validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}PathParams_{{{paramName}}}{{/lambda.lowercase}}"
134+
custom(function = "validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}PathParams_{{{paramName}}}{{/lambda.lowercase}}"),
135135
{{/isByteArray}}
136136
{{/pattern}}
137137
{{#maximum}}
@@ -232,10 +232,10 @@ use crate::{models, types::*};
232232
{{/maxLength}}
233233
{{#pattern}}
234234
{{^isByteArray}}
235-
regex = "RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}QueryParams_{{{paramName}}}{{/lambda.uppercase}}",
235+
regex(path = *RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}QueryParams_{{{paramName}}}{{/lambda.uppercase}}),
236236
{{/isByteArray}}
237237
{{#isByteArray}}
238-
custom ="validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}QueryParams_{{{paramName}}}{{/lambda.lowercase}}"
238+
custom(function = "validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}QueryParams_{{{paramName}}}{{/lambda.lowercase}}"),
239239
{{/isByteArray}}
240240
{{/pattern}}
241241
{{#maximum}}
@@ -639,10 +639,10 @@ pub struct {{{classname}}} {
639639
{{/maxLength}}
640640
{{#pattern}}
641641
{{^isByteArray}}
642-
regex = "RE_{{#lambda.uppercase}}{{{classname}}}_{{{name}}}{{/lambda.uppercase}}",
642+
regex(path = *RE_{{#lambda.uppercase}}{{{classname}}}_{{{name}}}{{/lambda.uppercase}}),
643643
{{/isByteArray}}
644644
{{#isByteArray}}
645-
custom ="validate_byte_{{#lambda.lowercase}}{{{classname}}}_{{{name}}}{{/lambda.lowercase}}"
645+
custom(function = "validate_byte_{{#lambda.lowercase}}{{{classname}}}_{{{name}}}{{/lambda.lowercase}}"),
646646
{{/isByteArray}}
647647
{{/pattern}}
648648
{{#maximum}}

modules/openapi-generator/src/main/resources/rust-axum/server-operation-validate.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
{{/maxLength}}
2323
{{#pattern}}
2424
{{#isString}}
25-
regex = "RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}BodyValidator{{/lambda.uppercase}}",
25+
regex(path = *RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}BodyValidator{{/lambda.uppercase}}),
2626
{{/isString}}
2727
{{^isString}}
28-
custom ="validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}BodyValidator{{/lambda.lowercase}}",
28+
custom(function = "validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}BodyValidator{{/lambda.lowercase}}"),
2929
{{/isString}}
3030
{{/pattern}}
3131
{{#maximum}}
@@ -59,7 +59,7 @@
5959
{{^x-consumes-plain-text}}
6060
{{^hasValidation}}
6161
{{^isMap}}
62-
#[validate]
62+
#[validate(nested)]
6363
{{/isMap}}
6464
{{/hasValidation}}
6565
body: &'a {{{dataType}}},
@@ -218,4 +218,4 @@ Ok((
218218
{{/x-consumes-multipart}}
219219
{{/x-consumes-multipart-related}}
220220
))
221-
}
221+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.4.0-SNAPSHOT
1+
7.5.0-SNAPSHOT

samples/server/petstore/rust-axum/output/multipart-v3/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ conversion = [
2020
async-trait = "0.1"
2121
axum = { version = "0.7" }
2222
axum-extra = { version = "0.9", features = ["cookie", "multipart"] }
23-
base64 = "0.21"
23+
base64 = "0.22"
2424
bytes = "1"
2525
chrono = { version = "0.4", features = ["serde"] }
2626
frunk = { version = "0.4", optional = true }
@@ -40,7 +40,7 @@ tokio = { version = "1", default-features = false, features = [
4040
] }
4141
tracing = { version = "0.1", features = ["attributes"] }
4242
uuid = { version = "1", features = ["serde"] }
43-
validator = { version = "0.16", features = ["derive"] }
43+
validator = { version = "0.18", features = ["derive"] }
4444

4545
[dev-dependencies]
4646
tracing-subscriber = "0.3"

samples/server/petstore/rust-axum/output/multipart-v3/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ server, you can easily generate a server stub.
1212
To see how to make this your own, look here: [README]((https://openapi-generator.tech))
1313

1414
- API version: 1.0.7
15-
15+
- Generator version: 7.5.0-SNAPSHOT
1616

1717

1818

samples/server/petstore/rust-axum/output/multipart-v3/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
trivial_casts,
44
unused_variables,
55
unused_mut,
6-
unused_imports,
76
unused_extern_crates,
8-
non_camel_case_types
7+
non_camel_case_types,
8+
unused_imports,
9+
unused_attributes
910
)]
10-
#![allow(unused_imports, unused_attributes)]
1111
#![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)]
1212

1313
use async_trait::async_trait;

0 commit comments

Comments
 (0)