Skip to content

Commit

Permalink
Replace svix-lib-rust template with rust example template (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte authored Mar 3, 2025
1 parent be91d49 commit 7964c37
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 181 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
{#
This example template is a simplified version of the one we use in
https://github.com/svix/svix-webhooks
It currently depends on the (non-generated) `crate::error::Result`,
`crate::Configuration` and `crate::request::Request`
A PR to make it more generic (e.g. use reqwest directly) would be welcome
-#}
// this file is @generated
{% set resource_type_name = resource.name | to_upper_camel_case -%}

use crate::{
Expand All @@ -8,25 +18,12 @@ use crate::{

{% for op in resource.operations -%}
{% if op | has_query_or_header_params %}
{% if not op | has_required_query_or_header_params -%}
#[derive(Default)]
{% endif -%}
pub struct {{ resource_type_name }}{{ op.name | to_upper_camel_case }}Options {
{% for p in op.query_params -%}
{% if p.type.is_datetime() -%}
{% set ty = "String" -%}
{% else -%}
{% set ty = p.type.to_rust() -%}
{% endif -%}
{% set ty = p.type.to_rust() -%}
{% if not p.required %}{% set ty %}Option<{{ ty }}>{% endset %}{% endif %}
{% if p.description is defined -%}
{{ p.description | to_doc_comment(style="rust") }}
{# we currently use String for date-time params, for backwards compat -#}
{# document the format so it's not _that_ awkward -#}
{% if p.type.is_datetime() -%}
///
/// RFC3339 date string.
{% endif -%}
{% endif -%}
pub {{ p.name | to_snake_case }}: {{ ty }},
{% endfor -%}
Expand Down Expand Up @@ -95,11 +92,6 @@ impl<'a> {{ resource_type_name }}<'a> {
;
{% endif -%}

{% if has_header_params -%}
{# unpack PostOptions -#}
let PostOptions { idempotency_key } = options.unwrap_or_default();
{% endif -%}

{# make the request #}
crate::request::Request::new(http1::Method::{{ op.method | upper }}, "{{ op.path }}")

Expand Down Expand Up @@ -131,15 +123,4 @@ impl<'a> {{ resource_type_name }}<'a> {
.execute(self.cfg)
.await
}

{% set extra_path -%}
api_extra/{{ resource.name | to_snake_case }}_{{ op.name | to_snake_case }}.rs
{%- endset -%}
{% include extra_path ignore missing %}
{% endfor %}
}

{% set extra_path -%}
api_extra/{{ resource.name | to_snake_case }}.rs
{%- endset -%}
{% include extra_path ignore missing %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// this file is @generated
{% for resource in api.resources -%}
mod {{ resource.name | to_snake_case }};
{% endfor %}
Expand All @@ -8,7 +9,7 @@ pub use self::{
{{ resource.name | to_snake_case }}::{
{{ resource_type_name }},
{% for op in resource.operations -%}
{% if op.query_params | length > 0 -%}
{% if op | has_query_or_header_params -%}
{{ resource_type_name }}{{ op.name | to_upper_camel_case }}Options,
{% endif -%}
{% endfor -%}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@ use std::fmt;
use serde::{Deserialize, Serialize};

{{ doc_comment }}
#[derive(
Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize,
)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum {{ type.name | to_upper_camel_case }} {
{% for value in type.values -%}
{% if loop.first -%}
#[default]
{% endif -%}
#[serde(rename = "{{ value }}")]
{{ value | to_upper_camel_case }},
{% endfor -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::{
};

{{ doc_comment }}
#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct {{ type.name | to_upper_camel_case }} {
{% for field in type.fields %}
{% if field.description is defined -%}
Expand Down
16 changes: 0 additions & 16 deletions templates/svix-lib-rust/api_extra/application_create.rs

This file was deleted.

33 changes: 0 additions & 33 deletions templates/svix-lib-rust/api_extra/message.rs

This file was deleted.

This file was deleted.

54 changes: 0 additions & 54 deletions templates/svix-lib-rust/api_extra/message_expunge_content.rs

This file was deleted.

0 comments on commit 7964c37

Please sign in to comment.