-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include "simple data types" from NIST Metaschema #107
Comments
This task is needed by: |
Note that XSD does not define these as primitives, but with regexes. If I were architecting this (which I'm not), I would not be implementing these as primitives in lutaml-model, but rather supporting the way XSD defines types... |
When you say "XSD" you mean "the metaschema XSD" or "the XSD standard"? |
I mean the XSD Standard. The NIST metaschema uses:
so it defines this IPV4AddressDatatype type as a restriction ultimately on xs:string. Maybe Lutaml-model should define the primitives of the XSD standard. (I'm not convinced, but maybe.) But it should certainly not be defining composite types of arbitrary schemas as primitives. It too should be realising XSD restrictions. Making lutaml-model support XSD and all its baroque and by now legacy functionality—is going to make our life very uncomfortable. We should not be compounding it by hardcoding types from XSD instances. |
@opoudjis Metaschema data types are actually defined in the Metaschema language itself, so the XSD here is informative being an implementation language of the Metaschema. I would not say that Meteaschema is an "XSD instance" since it does not depend on the existence of XSD. The point for incorporating Metaschema simple data types into lutaml-model is an alignment between two "information modeling languages". Defining a regex pattern restriction is acceptable for lutaml-model models, given that we already have enum. However, the patterns like |
@ronaldtse We are now supporting |
@suleman-uzair do we support |
@ronaldtse, since we are supporting xs:simpleType as a separate class inherited by
The generated class from an
Yes, We do support xs:pattern. Below are the classes generated (along with some other classes) from the simpleType examples provided by @opoudjis in the above comment. # frozen_string_literal: true
require "lutaml/model"
class StringDatatype < Lutaml::Model::Type::String
def self.cast(value)
return nil if value.nil?
value = super(value)
value
end
end # frozen_string_literal: true
require "lutaml/model"
require_relative 'string_datatype'
class IPV4AddressDatatype < StringDatatype
def self.cast(value)
return nil if value.nil?
value = super(value)
pattern = %r{(((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]).){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]))}
raise_pattern_error(value, pattern) unless value.match?(pattern)
value
end
private
def self.raise_pattern_error(value, pattern)
raise Lutaml::Model::Type::InvalidValueError, "The value #{value} does not match the required pattern: #{pattern}"
end
end
# frozen_string_literal: true
require "lutaml/model"
class WhiteSpaces < Lutaml::Model::Type::String
def self.cast(value)
return nil if value.nil?
value = super(value)
pattern = %r{(\S(.*\S)?)}
raise_pattern_error(value, pattern) unless value.match?(pattern)
value
end
private
def self.raise_pattern_error(value, pattern)
raise Lutaml::Model::Type::InvalidValueError, "The value #{value} does not match the required pattern: #{pattern}"
end
end Let me know if we require any changes in this implementation. |
We need to implement the "simple data types" defined by NIST Metaschema in lutaml-model:
The simple data types are provided here:
The documentation for these types is at:
This task involves implementing the datatypes, adding specs (just use the samples provided on the page) and documenting them in the README.
We already cover most of these data types, but we need to add a number of them like IPv4, IPv6 (we used to have them but removed).
The text was updated successfully, but these errors were encountered: