/// Creates Endpoint definition according to Swagger 2.0 specification
Creates Endpoint definition according to Swagger 2.0 specification
Creates Endpoint definition according to Swagger 2 . 0 specification
fn build_endpoint_definition(endpoint: &framework::Endpoint, context: &mut WalkContext) -> JsonValue {
    jsonway::object(|def| {
        // A list of tags for API documentation control. Tags can be used for logical grouping
        // of operations by resources or any other qualifier.
        // def.array("tags", |tags| { });
        if endpoint.summary.is_some() {
            // A short summary of what the operation does. For maximum readability in the swagger-ui,
            // this field SHOULD be less than 120 characters.
            def.set("summary", endpoint.summary.as_ref().unwrap().clone());
        }
        if endpoint.desc.is_some() {
            // A verbose explanation of the operation behavior.
            // GFM syntax can be used for rich text representation.
            def.set("description",  endpoint.desc.as_ref().unwrap().clone());
        }
        // Required. The list of possible responses as they are returned from executing this operation.
        def.object("responses",  |responses| {
            responses.object("200", |default| {
                // Required. A short description of the response.
                // GFM syntax can be used for rich text representation.
                default.set("description", "Default response".to_string());
                // A definition of the response structure. It can be a primitive, an array or an object.
                // If this field does not exist, it means no content is returned as part of the response.
                // As an extension to the Schema Object, its root type value may also be "file".
                // This SHOULD be accompanied by a relevant produces mime-type.
                default.object("schema", |schema| {});
                // A list of headers that are sent with the response.
                default.object("headers", |headers| {});
                // An example of the response message.
                default.object("examples", |examples| {});
            })
        });
        // TODO Implement the rest of the Swagger 2.0 spec
        // // External Documentation Object
        // // Additional external documentation for this operation.
        // def.object("externalDocs", |external_docs| {
        //     // A short description of the target documentation.
        //     // GFM syntax can be used for rich text representation.
        //     external_docs.set("description", "Description".to_string());
        //     //  Required. The URL for the target documentation. Value MUST be in the format of a URL.
        //     external_docs.set("url", "http://google.com".to_string());
        // });
        // // A friendly name for the operation. The id MUST be unique among all operations described
        // // in the API. Tools and libraries MAY use the operation id to uniquely identify an operation.
        // def.set("operationId", "OP".to_string());
        if endpoint.consumes.is_some() {
            // A list of MIME types the operation can consume.
            // This overrides the [consumes](#swaggerConsumes) definition at the Swagger Object.
            // An empty value MAY be used to clear the global definition.
            // Value MUST be as described under Mime Types.
            def.array("consumes", |consumes| {
                let consumes_spec = endpoint.consumes.as_ref().unwrap();
                for mime in consumes_spec.iter() {
                    consumes.push(mime.to_string())
                }
            });
        }
        if endpoint.produces.is_some() {
            // A list of MIME types the operation can produce.
            // This overrides the [produces](#swaggerProduces) definition at the Swagger Object.
            // An empty value MAY be used to clear the global definition.
            // Value MUST be as described under Mime Types.
            def.array("produces", |produces| {
                let produces_spec = endpoint.produces.as_ref().unwrap();
                for mime in produces_spec.iter() {
                    produces.push(mime.to_string())
                }
            });
        }
        // A list of parameters that are applicable for this operation.
        // If a parameter is already defined at the Path Item, the new definition will override it,
        // but can never remove it. The list MUST NOT include duplicated parameters.
        // A unique parameter is defined by a combination of a name and location.
        // The list can use the Reference Object to link to parameters that are
        // defined at the Swagger Object's parameters. There can be one "body" parameter at most.
        def.array("parameters", |parameters| {
            let params = extract_params(&endpoint.coercer, &endpoint.path);
            let mut final_params = vec![];
            for param in context.params.iter() {
                final_params.push(param.clone())
            }
            for param in params.iter() {
                final_params.push(param.clone())
            }
            match endpoint.method {
                method::Method::Post |
                method::Method::Put |
                method::Method::Patch => {
                    for param in final_params.iter_mut() {
                        match param.place {
                            Place::Query => param.place = Place::FormData,
                            _ => ()
                        }
                    }
                },
                _ => ()
            };
            parameters.map(final_params.iter(), |param| param.to_json());
        });
        // // The transfer protocol for the operation. Values MUST be from the list: "http", "https",
        // // "ws", "wss". The value overrides the Swagger Object schemes definition.
        // def.array("schemes", |schemes| {});
        // // Declares this operation to be deprecated. Usage of the declared operation should be refrained.
        // // Default value is false.
        // def.set("deprecated", false);
        // // A declaration of which security schemes are applied for this operation.
        // // The list of values describes alternative security schemes that can be used
        // // (that is, there is a logical OR between the security requirements).
        // // This definition overrides any declared top-level security.
        // // To remove a top-level security declaration, an empty array can be used.
        // def.array("security", |security| {});
    }).unwrap()
}
fn build_endpoint_definition ( endpoint : & framework :: Endpoint , context : & mut WalkContext ) -> JsonValue { jsonway :: object ( | def | { // A list of tags for API documentation control. Tags can be used for logical grouping // of operations by resources or any other qualifier. // def.array("tags", |tags| { }); if endpoint . summary . is_some ( ) { // A short summary of what the operation does. For maximum readability in the swagger-ui, // this field SHOULD be less than 120 characters. def . set ( " " , endpoint . summary . as_ref ( ) . unwrap ( ) . clone ( ) ) ; } if endpoint . desc . is_some ( ) { // A verbose explanation of the operation behavior. // GFM syntax can be used for rich text representation. def . set ( " " , endpoint . desc . as_ref ( ) . unwrap ( ) . clone ( ) ) ; } // Required. The list of possible responses as they are returned from executing this operation. def . object ( " " , | responses | { responses . object ( " " , | default | { // Required. A short description of the response. // GFM syntax can be used for rich text representation. default . set ( " " , " " . to_string ( ) ) ; // A definition of the response structure. It can be a primitive, an array or an object. // If this field does not exist, it means no content is returned as part of the response. // As an extension to the Schema Object, its root type value may also be "file". // This SHOULD be accompanied by a relevant produces mime-type. default . object ( " " , | schema | { } ) ; // A list of headers that are sent with the response. default . object ( " " , | headers | { } ) ; // An example of the response message. default . object ( " " , | examples | { } ) ; } ) } ) ; // TODO Implement the rest of the Swagger 2.0 spec // // External Documentation Object // // Additional external documentation for this operation. // def.object("externalDocs", |external_docs| { //     // A short description of the target documentation. //     // GFM syntax can be used for rich text representation. //     external_docs.set("description", "Description".to_string()); //     //  Required. The URL for the target documentation. Value MUST be in the format of a URL. //     external_docs.set("url", "http://google.com".to_string()); // }); // // A friendly name for the operation. The id MUST be unique among all operations described // // in the API. Tools and libraries MAY use the operation id to uniquely identify an operation. // def.set("operationId", "OP".to_string()); if endpoint . consumes . is_some ( ) { // A list of MIME types the operation can consume. // This overrides the [consumes](#swaggerConsumes) definition at the Swagger Object. // An empty value MAY be used to clear the global definition. // Value MUST be as described under Mime Types. def . array ( " " , | consumes | { let consumes_spec = endpoint . consumes . as_ref ( ) . unwrap ( ) ; for mime in consumes_spec . iter ( ) { consumes . push ( mime . to_string ( ) ) } } ) ; } if endpoint . produces . is_some ( ) { // A list of MIME types the operation can produce. // This overrides the [produces](#swaggerProduces) definition at the Swagger Object. // An empty value MAY be used to clear the global definition. // Value MUST be as described under Mime Types. def . array ( " " , | produces | { let produces_spec = endpoint . produces . as_ref ( ) . unwrap ( ) ; for mime in produces_spec . iter ( ) { produces . push ( mime . to_string ( ) ) } } ) ; } // A list of parameters that are applicable for this operation. // If a parameter is already defined at the Path Item, the new definition will override it, // but can never remove it. The list MUST NOT include duplicated parameters. // A unique parameter is defined by a combination of a name and location. // The list can use the Reference Object to link to parameters that are // defined at the Swagger Object's parameters. There can be one "body" parameter at most. def . array ( " " , | parameters | { let params = extract_params ( & endpoint . coercer , & endpoint . path ) ; let mut final_params = vec ! [ ] ; for param in context . params . iter ( ) { final_params . push ( param . clone ( ) ) } for param in params . iter ( ) { final_params . push ( param . clone ( ) ) } match endpoint . method { method :: Method :: Post | method :: Method :: Put | method :: Method :: Patch => { for param in final_params . iter_mut ( ) { match param . place { Place :: Query => param . place = Place :: FormData , _ => ( ) } } } , _ => ( ) } ; parameters . map ( final_params . iter ( ) , | param | param . to_json ( ) ) ; } ) ; // // The transfer protocol for the operation. Values MUST be from the list: "http", "https", // // "ws", "wss". The value overrides the Swagger Object schemes definition. // def.array("schemes", |schemes| {}); // // Declares this operation to be deprecated. Usage of the declared operation should be refrained. // // Default value is false. // def.set("deprecated", false); // // A declaration of which security schemes are applied for this operation. // // The list of values describes alternative security schemes that can be used // // (that is, there is a logical OR between the security requirements). // // This definition overrides any declared top-level security. // // To remove a top-level security declaration, an empty array can be used. // def.array("security", |security| {}); } ) . unwrap ( ) }
Creates Endpoint definition according to Swagger 2.0 specification
Creates Endpoint definition according to Swagger 2 . 0 specification
endpoint
&framework::Endpoint
context
&mut WalkContext