All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rust-server.lib.mustache Maven / Gradle / Ivy

#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)]

#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;

#[cfg(any(feature = "client", feature = "server"))]
#[macro_use]
extern crate hyper;
#[cfg(any(feature = "client", feature = "server"))]
#[macro_use]
extern crate url;

// Crates for conversion support
#[cfg(feature = "conversion")]
#[macro_use]
extern crate frunk_derives;
#[cfg(feature = "conversion")]
#[macro_use]
extern crate frunk_enum_derive;
#[cfg(feature = "conversion")]
extern crate frunk_core;

extern crate mime;
extern crate serde;
extern crate serde_json;
{{#usesXml}}extern crate serde_xml_rs;{{/usesXml}}
extern crate futures;
extern crate chrono;
extern crate swagger;
{{#apiUsesUuid}}
extern crate uuid;
{{/apiUsesUuid}}

use futures::Stream;
use std::io::Error;

#[allow(unused_imports)]
use std::collections::HashMap;

#[cfg(any(feature = "client", feature = "server"))]
mod mimetypes;

#[deprecated(note = "Import swagger-rs directly")]
pub use swagger::{ApiError, ContextWrapper};
#[deprecated(note = "Import futures directly")]
pub use futures::Future;

pub const BASE_PATH: &'static str = "{{{basePathWithoutHost}}}";
pub const API_VERSION: &'static str = "{{{appVersion}}}";

{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}
#[derive(Debug, PartialEq)]
pub enum {{{operationId}}}Response {
{{#responses}}
  {{#message}}
    /// {{{message}}}{{/message}}
    {{#vendorExtensions}}
    {{{x-responseId}}}
    {{/vendorExtensions}}
    {{^dataType}}
      {{#hasHeaders}}
    {
      {{/hasHeaders}}
    {{/dataType}}
    {{#dataType}}
      {{^hasHeaders}}
    ({{{dataType}}})
      {{/hasHeaders}}
      {{#hasHeaders}}
    {
        body: {{{dataType}}},
      {{/hasHeaders}}
    {{/dataType}}
    {{#headers}}
        {{{name}}}: {{{datatype}}},
      {{#-last}}
    }
      {{/-last}}
    {{/headers}}
    {{^-last}}
    ,
    {{/-last}}
{{/responses}}
}
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}

/// API
pub trait Api {
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}
{{#summary}}    /// {{{summary}}}{{/summary}}
    fn {{#vendorExtensions}}{{{operation_id}}}{{/vendorExtensions}}(&self{{#allParams}}, {{{paramName}}}: {{^required}}Option<{{/required}}{{#isListContainer}}&{{/isListContainer}}{{{dataType}}}{{^required}}>{{/required}}{{/allParams}}, context: &C) -> Box>;
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
}

/// API without a `Context`
pub trait ApiNoContext {
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}
{{#summary}}    /// {{{summary}}}{{/summary}}
    fn {{#vendorExtensions}}{{{operation_id}}}{{/vendorExtensions}}(&self{{#allParams}}, {{{paramName}}}: {{^required}}Option<{{/required}}{{#isListContainer}}&{{/isListContainer}}{{{dataType}}}{{^required}}>{{/required}}{{/allParams}}) -> Box>;
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
}

/// Trait to extend an API to make it easy to bind it to a context.
pub trait ContextWrapperExt<'a, C> where Self: Sized {
    /// Binds this API to a context.
    fn with_context(self: &'a Self, context: C) -> ContextWrapper<'a, Self, C>;
}

impl<'a, T: Api + Sized, C> ContextWrapperExt<'a, C> for T {
    fn with_context(self: &'a T, context: C) -> ContextWrapper<'a, T, C> {
         ContextWrapper::::new(self, context)
    }
}

impl<'a, T: Api, C> ApiNoContext for ContextWrapper<'a, T, C> {
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}
{{#summary}}    /// {{{summary}}}{{/summary}}
    fn {{#vendorExtensions}}{{{operation_id}}}{{/vendorExtensions}}(&self{{#allParams}}, {{{paramName}}}: {{^required}}Option<{{/required}}{{#isListContainer}}&{{/isListContainer}}{{{dataType}}}{{^required}}>{{/required}}{{/allParams}}) -> Box> {
        self.api().{{#vendorExtensions}}{{{operation_id}}}{{/vendorExtensions}}({{#allParams}}{{{paramName}}}, {{/allParams}}&self.context())
    }
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
}

#[cfg(feature = "client")]
pub mod client;

// Re-export Client as a top-level name
#[cfg(feature = "client")]
pub use self::client::Client;

#[cfg(feature = "server")]
pub mod server;

// Re-export router() as a top-level name
#[cfg(feature = "server")]
pub use self::server::Service;

pub mod models;




© 2015 - 2024 Weber Informatics LLC | Privacy Policy