STATICALLY CHECKING INTER-PROPERTY CONSTRAINTS and Its Applications in Web Apis
Total Page:16
File Type:pdf, Size:1020Kb
Proefschrift ingediend met het oog op het behalen van een doctoraatsdiploma Dissertation submitted in fulfilment of the requirement for the degree of Doctor of Philosophy in Sciences STATICALLY CHECKING INTER-PROPERTY CONSTRAINTS and its Applications in Web APIs Nathalie Oostvogels Promotor: Prof. Dr. Wolfgang De Meuter Copromotor: Prof. Dr. Joeri De Koster Faculty of Science and Bio-Engineering Sciences Statically Checking Inter-property Constraints and its Applications in Web APIs Nathalie Oostvogels Dissertation submitted in fulfillment of the requirement for the degree of Doctor of Sciences April 2019 Jury: Prof. Dr. Wolfgang De Meuter, Vrije Universiteit Brussel (promotor) Prof. Dr. Joeri De Koster, Vrije Universiteit Brussel (copromotor) Prof. Dr. Ann Now´e,Vrije Universiteit Brussel (chair) Prof. Dr. Dominique Devriese, Vrije Universiteit Brussel (secretary) Prof. Dr. Ann Dooms, Vrije Universiteit Brussel Prof. Dr. Tobias Wrigstad, Uppsala University Dr. Manuel Serrano, INRIA Printed by: Crazy Copy Center Productions VUB Pleinlaan 2, 1050 Brussel Tel / fax : +32 2 629 33 44 [email protected] www.crazycopy.be ISBN 978 94 930 7921 2 NUR 989 Acknowledgements: The work in this dissertation has been funded by a PhD Fellowship of the Re- search Foundation - Flanders (FWO) and the SBO project Tearless by the Agency for Innovation and Entrepreneurship (VLAIO). Copyright: All rights reserved. No part of this publication may be produced in any form by print, photoprint, microfilm, electronic or any other means without permission from the author. c 2019 Nathalie Oostvogels Abstract Software applications do not stand on their own: their code often uses libraries to incorporate functionality to facilitate the development process (such as abstrac- tions and helper functions) or to integrate functionality from third parties. Li- braries offer their functionality via an Application Programming Interface (API), which is a contract between the library and the user. It defines which methods are provided, and imposes constraints on the data or fields that are exchanged. Constraints dictate the presence of fields, the type of fields, and the allowed values for fields. Constraints imposed on a singular field are clearly indicated in the documentation and well-supported in tooling and specification languages. Next to singular constraints, API documentation often describes relations between fields. For example, some fields may only be provided together, or the value of a field may impose constraints on other parts of the data. In this dissertation, we demonstrate the prevalence of such constraints in web APIs. We show that there is no structural support for these inter-property con- straints: they cannot be expressed by contemporary API specification languages such as OpenAPI. This lack of support extends to programming languages, whose type system can only express and validate single-property constraints, but not inter-property constraints. This dissertation presents a statically-typed program- ming language that fills this gap. Our programming language, TIPC, features a natural extension to inter- face definitions which allows enforcing presence constraints between properties. TIPC ensures that objects with inter-property constraints satisfy these constraints throughout the program. Furthermore, it enables programmers to refine interface types using its flow-sensitive type system. We present a formal specification of the syntax, operational semantics and type system of TIPC, along with soundness proofs. As a proof of concept, we use TIPC as a model to extend the TypeScript compiler with support for inter-property constraints. Finally, we extend the OpenAPI specification language with support for fully generalised inter-property constraints. This language serves as a proving ground for inter-property constraint aware tooling. Concretely, a first artefact presents an intercepting middleware that verifies constraints on both the caller side and the library side. A second artefact shows how interfaces enabled with inter-property constraints can be generated from an API specification. Both artefacts enable the automatic verification of inter-property constraints in applications, respectively at runtime and at compile-time. iii Samenvatting Softwareprogramma’s staan niet op zichzelf: ze integreren vaak functionaliteit van bestaande codebibliotheken. De functionaliteit die zulke bibliotheken aan- bieden, kan het ontwikkelingsproces bevorderen of functionaliteit van derde par- tijen beschikbaar stellen. Deze functionaliteit wordt beschikbaar gesteld via een API (een programmeerinterface), die een contract vormt tussen de codebibliotheek en de gebruiker. Dit contract beschrijft welke methodes aangeboden worden en welke vereisten er worden gelegd op de data of velden die worden uitgewisseld. Vereisten leggen restricties op de aanwezigheid van velden, op hun type en hun toegestane waardes. Vereisten op een enkel veld zijn goed aangeduid in de documentatie en zijn goed ondersteund door programmeerhulpmiddelen en specificatietalen. Naast vereisten op een enkel veld, legt de documentatie van API’s ook nog eisen op tussen velden. Sommige velden mogen bijvoorbeeld enkel samen voorkomen, of de waarde van een veld kan de vereisten op een ander veld be¨ınvloeden. In deze verhandeling tonen wij het voorkomen van zulke vereisten in de documentatie van web API’s. We tonen dat er geen structurele ondersteuning bestaat voor inter-veld vereis- ten: ze kunnen niet worden uitgedrukt in hedendaagse specificatietalen zoals OpenAPI. Ook programmeertalen bieden geen ondersteuning: hun typesystemen kunnen enkel vereisten over een enkel veld uitdrukken. Deze verhandeling presen- teert een statisch getypeerde programmeertaal die deze kloof dicht. Onze programmeertaal, TIPC, heeft een natuurlijke uitbreiding van interface definities die ervoor zorgt dat aanwezigheidsvereisten tussen velden kunnen wor- den opgelegd. TIPC garandeert dat objecten met inter-veld vereisten tijdens het hele programma aan deze eisen voldoen. Bovendien zorgt TIPC ervoor dat programmeurs de interface types specifieker kunnen maken doordat het typesys- teem rekening houdt met if-testen in het programmaverloop. We presenteren een formele specificatie van de syntaxis, operationele semantiek en het typesysteem van TIPC, samen met een bewijs van correctheid. We integreren het TIPC model in de TypeScript compiler, waardoor we een uitbreiding op TypeScript verkrijgen die inter-veld vereisten kan garanderen. Tenslotte breiden we de OpenAPI specificatietaal uit met ondersteuning voor algemene inter-veld vereisten. Deze taal dient als een basis om hulpprogramma’s met inter-veld constraints te testen. Een eerste artifact presenteert een middleware die nagaat of aan de vereisten wordt voldaan, zowel aan de kant van de gebruiker als de kant van de codebibliotheek. Een tweede artifact toont hoe interfaces met inter-veld vereisten gegenereerd kunnen worden uit API specificaties. Beide artifacten zorgen ervoor dat er automatisch wordt nagegaan of inter-veld vereisten worden voldaan, zowel tijdens het uitvoeren als vooraf. v Acknowledgments First of all, I would like to thank the two people who promote this work: Wolf and Joeri. Wolf, I want to sincerely thank you for giving me the opportunity to pursue a PhD. You let me take my time to figure out what the topic of this PhD was going to be, which shaped this PhD to what it is today. I would like to thank the members of the jury, Dominique Devriese, Ann Dooms, Ann Now´e,Manuel Serrano, and Tobias Wrigstad, for the interesting discussions, which resulted in new insights that definitely improved this dissertation. Next to the promotors and jury members, I would like to thank the extra proofreaders of my text: Quentin and Dries. I would like to thank the unique bunch of people whom I may call my col- leagues. There are a few (ex-)colleagues (going on friends) I want to thank in particular. For the most part of this PhD, I have had the privilege of working together with one of my bestest friends. Simon: it has been an honour to have you by my side to teach a few hundred 18-year olds the ins and outs of algorithms and data structures. A big thanks to het olijke (office-sharing) duo: Thierry and Janwillem. You guys were always up for PhD-related discussions which shaped and structured my thoughts and worries about inter-property constraints, as well as the (equally as important) non-PhD-related discussions. Jesse, thank you for your brutally honest view on things. Laure, your absence at SOFT (and the emptiness of your bowl of candy) is not going unnoticed. Lara, thanks for the talks about the little things in life, the sad things, the happy things, and the big things. One of Wolf’s selling points of a PhD is that it comes along with the chance of exploring the world, and he was certainly right. A big thanks (again) to my travel buddies throughout the years: chasing Oregon’s waterfalls with Thierry & Laure, finally going on “Romereis” with Laure & Janwillem (I can recommend them as tour guides!), and lunching at the foot of a Canadian glacier with Janwillem. Many friends and family have supported me during the past few years. I want to truly thank you all for all the diversions in the form of board gaming nights, food and/or Sunday afternoon teas. It is impossible (and too dangerous) to list everyone, but special shoutout to the OG: Killian, Koen, and Murielle! Before this acknowledgment section ends and the actual dissertation starts, I want to thank the most important people in my life. In het dankwoord