Skip to content

Commit

Permalink
fix use
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Nov 10, 2024
1 parent c68c07b commit 4ab0cac
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 41 deletions.
25 changes: 3 additions & 22 deletions src/Generator/Rust.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ protected function writeStruct(Code\Name $name, array $properties, ?string $exte

protected function writeMap(Code\Name $name, string $type, MapDefinitionType $origin): string
{
return 'pub type ' . $name->getClass() . ' = HashMap<String, ' . $type . '>;' . "\n";
return 'pub type ' . $name->getClass() . ' = std::collections::HashMap<String, ' . $type . '>;' . "\n";
}

protected function writeArray(Code\Name $name, string $type, ArrayDefinitionType $origin): string
{
return 'pub type ' . $name->getClass() . ' = LinkedList<' . $type . '>;' . "\n";
return 'pub type ' . $name->getClass() . ' = std::collections::LinkedList<' . $type . '>;' . "\n";
}

protected function writeHeader(DefinitionTypeAbstract $origin, Code\Name $className): string
Expand Down Expand Up @@ -113,26 +113,7 @@ protected function writeHeader(DefinitionTypeAbstract $origin, Code\Name $classN
private function getImports(DefinitionTypeAbstract $origin): array
{
$imports = [];

if ($origin instanceof StructDefinitionType) {
$imports[] = 'use serde::{Serialize, Deserialize};';
}

if (TypeUtil::contains($origin, MapDefinitionType::class)) {
$imports[] = 'use std::collections::HashMap;';
}

if (TypeUtil::contains($origin, StringPropertyType::class, Format::DATE)) {
$imports[] = 'use chrono::NaiveDate;';
}

if (TypeUtil::contains($origin, StringPropertyType::class, Format::DATETIME)) {
$imports[] = 'use chrono::NaiveDateTime;';
}

if (TypeUtil::contains($origin, StringPropertyType::class, Format::TIME)) {
$imports[] = 'use chrono::NaiveTime;';
}
$imports[] = 'use serde::{Serialize, Deserialize};';

$refs = TypeUtil::findRefs($origin);
foreach ($refs as $ref) {
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/Type/Rust.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getContentType(ContentType $contentType, int $context): string
{
return match ($contentType->getShape()) {
ContentType::BINARY => 'Bytes',
ContentType::FORM => 'HashMap<string, string>',
ContentType::FORM => 'std::collections::HashMap<string, string>',
ContentType::JSON => 'serde_json::Value',
ContentType::MULTIPART => $this->getString(),
ContentType::TEXT, ContentType::XML => $this->getString(),
Expand Down Expand Up @@ -85,7 +85,7 @@ protected function getArray(string $type): string

protected function getMap(string $type): string
{
return 'HashMap<String, ' . $type . '>';
return 'std::collections::HashMap<String, ' . $type . '>';
}

protected function getGroup(string $type): string
Expand Down
2 changes: 1 addition & 1 deletion tests/Generator/resource/rust/complex/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct Operation {
_return: Option<Response>,

#[serde(rename = "arguments")]
arguments: Option<HashMap<String, Argument>>,
arguments: Option<std::collections::HashMap<String, Argument>>,

#[serde(rename = "throws")]
throws: Option<Vec<Response>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct ReferencePropertyType {
target: Option<String>,

#[serde(rename = "template")]
template: Option<HashMap<String, String>>,
template: Option<std::collections::HashMap<String, String>>,

}

Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ pub struct StructDefinitionType {
base: Option<bool>,

#[serde(rename = "properties")]
properties: Option<HashMap<String, PropertyType>>,
properties: Option<std::collections::HashMap<String, PropertyType>>,

#[serde(rename = "discriminator")]
discriminator: Option<String>,

#[serde(rename = "mapping")]
mapping: Option<HashMap<String, String>>,
mapping: Option<std::collections::HashMap<String, String>>,

}

6 changes: 3 additions & 3 deletions tests/Generator/resource/rust/complex/type_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use operation::Operation;
#[derive(Serialize, Deserialize)]
pub struct TypeAPI {
#[serde(rename = "import")]
import: Option<HashMap<String, String>>,
import: Option<std::collections::HashMap<String, String>>,

#[serde(rename = "definitions")]
definitions: Option<HashMap<String, DefinitionType>>,
definitions: Option<std::collections::HashMap<String, DefinitionType>>,

#[serde(rename = "root")]
root: Option<String>,
Expand All @@ -23,7 +23,7 @@ pub struct TypeAPI {
security: Option<Security>,

#[serde(rename = "operations")]
operations: Option<HashMap<String, Operation>>,
operations: Option<std::collections::HashMap<String, Operation>>,

}

4 changes: 2 additions & 2 deletions tests/Generator/resource/rust/complex/type_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use definition_type::DefinitionType;
#[derive(Serialize, Deserialize)]
pub struct TypeSchema {
#[serde(rename = "import")]
import: Option<HashMap<String, String>>,
import: Option<std::collections::HashMap<String, String>>,

#[serde(rename = "definitions")]
definitions: Option<HashMap<String, DefinitionType>>,
definitions: Option<std::collections::HashMap<String, DefinitionType>>,

#[serde(rename = "root")]
root: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions tests/Generator/resource/rust/default/meta.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use serde::{Serialize, Deserialize};

pub type Meta = HashMap<String, String>;
pub type Meta = std::collections::HashMap<String, String>;

9 changes: 3 additions & 6 deletions tests/Generator/resource/rust/default/news.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use serde::{Serialize, Deserialize};
use chrono::NaiveDate;
use chrono::NaiveDateTime;
use chrono::NaiveTime;
use meta::Meta;
use author::Author;

Expand All @@ -12,13 +9,13 @@ pub struct News {
config: Option<Meta>,

#[serde(rename = "inlineConfig")]
inline_config: Option<HashMap<String, String>>,
inline_config: Option<std::collections::HashMap<String, String>>,

#[serde(rename = "mapTags")]
map_tags: Option<HashMap<String, String>>,
map_tags: Option<std::collections::HashMap<String, String>>,

#[serde(rename = "mapReceiver")]
map_receiver: Option<HashMap<String, Author>>,
map_receiver: Option<std::collections::HashMap<String, Author>>,

#[serde(rename = "tags")]
tags: Option<Vec<String>>,
Expand Down

0 comments on commit 4ab0cac

Please sign in to comment.