this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

lexicon: fix 'params' issue (#1154)

The root cause was that this package was assuming that query and
procedure "params" were required, when they are actually optional.

This corrects them to be optional (pointer type), and skips validation
when nil.

Also adds "minimal" example schemas as regression tests.

Fixes: https://github.com/bluesky-social/indigo/issues/1153

authored by

bnewbold and committed by
GitHub
c5eaa30f b7ac8254

+191 -17
+37 -16
atproto/lexicon/language.go
··· 83 83 } 84 84 s.Inner = v 85 85 case SchemaQuery: 86 - for i, val := range v.Parameters.Properties { 87 - val.SetBase(base) 88 - v.Parameters.Properties[i] = val 86 + if v.Parameters != nil { 87 + for i, val := range v.Parameters.Properties { 88 + val.SetBase(base) 89 + v.Parameters.Properties[i] = val 90 + } 89 91 } 90 92 if v.Output != nil && v.Output.Schema != nil { 91 93 v.Output.Schema.SetBase(base) 92 94 } 93 95 s.Inner = v 94 96 case SchemaProcedure: 95 - for i, val := range v.Parameters.Properties { 96 - val.SetBase(base) 97 - v.Parameters.Properties[i] = val 97 + if v.Parameters != nil { 98 + for i, val := range v.Parameters.Properties { 99 + val.SetBase(base) 100 + v.Parameters.Properties[i] = val 101 + } 98 102 } 99 103 if v.Input != nil && v.Input.Schema != nil { 100 104 v.Input.Schema.SetBase(base) ··· 104 108 } 105 109 s.Inner = v 106 110 case SchemaSubscription: 107 - for i, val := range v.Parameters.Properties { 108 - val.SetBase(base) 109 - v.Parameters.Properties[i] = val 111 + if v.Parameters != nil { 112 + for i, val := range v.Parameters.Properties { 113 + val.SetBase(base) 114 + v.Parameters.Properties[i] = val 115 + } 110 116 } 111 117 if v.Message != nil { 112 118 v.Message.Schema.SetBase(base) ··· 326 332 type SchemaQuery struct { 327 333 Type string `json:"type"` // "query" 328 334 Description *string `json:"description,omitempty"` 329 - Parameters SchemaParams `json:"parameters"` 330 - Output *SchemaBody `json:"output"` 335 + Parameters *SchemaParams `json:"parameters"` // optional 336 + Output *SchemaBody `json:"output"` // optional 331 337 Errors []SchemaError `json:"errors,omitempty"` // optional 332 338 } 333 339 ··· 337 343 return err 338 344 } 339 345 } 346 + if s.Parameters != nil { 347 + if err := s.Parameters.CheckSchema(); err != nil { 348 + return err 349 + } 350 + } 340 351 for _, e := range s.Errors { 341 352 if err := e.CheckSchema(); err != nil { 342 353 return err 343 354 } 344 355 } 345 - return s.Parameters.CheckSchema() 356 + return nil 346 357 } 347 358 348 359 type SchemaProcedure struct { 349 360 Type string `json:"type"` // "procedure" 350 361 Description *string `json:"description,omitempty"` 351 - Parameters SchemaParams `json:"parameters"` 362 + Parameters *SchemaParams `json:"parameters"` // optional 352 363 Output *SchemaBody `json:"output"` // optional 353 364 Errors []SchemaError `json:"errors,omitempty"` // optional 354 365 Input *SchemaBody `json:"input"` // optional ··· 365 376 return err 366 377 } 367 378 } 379 + if s.Parameters != nil { 380 + if err := s.Parameters.CheckSchema(); err != nil { 381 + return err 382 + } 383 + } 368 384 for _, e := range s.Errors { 369 385 if err := e.CheckSchema(); err != nil { 370 386 return err 371 387 } 372 388 } 373 - return s.Parameters.CheckSchema() 389 + return nil 374 390 } 375 391 376 392 type SchemaSubscription struct { 377 393 Type string `json:"type"` // "subscription" 378 394 Description *string `json:"description,omitempty"` 379 - Parameters SchemaParams `json:"parameters"` 395 + Parameters *SchemaParams `json:"parameters"` // optional 380 396 Message *SchemaMessage `json:"message,omitempty"` // TODO(specs): is this really optional? 381 397 } 382 398 ··· 386 402 return err 387 403 } 388 404 } 389 - return s.Parameters.CheckSchema() 405 + if s.Parameters != nil { 406 + if err := s.Parameters.CheckSchema(); err != nil { 407 + return err 408 + } 409 + } 410 + return nil 390 411 } 391 412 392 413 type SchemaPermissionSet struct {
+16
atproto/lexicon/testdata/catalog/minimal-procedure.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "example.lexicon.minimal.procedure", 4 + "description": "demonstrates lexicon features for the procedure type", 5 + "defs": { 6 + "main": { 7 + "type": "procedure", 8 + "input": { 9 + "encoding": "application/json", 10 + "schema": { 11 + "type": "object" 12 + } 13 + } 14 + } 15 + } 16 + }
+12
atproto/lexicon/testdata/catalog/minimal-query.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "example.lexicon.minimal.query", 4 + "revision": 1, 5 + "description": "exercizes many lexicon features for the query type", 6 + "defs": { 7 + "main": { 8 + "type": "query", 9 + "description": "a query type" 10 + } 11 + } 12 + }
+78
atproto/lexicon/testdata/catalog/procedure.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "example.lexicon.procedure", 4 + "description": "demonstrates lexicon features for the procedure type", 5 + "defs": { 6 + "main": { 7 + "type": "procedure", 8 + "parameters": { 9 + "type": "params", 10 + "properties": { 11 + "boolean": { 12 + "type": "boolean", 13 + "description": "field of type boolean" 14 + }, 15 + "integer": { 16 + "type": "integer", 17 + "description": "field of type integer" 18 + }, 19 + "string": { 20 + "type": "string", 21 + "description": "field of type string" 22 + } 23 + } 24 + }, 25 + "input": { 26 + "encoding": "application/json", 27 + "schema": { 28 + "type": "object", 29 + "required": [ 30 + "preferences" 31 + ], 32 + "properties": { 33 + "preferences": { 34 + "type": "ref", 35 + "ref": "app.bsky.actor.defs#preferences" 36 + } 37 + } 38 + } 39 + }, 40 + "output": { 41 + "encoding": "application/json", 42 + "schema": { 43 + "type": "object", 44 + "required": [], 45 + "properties": { 46 + "blob": { 47 + "type": "blob", 48 + "description": "field of type blob" 49 + }, 50 + "unknown": { 51 + "type": "unknown", 52 + "description": "field of type unknown" 53 + }, 54 + "array": { 55 + "type": "array", 56 + "description": "field of type array", 57 + "items": { 58 + "type": "integer" 59 + } 60 + }, 61 + "object": { 62 + "type": "object", 63 + "description": "field of type null", 64 + "properties": { 65 + "a": { 66 + "type": "integer" 67 + }, 68 + "b": { 69 + "type": "integer" 70 + } 71 + } 72 + } 73 + } 74 + } 75 + } 76 + } 77 + } 78 + }
+1 -1
atproto/lexicon/testdata/catalog/record.json
··· 2 2 "lexicon": 1, 3 3 "id": "example.lexicon.record", 4 4 "revision": 1, 5 - "description": "exercizes many lexicon features for the record type", 5 + "description": "demonstrates lexicon features for the record type", 6 6 "defs": { 7 7 "main": { 8 8 "type": "record",
+47
atproto/lexicon/testdata/catalog/subscription.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "example.lexicon.subscription", 4 + "description": "demonstrates lexicon features for the subscription type", 5 + "defs": { 6 + "main": { 7 + "type": "subscription", 8 + "parameters": { 9 + "type": "params", 10 + "properties": { 11 + "cursor": { 12 + "type": "integer", 13 + "description": "start at the given sequence number" 14 + } 15 + } 16 + }, 17 + "message": { 18 + "schema": { 19 + "type": "union", 20 + "refs": ["#yo", "#info"] 21 + } 22 + }, 23 + "errors": [{ "name": "FutureCursor" }] 24 + }, 25 + "yo": { 26 + "type": "object", 27 + "required": ["seq", "yo"], 28 + "properties": { 29 + "seq": { "type": "integer" }, 30 + "yo": { "type": "boolean" } 31 + } 32 + }, 33 + "info": { 34 + "type": "object", 35 + "required": ["name"], 36 + "properties": { 37 + "name": { 38 + "type": "string", 39 + "knownValues": ["OutdatedCursor"] 40 + }, 41 + "message": { 42 + "type": "string" 43 + } 44 + } 45 + } 46 + } 47 + }