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

when the specification fails
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

‹#›

When the specification fails:

documenting inter-parameter constraints

slide-2
SLIDE 2

Nathalie Oostvogels

PhD student
 Vrije Universiteit Brussel @noostvog

About me

slide-3
SLIDE 3

Third party web services

3

slide-4
SLIDE 4

Web API specifications

4

slide-5
SLIDE 5

Web API specifications

5

  • ptional

number

  • ptional

string required string max length = 280 max length = 15

slide-6
SLIDE 6

API specification languages

6

tools

Specification editors Code generators Documentation generators

slide-7
SLIDE 7

Web API specifications

7

  • ptional

number

  • ptional

string max length = 15 required string max length = 280

slide-8
SLIDE 8

Web API specifications

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

slide-9
SLIDE 9

Web API specifications

9

  • ptional

number

  • ptional

string required string max length = 140 max length = 15 Either user_id

  • r

screen_name

slide-10
SLIDE 10

inter-parameter constraints

slide-11
SLIDE 11

Inter-parameter constraints

Exclusive Constraints Dependent Constraints Group Constraints

11

slide-12
SLIDE 12

Exclusive constraints

12

○ exactly one of a set of parameters is required

Silent choice: Twitter chooses screen_name over user_id

slide-13
SLIDE 13

Dependent constraints

13

○ constraints on a parameter depend on a 
 property of another parameter

Silent choice: Facebook ignores details of link when link is not provided

slide-14
SLIDE 14

Dependent constraints

14

○ 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”.

slide-15
SLIDE 15

Group constraints

15

○ 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

slide-16
SLIDE 16

Nested inter-parameter constraints

16

“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

  • wner_screen_name parameters.”

XOR XOR

slide-17
SLIDE 17

Inter-parameter constraints in web

17

○ 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

slide-18
SLIDE 18

are common in web APIs

inter-parameter constraints

slide-19
SLIDE 19

API specification languages

19

slide-20
SLIDE 20

are common in web APIs

inter-parameter constraints

but cannot be expressed in specification languages

slide-21
SLIDE 21

API specification languages

21

slide-22
SLIDE 22

JSON Schema

22

Exclusive Constraints Dependent Constraints Group Constraints

slide-23
SLIDE 23

JSON Schema

23

Exclusive Constraints Dependent Constraints Group 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}

slide-24
SLIDE 24

JSON Schema

24

Exclusive Constraints Dependent Constraints Group Constraints

{ type : 'object', properties : { pic : { type : 'image'}, pic_name : { type : 'string'}, pic_date : { type : 'date'}}, dependencies : { 'pic_name' : ['pic'], 'pic_date' : ['pic']}};

slide-25
SLIDE 25

JSON Schema

25

Exclusive Constraints Dependent Constraints Group Constraints

{ type : 'object', properties: { long : { type : 'number'}, lat : { type : 'number'}}, dependencies : { 'long' : ['lat'], ‘lat' : ['long']}};

slide-26
SLIDE 26

JSON Schema

26

Exclusive Constraints Dependent Constraints Group Constraints

− too coarse-grained − no one-to-one mapping − no support for value dependencies

slide-27
SLIDE 27

are common in web APIs

inter-parameter constraints

but cannot be expressed in specification languages

slide-28
SLIDE 28

A new specification language for web APIs

28

x-constraints:

  • present(screen_name) XOR

present(user_id) paths: /direct_messages/new: post: parameters:

  • name: user_id

type: number

  • name: screen_name

type: string

  • name: text


type: string required: true

slide-29
SLIDE 29

A new specification language for web APIs

29

x-constraints:

  • present(screen_name) XOR

present(user_id) paths: /direct_messages/new: post: parameters:

  • name: user_id

type: number

  • name: screen_name

type: string

  • name: text


type: string required: true

x-constraint-definitions:

  • minimum(f, v) := value(f) >= v
  • required(f) := present(f)
  • string?(f) := type(f) = string
  • number?(f) := type(f) = number
  • xor(f1, f2) := 


present(f1) XOR present(f2)


  • pp-dependent(f1, f2) :=


present(f1) -> present(f2)

  • pv-dependent(f1, f2, v) := 


present(f1) -> (value(f2) = v)

  • group(f1, f2) := 


present(f1) <-> present(f2)

slide-30
SLIDE 30

Integration in languages

30

tools

Specification editors Code generators Documentation generators

slide-31
SLIDE 31

Specification editors

31

(list_id XOR slug) AND (slug -> (owner_screen_name XOR owner_id))

○ 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

  • wner using the owner_id or owner_screen_name parameters.”
  • (list_id XOR slug) AND

(slug -> (owner_screen_name XOR owner_id))

slide-32
SLIDE 32

Truth Table

32

list_id slug

  • wner_screen_n

ame

  • wner_id

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 F

slide-33
SLIDE 33

Specification editors

33

slug XOR list_id slug -> (owner_screen_name XOR owner_id)

  • wner_screen_name -> slug
  • wner_id -> slug

○ 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

  • wner using the owner_id or owner_screen_name parameters.”
slide-34
SLIDE 34

Documentation tools

34

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

slide-35
SLIDE 35

35

Code Generators

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

slide-36
SLIDE 36

36

Code Generators

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

slide-37
SLIDE 37

37

Constraint-centric interfaces

interface PrivateMessage{ user_id: number; screen_name: string; text: string; } constraining { user_id XOR screen_name }

Assign object to interface

02 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; } }

slide-38
SLIDE 38

are common in web APIs

inter-parameter constraints

but cannot be expressed in specification languages ○ extended specification languages enable better tool support

slide-39
SLIDE 39

Exclusive constraint: either or one of

Spotter guide to inter-parameter constraints:

@noostvog https:/ /github.com/noostvog/Verify-Request

Dependent constraint: additional or providing Group constraint: corresponding or providing