Bugfixes as part of testing.
- Add missing ActivityPub actor and object properties - Introspect type when deserializing - Unknown on properties is now an interface - Can now generate code when an extends hierarchy is specified multiple times as a range.
このコミットが含まれているのは:
コミット
f90d161ed1
|
@ -4823,6 +4823,536 @@
|
|||
},
|
||||
"name": "deleted",
|
||||
"url": "https://www.w3.org/TR/activitystreams-vocabulary/#dfn-deleted"
|
||||
},
|
||||
{
|
||||
"id": "https://www.w3.org/TR/activitypub/#inbox",
|
||||
"type": [
|
||||
"rdf:Property",
|
||||
"owl:FunctionalProperty"
|
||||
],
|
||||
"example": {
|
||||
"id": "https://www.w3.org/TR/activitypub/#example9",
|
||||
"type": "http://schema.org/CreativeWork",
|
||||
"mainEntity": {
|
||||
"@context": ["https://www.w3.org/ns/activitystreams", {"@language": "ja"}],
|
||||
"type": "Person",
|
||||
"id": "https://kenzoishii.example.com/",
|
||||
"following": "https://kenzoishii.example.com/following.json",
|
||||
"followers": "https://kenzoishii.example.com/followers.json",
|
||||
"liked": "https://kenzoishii.example.com/liked.json",
|
||||
"inbox": "https://kenzoishii.example.com/inbox.json",
|
||||
"outbox": "https://kenzoishii.example.com/feed.json",
|
||||
"preferredUsername": "kenzoishii",
|
||||
"name": "石井健蔵",
|
||||
"summary": "この方はただの例です",
|
||||
"icon": ["https://kenzoishii.example.com/image/165987aklre4"]
|
||||
},
|
||||
"name": "Example 9"
|
||||
},
|
||||
"notes": "A reference to an ActivityStreams OrderedCollection comprised of all the messages received by the actor.",
|
||||
"domain": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": [
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Application",
|
||||
"name": "Application"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Group",
|
||||
"name": "Group"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Organization",
|
||||
"name": "Organization"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Person",
|
||||
"name": "Person"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Service",
|
||||
"name": "Service"
|
||||
}
|
||||
]
|
||||
},
|
||||
"isDefinedBy": "https://www.w3.org/TR/activitypub/#inbox",
|
||||
"range": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": {
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#OrderedCollection",
|
||||
"name": "OrderedCollection"
|
||||
}
|
||||
},
|
||||
"name": "inbox",
|
||||
"url": "https://www.w3.org/TR/activitypub/#inbox"
|
||||
},
|
||||
{
|
||||
"id": "https://www.w3.org/TR/activitypub/#outbox",
|
||||
"type": [
|
||||
"rdf:Property",
|
||||
"owl:FunctionalProperty"
|
||||
],
|
||||
"example": {
|
||||
"id": "https://www.w3.org/TR/activitypub/#example9",
|
||||
"type": "http://schema.org/CreativeWork",
|
||||
"mainEntity": {
|
||||
"@context": ["https://www.w3.org/ns/activitystreams", {"@language": "ja"}],
|
||||
"type": "Person",
|
||||
"id": "https://kenzoishii.example.com/",
|
||||
"following": "https://kenzoishii.example.com/following.json",
|
||||
"followers": "https://kenzoishii.example.com/followers.json",
|
||||
"liked": "https://kenzoishii.example.com/liked.json",
|
||||
"inbox": "https://kenzoishii.example.com/inbox.json",
|
||||
"outbox": "https://kenzoishii.example.com/feed.json",
|
||||
"preferredUsername": "kenzoishii",
|
||||
"name": "石井健蔵",
|
||||
"summary": "この方はただの例です",
|
||||
"icon": ["https://kenzoishii.example.com/image/165987aklre4"]
|
||||
},
|
||||
"name": "Example 9"
|
||||
},
|
||||
"notes": "An ActivityStreams OrderedCollection comprised of all the messages produced by the actor",
|
||||
"domain": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": [
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Application",
|
||||
"name": "Application"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Group",
|
||||
"name": "Group"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Organization",
|
||||
"name": "Organization"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Person",
|
||||
"name": "Person"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Service",
|
||||
"name": "Service"
|
||||
}
|
||||
]
|
||||
},
|
||||
"isDefinedBy": "https://www.w3.org/TR/activitypub/#outbox",
|
||||
"range": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": {
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#OrderedCollection",
|
||||
"name": "OrderedCollection"
|
||||
}
|
||||
},
|
||||
"name": "outbox",
|
||||
"url": "https://www.w3.org/TR/activitypub/#outbox"
|
||||
},
|
||||
{
|
||||
"id": "https://www.w3.org/TR/activitypub/#following",
|
||||
"type": [
|
||||
"rdf:Property",
|
||||
"owl:FunctionalProperty"
|
||||
],
|
||||
"example": {
|
||||
"id": "https://www.w3.org/TR/activitypub/#example9",
|
||||
"type": "http://schema.org/CreativeWork",
|
||||
"mainEntity": {
|
||||
"@context": ["https://www.w3.org/ns/activitystreams", {"@language": "ja"}],
|
||||
"type": "Person",
|
||||
"id": "https://kenzoishii.example.com/",
|
||||
"following": "https://kenzoishii.example.com/following.json",
|
||||
"followers": "https://kenzoishii.example.com/followers.json",
|
||||
"liked": "https://kenzoishii.example.com/liked.json",
|
||||
"inbox": "https://kenzoishii.example.com/inbox.json",
|
||||
"outbox": "https://kenzoishii.example.com/feed.json",
|
||||
"preferredUsername": "kenzoishii",
|
||||
"name": "石井健蔵",
|
||||
"summary": "この方はただの例です",
|
||||
"icon": ["https://kenzoishii.example.com/image/165987aklre4"]
|
||||
},
|
||||
"name": "Example 9"
|
||||
},
|
||||
"notes": "A link to an ActivityStreams collection of the actors that this actor is following",
|
||||
"domain": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": [
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Application",
|
||||
"name": "Application"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Group",
|
||||
"name": "Group"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Organization",
|
||||
"name": "Organization"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Person",
|
||||
"name": "Person"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Service",
|
||||
"name": "Service"
|
||||
}
|
||||
]
|
||||
},
|
||||
"isDefinedBy": "https://www.w3.org/TR/activitypub/#following",
|
||||
"range": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": [
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#OrderedCollection",
|
||||
"name": "OrderedCollection"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Collection",
|
||||
"name": "Collection"
|
||||
}
|
||||
]
|
||||
},
|
||||
"name": "following",
|
||||
"url": "https://www.w3.org/TR/activitypub/#following"
|
||||
},
|
||||
{
|
||||
"id": "https://www.w3.org/TR/activitypub/#followers",
|
||||
"type": [
|
||||
"rdf:Property",
|
||||
"owl:FunctionalProperty"
|
||||
],
|
||||
"example": {
|
||||
"id": "https://www.w3.org/TR/activitypub/#example9",
|
||||
"type": "http://schema.org/CreativeWork",
|
||||
"mainEntity": {
|
||||
"@context": ["https://www.w3.org/ns/activitystreams", {"@language": "ja"}],
|
||||
"type": "Person",
|
||||
"id": "https://kenzoishii.example.com/",
|
||||
"following": "https://kenzoishii.example.com/following.json",
|
||||
"followers": "https://kenzoishii.example.com/followers.json",
|
||||
"liked": "https://kenzoishii.example.com/liked.json",
|
||||
"inbox": "https://kenzoishii.example.com/inbox.json",
|
||||
"outbox": "https://kenzoishii.example.com/feed.json",
|
||||
"preferredUsername": "kenzoishii",
|
||||
"name": "石井健蔵",
|
||||
"summary": "この方はただの例です",
|
||||
"icon": ["https://kenzoishii.example.com/image/165987aklre4"]
|
||||
},
|
||||
"name": "Example 9"
|
||||
},
|
||||
"notes": "A link to an ActivityStreams collection of the actors that follow this actor",
|
||||
"domain": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": [
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Application",
|
||||
"name": "Application"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Group",
|
||||
"name": "Group"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Organization",
|
||||
"name": "Organization"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Person",
|
||||
"name": "Person"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Service",
|
||||
"name": "Service"
|
||||
}
|
||||
]
|
||||
},
|
||||
"isDefinedBy": "https://www.w3.org/TR/activitypub/#followers",
|
||||
"range": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": [
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#OrderedCollection",
|
||||
"name": "OrderedCollection"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Collection",
|
||||
"name": "Collection"
|
||||
}
|
||||
]
|
||||
},
|
||||
"name": "followers",
|
||||
"url": "https://www.w3.org/TR/activitypub/#followers"
|
||||
},
|
||||
{
|
||||
"id": "https://www.w3.org/TR/activitypub/#liked",
|
||||
"type": [
|
||||
"rdf:Property",
|
||||
"owl:FunctionalProperty"
|
||||
],
|
||||
"example": {
|
||||
"id": "https://www.w3.org/TR/activitypub/#example9",
|
||||
"type": "http://schema.org/CreativeWork",
|
||||
"mainEntity": {
|
||||
"@context": ["https://www.w3.org/ns/activitystreams", {"@language": "ja"}],
|
||||
"type": "Person",
|
||||
"id": "https://kenzoishii.example.com/",
|
||||
"following": "https://kenzoishii.example.com/following.json",
|
||||
"followers": "https://kenzoishii.example.com/followers.json",
|
||||
"liked": "https://kenzoishii.example.com/liked.json",
|
||||
"inbox": "https://kenzoishii.example.com/inbox.json",
|
||||
"outbox": "https://kenzoishii.example.com/feed.json",
|
||||
"preferredUsername": "kenzoishii",
|
||||
"name": "石井健蔵",
|
||||
"summary": "この方はただの例です",
|
||||
"icon": ["https://kenzoishii.example.com/image/165987aklre4"]
|
||||
},
|
||||
"name": "Example 9"
|
||||
},
|
||||
"notes": "A link to an ActivityStreams collection of objects this actor has liked",
|
||||
"domain": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": [
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Application",
|
||||
"name": "Application"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Group",
|
||||
"name": "Group"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Organization",
|
||||
"name": "Organization"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Person",
|
||||
"name": "Person"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Service",
|
||||
"name": "Service"
|
||||
}
|
||||
]
|
||||
},
|
||||
"isDefinedBy": "https://www.w3.org/TR/activitypub/#liked",
|
||||
"range": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": [
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#OrderedCollection",
|
||||
"name": "OrderedCollection"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Collection",
|
||||
"name": "Collection"
|
||||
}
|
||||
]
|
||||
},
|
||||
"name": "liked",
|
||||
"url": "https://www.w3.org/TR/activitypub/#liked"
|
||||
},
|
||||
{
|
||||
"id": "https://www.w3.org/TR/activitypub/#likes",
|
||||
"type": [
|
||||
"rdf:Property",
|
||||
"owl:FunctionalProperty"
|
||||
],
|
||||
"notes": "This is a list of all Like activities with this object as the object property",
|
||||
"domain": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": {
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Object",
|
||||
"name": "Object"
|
||||
}
|
||||
},
|
||||
"isDefinedBy": "https://www.w3.org/TR/activitypub/#likes",
|
||||
"range": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": [
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#OrderedCollection",
|
||||
"name": "OrderedCollection"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Collection",
|
||||
"name": "Collection"
|
||||
}
|
||||
]
|
||||
},
|
||||
"name": "likes",
|
||||
"url": "https://www.w3.org/TR/activitypub/#likes"
|
||||
},
|
||||
{
|
||||
"id": "https://www.w3.org/TR/activitypub/#shares",
|
||||
"type": [
|
||||
"rdf:Property",
|
||||
"owl:FunctionalProperty"
|
||||
],
|
||||
"notes": "This is a list of all Announce activities with this object as the object property",
|
||||
"domain": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": {
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Object",
|
||||
"name": "Object"
|
||||
}
|
||||
},
|
||||
"isDefinedBy": "https://www.w3.org/TR/activitypub/#shares",
|
||||
"range": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": [
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#OrderedCollection",
|
||||
"name": "OrderedCollection"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Collection",
|
||||
"name": "Collection"
|
||||
}
|
||||
]
|
||||
},
|
||||
"name": "shares",
|
||||
"url": "https://www.w3.org/TR/activitypub/#shares"
|
||||
},
|
||||
{
|
||||
"id": "https://www.w3.org/TR/activitypub/#streams",
|
||||
"type": "rdf:Property",
|
||||
"notes": "A list of supplementary Collections which may be of interest",
|
||||
"domain": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": [
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Application",
|
||||
"name": "Application"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Group",
|
||||
"name": "Group"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Organization",
|
||||
"name": "Organization"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Person",
|
||||
"name": "Person"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Service",
|
||||
"name": "Service"
|
||||
}
|
||||
]
|
||||
},
|
||||
"isDefinedBy": "https://www.w3.org/TR/activitypub/#streams",
|
||||
"range": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": [
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#OrderedCollection",
|
||||
"name": "OrderedCollection"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Collection",
|
||||
"name": "Collection"
|
||||
}
|
||||
]
|
||||
},
|
||||
"name": "streams",
|
||||
"url": "https://www.w3.org/TR/activitypub/#streams"
|
||||
},
|
||||
{
|
||||
"id": "https://www.w3.org/TR/activitypub/#preferredUsername",
|
||||
"type": [
|
||||
"rdf:Property",
|
||||
"owl:FunctionalProperty"
|
||||
],
|
||||
"notes": "A short username which may be used to refer to the actor, with no uniqueness guarantees",
|
||||
"domain": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": [
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Application",
|
||||
"name": "Application"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Group",
|
||||
"name": "Group"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Organization",
|
||||
"name": "Organization"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Person",
|
||||
"name": "Person"
|
||||
},
|
||||
{
|
||||
"type": "owl:Class",
|
||||
"url": "https://www.w3.org/ns/activitystreams#Service",
|
||||
"name": "Service"
|
||||
}
|
||||
]
|
||||
},
|
||||
"isDefinedBy": "https://www.w3.org/TR/activitypub/#preferredUsername",
|
||||
"range": {
|
||||
"type": "owl:Class",
|
||||
"unionOf": [
|
||||
"xsd:string",
|
||||
"rdf:langString"
|
||||
]
|
||||
},
|
||||
"name": "preferredUsername",
|
||||
"url": "https://www.w3.org/TR/activitypub/#preferredUsername"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -317,7 +317,7 @@ func (p *FunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, *co
|
|||
/*params=*/ nil,
|
||||
[]jen.Code{jen.Interface(), jen.Error()},
|
||||
[]jen.Code{serializeFns, jen.Return(
|
||||
jen.String().Parens(jen.Id(codegen.This()).Dot(unknownMemberName)),
|
||||
jen.Id(codegen.This()).Dot(unknownMemberName),
|
||||
jen.Nil(),
|
||||
)},
|
||||
fmt.Sprintf("%s converts this into an interface representation suitable for marshalling into a text or binary format. Applications should not need this function as most typical use cases serialize types instead of individual properties. It is exposed for alternatives to go-fed implementations to use.", p.serializeFnName()))
|
||||
|
@ -384,7 +384,7 @@ func (p *FunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, *co
|
|||
).Block(
|
||||
jen.Id("alias").Op("=").Id("a"),
|
||||
),
|
||||
p.wrapDeserializeCode(valueDeserializeFns, typeDeserializeFns, false).Line().Return(
|
||||
p.wrapDeserializeCode(valueDeserializeFns, typeDeserializeFns).Line().Return(
|
||||
jen.Nil(),
|
||||
jen.Qual("fmt", "Errorf").Call(
|
||||
jen.Lit("could not deserialize %q property"),
|
||||
|
@ -430,7 +430,7 @@ func (p *FunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, *co
|
|||
),
|
||||
jen.Id("ok"),
|
||||
).Block(
|
||||
p.wrapDeserializeCode(valueDeserializeFns, typeDeserializeFns, true),
|
||||
p.wrapDeserializeCode(valueDeserializeFns, typeDeserializeFns),
|
||||
),
|
||||
jen.Return(
|
||||
jen.Nil(),
|
||||
|
@ -981,7 +981,7 @@ func (p *FunctionalPropertyGenerator) multiTypeFuncs() []*codegen.Method {
|
|||
// unknownMemberDef returns the definition of a struct member that handles
|
||||
// a property whose type is unknown.
|
||||
func (p *FunctionalPropertyGenerator) unknownMemberDef() jen.Code {
|
||||
return jen.Id(unknownMemberName).Index().Byte()
|
||||
return jen.Id(unknownMemberName).Interface()
|
||||
}
|
||||
|
||||
// iriMemberDef returns the definition of a struct member that handles
|
||||
|
@ -992,7 +992,7 @@ func (p *FunctionalPropertyGenerator) iriMemberDef() jen.Code {
|
|||
|
||||
// wrapDeserializeCode generates the "else if it's a []byte" code and IRI code
|
||||
// used for deserializing unknown values.
|
||||
func (p *FunctionalPropertyGenerator) wrapDeserializeCode(valueExisting, typeExisting jen.Code, errorAtEnd bool) *jen.Statement {
|
||||
func (p *FunctionalPropertyGenerator) wrapDeserializeCode(valueExisting, typeExisting jen.Code) *jen.Statement {
|
||||
iriCode := jen.Empty()
|
||||
if !p.hasURIKind() {
|
||||
iriCode = jen.If(
|
||||
|
@ -1032,44 +1032,24 @@ func (p *FunctionalPropertyGenerator) wrapDeserializeCode(valueExisting, typeExi
|
|||
jen.Id("ok"),
|
||||
).Block(
|
||||
typeExisting,
|
||||
).Else()
|
||||
).Line()
|
||||
}
|
||||
if p.hasValueKind() {
|
||||
iriCode = iriCode.Add(valueExisting).Else()
|
||||
iriCode = iriCode.Add(valueExisting).Line()
|
||||
}
|
||||
iriCode = iriCode.Add(
|
||||
jen.If(
|
||||
jen.List(
|
||||
jen.Id("str"),
|
||||
jen.Id("ok"),
|
||||
).Op(":=").Id("i").Assert(
|
||||
jen.String(),
|
||||
),
|
||||
jen.Id("ok"),
|
||||
).Block(
|
||||
jen.Id(codegen.This()).Op(":=").Op("&").Id(p.StructName()).Values(
|
||||
jen.Dict{
|
||||
jen.Id(unknownMemberName): jen.Index().Byte().Parens(jen.Id("str")),
|
||||
jen.Id(aliasMember): jen.Id("alias"),
|
||||
},
|
||||
),
|
||||
jen.Return(
|
||||
jen.Id(codegen.This()),
|
||||
jen.Nil(),
|
||||
),
|
||||
jen.Id(codegen.This()).Op(":=").Op("&").Id(p.StructName()).Values(
|
||||
jen.Dict{
|
||||
jen.Id(unknownMemberName): jen.Id("i"),
|
||||
jen.Id(aliasMember): jen.Id("alias"),
|
||||
},
|
||||
),
|
||||
jen.Line(),
|
||||
jen.Return(
|
||||
jen.Id(codegen.This()),
|
||||
jen.Nil(),
|
||||
),
|
||||
)
|
||||
if errorAtEnd {
|
||||
iriCode = iriCode.Else().Block(
|
||||
jen.Return(
|
||||
jen.Nil(),
|
||||
jen.Qual("fmt", "Errorf").Call(
|
||||
jen.Lit("could not deserialize %q property"),
|
||||
jen.Lit(p.PropertyName()),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
return iriCode
|
||||
}
|
||||
|
||||
|
|
|
@ -232,7 +232,7 @@ func (p *PropertyGenerator) SetKindFns(docName, idName string, qualKind *jen.Sta
|
|||
for i, kind := range p.kinds {
|
||||
if kind.Name.LowerName == docName {
|
||||
if kind.SerializeFn != nil || kind.DeserializeFn != nil || kind.LessFn != nil {
|
||||
return fmt.Errorf("property kind already has serialization functions set for %q", docName)
|
||||
return fmt.Errorf("property kind already has serialization functions set for %q: %s", docName, p.PropertyName())
|
||||
}
|
||||
kind.ConcreteKind = qualKind
|
||||
kind.DeserializeFn = deser.On(managerInitName())
|
||||
|
|
|
@ -784,7 +784,7 @@ func (r *ResolverGenerator) resolverFunctions(name, comment string) (f []*codege
|
|||
r.pkg.Path(),
|
||||
fmt.Sprintf("%s%s", constructorName, name),
|
||||
[]jen.Code{
|
||||
jen.Id("callbacks").Index().Interface(),
|
||||
jen.Id("callbacks").Op("...").Interface(),
|
||||
},
|
||||
[]jen.Code{
|
||||
jen.Op("*").Id(name),
|
||||
|
|
|
@ -187,14 +187,20 @@ func (t *TypeGenerator) apply(m *ManagerGenerator) error {
|
|||
kind := jen.Qual(t.PublicPackage().Path(), t.InterfaceName())
|
||||
// Refursively-applying function.
|
||||
var setKindsOnWhoseProps func(whichType *TypeGenerator) error
|
||||
// Map to ensure we only call each property once.
|
||||
propsSet := make(map[Property]bool)
|
||||
setKindsOnWhoseProps = func(whichType *TypeGenerator) error {
|
||||
// Apply this TypeGenerator's kinds to whichType's range of
|
||||
// properties.
|
||||
for _, p := range whichType.rangeProperties {
|
||||
if propsSet[p] {
|
||||
continue
|
||||
}
|
||||
// Kluge: convert.toIdentifier must match this!
|
||||
if e := p.SetKindFns(t.TypeName(), strings.Title(t.TypeName()), kind, deser); e != nil {
|
||||
return e
|
||||
}
|
||||
propsSet[p] = true
|
||||
}
|
||||
// Recursively apply this TypeGenerator's kinds to the parents
|
||||
// of whichType.
|
||||
|
@ -635,6 +641,13 @@ func (t *TypeGenerator) serializationMethod() (ser *codegen.Method) {
|
|||
jen.Id("m").Op(":=").Make(
|
||||
jen.Map(jen.String()).Interface(),
|
||||
),
|
||||
jen.Id("typeName").Op(":=").Lit(t.TypeName()),
|
||||
jen.If(
|
||||
jen.Len(jen.Id(codegen.This()).Dot(aliasMember)).Op(">").Lit(0),
|
||||
).Block(
|
||||
jen.Id("typeName").Op("=").Id(codegen.This()).Dot(aliasMember).Op("+").Lit(":").Op("+").Lit(t.TypeName()),
|
||||
),
|
||||
jen.Id("m").Index(jen.Lit("type")).Op("=").Id("typeName"),
|
||||
serCode,
|
||||
unknownCode,
|
||||
jen.Return(jen.Id("m"), jen.Nil()),
|
||||
|
@ -774,6 +787,7 @@ func (t *TypeGenerator) deserializationFn() (deser *codegen.Function) {
|
|||
[]jen.Code{jen.Op("*").Id(t.TypeName()), jen.Error()},
|
||||
[]jen.Code{
|
||||
jen.Id("alias").Op(":=").Lit(""),
|
||||
jen.Id("aliasPrefix").Op(":=").Lit(""),
|
||||
jen.If(
|
||||
jen.List(
|
||||
jen.Id("a"),
|
||||
|
@ -782,11 +796,86 @@ func (t *TypeGenerator) deserializationFn() (deser *codegen.Function) {
|
|||
jen.Id("ok"),
|
||||
).Block(
|
||||
jen.Id("alias").Op("=").Id("a"),
|
||||
jen.Id("aliasPrefix").Op("=").Id("a").Op("+").Lit(":"),
|
||||
),
|
||||
jen.Id(codegen.This()).Op(":=").Op("&").Id(t.TypeName()).Values(jen.Dict{
|
||||
jen.Id(aliasMember): jen.Id("alias"),
|
||||
jen.Id(unknownMember): jen.Make(jen.Map(jen.String()).Interface()),
|
||||
}),
|
||||
jen.If(
|
||||
jen.List(
|
||||
jen.Id("typeValue"),
|
||||
jen.Id("ok"),
|
||||
).Op(":=").Id("m").Index(jen.Lit("type")),
|
||||
jen.Op("!").Id("ok"),
|
||||
).Block(
|
||||
jen.Return(
|
||||
jen.Nil(),
|
||||
jen.Qual("fmt", "Errorf").Call(jen.Lit("no \"type\" property in map")),
|
||||
),
|
||||
).Else().If(
|
||||
jen.List(
|
||||
jen.Id("typeString"),
|
||||
jen.Id("ok"),
|
||||
).Op(":=").Id("typeValue").Assert(jen.String()),
|
||||
jen.Id("ok"),
|
||||
).Block(
|
||||
jen.Id("typeName").Op(":=").Qual("strings", "TrimPrefix").Call(
|
||||
jen.Id("typeString"),
|
||||
jen.Id("aliasPrefix"),
|
||||
),
|
||||
jen.If(
|
||||
jen.Id("typeName").Op("!=").Lit(t.TypeName()),
|
||||
).Block(
|
||||
jen.Return(
|
||||
jen.Nil(),
|
||||
jen.Qual("fmt", "Errorf").Call(jen.Lit("\"type\" property is not of %q type: %s"), jen.Lit(t.TypeName()), jen.Id("typeName")),
|
||||
),
|
||||
),
|
||||
jen.Commentf("Fall through, success in finding a proper Type"),
|
||||
).Else().If(
|
||||
jen.List(
|
||||
jen.Id("arrType"),
|
||||
jen.Id("ok"),
|
||||
).Op(":=").Id("typeValue").Assert(jen.Index().Interface()),
|
||||
jen.Id("ok"),
|
||||
).Block(
|
||||
jen.Id("found").Op(":=").False(),
|
||||
jen.For(
|
||||
jen.List(
|
||||
jen.Id("_"),
|
||||
jen.Id("elemVal"),
|
||||
).Op(":=").Range().Id("arrType"),
|
||||
).Block(
|
||||
jen.If(
|
||||
jen.List(
|
||||
jen.Id("typeString"),
|
||||
jen.Id("ok"),
|
||||
).Op(":=").Id("elemVal").Assert(jen.String()),
|
||||
jen.Id("ok").Op("&&").Qual("strings", "TrimPrefix").Call(
|
||||
jen.Id("typeString"),
|
||||
jen.Id("aliasPrefix"),
|
||||
).Op("==").Lit(t.TypeName()),
|
||||
).Block(
|
||||
jen.Id("found").Op("=").True(),
|
||||
jen.Break(),
|
||||
),
|
||||
),
|
||||
jen.If(
|
||||
jen.Op("!").Id("found"),
|
||||
).Block(
|
||||
jen.Return(
|
||||
jen.Nil(),
|
||||
jen.Qual("fmt", "Errorf").Call(jen.Lit("could not find a \"type\" property of value %q"), jen.Lit(t.TypeName())),
|
||||
),
|
||||
),
|
||||
jen.Commentf("Fall through, success in finding a proper Type"),
|
||||
).Else().Block(
|
||||
jen.Return(
|
||||
jen.Nil(),
|
||||
jen.Qual("fmt", "Errorf").Call(jen.Lit("\"type\" property is unrecognized type: %T"), jen.Id("typeValue")),
|
||||
),
|
||||
),
|
||||
deserCode,
|
||||
unknownCode,
|
||||
jen.Return(jen.Id(codegen.This()), jen.Nil()),
|
||||
|
@ -837,7 +926,7 @@ func (t *TypeGenerator) allGetters() (m []*codegen.Method) {
|
|||
// allSetters returns all property Setters for this type.
|
||||
func (t *TypeGenerator) allSetters() (m []*codegen.Method) {
|
||||
for _, property := range t.allProperties() {
|
||||
m = append(m, codegen.NewCommentedValueMethod(
|
||||
m = append(m, codegen.NewCommentedPointerMethod(
|
||||
t.PrivatePackage().Path(),
|
||||
fmt.Sprintf("Set%s", t.memberName(property)),
|
||||
t.TypeName(),
|
||||
|
|
読み込み中…
新しいイシューから参照