Skip to content

Commit

Permalink
missing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DDtKey committed Feb 21, 2024
1 parent aabda23 commit 671003b
Show file tree
Hide file tree
Showing 52 changed files with 107 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.FileSchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.media.*;
import io.swagger.v3.parser.util.SchemaTypeUtil;
import joptsimple.internal.Strings;
import org.openapitools.codegen.*;
Expand All @@ -42,6 +39,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;

public class RustClientCodegen extends AbstractRustCodegen implements CodegenConfig {
private final Logger LOGGER = LoggerFactory.getLogger(RustClientCodegen.class);
Expand Down Expand Up @@ -221,13 +219,24 @@ public CodegenModel fromModel(String name, Schema model) {
throw new RuntimeException("oneOf size does not match the model");
}

Map<String, String> mappedNameByRef = Optional.ofNullable(model.getDiscriminator())
.map(Discriminator::getMapping)
.map(mapping -> mapping.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey))
)
.orElse(Collections.emptyMap());

for (int i = 0; i < oneOfs.size(); i++) {
CodegenProperty oneOf = oneOfs.get(i);
Schema schema = schemas.get(i);
String aliasType = getTypeDeclaration(schema);
if (aliasType.startsWith("models::")) {
aliasType = aliasType.substring("models::".length());
}
if (oneOf.getRef() != null) {
oneOf.setBaseName(mappedNameByRef.get(oneOf.getRef()));
}
oneOf.setName(aliasType);
}
}
Expand All @@ -239,10 +248,6 @@ public CodegenModel fromModel(String name, Schema model) {
public ModelsMap postProcessModels(ModelsMap objs) {
// Remove the discriminator field from the model, serde will take care of this
for (ModelMap model : objs.getModels()) {
System.out.println("\nMODEL: \n\n");
System.out.println(model);
System.out.println("\n\n\n");

CodegenModel cm = model.getModel();

if (cm.discriminator != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::option::Option;
use hyper;
use futures::Future;

use crate::models;
use super::{Error, configuration};
use super::request as __internal_request;

Expand Down
12 changes: 3 additions & 9 deletions modules/openapi-generator/src/main/resources/rust/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,15 @@ pub enum {{{classname}}} {
{{/mappedModels}}
{{/oneOf}}
{{^oneOf.isEmpty}}
{{#mappedModels}}
{{#description}}
/// {{{.}}}
{{/description}}
#[serde(rename="{{mappingName}}")]
{{{modelName}}}(Box<{{{modelName}}}>),
{{/mappedModels}}
{{^mappedModels}}
{{#composedSchemas.oneOf}}
{{#description}}
/// {{{.}}}
{{/description}}
{{#baseName}}
#[serde(rename="{{{.}}}")]
{{/baseName}}
{{{name}}}(Box<{{{dataType}}}>),
{{/composedSchemas.oneOf}}
{{/mappedModels}}
{{/oneOf.isEmpty}}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use reqwest;

use crate::apis::ResponseContent;
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};

{{#operations}}
Expand Down
28 changes: 28 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
Expand Up @@ -17,6 +17,7 @@ use std::option::Option;
use hyper;
use futures::Future;

use crate::models;
use super::{Error, configuration};
use super::request as __internal_request;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::models;
#[serde(tag = "realtype")]
pub enum CreateStateRequest {
#[serde(rename="a-type")]
ObjA(Box<ObjA>),
ObjA(Box<models::ObjA>),
#[serde(rename="b-type")]
ObjB(Box<ObjB>),
ObjB(Box<models::ObjB>),
}

impl Default for CreateStateRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use crate::models;
#[serde(tag = "realtype")]
pub enum CustomOneOfArraySchemaInner {
#[serde(rename="a-type")]
ObjA(Box<ObjA>),
ObjA(Box<models::ObjA>),
#[serde(rename="b-type")]
ObjB(Box<ObjB>),
ObjB(Box<models::ObjB>),
#[serde(rename="c-type")]
ObjC(Box<ObjC>),
ObjC(Box<models::ObjC>),
}

impl Default for CustomOneOfArraySchemaInner {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::models;
#[serde(tag = "realtype")]
pub enum CustomOneOfSchema {
#[serde(rename="a-type")]
ObjA(Box<ObjA>),
ObjA(Box<models::ObjA>),
#[serde(rename="b-type")]
ObjB(Box<ObjB>),
ObjB(Box<models::ObjB>),
}

impl Default for CustomOneOfSchema {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use crate::models;
#[serde(tag = "realtype")]
pub enum GetState200Response {
#[serde(rename="a-type")]
ObjA(Box<ObjA>),
ObjA(Box<models::ObjA>),
#[serde(rename="b-type")]
ObjB(Box<ObjB>),
ObjB(Box<models::ObjB>),
#[serde(rename="d-type")]
ObjD(Box<ObjD>),
ObjD(Box<models::ObjD>),
}

impl Default for GetState200Response {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::option::Option;
use hyper;
use futures::Future;

use crate::models;
use super::{Error, configuration};
use super::request as __internal_request;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::option::Option;
use hyper;
use futures::Future;

use crate::models;
use super::{Error, configuration};
use super::request as __internal_request;

Expand Down
1 change: 1 addition & 0 deletions samples/client/others/rust/hyper/oneOf/src/apis/bar_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::option::Option;
use hyper;
use futures::Future;

use crate::models;
use super::{Error, configuration};
use super::request as __internal_request;

Expand Down
1 change: 1 addition & 0 deletions samples/client/others/rust/hyper/oneOf/src/apis/foo_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::option::Option;
use hyper;
use futures::Future;

use crate::models;
use super::{Error, configuration};
use super::request as __internal_request;

Expand Down
4 changes: 2 additions & 2 deletions samples/client/others/rust/hyper/oneOf/src/models/fruit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::models;
#[serde(tag = "fruitType")]
pub enum Fruit {
#[serde(rename="APPLE")]
Apple(Box<Apple>),
Apple(Box<models::Apple>),
#[serde(rename="BANANA")]
Banana(Box<Banana>),
Banana(Box<models::Banana>),
}

impl Default for Fruit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use reqwest;

use crate::apis::ResponseContent;
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use reqwest;

use crate::apis::ResponseContent;
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::models;
#[serde(tag = "realtype")]
pub enum CreateStateRequest {
#[serde(rename="a-type")]
ObjA(Box<ObjA>),
ObjA(Box<models::ObjA>),
#[serde(rename="b-type")]
ObjB(Box<ObjB>),
ObjB(Box<models::ObjB>),
}

impl Default for CreateStateRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use crate::models;
#[serde(tag = "realtype")]
pub enum CustomOneOfArraySchemaInner {
#[serde(rename="a-type")]
ObjA(Box<ObjA>),
ObjA(Box<models::ObjA>),
#[serde(rename="b-type")]
ObjB(Box<ObjB>),
ObjB(Box<models::ObjB>),
#[serde(rename="c-type")]
ObjC(Box<ObjC>),
ObjC(Box<models::ObjC>),
}

impl Default for CustomOneOfArraySchemaInner {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::models;
#[serde(tag = "realtype")]
pub enum CustomOneOfSchema {
#[serde(rename="a-type")]
ObjA(Box<ObjA>),
ObjA(Box<models::ObjA>),
#[serde(rename="b-type")]
ObjB(Box<ObjB>),
ObjB(Box<models::ObjB>),
}

impl Default for CustomOneOfSchema {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use crate::models;
#[serde(tag = "realtype")]
pub enum GetState200Response {
#[serde(rename="a-type")]
ObjA(Box<ObjA>),
ObjA(Box<models::ObjA>),
#[serde(rename="b-type")]
ObjB(Box<ObjB>),
ObjB(Box<models::ObjB>),
#[serde(rename="d-type")]
ObjD(Box<ObjD>),
ObjD(Box<models::ObjD>),
}

impl Default for GetState200Response {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use reqwest;

use crate::apis::ResponseContent;
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use reqwest;

use crate::apis::ResponseContent;
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use reqwest;

use crate::apis::ResponseContent;
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use reqwest;

use crate::apis::ResponseContent;
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};


Expand Down
4 changes: 2 additions & 2 deletions samples/client/others/rust/reqwest/oneOf/src/models/fruit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::models;
#[serde(tag = "fruitType")]
pub enum Fruit {
#[serde(rename="APPLE")]
Apple(Box<Apple>),
Apple(Box<models::Apple>),
#[serde(rename="BANANA")]
Banana(Box<Banana>),
Banana(Box<models::Banana>),
}

impl Default for Fruit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::option::Option;
use hyper;
use futures::Future;

use crate::models;
use super::{Error, configuration};
use super::request as __internal_request;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::option::Option;
use hyper;
use futures::Future;

use crate::models;
use super::{Error, configuration};
use super::request as __internal_request;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::option::Option;
use hyper;
use futures::Future;

use crate::models;
use super::{Error, configuration};
use super::request as __internal_request;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::option::Option;
use hyper;
use futures::Future;

use crate::models;
use super::{Error, configuration};
use super::request as __internal_request;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::option::Option;
use hyper;
use futures::Future;

use crate::models;
use super::{Error, configuration};
use super::request as __internal_request;

Expand Down
Loading

0 comments on commit 671003b

Please sign in to comment.