Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless Eq and Hash derives #2108

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions crates/lgn-api-codegen/src/rust/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,6 @@ pub fn join_types(
}
}

#[allow(clippy::unnecessary_wraps)]
pub fn fmt_struct_derive(type_: &Option<Box<Type>>) -> ::askama::Result<String> {
Ok(match type_ {
Some(type_) if matches!(**type_, Type::Any) => {
"#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]"
}
_ => "#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]",
}
.to_string())
}

fn is_keyword(name: &str) -> bool {
KEYWORDS.contains(&name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod cars {

use lgn_online::codegen::Error;

#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct TestAdditionalPropertiesCompositeAny200Response {
#[serde(flatten)]
pub __additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
Expand All @@ -24,7 +24,7 @@ pub mod cars {
pub time: Option<u32>,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct TestAdditionalPropertiesCompositeSchema200Response {
#[serde(flatten)]
pub __additional_properties: std::collections::BTreeMap<String, super::components::Pet>,
Expand All @@ -38,7 +38,7 @@ pub mod cars {
pub time: Option<u32>,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum TestOneOf200Response {
#[serde(rename = "option1")]
Option1(super::components::Pet),
Expand Down Expand Up @@ -635,7 +635,7 @@ pub mod cars {

// Request type.

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq)]
pub struct TestHeadersRequest {
pub x_string_header: Option<String>,
pub x_bytes_header: Option<lgn_online::codegen::Bytes>,
Expand Down Expand Up @@ -814,7 +814,7 @@ pub mod cars {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
struct GetCarsQuery {
#[serde(rename = "other_query")]
other_query: String,
Expand All @@ -828,7 +828,7 @@ pub mod cars {

// Request type.

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq)]
pub struct GetCarsRequest {
pub space_id: String,
pub other_query: String,
Expand Down Expand Up @@ -885,7 +885,7 @@ pub mod cars {

// Request type.

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq)]
pub struct CreateCarRequest {
pub space_id: String,
pub span_id: Option<String>,
Expand Down Expand Up @@ -928,7 +928,7 @@ pub mod cars {

// Request type.

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq)]
pub struct GetCarRequest {
pub space_id: String,
pub car_id: i64,
Expand Down Expand Up @@ -993,7 +993,7 @@ pub mod cars {

// Request type.

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq)]
pub struct DeleteCarRequest {
pub space_id: String,
pub car_id: i64,
Expand Down Expand Up @@ -1045,7 +1045,7 @@ pub mod cars {

// Request type.

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq)]
pub struct TestBinaryRequest {
pub space_id: String,
pub body: lgn_online::codegen::Bytes,
Expand Down Expand Up @@ -2788,7 +2788,7 @@ pub mod cars {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
struct GetCarsQuery {
#[serde(rename = "other_query")]
other_query: String,
Expand Down Expand Up @@ -3659,14 +3659,14 @@ pub mod components {

use lgn_online::codegen::Error;

#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Alpha {
#[serde(rename = "beta")]
#[serde(skip_serializing_if = "Option::is_none")]
pub beta: Option<Beta>,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Beta(pub Vec<Gamma>);

impl From<Vec<Gamma>> for Beta {
Expand All @@ -3675,7 +3675,7 @@ pub mod components {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Car {
#[serde(rename = "code")]
pub code: u32,
Expand All @@ -3698,7 +3698,7 @@ pub mod components {
}

/// The car color.
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum CarColor {
#[serde(rename = "red")]
Red,
Expand Down Expand Up @@ -3764,7 +3764,7 @@ pub mod components {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Cars(pub Vec<Car>);

impl From<Vec<Car>> for Cars {
Expand All @@ -3773,13 +3773,13 @@ pub mod components {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum Gamma {
#[serde(rename = "option1")]
Option1(Box<Alpha>),
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Pet {
#[serde(rename = "name")]
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
6 changes: 3 additions & 3 deletions crates/lgn-api-codegen/src/rust/templates/client.rs.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use lgn_tracing::debug;
{% for (path, routes) in api.paths %}
{% for route in routes %}
{% if !route.parameters.query.is_empty() -%}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
struct {{ route.name|pascal_case }}Query {
{% for parameter in route.parameters.query -%}
#[serde(rename = "{{ parameter.name }}")]
Expand All @@ -25,7 +25,7 @@ use lgn_tracing::debug;
// Request type.
{% let request_type = "{}Request"|format(route.name|pascal_case) %}

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq)]
pub struct {{ request_type }} {
{% for parameter in route.parameters -%}
{%- if parameter.required -%}
Expand All @@ -46,7 +46,7 @@ use lgn_tracing::debug;

// Response type.
{% let response_type = "{}Response"|format(route.name|pascal_case) %}

#[derive(Debug)]
pub enum {{ response_type }} {
{% for (status_code, response) in route.responses -%}
Expand Down
8 changes: 4 additions & 4 deletions crates/lgn-api-codegen/src/rust/templates/models.rs.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use lgn_online::codegen::Error;
{% if let Some(description) = model.description %}/// {{ description }}{% endif -%}
{% match model.type_ %}
{% when Type::Enum with { variants } %}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum {{ model|fmt_model_name(ctx) }}
{
{%- for variant in variants -%}
Expand Down Expand Up @@ -63,7 +63,7 @@ use lgn_online::codegen::Error;
}
}
{% when Type::OneOf with { types } %}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum {{ model|fmt_model_name(ctx) }}
{
{%- for type_ in types -%}
Expand All @@ -72,7 +72,7 @@ use lgn_online::codegen::Error;
{%- endfor -%}
}
{% when Type::Struct with { fields, map } %}
{{ map|fmt_struct_derive }}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct {{ model|fmt_model_name(ctx) }} {
{% match map %}
{% when Some with (map) %}
Expand All @@ -92,7 +92,7 @@ use lgn_online::codegen::Error;
{% endfor %}
}
{% when t %}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct {{ model|fmt_model_name(ctx) }}(pub {{ t|fmt_type(ctx, module_path) }});

impl From<{{ t|fmt_type(ctx, module_path) }}> for {{ model|fmt_model_name(ctx) }} {
Expand Down
2 changes: 1 addition & 1 deletion crates/lgn-api-codegen/src/rust/templates/server.rs.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use lgn_tracing::error;
{% for (path, routes) in api.paths %}
{% for route in routes %}
{% if !route.parameters.query.is_empty() -%}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
struct {{ route.name|pascal_case }}Query {
{% for parameter in route.parameters.query -%}
#[serde(rename = "{{ parameter.name }}")]
Expand Down