Repository navigation
Please provide examples of how to resolve conflicts in type names #316
Replies: 9 comments
|
Both names unify to That needs the step-by-step pipeline instead of use anyhow::{anyhow, Error};
use quote::ToTokens;
use xsd_parser::{
config::{Config, IdentQuadruple, Schema},
exec_generator, exec_interpreter, exec_optimizer, exec_parser, exec_render,
models::IdentType,
};
fn main() -> Result<(), Error> {
let mut config = Config::default();
config.parser.schemas = vec![Schema::File("schema.xsd".into())];
let schemas = exec_parser(config.parser)?;
let mut types = exec_interpreter(config.interpreter, &schemas)?;
// Give one of the two colliding types its own Rust name.
let ident = IdentQuadruple::from((IdentType::Type, "base:BONumber")).resolve(&schemas)?;
types
.items
.get_mut(&ident)
.ok_or_else(|| anyhow!("type base:BONumber not found"))?
.display_name = Some("BoNumber".into());
let types = exec_optimizer(config.optimizer, types)?;
let data_types = exec_generator(config.generator, &schemas, &types)?;
let module = exec_render(config.renderer, &data_types)?;
println!("{}", module.to_token_stream());
Ok(())
}With plain The Your |
|
Oh, I didn’t expect that. Java Maven plugin creates JAXB code, and it is translated faster than the cargo build process. The project contains 18 xsd files with a total size of more than 10 MByte. I think that if the module consisted not of 3 files, but of several folders with nested files, I would wait for the code to be translated before restarting Linux. |
|
Hey @alexinsmail, @kasparovabi already covered the first case (same namespace), so here's the rest. Same name in different namespaces (
|
|
@Bergmann89 Thank you for the detailed response. Right now, I'm using this set of parameters I provided an example of processing one XSD file in the list. I tried splitting large files using r2factor. This is the pierreaubert/r2factor project on GitHub. XSD schemas contain named types and nested anonymous types. One line in the generated file xs/mod.rs is still killing me. It seems this comes from here |
|
The Enable config.generator.flags |= GeneratorFlags::BUILD_IN_ABSOLUTE_PATHS;I've added a check in #327, that now throws an error if this happens and a suitable error message that guide the use what to do. About the size: About one file per type: |
|
It would be much more interesting to specify a list of rootElement, or xpath, for which a set of objects needs to be generated. Honestly. There are a couple of xsds that describe elements which are information exchange documents. For a specific task, a small set of documents is selected from the overall set of documents. Build a dependency tree for the specified set of starting elements. Discard all unnecessary types. Is it possible to implement such an idea in reality? |
|
That's exactly what In your config, let config = Config::default()
.with_quick_xml()
.with_generate([
(IdentType::Element, "in:OrderRequest"),
(IdentType::Element, "in:InvoiceRequest"),
(IdentType::Element, "out:OrderResponse"),
]);The prefixes ( use xsd_parser::config::{IdentQuadruple, NamespaceIdent};
let root = IdentQuadruple::from((IdentType::Element, "OrderRequest"))
.with_ns(NamespaceIdent::namespace(b"http://example.com/incoming"));You still pass all 18 schema files to the parser, so all references can be resolved, but only the types your selected documents actually use end up in the generated code. For a small set of documents out of a large schema set, this usually shrinks the output dramatically. |
|
Thanks for the help. If anything, I’m still using Perhaps we should switch to building from GitHub. The original xsd doesn’t define a unique name. I’m trying to create it with and without config.with_generate. The "confirmation" component is a response of the type "success" or "error" + a list of error strings. I’m comparing directories using the meld program on Linux. It shows that the files are the same. After the work, I see directories and *.rs files for all the listed schemas. |
|
I apologize. I figured out my code. After with_generate, I reassigned the new config.generator. |
Uh oh!
There was an error while loading. Please reload this page.
This is probably a repetition of other people’s topics. I think I’m not the first one to have encountered such problems.
Cargo.toml
Let’s consider an example:
ERROR xsd_parser: error: Generator error: Type name
BoNumberTypeis generated for both {example.com/base/1}Type(BONumber) and {example.com/base/1}Type(boNumberType)! Use different module flags or a custom naming convention to tell them apart.It’s not clear what needs to be done.
In theory, you can do it very simply:
config.generator.type_postfix.type_ = "".into();
By default, the configuration looks like this:
config.generator.type_postfix.type_ = Type".into();
It seems he solves it like this:
The solver should have recognized the conflict and made a decision along these lines:
The proposal to use trait Naming looks interesting, but it’s not logical.
Sample from xsd-parser/examples/custom_naming.rs
The presented example does not solve the problem of recognizing which namespace the mutable type name belongs to.
We’ll stumble over this a bit later.
For a narrow set of types, you can define rules for generating type names.
For most types, a basic implementation based on the config.generator.type_postfix parameter is sufficient.
We don’t have the option to refer to the basic implementation of trait Naming, which is described in the config.generator.type_postfix parameters.
Rust is not an OOP language. We don’t have a super method call. It’s useful to have a good solution.
Example of the same name in different namespaces.
BaseTypes.xsd
CommonType.xsd
ERROR xsd_parser: error: Generator error: Type name
ParticipantTypeis generated for both {http://example.com/base/1}Type(participantType) and {http://example.com/common/1}Type(participantType)! Use different module flags or a custom naming to tell them apart.As we can see, the “unify” method doesn’t help here. Let’s combine the first example with the last example. The task turns out to be non‑trivial.
“Use different module flags.” Please provide an example of such a solution.
All reactions