Skip to content

Commit

Permalink
fix(*): fix XSD generation (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickersoft authored Oct 30, 2023
1 parent bfe8ad4 commit 8dd4218
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 36 deletions.
2 changes: 1 addition & 1 deletion examples/dictionary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ety>
<sense pos="n">
<definition value="A book or electronic resource that lists the words of a language and gives their meaning or translation">
<example>I'll look up “love” in the dictionary</example>
<example yo="poop">I'll look up “love” in the dictionary</example>
<example>The website gives access to an online dictionary</example>
<example>The dictionary definition of “smile”</example>
</definition>
Expand Down
4 changes: 3 additions & 1 deletion examples/example1.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<dictionary name="Example Dictionary 1">
<?xml version="1.0" encoding="UTF-8"?>
<dictionary name="Example Dictionary 1"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../odict.xsd">
<entry term="run">
<ety description="Latin root">
<sense pos="v">
Expand Down
14 changes: 8 additions & 6 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
GOLANG_CROSS_VERSION := "v1.21.3"

# ---------------------------------------------------------------------------- #
# Global #
# ---------------------------------------------------------------------------- #
Expand All @@ -14,13 +16,13 @@

@schema: (go "schema") (cli "schema") (js "schema")

@run +args="": build
go run odict {{args}}
@xsd:
go run xsd/xsd.go
@xsd:
go run xsd/xsd.go

@run +args="":
go run odict.go {{args}}

@test: deps (go "test") (jvm "test") (python "test") (js "test") clean
@test: deps xsd (go "test") (jvm "test") (python "test") (js "test") clean

@clean: (python "clean") (jvm "clean") (js "clean")
rm -rf **/*.odict
Expand Down
4 changes: 2 additions & 2 deletions lib/types/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
type DefinitionRepresentable struct {
ID string `json:"id,omitempty" xml:"id,attr,omitempty"`
Value MDString `json:"value,omitempty" xml:"value,attr"`
Examples []string `json:"examples,omitempty" xml:"example"`
Notes []NoteRepresentable `json:"notes,omitempty" xml:"note"`
Examples []string `json:"examples,omitempty" xml:"example,omitempty"`
Notes []NoteRepresentable `json:"notes,omitempty" xml:"note,omitempty"`
}

func (definition *Definition) AsRepresentable() DefinitionRepresentable {
Expand Down
2 changes: 1 addition & 1 deletion lib/types/dictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type DictionaryRepresentable struct {
ID string `json:"id" xml:"id,attr"`
ID string `json:"id" xml:"id,attr,omitempty"`
Name string `json:"name" xml:"name,attr,omitempty"`
Entries KVMap[string, EntryRepresentable] `json:"entries" xml:"entry"`
XMLName xml.Name `json:"-" xml:"dictionary"`
Expand Down
2 changes: 1 addition & 1 deletion lib/types/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type EntryRepresentable struct {
Term string `json:"term" xml:"term,attr"`
Pronunciation string `json:"pronunciation,omitempty" xml:"pronunciation,attr,omitempty"`
SeeAlso string `json:"see,omitempty" xml:"see,attr,omitempty"`
Etymologies []EtymologyRepresentable `json:"etymologies" xml:"ety"`
Etymologies []EtymologyRepresentable `json:"etymologies" xml:"ety,omitempty"`
XMLName xml.Name `json:"-" xml:"entry"`
}

Expand Down
2 changes: 1 addition & 1 deletion lib/types/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

type GroupRepresentable struct {
ID string `json:"id,omitempty" xml:"id,attr,omitempty"`
Description MDString `json:"description" xml:"description,attr"`
Description MDString `json:"description" xml:"description,attr,omitempty"`
Definitions []DefinitionRepresentable `json:"definitions" xml:"definition"`
}

Expand Down
6 changes: 3 additions & 3 deletions lib/types/sense.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
)

type SenseRepresentable struct {
POS PartOfSpeech `json:"-" xml:"pos,attr"`
Definitions []DefinitionRepresentable `json:"definitions,omitempty" xml:"definition"`
Groups []GroupRepresentable `json:"groups,omitempty" xml:"group"`
POS PartOfSpeech `json:"-" xml:"pos,attr,omitempty"`
Groups []GroupRepresentable `json:"groups,omitempty" xml:"group,omitempty"`
Definitions []DefinitionRepresentable `json:"definitions,omitempty" xml:"definition,omitempty"`
XMLName xml.Name `json:"-" xml:"sense"`
}

Expand Down
40 changes: 20 additions & 20 deletions odict.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,58 @@
<xs:element minOccurs="1" maxOccurs="unbounded" name="entry">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="ety">
<xs:element minOccurs="0" maxOccurs="unbounded" name="ety">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="sense">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="definition">
<xs:element minOccurs="0" maxOccurs="unbounded" name="group">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="example" type="xs:string" />
<xs:element minOccurs="1" maxOccurs="unbounded" name="note">
<xs:element minOccurs="1" maxOccurs="unbounded" name="definition">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="example" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="example" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="note">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="example" type="xs:string" />
</xs:sequence>
<xs:attribute name="id" type="xs:string" />
<xs:attribute use="required" name="value" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:string" />
<xs:attribute use="required" name="value" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:string" />
<xs:attribute use="required" name="value" type="xs:string" />
<xs:attribute name="description" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element minOccurs="1" maxOccurs="unbounded" name="group">
<xs:element minOccurs="0" maxOccurs="unbounded" name="definition">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="definition">
<xs:element minOccurs="0" maxOccurs="unbounded" name="example" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="note">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="example" type="xs:string" />
<xs:element minOccurs="1" maxOccurs="unbounded" name="note">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="example" type="xs:string" />
</xs:sequence>
<xs:attribute name="id" type="xs:string" />
<xs:attribute use="required" name="value" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:string" />
<xs:attribute use="required" name="value" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:string" />
<xs:attribute use="required" name="description" type="xs:string" />
<xs:attribute use="required" name="value" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute use="required" name="pos" type="xs:string" />
<xs:attribute name="pos" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
Expand All @@ -72,7 +72,7 @@
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute use="required" name="id" type="xs:string" />
<xs:attribute name="id" type="xs:string" />
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
Expand Down

0 comments on commit 8dd4218

Please sign in to comment.