when the specification fails
play

When the specification fails: documenting inter-parameter - PowerPoint PPT Presentation

# When the specification fails: documenting inter-parameter constraints About me Nathalie Oostvogels PhD student Vrije Universiteit Brussel @noostvog Third party web services 3 Web API specifications 4 Web API specifications


  1. ‹#› When the specification fails: documenting inter-parameter constraints

  2. About me Nathalie Oostvogels PhD student 
 Vrije Universiteit Brussel � @noostvog

  3. Third party web services 3

  4. Web API specifications 4

  5. Web API specifications � � optional number � � � max length optional string = 15 � � � max length required string = 280 5

  6. API specification languages tools Specification Code generators editors Documentation generators 6

  7. Web API specifications � � optional number � � � max length optional string = 15 � � � max length required string = 280 7

  8. Web API specifications � “Incompatible parameters specified in the request” � “Some co-ordinate parameters were blank” � “You must specify either a list ID or a slug and owner” 8

  9. Web API specifications � � � optional number Either user_id or � � � screen_name max length optional string = 15 � � � max length required string = 140 9

  10. inter-parameter constraints

  11. Inter-parameter constraints Exclusive Dependent Group Constraints Constraints Constraints 11

  12. Exclusive constraints ○ exactly one of a set of parameters is required Silent choice: Twitter chooses screen_name over user_id 12

  13. Dependent constraints ○ constraints on a parameter depend on a 
 property of another parameter Silent choice: Facebook ignores details of link when link is not provided 13

  14. Dependent constraints ○ constraints on a parameter depend on a 
 property of another parameter the property infoWindow is ignored, when suppressInfoWindows is “true” when searching for an item, condiTon cannot be set to “new” when the availability parameter is set to “available”. 14

  15. Group constraints ○ a set of parameters should either be all 
 excluded from a request or all included Silent choice: Twitter ignores latitude when longitude is not provided 15

  16. Nested inter-parameter constraints XOR “You can idenDfy a list by its slug instead of its list_id . If you decide to do so, note that you will also have to specify the list owner using the owner_id or owner_screen_name parameters.” XOR 16

  17. Inter-parameter constraints in web ○ Every kind of inter-parameter constraints occurs at 
 at least once in every web API ○ Exclusive constraints in 1/3 entry points in Twitter ○ Exclusive constraints in 1/5 entry points in YouTube 17

  18. inter-parameter constraints are common in web APIs

  19. API specification languages 19

  20. inter-parameter constraints are common in web APIs but cannot be expressed in specification languages

  21. API specification languages 21

  22. JSON Schema Exclusive Dependent Group Constraints Constraints Constraints 22

  23. JSON Schema Exclusive Dependent Group Constraints Constraints Constraints {oneOf : [{ type : "object", 
 properties : {"a" : {type : "string"}}}, { type : "object", properties : {"b" : {type : "number"}}}]}; {a:“foo”} {b:42} {a:“foo”, b:42} {a:42, b:42} � 23

  24. JSON Schema Exclusive Dependent Group Constraints Constraints Constraints { type : 'object', properties : { pic : { type : 'image'}, pic_name : { type : 'string'}, pic_date : { type : 'date'}}, dependencies : { 'pic_name' : ['pic'], 'pic_date' : ['pic']}}; 24

  25. JSON Schema Exclusive Dependent Group Constraints Constraints Constraints { type : 'object', properties: { long : { type : 'number'}, lat : { type : 'number'}}, dependencies : { 'long' : ['lat'], ‘lat' : ['long']}}; 25

  26. JSON Schema Exclusive Dependent Group Constraints Constraints Constraints − no support for − too coarse-grained − no one-to-one mapping value dependencies 26

  27. inter-parameter constraints are common in web APIs but cannot be expressed in specification languages

  28. A new specification language for web APIs paths: /direct_messages/new: post: parameters: - name: user_id type: number - name: screen_name type: string - name: text 
 type: string required: true x-constraints: - present(screen_name) XOR present(user_id) 28

  29. A new specification language for web APIs x-constraint-definitions: paths: - minimum(f, v) := value(f) >= v /direct_messages/new: - required(f) := present(f) post: - string?(f) := type(f) = string - number?(f) := type(f) = number parameters: - name: user_id - xor(f1, f2) := 
 type: number present(f1) XOR present(f2) 
 - name: screen_name - pp-dependent(f1, f2) := 
 type: string present(f1) -> present(f2) - name: text 
 type: string - pv-dependent(f1, f2, v) := 
 required: true present(f1) -> (value(f2) = v) x-constraints: - group(f1, f2) := 
 - present(screen_name) XOR present(f1) <-> present(f2) present(user_id) 29

  30. Integration in languages tools Specification Code generators editors Documentation generators 30

  31. Specification editors ○ provide truth table for inter-parameter constraints “You can idenDfy a list by its slug instead of its list_id . If you decide to do so, note that you will also have to specify the list owner using the owner_id or owner_screen_name parameters.” (list_id XOR slug) AND ( list_id XOR slug) AND � (slug -> (owner_screen_name XOR owner_id)) (slug -> ( owner_screen_name XOR owner_id)) 31

  32. Truth Table list_id slug owner_screen_n owner_id ame T T T T T T T F T T F T T T F F T F T T T F T F T F F T T F F F F T T T F T T F F T F T F T F F F F T T F F T F F F F T F F F F 32 F

  33. Specification editors ○ provide truth table for inter-parameter constraints “You can idenDfy a list by its slug instead of its list_id . If you decide to do so, note that you will also have to specify the list owner using the owner_id or owner_screen_name parameters.” slug XOR list_id � slug -> (owner_screen_name XOR owner_id) owner_screen_name -> slug owner_id -> slug 33

  34. Documentation tools ○ render the inter-parameter constraints as a 
 separate block in the documentation ○ indication that field is part of inter-parameter 
 constraint 34

  35. Code Generators public privateMessagePost (user_id: number, screen_name: string, text: string) constraining { user_id XOR screen_name} { … } 35

  36. Code Generators public privateMessagePost (obj: PrivateMessage ) { … } interface PrivateMessage { user_id: number; screen_name: string; text: string; } constraining { user_id XOR screen_name } 36

  37. Constraint-centric interfaces interface PrivateMessage { user_id: number; screen_name: string; text: string; } constraining { user_id XOR screen_name 02 } Assign object to interface 1 let msg1: PrivateMessage = {text: “Hello”, user_id: 42}; Accessing fields 2 function getUserInfo(msg: PrivateMessage) { if (msg.user_id !== undefined) { msg.user_id; } else { msg.screen_name; } 37 }

  38. inter-parameter constraints are common in web APIs but cannot be expressed in specification languages ○ extended specification languages enable better tool support

  39. Spotter guide to inter-parameter constraints: Exclusive constraint: either or one of Dependent constraint: additional or providing Group constraint: corresponding or providing � https:/ /github.com/noostvog/Verify-Request � @noostvog

Recommend


More recommend