{"id":17230081,"url":"https://github.com/robinbuschmann/xsd-decorators","last_synced_at":"2025-03-25T19:42:22.316Z","repository":{"id":55545389,"uuid":"80720226","full_name":"RobinBuschmann/xsd-decorators","owner":"RobinBuschmann","description":"Decorators for creating xsd schemas.","archived":false,"fork":false,"pushed_at":"2019-12-17T09:43:36.000Z","size":84,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-03T08:38:29.309Z","etag":null,"topics":["annotations","decorators","xml","xsd","xsd-schema"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobinBuschmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-02T11:50:14.000Z","updated_at":"2020-03-12T10:21:23.000Z","dependencies_parsed_at":"2022-08-15T02:51:03.731Z","dependency_job_id":null,"html_url":"https://github.com/RobinBuschmann/xsd-decorators","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinBuschmann%2Fxsd-decorators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinBuschmann%2Fxsd-decorators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinBuschmann%2Fxsd-decorators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinBuschmann%2Fxsd-decorators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobinBuschmann","download_url":"https://codeload.github.com/RobinBuschmann/xsd-decorators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245534220,"owners_count":20631272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["annotations","decorators","xml","xsd","xsd-schema"],"created_at":"2024-10-15T04:52:23.854Z","updated_at":"2025-03-25T19:42:22.285Z","avatar_url":"https://github.com/RobinBuschmann.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/RobinBuschmann/xsd-decorators.png?branch=master)](https://travis-ci.org/RobinBuschmann/xsd-decorators)\n\n# xsd-decorators\nDecorators for creating [xsd schemas](https://www.w3.org/TR/xmlschema11-1/).\n\n## Installation\n```\nnpm install xsd-decorators --save\n```\n\n## Usage\n### 1. Annotate class\n\n```typescript\nimport {XSDComplexType, XSDElement} from \"xsd-decorators\";\n\n@XSDComplexType({\n  choices: {\n    [PurchaseOrder.PaymentChoice]: {\n      minOccurs: 1,\n      maxOccurs: 1\n    }\n  }\n})\nexport class PurchaseOrder {\n\n  private static readonly PaymentChoice = 'payment-choice';\n\n  @XSDAttribute\n  dateTime: Date;\n\n  @XSDElement({\n    minOccurs: 1,\n    maxOccurs: 1,\n  })\n  shipTo: Customer;\n\n  @XSDElement({\n    minOccurs: 1,\n    maxOccurs: 1,\n  })\n  billTo: Customer;\n\n  @XSDElement({\n    enumeration: ['same-day', 'express', 'lazy']\n  })\n  delivery: string;\n\n  @XSDElement({\n    choiceName: PurchaseOrder.PaymentChoice\n  })\n  payPalPayment: PayPalPayment;\n\n  @XSDElement({\n    choiceName: PurchaseOrder.PaymentChoice\n  })\n  creditCardPayment: CreditCardPayment;\n\n  @XSDElement({\n    maxOccurs: 10,\n    maxLength: 250\n  })\n  comment: string;\n\n  @XSDElement\n  items: Items;\n\n}\n```\n(Click [here](https://github.com/RobinBuschmann/xsd-decorators/tree/master/test/models) for full example )\n\n### 2. Create schema\n```typescript\nimport {createSchemaXml} from \"xsd-decorators\";\n\nconst xml = createSchemaXml({\n  elementName: 'purchaseOrder',\n  target: PurchaseOrder,\n  targetNamespace: 'http://purchase.example.com',\n  namespaces: {\n    wsdl: 'http://schemas.xmlsoap.org/wsdl/'\n  }\n});\n\n```\n**Result**\n```xml\n\u003c?xml version='1.0' encoding='UTF-8'?\u003e\n\u003cxsd:schema attributeFormDefault='unqualified' elementFormDefault='unqualified' xmlns:xsd='http://www.w3.org/2001/XMLSchema' targetNamespace='http://purchase.example.com' xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'\u003e\n  \u003cxsd:element name='purchaseOrder' type='tns:PurchaseOrder'/\u003e\n  \u003cxsd:complexType name='PurchaseOrder'\u003e\n    \u003cxsd:sequence\u003e\n      \u003cxsd:element name='shipTo' type='tns:Customer' minOccurs='1' maxOccurs='1'/\u003e\n      \u003cxsd:element name='billTo' type='tns:Customer' minOccurs='1' maxOccurs='1'/\u003e\n      \u003cxsd:element name='delivery' type='tns:deliveryType'/\u003e\n      \u003cxsd:element name='comment' type='tns:Length0-250Type' maxOccurs='10'/\u003e\n      \u003cxsd:element name='items' type='tns:Items'/\u003e\n      \u003cxsd:choice minOccurs='1' maxOccurs='1'\u003e\n        \u003cxsd:element name='payPalPayment' type='tns:PayPalPayment'/\u003e\n        \u003cxsd:element name='creditCardPayment' type='tns:CreditCardPayment'/\u003e\n      \u003c/xsd:choice\u003e\n    \u003c/xsd:sequence\u003e\n    \u003cxsd:attribute name='dateTime' type='xsd:dateTime'/\u003e\n  \u003c/xsd:complexType\u003e\n  \u003cxsd:complexType name='PayPalPayment'/\u003e\n  \u003cxsd:complexType name='CreditCardPayment'/\u003e\n  \u003cxsd:complexType name='Customer'\u003e\n    \u003cxsd:sequence\u003e\n      \u003cxsd:element name='name' type='xsd:string'/\u003e\n      \u003cxsd:element name='street' type='xsd:string'/\u003e\n      \u003cxsd:element name='city' type='xsd:string'/\u003e\n      \u003cxsd:element name='state' type='xsd:string'/\u003e\n      \u003cxsd:element name='zip' type='xsd:decimal'/\u003e\n    \u003c/xsd:sequence\u003e\n    \u003cxsd:attribute name='country' type='xsd:string'/\u003e\n  \u003c/xsd:complexType\u003e\n  \u003cxsd:complexType name='Items'\u003e\n    \u003cxsd:sequence\u003e\n      \u003cxsd:element name='item' type='tns:Item' maxOccurs='unbounded'/\u003e\n      \u003cxsd:element name='totalWeight' type='tns:totalWeightSimpleContentType'/\u003e\n    \u003c/xsd:sequence\u003e\n  \u003c/xsd:complexType\u003e\n  \u003cxsd:complexType name='Item'\u003e\n    \u003cxsd:sequence\u003e\n      \u003cxsd:element name='productName' type='xsd:string'/\u003e\n      \u003cxsd:element name='quantity' type='xsd:int'/\u003e\n      \u003cxsd:element name='price' type='xsd:decimal'/\u003e\n      \u003cxsd:element name='comment' type='xsd:string'/\u003e\n    \u003c/xsd:sequence\u003e\n    \u003cxsd:attribute name='partNum' type='tns:SKU'/\u003e\n  \u003c/xsd:complexType\u003e\n  \u003cxsd:complexType name='totalWeightSimpleContentType'\u003e\n    \u003cxsd:simpleContent\u003e\n      \u003cxsd:extension base='xsd:int'\u003e\n        \u003cxsd:attribute name='unit' type='xsd:string'/\u003e\n      \u003c/xsd:extension\u003e\n    \u003c/xsd:simpleContent\u003e\n  \u003c/xsd:complexType\u003e\n  \u003cxsd:simpleType name='deliveryType'\u003e\n    \u003cxsd:restriction base='xsd:string'\u003e\n      \u003cxsd:enumeration value='same-day'/\u003e\n      \u003cxsd:enumeration value='express'/\u003e\n      \u003cxsd:enumeration value='lazy'/\u003e\n    \u003c/xsd:restriction\u003e\n  \u003c/xsd:simpleType\u003e\n  \u003cxsd:simpleType name='Length0-250Type'\u003e\n    \u003cxsd:restriction base='xsd:string'\u003e\n      \u003cxsd:pattern value='^.{0,250}$'/\u003e\n    \u003c/xsd:restriction\u003e\n  \u003c/xsd:simpleType\u003e\n  \u003cxsd:simpleType name='SKU'\u003e\n    \u003cxsd:restriction base='xsd:string'\u003e\n      \u003cxsd:pattern value='\\d{3}-[A-Z]{2}'/\u003e\n    \u003c/xsd:restriction\u003e\n  \u003c/xsd:simpleType\u003e\n\u003c/xsd:schema\u003e\n```\nxsd-decorators uses [xml-decorators](https://www.npmjs.com/package/xml-decorators), \nwhich uses [js2xmlparser](https://www.npmjs.com/package/js2xmlparser), for serialization.\nSo if you want to retrieve the js2xmlparser schema call `createJsonSchema` with the same \noptions.\n\n## Documentation\n### complex type options\n| name     | type                            | description                                                                 |\n|----------|---------------------------------|-----------------------------------------------------------------------------|\n| name?    | string                          | Alternative name of complex type. Overrides inferred name of class.         |\n| suffix?  | string                          | Adds a suffix to the name of complex type.                                  |\n| prefix?  | string                          | Adds a prefix to the name of complex type.                                  |\n| choices? | {[name: string]: \u003cchoice options\u003e} | Key/value pairs, for defining choice options for specified key/choice name. |\n\n### element options\n| name            | type                                                                                     | description                                                                                                                     |\n|-----------------|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|\n| type?           | [xsd primitive type](https://www.w3.org/TR/xmlschema11-2/#built-in-primitive-datatypes)\u0026#124;Class type    | The type of the xsd:element. Normally the type value will be inferred from the type annotation, but this is not always possible.                                                    |\n| simpleTypeName? | string                                                                                   | Overrides inferred simple type name.                                                                                            |\n| choiceName?     | string                                                                                   | Identifies to which choice the annotated element belongs.                                                                       |\n| minOccurs?      | number                                                                                   | see (w3: declare an element)[https://www.w3.org/TR/xmlschema11-1/#declare-element]                                              |\n| maxOccurs?      | number                                                                                   | see (w3: declare an element)[https://www.w3.org/TR/xmlschema11-1/#declare-element]                                              |\n| minLength?      | number                                                                                   | Creates a xsd:pattern to restrict the length of the elements value to the specified value. (TODO: use native minLength instead) |\n| maxLength?      | number                                                                                   | Creates a xsd:pattern to restrict the length of the elements value to the specified value. (TODO: use native minLength instead) |\n| enumeration?    | Array\u003cnumber\u0026#124;string\u003e                                                                | A list of valid values for the annotated element.                                                                               |\n| pattern?        | RegExp                                                                                   | Restricts the value of the annotated element by a specified regular expression.                                                 |\n| attributes?     | {[attrName: string]: \u003cattr options\u003e}                                                     | Defines attributes for the xsd:element. (Only available for primitive types or primitive arrays - For complex types, define attributes with the attribute annotation in the corresponding class)                                                 |\n\n### attribute options\n| name            | type                                                                                     | description                                                                                                                     |\n|-----------------|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|\n| type?           | [xsd primitive type](https://www.w3.org/TR/xmlschema11-2/#built-in-primitive-datatypes)\u0026#124;Class type    | The type of the xsd:element. Normally the type value will be inferred from the type annotation, but this is not always possible.                                                    |\n| simpleTypeName? | string                                                                                   | Overrides inferred simple type name.                                                                                            |\n| minLength?      | number                                                                                   | Creates a xsd:pattern to restrict the length of the elements value to the specified value. (TODO: use native minLength instead) |\n| maxLength?      | number                                                                                   | Creates a xsd:pattern to restrict the length of the elements value to the specified value. (TODO: use native minLength instead) |\n| enumeration?    | Array\u003cnumber\u0026#124;string\u003e                                                                | A list of valid values for the annotated element.                                                                               |\n| pattern?        | RegExp                                                                                   | Restricts the value of the annotated element by a specified regular expression.                                                 |\n\n### type inference\nThe following javascript types can automatically inferred to a xsd type\n\n| js type         | xsd primitive type  |\n|-----------------|---------------------|\n| String          | xsd:string          |\n| Number          | xsd:int             |\n| Date            | xsd:dateTime        |\n| Boolean         | xsd:boolean         |\n\nWhen passing a class/constructor function with `@XSDComplexType` annotation, \nxsd-decorators automatically resolves the xsd type for you.\n\n## Features\n\n- [ ] xsd:annotation\n- [x] xsd:attribute\n- [x] xsd:choice (implicit through decorator options)\n- [x] xsd:complexType\n- [x] xsd:element\n- [ ] xsd:group\n- [ ] xsd:import\n- [ ] xsd:include\n- [x] xsd:restrictions (implicit through decorator options)\n  - [x] xsd:enumeration\n  - [ ] xsd:fractionDigits\n  - [ ] xsd:length\n  - [ ] xsd:maxExclusive\n  - [ ] xsd:maxInclusive\n  - [x] xsd:maxLength\n  - [ ] xsd:minExclusive\n  - [ ] xsd:minInclusive\n  - [x] xsd:minLength\n  - [x] xsd:pattern\n  - [ ] xsd:totalDigits\n  - [ ] xsd:whiteSpace\n- [x] xsd:simpleType (implicit through decorator options)\n- [ ] ...","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinbuschmann%2Fxsd-decorators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobinbuschmann%2Fxsd-decorators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinbuschmann%2Fxsd-decorators/lists"}