"id" and "type" are JSONLD, not ActivityStream, properties

This was a fucking nightmare, as expected. All because the PublicKey
type is not really a derivation of the ActivityStreams "Object", which I
had been hackily relying on for things to inherit the JSONLD "id" and
"type" properties.

This breaks the "id" and "type" JSONLD properties into first-class
properties known within the tool, which for now is a patchy job of duct
tape to cover the leaks.

If someone wants "PublicKey" to have more default supported properties,
I will kindly ask them to fork a code generation that suits them. This
took way too much effort to treat PublicKey like a grab bag.

This isn't the fix for, but is on the road to fixing, the known bug
about aggressive deserialization of "PublicKey" into other types. In
fact, this is on the way to *correctly* fix it without a horrible patch
in the generated code (imagine being hacky in []jen.Code{...}, that's
too much poo to put into the meta code).

The things I do to support incomplete ontologies and major Federation
players that, for whatever reason on this god-forsaken planet, decided
to adopt the ontology and type everything except "PublicKey" (I don't
count "endpoints" because that is a pile of steaming poo for another
different reason in addition to this one, and is completely optional).
このコミットが含まれているのは:
Cory Slep 2019-10-21 22:06:37 +02:00
コミット 07df3adee5
9個のファイルの変更311行の追加200行の削除

ファイルの表示

@ -1737,88 +1737,6 @@
"properties": {
"type": "owl:Ontology",
"members": [
{
"id": "https://www.w3.org/TR/activitystreams-vocabulary/@id",
"type": [
"rdf:Property",
"owl:ObjectProperty",
"owl:FunctionalProperty"
],
"example": {
"id": "https://www.w3.org/TR/activitystreams-vocabulary/#exid-jsonld",
"type": "http://schema.org/CreativeWork",
"mainEntity": {
"id": "http://example.org/foo",
"name": "Foo"
},
"name": "Example 61"
},
"notes": "Provides the globally unique identifier for an Object or Link.",
"domain": {
"type": "owl:Class",
"unionOf": [
{
"type": "owl:Class",
"url": "https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object",
"name": "Object"
},
{
"type": "owl:Class",
"url": "https://www.w3.org/TR/activitystreams-vocabulary/#dfn-link",
"name": "Link"
}
]
},
"isDefinedBy": "https://www.w3.org/TR/activitystreams-vocabulary/#dfn-id",
"range": {
"type": "owl:Class",
"unionOf": "xsd:anyURI"
},
"name": "id",
"url": "https://www.w3.org/TR/activitystreams-vocabulary/#dfn-id"
},
{
"id": "https://www.w3.org/TR/activitystreams-vocabulary/@type",
"type": [
"rdf:Property",
"owl:ObjectProperty"
],
"example": {
"id": "https://www.w3.org/TR/activitystreams-vocabulary/#extype-jsonld",
"type": "http://schema.org/CreativeWork",
"mainEntity": {
"type": "http://example.org/Foo",
"summary": "A foo"
},
"name": "Example 62"
},
"notes": "Identifies the Object or Link type. Multiple values may be specified.",
"domain": {
"type": "owl:Class",
"unionOf": [
{
"type": "owl:Class",
"url": "https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object",
"name": "Object"
},
{
"type": "owl:Class",
"url": "https://www.w3.org/TR/activitystreams-vocabulary/#dfn-link",
"name": "Link"
}
]
},
"isDefinedBy": "https://www.w3.org/TR/activitystreams-vocabulary/#dfn-type",
"range": {
"type": "owl:Class",
"unionOf": [
"xsd:anyURI",
"xsd:string"
]
},
"name": "type",
"url": "https://www.w3.org/TR/activitystreams-vocabulary/#dfn-type"
},
{
"id": "https://www.w3.org/ns/activitystreams#actor",
"type": "rdf:Property",

ファイルの表示

@ -7,15 +7,15 @@ import (
"github.com/go-fed/activity/astool/codegen"
"github.com/go-fed/activity/astool/gen"
"github.com/go-fed/activity/astool/rdf"
"github.com/go-fed/activity/astool/rdf/xsd"
"net/url"
"sort"
"strings"
)
const (
interfacePkg = "vocab"
resolverPkg = "resolver"
typePropertyName = "type"
interfacePkg = "vocab"
resolverPkg = "resolver"
)
// File is a code-generated file.
@ -217,16 +217,70 @@ const (
// implementations. Developers' applications should only rely on the interfaces,
// which are used internally anyway.
type Converter struct {
GenRoot *gen.PackageManager
PackagePolicy PackagePolicy
typeProperty *gen.PropertyGenerator
typePropertyVocabName string
GenRoot *gen.PackageManager
PackagePolicy PackagePolicy
// Properties stemming from JSONLD
idProperty *gen.FunctionalPropertyGenerator
typeProperty *gen.NonFunctionalPropertyGenerator
}
// Convert turns a ParsedVocabulary into a set of code-generated files.
func (c *Converter) Convert(p *rdf.ParsedVocabulary) (f []*File, e error) {
v := newVocabulary()
done := make(map[string]bool)
// Step 0: Create the "@id" and "@type" properties
fmt.Println(p.References)
var xsdAnyUriKinds []gen.Kind
var xsdStringKinds []gen.Kind
var xsdAnyUri *url.URL
var xsdString *url.URL
xsdAnyUri, e = url.Parse(xsd.XmlSpec + xsd.AnyURISpec)
if e != nil {
return
}
xsdString, e = url.Parse(xsd.XmlSpec + xsd.StringSpec)
if e != nil {
return
}
xsdAnyUriKinds, e = c.propertyKinds(rdf.VocabularyProperty{
Range: []rdf.VocabularyReference{{
Name: xsd.AnyURISpec,
URI: xsdAnyUri,
Vocab: xsd.XmlSpec,
}},
}, v.Values, p.Vocab, p.References)
if e != nil {
return
}
xsdStringKinds, e = c.propertyKinds(rdf.VocabularyProperty{
Range: []rdf.VocabularyReference{{
Name: xsd.StringSpec,
URI: xsdString,
Vocab: xsd.XmlSpec,
}},
}, v.Values, p.Vocab, p.References)
if e != nil {
return
}
var idPkg, typePkg *gen.PackageManager
idPkg, e = c.propertyPackageManager(rdf.VocabularyProperty{Name:"id"}, gen.JSONLDVocabName)
if e != nil {
return
}
c.idProperty, e = gen.NewIdProperty(idPkg, xsdAnyUriKinds[0])
if e != nil {
return
}
typePkg, e = c.propertyPackageManager(rdf.VocabularyProperty{Name:"type"}, gen.JSONLDVocabName)
if e != nil {
return
}
c.typeProperty, e = gen.NewTypeProperty(typePkg, xsdAnyUriKinds[0], xsdStringKinds[0])
if e != nil {
return
}
v.FProps[gen.JSONLDIdName] = c.idProperty
v.NFProps[gen.JSONLDTypeName] = c.typeProperty
// Step 1: Convert referenced specifications
for i, vocabURI := range p.Order {
refP := p.Clone()
@ -329,12 +383,23 @@ func (c *Converter) convertToFiles(v vocabulary) (f []*File, e error) {
}
f = append(f, pkgFiles...)
}
// JSONLD
var files []*File
files, e = c.jsonLDToFiles()
if e != nil {
return
}
f = append(f, files...)
files, e = c.jsonLDRootFiles(pub, v.Manager)
if e != nil {
return
}
f = append(f, files...)
// This vocabulary
for _, v := range v.Values {
pkg := c.valuePackage(v)
f = append(f, convertValue(pkg, v))
}
var files []*File
files, e = c.toFiles(v)
if e != nil {
return
@ -366,6 +431,18 @@ func (c *Converter) convertToFiles(v vocabulary) (f []*File, e error) {
FileName: "gen_manager.go",
Directory: pub.WriteDir(),
})
// JSONLD types
var idFiles, typeFiles []*File
idFiles, e = c.propertyPackageFiles(&c.idProperty.PropertyGenerator, gen.JSONLDVocabName)
if e != nil {
return
}
f = append(f, idFiles...)
typeFiles, e = c.propertyPackageFiles(&c.typeProperty.PropertyGenerator, gen.JSONLDVocabName)
if e != nil {
return
}
f = append(f, typeFiles...)
// Root Package Documentation
rootDocFile := jen.NewFilePath(pub.Path())
rootDocFile.PackageComment(gen.GenRootPackageComment(pub.Name()))
@ -409,16 +486,8 @@ func (c *Converter) convertVocabulary(p *rdf.ParsedVocabulary, refs map[string]*
for k, prop := range p.Vocab.Properties {
if prop.Functional {
v.FProps[k], e = c.convertFunctionalProperty(prop, v.Values, p.Vocab, p.References, refs)
if c.typeProperty == nil && prop.Name == typePropertyName {
c.typeProperty = &(v.FProps[k].PropertyGenerator)
c.typePropertyVocabName = v.Name
}
} else {
v.NFProps[k], e = c.convertNonFunctionalProperty(prop, v.Values, p.Vocab, p.References, refs)
if c.typeProperty == nil && prop.Name == typePropertyName {
c.typeProperty = &(v.NFProps[k].PropertyGenerator)
c.typePropertyVocabName = v.Name
}
}
if e != nil {
return
@ -467,8 +536,8 @@ func (c *Converter) convertGenRoot(v *vocabulary) (e error) {
v.Manager, e = gen.NewManagerGenerator(
c.GenRoot.PublicPackage(),
v.allTypeArray(),
v.allFuncPropArray(),
v.allNonFuncPropArray())
append(v.allFuncPropArray(), c.idProperty),
append(v.allNonFuncPropArray(), c.typeProperty))
return
}
@ -640,6 +709,8 @@ func (c *Converter) convertType(t rdf.VocabularyType,
if len(examples) > 0 {
comment = fmt.Sprintf("%s\n\n%s", comment, strings.Join(examples, "\n\n"))
}
// Always include the type and id JSONLD properties
p = append(p, []gen.Property{c.typeProperty, c.idProperty}...)
tg, e = gen.NewTypeGenerator(
v.GetName(),
v.URI,
@ -878,10 +949,24 @@ func (c *Converter) packageManager(s, vocabName string) (pkg *gen.PackageManager
return
}
// jsonLDRootFiles creates files that are applied for JSONLD.
//
// TODO: This function looks a lot like the next one (copy/paste). Deduplicate.
func (c *Converter) jsonLDRootFiles(pkg gen.Package, m *gen.ManagerGenerator) (f []*File, e error) {
pg := gen.NewPackageGenerator(gen.JSONLDVocabName, m, c.typeProperty)
_, propCtors, _, _, _, _ := pg.RootDefinitions(gen.JSONLDVocabName, []*gen.TypeGenerator{}, []*gen.PropertyGenerator{&c.typeProperty.PropertyGenerator, &c.idProperty.PropertyGenerator})
lowerVocabName := strings.ToLower(gen.JSONLDVocabName)
if file := funcsToFile(pkg, propCtors, fmt.Sprintf("gen_pkg_%s_property_constructors.go", lowerVocabName)); file != nil {
f = append(f, file)
}
return
}
// rootFiles creates files that are applied for all vocabularies. These files
// are the ones typically used by developers.
func (c *Converter) rootFiles(pkg gen.Package, vocabName string, v vocabulary, m *gen.ManagerGenerator) (f []*File, e error) {
pg := gen.NewPackageGenerator(c.typePropertyVocabName, m, c.typeProperty)
pg := gen.NewPackageGenerator(gen.JSONLDVocabName, m, c.typeProperty)
typeCtors, propCtors, ext, disj, extBy, isA := pg.RootDefinitions(vocabName, v.typeArray(), v.propArray())
lowerVocabName := strings.ToLower(vocabName)
if file := funcsToFile(pkg, typeCtors, fmt.Sprintf("gen_pkg_%s_type_constructors.go", lowerVocabName)); file != nil {
@ -908,7 +993,7 @@ func (c *Converter) rootFiles(pkg gen.Package, vocabName string, v vocabulary, m
// initFile creates the file with the init function that hooks together the
// runtime Manager.
func (c *Converter) initFile(pkg gen.Package, root vocabulary, m *gen.ManagerGenerator) (f *File, e error) {
pg := gen.NewPackageGenerator(c.typePropertyVocabName, m, c.typeProperty)
pg := gen.NewPackageGenerator(gen.JSONLDVocabName, m, c.typeProperty)
globalVar, initFn := pg.InitDefinitions(pkg, root.allTypeArray(), root.allPropArray())
initFile := jen.NewFilePath(pkg.Path())
initFile.Add(globalVar).Line().Add(initFn.Definition()).Line()
@ -933,7 +1018,7 @@ func (c *Converter) initFile(pkg gen.Package, root vocabulary, m *gen.ManagerGen
func (c *Converter) packageFiles(v vocabulary, m *gen.ManagerGenerator) (f []*File, e error) {
switch c.PackagePolicy {
case FlatUnderRoot:
pg := gen.NewPackageGenerator(c.typePropertyVocabName, m, c.typeProperty)
pg := gen.NewPackageGenerator(gen.JSONLDVocabName, m, c.typeProperty)
if tArr := v.typeArray(); len(tArr) > 0 {
// Only need one for all types.
pubI := pg.PublicDefinitions(tArr)
@ -1023,7 +1108,7 @@ func (c *Converter) packageFiles(v vocabulary, m *gen.ManagerGenerator) (f []*Fi
// is being generated in its own package.
func (c *Converter) typePackageFiles(tg *gen.TypeGenerator, vocabName string, m *gen.ManagerGenerator) (f []*File, e error) {
// Only need one for all types.
tpg := gen.NewTypePackageGenerator(c.typePropertyVocabName, m, c.typeProperty)
tpg := gen.NewTypePackageGenerator(gen.JSONLDVocabName, m, c.typeProperty)
pubI := tpg.PublicDefinitions([]*gen.TypeGenerator{tg})
// Public
pub := tg.PublicPackage()
@ -1190,6 +1275,67 @@ func (c *Converter) allExtendsAreIn(registry *rdf.RDFRegistry, t rdf.VocabularyT
return true
}
// jsonLDToFiles converts id and type to files.
//
// TODO: This function and the next are a lot of shared code (copy/paste).
// Deduplicate it.
func (c *Converter) jsonLDToFiles() (f []*File, e error) {
vName := strings.ToLower(gen.JSONLDVocabName)
// type property
var typePm *gen.PackageManager
typePm, e = c.propertyPackageManager(rdf.VocabularyProperty{Name:"type"}, gen.JSONLDVocabName)
if e != nil {
return
}
// Implementation
priv := typePm.PrivatePackage()
file := jen.NewFilePath(priv.Path())
s, t := c.typeProperty.Definitions()
file.Add(s.Definition()).Line().Add(t.Definition())
f = append(f, &File{
F: file,
FileName: fmt.Sprintf("gen_property_%s_%s.go", vName, c.typeProperty.PropertyName()),
Directory: priv.WriteDir(),
})
// Interface
pub := typePm.PublicPackage()
file = jen.NewFilePath(pub.Path())
for _, intf := range c.typeProperty.InterfaceDefinitions(typePm.PublicPackage()) {
file.Add(intf.Definition()).Line()
}
f = append(f, &File{
F: file,
FileName: fmt.Sprintf("gen_property_%s_%s_interface.go", vName, c.typeProperty.PropertyName()),
Directory: pub.WriteDir(),
})
// id property
var idPm *gen.PackageManager
idPm, e = c.propertyPackageManager(c.idProperty, gen.JSONLDVocabName)
if e != nil {
return
}
// Implementation
priv = idPm.PrivatePackage()
file = jen.NewFilePath(priv.Path())
file.Add(c.idProperty.Definition().Definition())
f = append(f, &File{
F: file,
FileName: fmt.Sprintf("gen_property_%s_%s.go", vName, c.idProperty.PropertyName()),
Directory: priv.WriteDir(),
})
// Interface
pub = idPm.PublicPackage()
file = jen.NewFilePath(pub.Path())
file.Add(c.idProperty.InterfaceDefinition(idPm.PublicPackage()).Definition())
f = append(f, &File{
F: file,
FileName: fmt.Sprintf("gen_property_%s_%s_interface.go", vName, c.idProperty.PropertyName()),
Directory: pub.WriteDir(),
})
return
}
// toFiles converts a vocabulary's types and properties to files.
func (c *Converter) toFiles(v vocabulary) (f []*File, e error) {
vName := strings.ToLower(v.Name)

ファイルの表示

@ -436,6 +436,18 @@ func (p *FunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, *co
),
)
}
aliasBlock := jen.Empty()
if p.vocabURI != nil {
aliasBlock = jen.If(
jen.List(
jen.Id("a"),
jen.Id("ok"),
).Op(":=").Id("aliasMap").Index(jen.Lit(p.vocabURI.String())),
jen.Id("ok"),
).Block(
jen.Id("alias").Op("=").Id("a"),
)
}
var deserialize *codegen.Function
if p.asIterator {
deserialize = codegen.NewCommentedFunction(
@ -445,15 +457,7 @@ func (p *FunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, *co
[]jen.Code{jen.Op("*").Id(p.StructName()), jen.Error()},
[]jen.Code{
jen.Id("alias").Op(":=").Lit(""),
jen.If(
jen.List(
jen.Id("a"),
jen.Id("ok"),
).Op(":=").Id("aliasMap").Index(jen.Lit(p.vocabURI.String())),
jen.Id("ok"),
).Block(
jen.Id("alias").Op("=").Id("a"),
),
aliasBlock,
p.wrapDeserializeCode(valueDeserializeFns, typeDeserializeFns),
},
fmt.Sprintf("%s creates an iterator from an element that has been unmarshalled from a text or binary format.", p.DeserializeFnName()))
@ -465,15 +469,7 @@ func (p *FunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, *co
[]jen.Code{jen.Op("*").Id(p.StructName()), jen.Error()},
[]jen.Code{
jen.Id("alias").Op(":=").Lit(""),
jen.If(
jen.List(
jen.Id("a"),
jen.Id("ok"),
).Op(":=").Id("aliasMap").Index(jen.Lit(p.vocabURI.String())),
jen.Id("ok"),
).Block(
jen.Id("alias").Op("=").Id("a"),
),
aliasBlock,
jen.Id("propName").Op(":=").Lit(p.PropertyName()),
jen.If(
jen.Len(jen.Id("alias")).Op(">").Lit(0),
@ -1133,6 +1129,14 @@ func (p *FunctionalPropertyGenerator) contextMethod() *codegen.Method {
).Block(
jen.Id("child").Op("=").Id(codegen.This()).Dot(p.getFnName(i)).Call().Dot(contextMethod).Call()))
}
mDef := jen.Var().Id("m").Map(jen.String()).String()
if p.vocabURI != nil {
mDef = jen.Id("m").Op(":=").Map(jen.String()).String().Values(
jen.Dict{
jen.Lit(p.vocabURI.String()): jen.Id(codegen.This()).Dot(aliasMember),
},
)
}
return codegen.NewCommentedValueMethod(
p.GetPrivatePackage().Path(),
contextMethod,
@ -1140,11 +1144,7 @@ func (p *FunctionalPropertyGenerator) contextMethod() *codegen.Method {
/*params=*/ nil,
[]jen.Code{jen.Map(jen.String()).String()},
[]jen.Code{
jen.Id("m").Op(":=").Map(jen.String()).String().Values(
jen.Dict{
jen.Lit(p.vocabURI.String()): jen.Id(codegen.This()).Dot(aliasMember),
},
),
mDef,
contextKind,
jen.Commentf("Since the literal maps in this function are determined at\ncode-generation time, this loop should not overwrite an existing key with a\nnew value."),
jen.For(

46
astool/gen/jsonld.go ノーマルファイル
ファイルの表示

@ -0,0 +1,46 @@
package gen
import ()
const (
JSONLDVocabName = "JSONLD"
JSONLDIdName = "id"
JSONLDTypeName = "type"
jsonLDIdCamelName = "Id"
jsonLDTypeCamelName = "Type"
jsonLDIdComment = `Provides the globally unique identifier for JSON-LD entities.`
jsonLDTypeComment = `Identifies the schema type(s) of the JSON-LD entity.`
)
// NewIdPropety returns the functional property for the JSON-LD "@id" property.
func NewIdProperty(pm *PackageManager, xsdAnyUri Kind) (*FunctionalPropertyGenerator, error) {
return NewFunctionalPropertyGenerator(
JSONLDVocabName,
nil,
"",
pm,
Identifier{
LowerName: JSONLDIdName,
CamelName: jsonLDIdCamelName,
},
jsonLDIdComment,
[]Kind{xsdAnyUri},
false)
}
// NewTypeProperty returns the non-functional property for the JSON-LD "@type"
// property.
func NewTypeProperty(pm *PackageManager, xsdAnyUri, xsdString Kind) (*NonFunctionalPropertyGenerator, error) {
return NewNonFunctionalPropertyGenerator(
JSONLDVocabName,
nil,
"",
pm,
Identifier{
LowerName: JSONLDTypeName,
CamelName: jsonLDTypeCamelName,
},
jsonLDTypeComment,
[]Kind{xsdAnyUri, xsdString},
false)
}

ファイルの表示

@ -614,6 +614,14 @@ func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method {
},
fmt.Sprintf("%s returns beyond-the-last iterator, which is nil. Can be used with the iterator's %s method and this property's %s method to iterate from front to back through all values.", endMethod, nextMethod, beginMethod)))
// Context Method
mDef := jen.Var().Id("m").Map(jen.String()).String()
if p.vocabURI != nil {
mDef = jen.Id("m").Op(":=").Map(jen.String()).String().Values(
jen.Dict{
jen.Lit(p.vocabURI.String()): jen.Id(codegen.This()).Dot(aliasMember),
},
)
}
methods = append(methods, codegen.NewCommentedValueMethod(
p.GetPrivatePackage().Path(),
contextMethod,
@ -621,11 +629,7 @@ func (p *NonFunctionalPropertyGenerator) funcs() []*codegen.Method {
/*params=*/ nil,
[]jen.Code{jen.Map(jen.String()).String()},
[]jen.Code{
jen.Id("m").Op(":=").Map(jen.String()).String().Values(
jen.Dict{
jen.Lit(p.vocabURI.String()): jen.Id(codegen.This()).Dot(aliasMember),
},
),
mDef,
jen.For(
jen.List(
jen.Id("_"),
@ -929,6 +933,18 @@ func (p *NonFunctionalPropertyGenerator) serializationFuncs() (*codegen.Method,
),
)
}
aliasBlock := jen.Empty()
if p.vocabURI != nil {
aliasBlock = jen.If(
jen.List(
jen.Id("a"),
jen.Id("ok"),
).Op(":=").Id("aliasMap").Index(jen.Lit(p.vocabURI.String())),
jen.Id("ok"),
).Block(
jen.Id("alias").Op("=").Id("a"),
)
}
deserialize := codegen.NewCommentedFunction(
p.GetPrivatePackage().Path(),
p.DeserializeFnName(),
@ -936,15 +952,7 @@ func (p *NonFunctionalPropertyGenerator) serializationFuncs() (*codegen.Method,
[]jen.Code{jen.Qual(p.GetPublicPackage().Path(), p.InterfaceName()), jen.Error()},
[]jen.Code{
jen.Id("alias").Op(":=").Lit(""),
jen.If(
jen.List(
jen.Id("a"),
jen.Id("ok"),
).Op(":=").Id("aliasMap").Index(jen.Lit(p.vocabURI.String())),
jen.Id("ok"),
).Block(
jen.Id("alias").Op("=").Id("a"),
),
aliasBlock,
jen.Id("propName").Op(":=").Lit(p.PropertyName()),
jen.If(
jen.Len(jen.Id("alias")).Op(">").Lit(0),

ファイルの表示

@ -165,11 +165,11 @@ type TypePackageGenerator struct {
func NewTypePackageGenerator(
typeVocabName string,
m *ManagerGenerator,
typeProperty *PropertyGenerator) *TypePackageGenerator {
typeProperty *NonFunctionalPropertyGenerator) *TypePackageGenerator {
return &TypePackageGenerator{
typeVocabName: typeVocabName,
m: m,
typeProperty: typeProperty,
typeProperty: &typeProperty.PropertyGenerator,
}
}
@ -222,11 +222,11 @@ type PackageGenerator struct {
}
// NewPackageGenerator creates a new PackageGenerator.
func NewPackageGenerator(typeVocabName string, m *ManagerGenerator, typeProperty *PropertyGenerator) *PackageGenerator {
func NewPackageGenerator(typeVocabName string, m *ManagerGenerator, typeProperty *NonFunctionalPropertyGenerator) *PackageGenerator {
return &PackageGenerator{
typeVocabName: typeVocabName,
m: m,
typeProperty: typeProperty,
typeProperty: &typeProperty.PropertyGenerator,
}
}

ファイルの表示

@ -37,10 +37,10 @@ const (
//
// TODO: Figure out how to obtain these names at code-generation
// runtime.
typeMember = "ActivityStreamsType"
getIdFunction = "GetActivityStreamsId"
setIdFunction = "SetActivityStreamsId"
idType = "ActivityStreamsIdProperty"
typeMember = JSONLDVocabName + jsonLDTypeCamelName
getIdFunction = getMethod + JSONLDVocabName + jsonLDIdCamelName
setIdFunction = setMethod + JSONLDVocabName + jsonLDIdCamelName
idType = JSONLDVocabName + jsonLDIdCamelName + "Property"
)
// typePropertyConstructorName returns the package variable name for the

ファイルの表示

@ -10,12 +10,12 @@ import (
)
const (
xmlName = "XMLSchema"
xmlSpec = "http://www.w3.org/2001/XMLSchema#"
anyURISpec = "anyURI"
XmlName = "XMLSchema"
XmlSpec = "http://www.w3.org/2001/XMLSchema#"
AnyURISpec = "anyURI"
dateTimeSpec = "dateTime"
floatSpec = "float"
stringSpec = "string"
StringSpec = "string"
booleanSpec = "boolean"
nonNegativeIntegerSpec = "nonNegativeInteger"
durationSpec = "duration"
@ -28,7 +28,7 @@ type XMLOntology struct {
// SpecURI returns the XML URI.
func (o *XMLOntology) SpecURI() string {
return xmlSpec
return XmlSpec
}
// Load the XML Ontology without an alias.
@ -40,43 +40,43 @@ func (o *XMLOntology) Load() ([]rdf.RDFNode, error) {
func (o *XMLOntology) LoadAsAlias(s string) ([]rdf.RDFNode, error) {
return []rdf.RDFNode{
&rdf.AliasedDelegate{
Spec: xmlSpec,
Spec: XmlSpec,
Alias: s,
Name: anyURISpec,
Name: AnyURISpec,
Delegate: &anyURI{pkg: o.Package},
},
&rdf.AliasedDelegate{
Spec: xmlSpec,
Spec: XmlSpec,
Alias: s,
Name: dateTimeSpec,
Delegate: &dateTime{pkg: o.Package},
},
&rdf.AliasedDelegate{
Spec: xmlSpec,
Spec: XmlSpec,
Alias: s,
Name: floatSpec,
Delegate: &float{pkg: o.Package},
},
&rdf.AliasedDelegate{
Spec: xmlSpec,
Spec: XmlSpec,
Alias: s,
Name: stringSpec,
Name: StringSpec,
Delegate: &xmlString{pkg: o.Package},
},
&rdf.AliasedDelegate{
Spec: xmlSpec,
Spec: XmlSpec,
Alias: s,
Name: booleanSpec,
Delegate: &boolean{pkg: o.Package},
},
&rdf.AliasedDelegate{
Spec: xmlSpec,
Spec: XmlSpec,
Alias: s,
Name: nonNegativeIntegerSpec,
Delegate: &nonNegativeInteger{pkg: o.Package},
},
&rdf.AliasedDelegate{
Spec: xmlSpec,
Spec: XmlSpec,
Alias: s,
Name: durationSpec,
Delegate: &duration{pkg: o.Package},
@ -87,7 +87,7 @@ func (o *XMLOntology) LoadAsAlias(s string) ([]rdf.RDFNode, error) {
// LoadSpecificAsAlias loads a specific node with an alias.
func (o *XMLOntology) LoadSpecificAsAlias(alias, name string) ([]rdf.RDFNode, error) {
switch name {
case anyURISpec:
case AnyURISpec:
return []rdf.RDFNode{
&rdf.AliasedDelegate{
Spec: "",
@ -114,7 +114,7 @@ func (o *XMLOntology) LoadSpecificAsAlias(alias, name string) ([]rdf.RDFNode, er
Delegate: &float{pkg: o.Package},
},
}, nil
case stringSpec:
case StringSpec:
return []rdf.RDFNode{
&rdf.AliasedDelegate{
Spec: "",
@ -163,13 +163,13 @@ func (o *XMLOntology) LoadElement(name string, payload map[string]interface{}) (
func (o *XMLOntology) GetByName(name string) (rdf.RDFNode, error) {
name = strings.TrimPrefix(name, o.SpecURI())
switch name {
case anyURISpec:
case AnyURISpec:
return &anyURI{pkg: o.Package}, nil
case dateTimeSpec:
return &dateTime{pkg: o.Package}, nil
case floatSpec:
return &float{pkg: o.Package}, nil
case stringSpec:
case StringSpec:
return &xmlString{pkg: o.Package}, nil
case booleanSpec:
return &boolean{pkg: o.Package}, nil
@ -200,17 +200,17 @@ func (a *anyURI) Exit(key string, ctx *rdf.ParsingContext) (bool, error) {
// Apply adds the anyURI value Kind to the XML namespace.
func (a *anyURI) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (bool, error) {
v, err := ctx.GetResultReferenceWithDefaults(xmlSpec, xmlName)
v, err := ctx.GetResultReferenceWithDefaults(XmlSpec, XmlName)
if err != nil {
return true, err
}
if len(v.Values[anyURISpec].Name) == 0 {
u, err := url.Parse(xmlSpec + anyURISpec)
if len(v.Values[AnyURISpec].Name) == 0 {
u, err := url.Parse(XmlSpec + AnyURISpec)
if err != nil {
return true, err
}
val := &rdf.VocabularyValue{
Name: anyURISpec,
Name: AnyURISpec,
URI: u,
DefinitionType: jen.Op("*").Qual("net/url", "URL"),
Zero: "&url.URL{}",
@ -218,7 +218,7 @@ func (a *anyURI) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (
IsURI: true,
SerializeFn: rdf.SerializeValueFunction(
a.pkg,
anyURISpec,
AnyURISpec,
jen.Op("*").Qual("net/url", "URL"),
[]jen.Code{
jen.Return(
@ -228,7 +228,7 @@ func (a *anyURI) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (
}),
DeserializeFn: rdf.DeserializeValueFunction(
a.pkg,
anyURISpec,
AnyURISpec,
jen.Op("*").Qual("net/url", "URL"),
[]jen.Code{
jen.Var().Id("u").Op("*").Qual("net/url", "URL"),
@ -273,7 +273,7 @@ func (a *anyURI) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (
}),
LessFn: rdf.LessFunction(
a.pkg,
anyURISpec,
AnyURISpec,
jen.Op("*").Qual("net/url", "URL"),
[]jen.Code{
jen.Return(
@ -281,7 +281,7 @@ func (a *anyURI) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (
),
}),
}
if err = v.SetValue(anyURISpec, val); err != nil {
if err = v.SetValue(AnyURISpec, val); err != nil {
return true, err
}
}
@ -307,12 +307,12 @@ func (d *dateTime) Exit(key string, ctx *rdf.ParsingContext) (bool, error) {
// Apply adds the xsd:dateTime value Kind to the XML namespace.
func (d *dateTime) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (bool, error) {
v, err := ctx.GetResultReferenceWithDefaults(xmlSpec, xmlName)
v, err := ctx.GetResultReferenceWithDefaults(XmlSpec, XmlName)
if err != nil {
return true, err
}
if len(v.Values[dateTimeSpec].Name) == 0 {
u, err := url.Parse(xmlSpec + dateTimeSpec)
u, err := url.Parse(XmlSpec + dateTimeSpec)
if err != nil {
return true, err
}
@ -417,12 +417,12 @@ func (f *float) Exit(key string, ctx *rdf.ParsingContext) (bool, error) {
// Apply adds xsd:float value Kind to the XML namespace.
func (f *float) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (bool, error) {
v, err := ctx.GetResultReferenceWithDefaults(xmlSpec, xmlName)
v, err := ctx.GetResultReferenceWithDefaults(XmlSpec, XmlName)
if err != nil {
return true, err
}
if len(v.Values[floatSpec].Name) == 0 {
u, err := url.Parse(xmlSpec + floatSpec)
u, err := url.Parse(XmlSpec + floatSpec)
if err != nil {
return true, err
}
@ -504,24 +504,24 @@ func (*xmlString) Exit(key string, ctx *rdf.ParsingContext) (bool, error) {
// Apply adds xsd:xmlString value Kind to the XML namespace.
func (s *xmlString) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (bool, error) {
v, err := ctx.GetResultReferenceWithDefaults(xmlSpec, xmlName)
v, err := ctx.GetResultReferenceWithDefaults(XmlSpec, XmlName)
if err != nil {
return true, err
}
if len(v.Values[stringSpec].Name) == 0 {
u, err := url.Parse(xmlSpec + stringSpec)
if len(v.Values[StringSpec].Name) == 0 {
u, err := url.Parse(XmlSpec + StringSpec)
if err != nil {
return true, err
}
val := &rdf.VocabularyValue{
Name: stringSpec,
Name: StringSpec,
URI: u,
DefinitionType: jen.String(),
Zero: "\"\"",
IsNilable: false,
SerializeFn: rdf.SerializeValueFunction(
s.pkg,
stringSpec,
StringSpec,
jen.Id("string"),
[]jen.Code{
jen.Return(
@ -531,7 +531,7 @@ func (s *xmlString) Apply(key string, value interface{}, ctx *rdf.ParsingContext
}),
DeserializeFn: rdf.DeserializeValueFunction(
s.pkg,
stringSpec,
StringSpec,
jen.Id("string"),
[]jen.Code{
jen.If(
@ -557,7 +557,7 @@ func (s *xmlString) Apply(key string, value interface{}, ctx *rdf.ParsingContext
}),
LessFn: rdf.LessFunction(
s.pkg,
stringSpec,
StringSpec,
jen.Id("string"),
[]jen.Code{
jen.Return(
@ -565,7 +565,7 @@ func (s *xmlString) Apply(key string, value interface{}, ctx *rdf.ParsingContext
),
}),
}
if err = v.SetValue(stringSpec, val); err != nil {
if err = v.SetValue(StringSpec, val); err != nil {
return true, err
}
}
@ -591,12 +591,12 @@ func (*boolean) Exit(key string, ctx *rdf.ParsingContext) (bool, error) {
// Apply adds boolean value Kind to the XML namespace.
func (b *boolean) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (bool, error) {
v, err := ctx.GetResultReferenceWithDefaults(xmlSpec, xmlName)
v, err := ctx.GetResultReferenceWithDefaults(XmlSpec, XmlName)
if err != nil {
return true, err
}
if len(v.Values[booleanSpec].Name) == 0 {
u, err := url.Parse(xmlSpec + booleanSpec)
u, err := url.Parse(XmlSpec + booleanSpec)
if err != nil {
return true, err
}
@ -709,12 +709,12 @@ func (*nonNegativeInteger) Exit(key string, ctx *rdf.ParsingContext) (bool, erro
// Apply adds xsd:nonNegativeInteger value Kind to the XML namespace.
func (n *nonNegativeInteger) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (bool, error) {
v, err := ctx.GetResultReferenceWithDefaults(xmlSpec, xmlName)
v, err := ctx.GetResultReferenceWithDefaults(XmlSpec, XmlName)
if err != nil {
return true, err
}
if len(v.Values[nonNegativeIntegerSpec].Name) == 0 {
u, err := url.Parse(xmlSpec + nonNegativeIntegerSpec)
u, err := url.Parse(XmlSpec + nonNegativeIntegerSpec)
if err != nil {
return true, err
}
@ -814,12 +814,12 @@ func (*duration) Exit(key string, ctx *rdf.ParsingContext) (bool, error) {
//
// Avoid at all costs.
func (d *duration) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (bool, error) {
v, err := ctx.GetResultReferenceWithDefaults(xmlSpec, xmlName)
v, err := ctx.GetResultReferenceWithDefaults(XmlSpec, XmlName)
if err != nil {
return true, err
}
if len(v.Values[durationSpec].Name) == 0 {
u, err := url.Parse(xmlSpec + durationSpec)
u, err := url.Parse(XmlSpec + durationSpec)
if err != nil {
return true, err
}

ファイルの表示

@ -33,13 +33,6 @@
"id": "https://w3id.org/security/v1#PublicKey",
"type": "owl:Class",
"notes": "A public key represents a public cryptographical key for a user",
"subClassOf": [
{
"type": "owl:Class",
"url": "https://www.w3.org/ns/activitystreams#Object",
"name": "as:Object"
}
],
"name": "PublicKey",
"url": "https://w3id.org/security/v1#PublicKey",
"@wtf_typeless": true