Giter VIP home page Giter VIP logo

Comments (5)

droyo avatar droyo commented on September 4, 2024

Thanks for catching the issue with minInclusive et al. Just pushed a fix for that.

I've looked at these schema and the first thing that jumps out at me is there's no target namespace. The xsdgen tool looks for the targetNamespace attribute on all schema and by default will generate type declarations for all target namespaces. I neglected to handle the case of no name space, detailed here in the spec: https://www.w3.org/TR/xmlschema-0/#UndeclaredTNS .

I tried adding targetNamespace="" to all the xsd, but hit the following error:

could not dereference {{http://www.w3.org/2001/XMLSchema element} [{{ ref} CatPIL}]}

That was due to a missing CatPIL.xsd. I tried fetching all the xsd and resorted to finding a repo online (https://github.com/anichelabs/amz-mws-xsd). After running against that, I got

complexType _anon353: could not find type "ItemLongStringNotNull" in namespace  for element value

I couldn't find where that type was defined.

from go-xml.

nikolay-turpitko avatar nikolay-turpitko commented on September 4, 2024

@droyo Thank you for trying help.

First of all, I should say, that I found a workaround for task at hand, so don't worry about that.

Just FYI: as a workaround I used xsd2inst tool from Apach xmlbeans to generate sample xml by xsd and generated Go structs from sample xml with xmljson2struct tool (github.com/wicast/xj2s). I also tried github.com/gnewton/chidley, but didn't like it's output - too much redundant code. BTW, this is an example of the code, I hoped to have from the tool (this is an output of xsd2inst):

type OrderAcknowledgement struct {
        MerchantOrderID string  `xml:"MerchantOrderID"`
        StatusCode      string  `xml:"StatusCode"`
        AmazonOrderItemCode     string  `xml:"Item>AmazonOrderItemCode"`
        MerchantOrderItemID     string  `xml:"Item>MerchantOrderItemID"`
        CancelReason    string  `xml:"Item>CancelReason"`
        AmazonOrderID   string  `xml:"AmazonOrderID"`
}

This is just to have an idea what I was looking for.

Next, regarding to nemespace issue, it's strange for me, because I was able to run your tool without errors with script and fix I described in the first message. Namely, all xml dependencies could be resolved with amzn-base.xsd. Only be warned, that Amazon has several versions of schema files, you should have all files from the single source for consistence. If you can use bash and curl please use exact command I provided - I found, that without last slash it downloads wrong version. Also, you could try to use this repo: https://raw.githubusercontent.com/highsource/jsonix-support/master/a/amzn/original-schemas/. But I'am sure, that URL and schema names from Amazon I provided earlier should be enough - I used them with other tools without any issues. BTW, there are no reference to "ItemLongStringNotNull" within my copy of schema.

from go-xml.

droyo avatar droyo commented on September 4, 2024

Thanks for your input.

I went back and followed your exact instructions, and you were right, the schema you provided are sufficient. After applying your fix and a fix to #16, I was able to generate schema by changing

//go:generate xsdgen ../zzz/amzn-base.xsd ../zzz/Price.xsd

to

//go:generate xsdgen -ns "" ../zzz/amzn-base.xsd ../zzz/Price.xsd

Here is what the declaration looks like for the type you provided:

type Anon1 struct {
	AmazonOrderID       AmazonOrderID       `xml:" AmazonOrderID"`
	MerchantOrderID     string              `xml:" MerchantOrderID"`
	StatusCode          StatusCode          `xml:" StatusCode"`
	Item                []Item              `xml:" Item"`
	AmazonOrderItemCode AmazonOrderItemCode `xml:" AmazonOrderItemCode"`
	MerchantOrderItemID string              `xml:" MerchantOrderItemID"`
	CancelReason        CancelReason        `xml:" CancelReason"`
}

// May be one of NoInventory, ShippingAddressUndeliverable, CustomerExchange, BuyerCanceled, GeneralAdjustment, CarrierCreditDecision, RiskAssessmentInformationNotValid, CarrierCoverageFailure, CustomerReturn, MerchandiseNotReceived
type CancelReason string

type Item struct {
	AmazonOrderItemCode AmazonOrderItemCode `xml:" AmazonOrderItemCode"`
	MerchantOrderItemID string              `xml:" MerchantOrderItemID"`
	CancelReason        CancelReason        `xml:" CancelReason"`
}

// Must match the pattern \d{14}
type AmazonOrderItemCode string

The type name is Anon1 due to #14

from go-xml.

droyo avatar droyo commented on September 4, 2024

So a couple things:

  • xsdgen (command nor package) doesn't fetch dependent schema for you; you have to specify all relevant files on the command line. Resolving all dependencies recursively would be a good feature (or separate command). Sometimes that's hard because the <import> or <include> statements don't have consistent URIs (or none at all).
  • There's a bug in lookupTargetNS that necessitated the -ns "" workaround. I neglected to consider the case when no target namespace is considered.

from go-xml.

nikolay-turpitko avatar nikolay-turpitko commented on September 4, 2024

@droyo Thank you! With -ns "" I was able to generate Go file. I think, this issue can be closed now.

from go-xml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.