-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schema): generating valid rust from schemas
It's very nice, even though there is some more work to be done here. It's just the beginning ... .
- Loading branch information
Showing
3 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
<% import util %>\ | ||
<%namespace name="lib" file="lib/lib.mako"/>\ | ||
<%namespace name="mutil" file="lib/util.mako"/>\ | ||
<%namespace name="schema" file="lib/schema.mako"/>\ | ||
<%block filter="util.rust_module_doc_comment">\ | ||
<%lib:docs />\ | ||
</%block> | ||
#![allow(non_snake_case)] | ||
extern crate cmn; | ||
extern crate "rustc-serialize" as rustc_serialize; | ||
extern crate "yup-oauth2" as oauth2; | ||
extern crate "yup-oauth2" as oauth2; | ||
use std::default::Default; | ||
use std::collections::HashMap; | ||
## SCHEMAS - normal ones | ||
% for s in schemas.values(): | ||
${schema.new(s)} | ||
% endfor | ||
## SCHEMAS - nested | ||
## some schemas are only used once and basically internal types. | ||
## We have to find them and process them as normal types | ||
% for s in util.iter_nested_types(schemas): | ||
${schema.new(s)} | ||
% endfor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<%! import util %>\ | ||
## Create new schema with everything. | ||
## 's' contains the schema structure from json to build | ||
<%def name="new(s)">\ | ||
<% assert s.type == "object" %>\ | ||
<%block filter="util.rust_doc_comment">\ | ||
${doc(s)}\ | ||
</%block> | ||
#[derive(RustcEncodable, RustcDecodable, Default, Clone)] | ||
pub struct ${s.id}\ | ||
% if 'properties' in s: | ||
{ | ||
% for pn, p in s.properties.iteritems(): | ||
${p.get('description', 'no description provided') | util.rust_doc_comment} | ||
pub ${util.mangle_ident(pn)}: ${util.to_rust_type(s.id, pn, p)}, | ||
% endfor | ||
} | ||
% else: | ||
; | ||
% endif | ||
</%def> | ||
|
||
<%def name="doc(s)">\ | ||
${s.get('description', 'There is no detailed description.')} | ||
</%def> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters