[][src]Trait paperclip::v2::codegen::Emitter

pub trait Emitter: Sized {
    type Definition: Schema + Debug;
    fn state(&self) -> &EmitterState;

    fn def_ns_name<'a>(
        &self,
        def: &'a Self::Definition
    ) -> Result<Box<dyn Iterator<Item = String> + 'a>, Error> { ... }
fn def_name(&self, def: &Self::Definition) -> Result<String, Error> { ... }
fn def_anon_name(
        &self,
        def: &Self::Definition,
        parents: &[&str]
    ) -> Option<String> { ... }
fn enum_variant(
        &self,
        def: &Self::Definition,
        value: &Value
    ) -> Option<ObjectVariant> { ... }
fn def_mod_path(&self, def: &Self::Definition) -> Result<PathBuf, Error> { ... }
fn unknown_op_mod_path(
        &self,
        path: &str,
        method: HttpMethod,
        op: &ResolvableOperation<Self::Definition>
    ) -> Result<PathBuf, Error> { ... }
fn unknown_op_object(
        &self,
        path: &str,
        method: HttpMethod,
        op: &ResolvableOperation<Self::Definition>
    ) -> Result<ApiObject, Error> { ... }
fn generate(
        &self,
        api: &ResolvableApi<Self::Definition>
    ) -> Result<(), Error> { ... }
fn build_def<'a>(
        &self,
        def: &Self::Definition,
        ctx: DefinitionContext<'a>
    ) -> Result<EmittedUnit, Error> { ... } }

Emitter represents the interface for generating the relevant modules, API object definitions and the associated calls.

Associated Types

type Definition: Schema + Debug

The associated Schema implementor.

Loading content...

Required methods

fn state(&self) -> &EmitterState

Returns a reference to the underlying state.

Loading content...

Provided methods

fn def_ns_name<'a>(
    &self,
    def: &'a Self::Definition
) -> Result<Box<dyn Iterator<Item = String> + 'a>, Error>

Returns an iterator of path components for the given definition.

NOTE: All components are snake_cased (including the definition name).

fn def_name(&self, def: &Self::Definition) -> Result<String, Error>

Returns the CamelCase name for the given definition.

fn def_anon_name(
    &self,
    def: &Self::Definition,
    parents: &[&str]
) -> Option<String>

Returns the CamelCase name for some definition based on its parent names. This is called whenever a definition doesn't have a name (i.e., through $ref) and we have to generate it.

fn enum_variant(
    &self,
    def: &Self::Definition,
    value: &Value
) -> Option<ObjectVariant>

Returns the enum variant of a possible value in the given definition.

fn def_mod_path(&self, def: &Self::Definition) -> Result<PathBuf, Error>

Returns the module path (from working directory) for the given definition.

NOTE: This should set .rs extension to the leaf path component.

fn unknown_op_mod_path(
    &self,
    path: &str,
    method: HttpMethod,
    op: &ResolvableOperation<Self::Definition>
) -> Result<PathBuf, Error>

Called whenever we encounter an operation that can't be added to any modules. By default, this returns miscellaneous.rs module in root.

NOTE: This should set .rs extension to the leaf path component.

fn unknown_op_object(
    &self,
    path: &str,
    method: HttpMethod,
    op: &ResolvableOperation<Self::Definition>
) -> Result<ApiObject, Error>

Called whenever we don't have an object for the module path returned by Emitter::unknown_op_mod_path method. By default, this returns an object (named Miscellaneous) representing an unit struct.

NOTE: Only the name and description fields can be relied upon when creating ApiObject. Others may be overridden.

fn generate(&self, api: &ResolvableApi<Self::Definition>) -> Result<(), Error>

Entrypoint for emitter. Given an API spec, generate code inside Rust modules in the configured working directory.

NOTE: Not meant to be overridden.

fn build_def<'a>(
    &self,
    def: &Self::Definition,
    ctx: DefinitionContext<'a>
) -> Result<EmittedUnit, Error>

Builds a schema. This resolves type aliases to known types and defines/reuses types based on the given context.

NOTE: Not meant to be overridden.

Loading content...

Implementors

impl<S: Schema + Debug> Emitter for DefaultEmitter<S>[src]

type Definition = S

Loading content...