Skip to content

Commit

Permalink
Revert "fix broken imports in structs"
Browse files Browse the repository at this point in the history
This reverts commit 53d32d7.
  • Loading branch information
DDtKey committed Feb 21, 2024
1 parent 53d32d7 commit 70976e5
Show file tree
Hide file tree
Showing 235 changed files with 664 additions and 428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
public static final String PREFER_UNSIGNED_INT = "preferUnsignedInt";
public static final String BEST_FIT_INT = "bestFitInt";

private static final String MODELS_MODULE_PREFIX = "crate::models::";

protected String packageName = "openapi";
protected String packageVersion = "1.0.0";
protected String apiDocPath = "docs/";
Expand Down Expand Up @@ -233,8 +231,8 @@ public CodegenModel fromModel(String name, Schema model) {
CodegenProperty oneOf = oneOfs.get(i);
Schema schema = schemas.get(i);
String aliasType = getTypeDeclaration(schema);
if (aliasType.startsWith(MODELS_MODULE_PREFIX)) {
aliasType = aliasType.substring(MODELS_MODULE_PREFIX.length());
if (aliasType.startsWith("models::")) {
aliasType = aliasType.substring("models::".length());
}
if (oneOf.getRef() != null) {
oneOf.setBaseName(mappedNameByRef.get(oneOf.getRef()));
Expand Down Expand Up @@ -439,65 +437,6 @@ public String modelDocFileFolder() {
return (outputFolder + "/" + modelDocPath).replace('/', File.separatorChar);
}

@Override
public String getTypeDeclaration(Schema p) {
Schema unaliasSchema = unaliasSchema(p);
if (ModelUtils.isArraySchema(unaliasSchema)) {
ArraySchema ap = (ArraySchema) unaliasSchema;
Schema inner = ap.getItems();
if (inner == null) {
LOGGER.warn("{}(array property) does not have a proper inner type defined.Default to string",
ap.getName());
inner = new StringSchema().description("TODO default missing array inner type to string");
}
return typeMapping.get("array") + "<" + getTypeDeclaration(inner) + ">";
} else if (ModelUtils.isMapSchema(unaliasSchema)) {
Schema inner = ModelUtils.getAdditionalProperties(unaliasSchema);
if (inner == null) {
LOGGER.warn("{}(map property) does not have a proper inner type defined. Default to string", unaliasSchema.getName());
inner = new StringSchema().description("TODO default missing map inner type to string");
}
String innerType = getTypeDeclaration(inner);
StringBuilder typeDeclaration = new StringBuilder(typeMapping.get("map")).append("<").append(typeMapping.get("string")).append(", ");
typeDeclaration.append(innerType).append(">");
return typeDeclaration.toString();
} else if (!org.apache.commons.lang3.StringUtils.isEmpty(p.get$ref())) {
String datatype;
try {
datatype = p.get$ref();

if (datatype.indexOf("#/components/schemas/") == 0) {
datatype = toModelName(datatype.substring("#/components/schemas/".length()));
datatype = MODELS_MODULE_PREFIX + datatype;
}
} catch (Exception e) {
LOGGER.warn("Error obtaining the datatype from schema (model):{}. Datatype default to Object", p);
datatype = "Object";
LOGGER.error(e.getMessage(), e);
}
return datatype;
}

// Not using the supertype invocation, because we want to UpperCamelize
// the type.
String schemaType = getSchemaType(unaliasSchema);
if (typeMapping.containsKey(schemaType)) {
return typeMapping.get(schemaType);
}

if (typeMapping.containsValue(schemaType)) {
return schemaType;
}

if (languageSpecificPrimitives.contains(schemaType)) {
return schemaType;
}

// return fully-qualified model name
// crate::models::{{classnameFile}}::{{classname}}
return MODELS_MODULE_PREFIX + toModelName(schemaType);
}

@Override
public String getSchemaType(Schema p) {
String schemaType = super.getSchemaType(p);
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::models;

{{>partial_header}}
{{#models}}
{{#model}}
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ No authorization required

## get_state

> crate::models::GetState200Response get_state()
> models::GetState200Response get_state()

### Parameters
Expand All @@ -48,7 +48,7 @@ This endpoint does not need any parameter.

### Return type

[**crate::models::GetState200Response**](getState_200_response.md)
[**models::GetState200Response**](getState_200_response.md)

### Authorization

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 All @@ -36,7 +37,7 @@ impl<C: hyper::client::connect::Connect> DefaultApiClient<C>

pub trait DefaultApi {
fn create_state(&self, create_state_request: crate::models::CreateStateRequest) -> Pin<Box<dyn Future<Output = Result<(), Error>>>>;
fn get_state(&self, ) -> Pin<Box<dyn Future<Output = Result<crate::models::GetState200Response, Error>>>>;
fn get_state(&self, ) -> Pin<Box<dyn Future<Output = Result<models::GetState200Response, Error>>>>;
}

impl<C: hyper::client::connect::Connect>DefaultApi for DefaultApiClient<C>
Expand All @@ -52,7 +53,7 @@ impl<C: hyper::client::connect::Connect>DefaultApi for DefaultApiClient<C>
}

#[allow(unused_mut)]
fn get_state(&self, ) -> Pin<Box<dyn Future<Output = Result<crate::models::GetState200Response, Error>>>> {
fn get_state(&self, ) -> Pin<Box<dyn Future<Output = Result<models::GetState200Response, Error>>>> {
let mut req = __internal_request::Request::new(hyper::Method::GET, "/state".to_string())
;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::models;

/*
* oneOf test
*
Expand All @@ -14,9 +16,9 @@
#[serde(tag = "realtype")]
pub enum CreateStateRequest {
#[serde(rename="a-type")]
ObjA(Box<crate::models::ObjA>),
ObjA(Box<models::ObjA>),
#[serde(rename="b-type")]
ObjB(Box<crate::models::ObjB>),
ObjB(Box<models::ObjB>),
}

impl Default for CreateStateRequest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::models;

/*
* oneOf test
*
Expand All @@ -14,11 +16,11 @@
#[serde(tag = "realtype")]
pub enum CustomOneOfArraySchemaInner {
#[serde(rename="a-type")]
ObjA(Box<crate::models::ObjA>),
ObjA(Box<models::ObjA>),
#[serde(rename="b-type")]
ObjB(Box<crate::models::ObjB>),
ObjB(Box<models::ObjB>),
#[serde(rename="c-type")]
ObjC(Box<crate::models::ObjC>),
ObjC(Box<models::ObjC>),
}

impl Default for CustomOneOfArraySchemaInner {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::models;

/*
* oneOf test
*
Expand All @@ -14,9 +16,9 @@
#[serde(tag = "realtype")]
pub enum CustomOneOfSchema {
#[serde(rename="a-type")]
ObjA(Box<crate::models::ObjA>),
ObjA(Box<models::ObjA>),
#[serde(rename="b-type")]
ObjB(Box<crate::models::ObjB>),
ObjB(Box<models::ObjB>),
}

impl Default for CustomOneOfSchema {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::models;

/*
* oneOf test
*
Expand All @@ -14,11 +16,11 @@
#[serde(tag = "realtype")]
pub enum GetState200Response {
#[serde(rename="a-type")]
ObjA(Box<crate::models::ObjA>),
ObjA(Box<models::ObjA>),
#[serde(rename="b-type")]
ObjB(Box<crate::models::ObjB>),
ObjB(Box<models::ObjB>),
#[serde(rename="d-type")]
ObjD(Box<crate::models::ObjD>),
ObjD(Box<models::ObjD>),
}

impl Default for GetState200Response {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::models;

/*
* oneOf test
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::models;

/*
* oneOf test
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::models;

/*
* oneOf test
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::models;

/*
* oneOf test
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Method | HTTP request | Description

## endpoint_get

> crate::models::EmptyObject endpoint_get()
> models::EmptyObject endpoint_get()
Get endpoint

### Parameters
Expand All @@ -19,7 +19,7 @@ This endpoint does not need any parameter.

### Return type

[**crate::models::EmptyObject**](EmptyObject.md)
[**models::EmptyObject**](EmptyObject.md)

### Authorization

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 All @@ -35,13 +36,13 @@ impl<C: hyper::client::connect::Connect> DefaultApiClient<C>
}

pub trait DefaultApi {
fn endpoint_get(&self, ) -> Pin<Box<dyn Future<Output = Result<crate::models::EmptyObject, Error>>>>;
fn endpoint_get(&self, ) -> Pin<Box<dyn Future<Output = Result<models::EmptyObject, Error>>>>;
}

impl<C: hyper::client::connect::Connect>DefaultApi for DefaultApiClient<C>
where C: Clone + std::marker::Send + Sync {
#[allow(unused_mut)]
fn endpoint_get(&self, ) -> Pin<Box<dyn Future<Output = Result<crate::models::EmptyObject, Error>>>> {
fn endpoint_get(&self, ) -> Pin<Box<dyn Future<Output = Result<models::EmptyObject, Error>>>> {
let mut req = __internal_request::Request::new(hyper::Method::GET, "/endpoint".to_string())
;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::models;

/*
* EmptyObject
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Method | HTTP request | Description

## root_get

> crate::models::Fruit root_get()
> models::Fruit root_get()

### Parameters
Expand All @@ -20,7 +20,7 @@ This endpoint does not need any parameter.

### Return type

[**crate::models::Fruit**](fruit.md)
[**models::Fruit**](fruit.md)

### Authorization

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

| Name | Description |
|---- | -----|
| Vec<crate::models::Grape> | |
| std::collections::HashMap<String, crate::models::Apple> | |
| Vec<models::Grape> | |
| std::collections::HashMap<String, models::Apple> | |

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

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 All @@ -35,14 +36,14 @@ impl<C: hyper::client::connect::Connect> DefaultApiClient<C>
}

pub trait DefaultApi {
fn root_get(&self, ) -> Pin<Box<dyn Future<Output = Result<crate::models::Fruit, Error>>>>;
fn root_get(&self, ) -> Pin<Box<dyn Future<Output = Result<models::Fruit, Error>>>>;
fn test(&self, body: Option<serde_json::Value>) -> Pin<Box<dyn Future<Output = Result<(), Error>>>>;
}

impl<C: hyper::client::connect::Connect>DefaultApi for DefaultApiClient<C>
where C: Clone + std::marker::Send + Sync {
#[allow(unused_mut)]
fn root_get(&self, ) -> Pin<Box<dyn Future<Output = Result<crate::models::Fruit, Error>>>> {
fn root_get(&self, ) -> Pin<Box<dyn Future<Output = Result<models::Fruit, Error>>>> {
let mut req = __internal_request::Request::new(hyper::Method::GET, "/".to_string())
;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::models;

/*
* fruity
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::models;

/*
* fruity
*
Expand All @@ -14,13 +16,13 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Fruit {
std::collections::HashMap<String, crate::models::Apple>(Box<std::collections::HashMap<String, crate::models::Apple>>),
Vec<crate::models::Grape>(Box<Vec<crate::models::Grape>>),
Apples(Box<std::collections::HashMap<String, models::Apple>>),
Grapes(Box<Vec<models::Grape>>),
}

impl Default for Fruit {
fn default() -> Self {
Self::std::collections::HashMap<String, crate::models::Apple>(Box::default())
Self::Apples(Box::default())
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::models;

/*
* fruity
*
Expand Down

0 comments on commit 70976e5

Please sign in to comment.