THRIFT-3417: "namespace xsd" is not really working

Client: XSD
Patch: Benjamin Gould

This closes #691
This commit is contained in:
BCG 2015-11-12 21:02:51 -05:00 committed by Jens Geyer
parent a6b120301a
commit cc193c1bec
4 changed files with 23 additions and 1 deletions

View File

@ -260,6 +260,11 @@ void t_xsd_generator::generate_service(t_service* tservice) {
f_xsd_.open(f_xsd_name.c_str());
string ns = program_->get_namespace("xsd");
const std::map<std::string, std::string> annot = program_->get_namespace_annotations("xsd");
const std::map<std::string, std::string>::const_iterator uri = annot.find("uri");
if (uri != annot.end()) {
ns = uri->second;
}
if (ns.size() > 0) {
ns = " targetNamespace=\"" + ns + "\" xmlns=\"" + ns + "\" "
+ "elementFormDefault=\"qualified\"";

View File

@ -324,6 +324,15 @@ public:
const std::map<std::string, std::string>& get_all_namespaces(){
return namespaces_;
}
void set_namespace_annotations(std::string language, std::map<std::string, std::string> annotations) {
namespace_annotations_[language] = annotations;
}
const std::map<std::string, std::string>& get_namespace_annotations(std::string language) {
return namespace_annotations_[language];
}
// Language specific namespace / packaging
void add_cpp_include(std::string path) { cpp_includes_.push_back(path); }
@ -371,6 +380,9 @@ private:
// Dynamic namespaces
std::map<std::string, std::string> namespaces_;
// Annotations for dynamic namespaces
std::map<std::string, std::map<std::string, std::string>> namespace_annotations_;
// C++ extra includes
std::vector<std::string> cpp_includes_;

View File

@ -297,13 +297,17 @@ Header:
{
pdebug("Header -> Include");
}
| tok_namespace tok_identifier tok_identifier
| tok_namespace tok_identifier tok_identifier TypeAnnotations
{
pdebug("Header -> tok_namespace tok_identifier tok_identifier");
declare_valid_program_doctext();
if (g_parse_mode == PROGRAM) {
g_program->set_namespace($2, $3);
}
if ($4 != NULL) {
g_program->set_namespace_annotations($2, $4->annotations_);
delete $4;
}
}
| tok_namespace '*' tok_identifier
{

View File

@ -36,6 +36,7 @@ namespace php ThriftTest
namespace delphi Thrift.Test
namespace cocoa ThriftTest
namespace lua ThriftTest
namespace xsd test (uri = 'http://thrift.apache.org/ns/ThriftTest')
// Presence of namespaces and sub-namespaces for which there is
// no generator should compile with warnings only