Comments (2)
Hey, sorry for such a delay.
They are supported when you generate models from the schema e.g.
json = <<~DATA
{
"type": "object",
"properties": {
"firstName": {
"anyOf": [
{ "type": "string" },
{ "type": "number" }
]
},
"lastName": {
"type": "string"
}
}
}
DATA
puts Shale::Schema.from_json([json]).values[0]
firstName attribute will have a type of Shale::Type::Value
meaning it will accept anything and won't type cast:
require 'shale'
class Root < Shale::Mapper
attribute :first_name, Shale::Type::Value
attribute :last_name, Shale::Type::String
json do
map 'firstName', to: :first_name
map 'lastName', to: :last_name
end
end
In XML schema ,xs:choice
has a different meaning:
xml = <<~DATA
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Person">
<xs:complexType>
<xs:choice>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
DATA
puts Shale::Schema.from_xml([xml]).values[0]
it will give you:
class Person < Shale::Mapper
attribute :first_name, Shale::Type::String
attribute :last_name, Shale::Type::String
xml do
root 'Person'
map_element 'FirstName', to: :first_name
map_element 'LastName', to: :last_name
end
end
If you want to generate schema from models, they are not supported as there is no way to mark attributes as belonging to union.
from shale.
Hey, Im closing this issue, if you have any other questions, let me know.
from shale.
Related Issues (20)
- XML tag without content HOT 2
- CSV support on a released version HOT 5
- Nested data in CSV HOT 11
- Mixin over inheritance HOT 1
- render_nil as a global setting HOT 5
- shalerb.org is crashing chrome HOT 2
- command line for converting between types HOT 2
- Cutting new release? HOT 3
- Polymorphic Types HOT 2
- Compiling a JSON schema -> Ruby fails when there are relative path $refs in the schema HOT 1
- Selecting columns while importing CSV HOT 1
- Idea for better rails/ActiveRecord integration HOT 2
- Allow more JSON Schema keywords HOT 1
- Ox adapter XML to object mapper not working with xml header specified HOT 2
- csv was loaded from standard library warning HOT 1
- Ability to pass options to YAML options HOT 1
- Allow customization of JSON schema $defs key and $ref HOT 4
- JSON map attributes are ignored when calling `as_json` HOT 2
- how to change output of a single attribute? HOT 3
- Add RBS type signature HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shale.