├── .gitignore ├── .travis.yml ├── Cargo.toml ├── LICENSE-MIT ├── README.md ├── src ├── derive_struct.rs ├── derive_enum.rs └── lib.rs ├── tests └── typescript.rs └── LICENSE-APACHE /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /target 3 | **/*.rs.bk 4 | Cargo.lock 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | script: cargo test --all 3 | rust: 4 | - stable 5 | - beta 6 | - nightly 7 | matrix: 8 | allow_failures: 9 | - rust: nightly 10 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasm-typescript-definition" 3 | version = "0.1.0" 4 | description = "serde support for exporting Typescript definitions using wasm-bindgen" 5 | readme = "README.md" 6 | authors = ["Tim Ryan ", "Sam Rijs "] 7 | license = "MIT/Apache-2.0" 8 | repository = "https://github.com/tcr/wasm-typescript-definition" 9 | 10 | [lib] 11 | proc-macro = true 12 | 13 | [dependencies] 14 | quote = "0.5" 15 | serde_derive_internals = "0.23" 16 | syn = "=0.13" 17 | serde = "1" 18 | wasm-bindgen = "0.2" 19 | 20 | [dev-dependencies] 21 | serde_derive = "1" 22 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Sam Rijs 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wasm-typescript-definition 2 | 3 | Exports serde-serializable structs and enums to Typescript definitions when used with wasm-bindgen. 4 | 5 | ```typescript 6 | #[derive(Serialize, TypescriptDefinition)] 7 | enum Enum { 8 | #[allow(unused)] 9 | V1 { 10 | #[serde(rename = "Foo")] 11 | foo: bool, 12 | }, 13 | #[allow(unused)] 14 | V2 { 15 | #[serde(rename = "Bar")] 16 | bar: i64, 17 | #[serde(rename = "Baz")] 18 | baz: u64, 19 | }, 20 | #[allow(unused)] 21 | V3 { 22 | #[serde(rename = "Quux")] 23 | quux: String, 24 | }, 25 | } 26 | ``` 27 | 28 | With the patched version of wasm-bindgen that supports typescript_custom_section (TODO), this will output in your `.d.ts` definition file: 29 | 30 | ```typescript 31 | export type Enum = 32 | | {"tag": "V1", "fields": { "Foo": boolean, }, } 33 | | {"tag": "V2", "fields": { "Bar": number, "Baz": number, }, } 34 | | {"tag": "V3", "fields": { "Quux": string, }, } 35 | ; 36 | ``` 37 | 38 | ## Credit 39 | 40 | Forked from [`rust-serde-schema` by @srijs](https://github.com/srijs/rust-serde-schema?files=1). 41 | 42 | ## License 43 | 44 | MIT or Apache-2.0, at your option. 45 | -------------------------------------------------------------------------------- /src/derive_struct.rs: -------------------------------------------------------------------------------- 1 | use quote; 2 | use serde_derive_internals::{ast, attr}; 3 | use type_to_ts; 4 | use collapse_list_bracket; 5 | use collapse_list_brace; 6 | use super::{derive_element, derive_field}; 7 | 8 | pub fn derive_struct<'a>( 9 | style: ast::Style, 10 | fields: Vec>, 11 | attr_container: &attr::Container, 12 | ) -> quote::Tokens { 13 | let tokens = match style { 14 | ast::Style::Struct => derive_struct_named_fields(fields, attr_container), 15 | ast::Style::Newtype => derive_struct_newtype(fields, attr_container), 16 | ast::Style::Tuple => derive_struct_tuple(fields, attr_container), 17 | ast::Style::Unit => derive_struct_unit(attr_container), 18 | }; 19 | 20 | tokens 21 | } 22 | 23 | fn derive_struct_newtype<'a>( 24 | fields: Vec>, 25 | _attr_container: &attr::Container, 26 | ) -> quote::Tokens { 27 | derive_element(0, 0, &fields[0]) 28 | } 29 | 30 | fn derive_struct_unit(_attr_container: &attr::Container) -> quote::Tokens { 31 | quote!{ 32 | {} 33 | } 34 | } 35 | 36 | fn derive_struct_named_fields<'a>( 37 | fields: Vec>, 38 | _attr_container: &attr::Container, 39 | ) -> quote::Tokens { 40 | collapse_list_brace(fields.into_iter().enumerate() 41 | .map(|(field_idx, field)| derive_field(0, field_idx, &field)) 42 | .collect::>()) 43 | } 44 | 45 | fn derive_struct_tuple<'a>( 46 | fields: Vec>, 47 | _attr_container: &attr::Container, 48 | ) -> quote::Tokens { 49 | collapse_list_bracket(fields.into_iter() 50 | .map(|field| type_to_ts(field.ty)) 51 | .collect::>()) 52 | } 53 | -------------------------------------------------------------------------------- /src/derive_enum.rs: -------------------------------------------------------------------------------- 1 | use quote; 2 | use serde_derive_internals::{ast, attr}; 3 | use collapse_list_bracket; 4 | use collapse_list_brace; 5 | use type_to_ts; 6 | use super::{derive_element, derive_field}; 7 | 8 | pub fn derive_enum<'a>( 9 | variants: Vec>, 10 | _attr_container: &attr::Container, 11 | ) -> quote::Tokens { 12 | let tokens = variants.into_iter().enumerate() 13 | .map(|(variant_idx, variant)| { 14 | let variant_name = variant.attrs.name().serialize_name(); 15 | match variant.style { 16 | ast::Style::Struct => { 17 | derive_struct_variant(&variant_name, variant_idx, &variant.fields) 18 | } 19 | ast::Style::Newtype => derive_newtype_variant(&variant_name, variant_idx, &variant.fields[0]), 20 | ast::Style::Tuple => derive_tuple_variant(&variant_name, variant_idx, &variant.fields), 21 | ast::Style::Unit => derive_unit_variant(&variant_name), 22 | } 23 | }) 24 | .fold(quote!{}, |mut agg, tokens| { agg.append_all(tokens); agg }); 25 | 26 | tokens 27 | } 28 | 29 | fn derive_unit_variant<'a>(variant_name: &str) -> quote::Tokens { 30 | quote!{ 31 | | { "tag": #variant_name, } 32 | } 33 | } 34 | 35 | fn derive_newtype_variant<'a>( 36 | variant_name: &str, _variant_idx: usize, 37 | field: &ast::Field<'a> 38 | ) -> quote::Tokens { 39 | let ty = type_to_ts(&field.ty); 40 | quote!{ 41 | | { "tag": #variant_name, "fields": #ty, } 42 | } 43 | } 44 | 45 | fn derive_struct_variant<'a>( 46 | variant_name: &str, 47 | variant_idx: usize, 48 | fields: &Vec>, 49 | ) -> quote::Tokens { 50 | let contents = collapse_list_brace(fields.into_iter().enumerate() 51 | .map(|(field_idx, field)| derive_field(variant_idx, field_idx, field)) 52 | .collect::>()); 53 | quote!{ 54 | | { "tag": #variant_name, "fields": #contents, } 55 | } 56 | } 57 | 58 | fn derive_tuple_variant<'a>( 59 | variant_name: &str, 60 | _variant_idx: usize, 61 | fields: &Vec>, 62 | ) -> quote::Tokens { 63 | let contents = collapse_list_bracket(fields.into_iter().enumerate() 64 | .map(|(element_idx, field)| derive_element(0, element_idx, &field)) 65 | .collect::>()); 66 | quote!{ 67 | | {"tag": #variant_name, "fields": #contents, } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate proc_macro; 2 | #[macro_use] 3 | extern crate quote; 4 | extern crate serde_derive_internals; 5 | extern crate syn; 6 | extern crate serde; 7 | 8 | use serde_derive_internals::{ast, Ctxt}; 9 | use syn::DeriveInput; 10 | 11 | mod derive_enum; 12 | mod derive_struct; 13 | 14 | 15 | #[cfg(feature = "bytes")] 16 | extern crate serde_bytes; 17 | 18 | 19 | 20 | #[proc_macro_derive(TypescriptDefinition)] 21 | pub fn derive_typescript_definition(input: proc_macro::TokenStream) -> proc_macro::TokenStream { 22 | // eprintln!(".........[input] {}", input); 23 | let input: DeriveInput = syn::parse(input).unwrap(); 24 | 25 | let cx = Ctxt::new(); 26 | let container = ast::Container::from_ast(&cx, &input); 27 | 28 | let typescript = match container.data { 29 | ast::Data::Enum(variants) => { 30 | derive_enum::derive_enum(variants, &container.attrs) 31 | } 32 | ast::Data::Struct(style, fields) => { 33 | derive_struct::derive_struct(style, fields, &container.attrs) 34 | } 35 | }; 36 | 37 | let typescript_string = typescript.to_string(); 38 | let typescript_ident = syn::Ident::from(format!("{}___typescript_definition", container.ident)); 39 | let export_ident = syn::Ident::from(format!("TS_EXPORT_{}", container.ident.to_string().to_uppercase())); 40 | 41 | // eprintln!("....[typescript] {:?}", typescript_string); 42 | // eprintln!("........[schema] {:?}", inner_impl); 43 | // eprintln!(); 44 | // eprintln!(); 45 | // eprintln!(); 46 | 47 | let mut expanded = quote!{ 48 | 49 | #[wasm_bindgen(typescript_custom_section)] 50 | const #export_ident : &'static str = #typescript_string; 51 | 52 | }; 53 | 54 | if cfg!(any(debug_assertions, feature = "test-export")) { 55 | expanded.append_all(quote!{ 56 | fn #typescript_ident ( ) -> &'static str { 57 | #typescript_string 58 | } 59 | }); 60 | } 61 | 62 | cx.check().unwrap(); 63 | 64 | expanded.into() 65 | } 66 | 67 | fn collapse_list_bracket(body: Vec) -> quote::Tokens { 68 | if body.len() == 1 { 69 | body[0].clone() 70 | } else { 71 | let tokens = body.into_iter().fold(quote!{}, |mut agg, tokens| { agg.append_all(quote!{ #tokens , }); agg }); 72 | quote!{ [ #tokens ] } 73 | } 74 | } 75 | 76 | fn collapse_list_brace(body: Vec) -> quote::Tokens { 77 | let tokens = body.into_iter().fold(quote!{}, |mut agg, tokens| { agg.append_all(quote!{ #tokens , }); agg }); 78 | quote!{ { #tokens } } 79 | } 80 | 81 | fn type_to_ts(ty: &syn::Type) -> quote::Tokens { 82 | // println!("??? {:?}", ty); 83 | use syn::Type::*; 84 | match ty { 85 | Slice(..) => quote!{ any }, 86 | Array(..) => quote!{ any }, 87 | Ptr(..) => quote!{ any }, 88 | Reference(..) => quote!{ any }, 89 | BareFn(..) => quote!{ any }, 90 | Never(..) => quote!{ any }, 91 | Tuple(..) => quote!{ any }, 92 | Path(inner) => { 93 | // let ty_string = format!("{}", inner.path); 94 | let result = quote!{ #inner }; 95 | match result.to_string().as_ref() { 96 | "u8" | "u16" | "u32" | "u64" | "u128" | "usize" | 97 | "i8" | "i16" | "i32" | "i64" | "i128" | "isize" => 98 | quote! { number }, 99 | "String" | "&str" | "&'static str" => 100 | quote! { string }, 101 | "bool" => quote!{ boolean }, 102 | _ => quote! { any }, 103 | } 104 | } 105 | TraitObject(..) => quote!{ any }, 106 | ImplTrait(..) => quote!{ any }, 107 | Paren(..) => quote!{ any }, 108 | Group(..) => quote!{ any }, 109 | Infer(..) => quote!{ any }, 110 | Macro(..) => quote!{ any }, 111 | Verbatim(..) => quote!{ any }, 112 | } 113 | } 114 | 115 | fn derive_field<'a>(_variant_idx: usize, _field_idx: usize, field: &ast::Field<'a>) -> quote::Tokens { 116 | let field_name = field.attrs.name().serialize_name(); 117 | let ty = type_to_ts(&field.ty); 118 | quote!{ 119 | #field_name: #ty 120 | } 121 | } 122 | 123 | fn derive_element<'a>(_variant_idx: usize, _element_idx: usize, field: &ast::Field<'a>) -> quote::Tokens { 124 | let ty = type_to_ts(&field.ty); 125 | quote!{ 126 | #ty 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /tests/typescript.rs: -------------------------------------------------------------------------------- 1 | #![allow(unused)] 2 | 3 | extern crate serde; 4 | #[macro_use] 5 | extern crate serde_derive; 6 | #[macro_use] 7 | extern crate wasm_typescript_definition; 8 | #[macro_use] 9 | extern crate quote; 10 | #[macro_use] 11 | extern crate wasm_bindgen; 12 | 13 | use std::borrow::Cow; 14 | use serde::de::value::Error; 15 | use wasm_typescript_definition::TypescriptDefinition; 16 | use wasm_bindgen::prelude::*; 17 | 18 | #[test] 19 | fn unit_struct() { 20 | #[derive(Serialize, TypescriptDefinition)] 21 | struct Unit; 22 | 23 | assert_eq!(Unit___typescript_definition(), quote!{ 24 | {} 25 | }.to_string()); 26 | } 27 | 28 | #[test] 29 | fn newtype_struct() { 30 | #[derive(Serialize, TypescriptDefinition)] 31 | struct Newtype(i64); 32 | 33 | assert_eq!(Newtype___typescript_definition(), quote!{ 34 | number 35 | }.to_string()); 36 | } 37 | 38 | #[test] 39 | fn tuple_struct() { 40 | #[derive(Serialize, TypescriptDefinition)] 41 | struct Tuple(i64, String); 42 | 43 | assert_eq!(Tuple___typescript_definition(), quote!{ 44 | [number, string,] 45 | }.to_string()); 46 | } 47 | 48 | #[test] 49 | fn struct_with_borrowed_fields() { 50 | #[derive(Serialize, TypescriptDefinition)] 51 | struct Borrow<'a> { 52 | raw: &'a str, 53 | cow: Cow<'a, str> 54 | } 55 | 56 | // TODO raw should be string(!) 57 | assert_eq!(Borrow___typescript_definition(), quote!{ 58 | {"raw": any, "cow": any,} 59 | }.to_string()); 60 | } 61 | 62 | #[test] 63 | fn struct_point_with_field_rename() { 64 | #[derive(Serialize, TypescriptDefinition)] 65 | struct Point { 66 | #[serde(rename = "X")] 67 | x: i64, 68 | #[serde(rename = "Y")] 69 | y: i64, 70 | } 71 | 72 | assert_eq!(Point___typescript_definition(), quote!{ 73 | {"X": number, "Y": number,} 74 | }.to_string()); 75 | } 76 | 77 | #[test] 78 | fn enum_with_renamed_newtype_variants() { 79 | #[derive(Serialize, TypescriptDefinition)] 80 | enum Enum { 81 | #[serde(rename = "Var1")] 82 | #[allow(unused)] 83 | V1(bool), 84 | #[serde(rename = "Var2")] 85 | #[allow(unused)] 86 | V2(i64), 87 | #[serde(rename = "Var3")] 88 | #[allow(unused)] 89 | V3(String), 90 | } 91 | 92 | assert_eq!(Enum___typescript_definition(), quote!{ 93 | | {"tag": "Var1", "fields": boolean,} 94 | | {"tag": "Var2", "fields": number,} 95 | | {"tag": "Var3", "fields": string,} 96 | }.to_string()); 97 | } 98 | 99 | #[test] 100 | fn enum_with_unit_variants() { 101 | #[derive(Serialize, TypescriptDefinition)] 102 | enum Enum { 103 | #[allow(unused)] 104 | V1, 105 | #[allow(unused)] 106 | V2, 107 | #[allow(unused)] 108 | V3, 109 | } 110 | 111 | assert_eq!(Enum___typescript_definition(), quote!{ 112 | | {"tag": "V1",} 113 | | {"tag": "V2",} 114 | | {"tag": "V3",} 115 | }.to_string()); 116 | } 117 | 118 | #[test] 119 | fn enum_with_tuple_variants() { 120 | #[derive(Serialize, TypescriptDefinition)] 121 | enum Enum { 122 | #[allow(unused)] 123 | V1(i64, String), 124 | #[allow(unused)] 125 | V2(i64, bool), 126 | #[allow(unused)] 127 | V3(i64, u64), 128 | } 129 | 130 | assert_eq!(Enum___typescript_definition(), quote!{ 131 | | {"tag": "V1", "fields": [number, string,],} 132 | | {"tag": "V2", "fields": [number, boolean,],} 133 | | {"tag": "V3", "fields": [number, number,],} 134 | }.to_string()); 135 | } 136 | 137 | #[test] 138 | fn enum_with_struct_variants_and_renamed_fields() { 139 | #[derive(Serialize, TypescriptDefinition)] 140 | enum Enum { 141 | #[allow(unused)] 142 | V1 { 143 | #[serde(rename = "Foo")] 144 | foo: bool, 145 | }, 146 | #[allow(unused)] 147 | V2 { 148 | #[serde(rename = "Bar")] 149 | bar: i64, 150 | #[serde(rename = "Baz")] 151 | baz: u64, 152 | }, 153 | #[allow(unused)] 154 | V3 { 155 | #[serde(rename = "Quux")] 156 | quux: String, 157 | }, 158 | } 159 | 160 | assert_eq!(Enum___typescript_definition(), quote!{ 161 | | {"tag": "V1", "fields": { "Foo": boolean, }, } 162 | | {"tag": "V2", "fields": { "Bar": number, "Baz": number, }, } 163 | | {"tag": "V3", "fields": { "Quux": string, }, } 164 | }.to_string()); 165 | } 166 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------