SlideShare a Scribd company logo
S
What is Swagger?
An introduction to a popular framework for REST APIs, Proof of Concepts and
Rapid Development. An indispensable tool for Software Engineers, Developers
and Architects.
Intro
My name is Philip A Senger, I have been a software developer for
over 20 years. Like many of you I have worked with dozens of
tools over the years. After using the Swagger Editor and Swagger
Markdown, I feel compelled to expand it usage. I now consider it
an essential tool for my daily development of REST APIs.
This presentation is designed to explain briefly what swagger is
and how to use some of the common tools around the
specification.
What is Swagger
S Swagger is a joint open source project by several vendors aimed at providing
representational language for RESTful service oriented end points.
S It is used by hundred of companies and is supposed by many vendors (
Apigee, Mulesoft, IBM, etc. )
S It has many open source sub supporting projects such as
S Swagger UI - an interactive website for your end points.
S Swagger Editor - a UI to help you write Mark down
S Swagger SDK Generators / Codeine - a SDK and tool to build your api's in a variety of
languages ( node js ).
Today we will be talking extensively about Swagger and the Swagger Editor.
Getting Started
S Markdown languages like Swagger typically don't come with an
editor ( eg Git markdown, Jade, etc ). Swagger Editor is the
exception. It was built roughly the same time and works fairly
well.
S The Swagger Editor gives you immediate feed back about the
endpoint and its syntax. While it is not great feedback it is
“good enough”.
S Since this is the first tool used by most to get started with
Swagger, Im going to go into the details of how to get it going
first.
Swagger Editor
S The best way to get started is with Swagger is with the
Swagger Editor. There are two ways to use it. You can either
run the online demo or clone the Git repository and run it
locally.
S The easiest and quickest entry ( without barriers ) is to go to
the website here, and use it.
http://editor.swagger.io/#/
S If you are a developer, and have node js, git on your desktop,
and some patience, you can clone the repo and run the app via
this URL
git clone https://github.com/swagger-api/swagger-editor.git
cd swagger-editor
npm start
File Format
Swagger is a specification, and like http which can transport either
SOAP or JSON, the actual content of swagger can be one of two
types. YAML ( Yet Another Markdown Language ) or JSON
(JavaScript Object Notation). I prefer YAML, because it simply is
less typing. However, YAML is tab sensitive, character sensitive,
and basically annoying if you are intolerant of this things.
The good news is, the Swagger-Editor can read and convert freely
between the two formats. So it is possible to keep the whole the
team happy.
Website you need to book
mark
S The Main Website
http://swagger.io/
S Schema and Specifications of Swagger
http://swagger.io/specification/
S Swagger Editor
http://editor.swagger.io/#/
S Git Repository for the Swagger Editor
https://github.com/swagger-api/swagger-editor.git
Basic Layout of a Swagger 2.0
File
The top level layout has three major identifiable sections. I
use the word identifiable because, the specification does not
declare order, but keeping it consistent makes sense.
S General Section ( Application settings )
S Paths Section ( End Points specific settings )
S Definitions Section ( Declaration of entities )
General Section
The General Section contains information that applies to the whole
application, Application settings. You will find in this area
information such as the version of swagger this file adheres
against, basic info such as the version, title, and summary,
copyright, security, the supported protocols such as https, the
base path of all the end points in this specification. Furthermore,
anything that can apply to application as a whole, such as what it
consumes, produces and security.
Sorry I won't cover the security section it is very complicated and
is not critical to getting an API together fast.
Sample of the General Section
swagger: '2.0'
info:
version: 1.0.0
title: 'User Profile Maintenance'
description: This endpoint is responsible for manage the user profile
information
schemes:
- https
basePath: /rest/v2/profile
consumes:
- application/json
produces:
- application/json
Paths Section
S Paths define the endpoints of the application, information,
summary, and also declare any specific details for the endpoint
such as security, consume or produces.
S Paths can contain path parameters.
S The stanza that declares the path should be unique to the
application. For example you can not contain two copies of
/user/remove/{id}:
S Within the Path section specifications can be declared for the
endpoint. For the purpose of this document we will cover the http
verbs.
Http Verbs
Immediately proceeding the path stanza are the http verbs
supported by the endpoint. For example, this is what a fully
operational endpoint would look like
/user/: <-- this is the endpoint and the following are the http verbs.
post:
get:
delete:
patch:
put:
Summary and Description
Within the verb stanza you will find two additional stanzas.
They are the summary and description. These fields can be
very complicated, containing additional markdown and can
span multiple lines. However, I have found that maintenance
becomes a little difficult when the structure spans more than
a single line. Summary should be a short and one line.
While description can contain more detail.
Example of Summary and
Description
paths:
/profile:
get:
summary: List of profiles
description: This end point is used to list all the users profile of a the
system.
Parameters and Responses
S Within the same verb stanza you will find two more
stanza in addition to the Summary and Description. They
are the parameters and responses. These two stanzas
are followed by a very complicated structure, which I will
go into detail next.
S Here is an example from the previous section with the
newly added Parameters and Responses added.
Example of Parameters and
Responses
/profile/{userid}:
post:
summary: Save or update a user profile
description: Used to modify and update a user profile associated with the user id.
parameters:
- name: userid
in: path
description: User Id of the profile.
required: true
type: integer
format: int32
responses:
200:
description: Successfully saved the user profile.
schema:
$ref: '#/definitions/SavedUserProfileResponse'
Parameters
Parameters can be found in the body, the path, or the
query parameter. This is defined with the in value.
While the parameter required can be either true or
false and obviously express if the value is required. In
this sample the parameter can be found in the path.
- name: orderid
in: path
description: Order Id of the order and is required
required: true
type: integer
format: int32
Parameters (continued)
S In this sample, the parameter is in the body, and take note that
the consumes must indicate what the payload of the body
confirms to. for example it could be a standard www form post
or a json body.
- name: body
in: body
description: The article you want to post to the blog
required: true
schema:
type: object
$ref: "#/definitions/ArticleBody"
Parameters (continued)
S In this sample the parameter is a query parameter called
type.
- name: type
in: query
type: string
required: false
description: Type of UPC that has been provided.
enum: [
'UPC-A',
'UPC-B',
'UPC-C',
'UPC-E'
]
Parameters (continued)
S if you notice there are two values type and format these
values can be found here.
Common Name type format Comments
integer integer int32 signed 32 bits
long integer int64 signed 64 bits
float number float
double number double
string string
byte string byte base64 encoded characters
binary string binary any sequence of octets
boolean boolean
date string date As defined by full-date - RFC3339
dateTime string date-time As defined by date-time - RFC3339
password string password Used to hint UIs the input needs to be obscured.
Parameters (continued)
Schema or object literals a little more complicated then
the primitives. You can choose to do it in line, but i
have found it to be very difficult to debug if the
Swagger file is invalid. So I usually do this for an array
of pets, then define pets in the definitions
schema:
type: array
items:
$ref: '#/definitions/pet'
Parameters (continued)
Or for an Object in place….
schema:
type: object
items:
$ref: '#/definitions/pet'
Responses
S Responses are similar in nature to the verbs except they
correspond to the HTTP status codes. So there is a 200,
400, etc. This is always followed by a description and if
appropriate a schema which can be an array, an object
or a reference to a definition ( which is what I prefer ).
S So in this example, we have a 200 and 404 response
defined, each with a schema defined in the definitions.
Responses (continued)
responses:
200:
description: Successfully retained the
user's profile.
schema:
$ref: '#/definitions/SaveProfileResponse'
404:
description: Request does not contain any
matching user profiles.
schema:
$ref: '#/definitions/SaveProfileResponse'
Definitions
The definition section contains all the object definitions for
the entire system and looks like the following example. Note
that all objects must be uniquely based on the name of the
object. The object name is followed by a description and
properties which will contain multiple names. Within that
name a description and type just like the properties. These
definitions can contain sub objects, which would intern be
defined in the definitions as well. While it is possible to
define sub objects in-line with the parent, I have found the
layout to be a challenge to navigate, I advise everyone to
keep the definitions flat.
Definitions (continued)
definitions:
ResponseStatusObj:
description: Response status
properties:
message:
description: The i18n message regarding to the status
type: string
orderId:
description: the new order id
type: integer
format: int32
ResponseError:
description: An error has occurred, this is the standard object
properties:
errorCode:
description: Error Code, refer error code dictionary
type: integer
format: int32
message:
description: i18n Error message
type: string
stackTrace:
description: Stack Trace
type: string
errors:
description: Errors from Proxy Server
type: array
items:
$ref: '#/definitions/FieldErrorObj'
FieldErrorObj:
description: Field level errors.
properties:
field:
description: The Field containing the error.
type: string
message:
description: The i18n error message.
type: string
Conclusion
S Swagger = Good
S The Swagger Editor isnt a professional piece of software but it is “Good
Enough”
S Use Swagger, it really makes development easy, a POC can be cranked
out really fast, and it allows you to spot problems with your models in
advance.
S I enjoy walking into the client, putting forth a spec or POC and getting feed
back fast. With all the tools available for this specification, it will only get
better.
Thank you for your time.

More Related Content

What's hot

Rest API with Swagger and NodeJS
Rest API with Swagger and NodeJSRest API with Swagger and NodeJS
Rest API with Swagger and NodeJS
Luigi Saetta
 
Swagger UI
Swagger UISwagger UI
Swagger UI
Walaa Hamdy Assy
 
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Edureka!
 
API Docs with OpenAPI 3.0
API Docs with OpenAPI 3.0API Docs with OpenAPI 3.0
API Docs with OpenAPI 3.0
Fabrizio Ferri-Benedetti
 
Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessible
Victor Trakhtenberg
 
Designing APIs with OpenAPI Spec
Designing APIs with OpenAPI SpecDesigning APIs with OpenAPI Spec
Designing APIs with OpenAPI Spec
Adam Paxton
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
Naphachara Rattanawilai
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
Spring Boot
Spring BootSpring Boot
Spring Boot
Jiayun Zhou
 
Angular overview
Angular overviewAngular overview
Angular overview
Thanvilahari
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
 
Writing REST APIs with OpenAPI and Swagger Ada
Writing REST APIs with OpenAPI and Swagger AdaWriting REST APIs with OpenAPI and Swagger Ada
Writing REST APIs with OpenAPI and Swagger Ada
Stephane Carrez
 
Swagger With REST APIs.pptx.pdf
Swagger With REST APIs.pptx.pdfSwagger With REST APIs.pptx.pdf
Swagger With REST APIs.pptx.pdf
Knoldus Inc.
 
Angular 9
Angular 9 Angular 9
Angular 9
Raja Vishnu
 
AngularJS
AngularJS AngularJS
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
Rasheed Waraich
 
API Presentation
API PresentationAPI Presentation
API Presentation
nityakulkarni
 
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariAngular Introduction By Surekha Gadkari
Angular Introduction By Surekha Gadkari
Surekha Gadkari
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
Santosh Kumar Kar
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Trey Howard
 

What's hot (20)

Rest API with Swagger and NodeJS
Rest API with Swagger and NodeJSRest API with Swagger and NodeJS
Rest API with Swagger and NodeJS
 
Swagger UI
Swagger UISwagger UI
Swagger UI
 
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
 
API Docs with OpenAPI 3.0
API Docs with OpenAPI 3.0API Docs with OpenAPI 3.0
API Docs with OpenAPI 3.0
 
Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessible
 
Designing APIs with OpenAPI Spec
Designing APIs with OpenAPI SpecDesigning APIs with OpenAPI Spec
Designing APIs with OpenAPI Spec
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Angular overview
Angular overviewAngular overview
Angular overview
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
Writing REST APIs with OpenAPI and Swagger Ada
Writing REST APIs with OpenAPI and Swagger AdaWriting REST APIs with OpenAPI and Swagger Ada
Writing REST APIs with OpenAPI and Swagger Ada
 
Swagger With REST APIs.pptx.pdf
Swagger With REST APIs.pptx.pdfSwagger With REST APIs.pptx.pdf
Swagger With REST APIs.pptx.pdf
 
Angular 9
Angular 9 Angular 9
Angular 9
 
AngularJS
AngularJS AngularJS
AngularJS
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
API Presentation
API PresentationAPI Presentation
API Presentation
 
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariAngular Introduction By Surekha Gadkari
Angular Introduction By Surekha Gadkari
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 

Similar to What is Swagger?

Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)
Katy Slemon
 
No sql injection in meteor.js application
No sql injection in meteor.js applicationNo sql injection in meteor.js application
No sql injection in meteor.js application
Designveloper
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
Sagar Nakul
 
Struts,Jsp,Servlet
Struts,Jsp,ServletStruts,Jsp,Servlet
Struts,Jsp,Servlet
dasguptahirak
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
Sagar Nakul
 
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptxWRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
salemsg
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
Krishnaov
 
Paper trail gem
Paper trail gemPaper trail gem
Paper trail gem
Bacancy Technology
 
Web 2.0 Lessonplan Day1
Web 2.0 Lessonplan Day1Web 2.0 Lessonplan Day1
Web 2.0 Lessonplan Day1
Jesse Thomas
 
cdac@parag.gajbhiye@test123
cdac@parag.gajbhiye@test123cdac@parag.gajbhiye@test123
cdac@parag.gajbhiye@test123
Parag Gajbhiye
 
Graphql
GraphqlGraphql
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesJBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
Tikal Knowledge
 
Apache Aries Blog Sample
Apache Aries Blog SampleApache Aries Blog Sample
Apache Aries Blog Sample
Skills Matter
 
NamingConvention
NamingConventionNamingConvention
NamingConvention
Jabed Hossain
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
Li Yi
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
Gabriel Walt
 
Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4
than sare
 
Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overview
skill-guru
 
iOS Swift application architecture
iOS Swift application architectureiOS Swift application architecture
iOS Swift application architecture
Romain Rochegude
 
* DJANGO - The Python Framework - Low Kian Seong, Developer
    * DJANGO - The Python Framework - Low Kian Seong, Developer    * DJANGO - The Python Framework - Low Kian Seong, Developer
* DJANGO - The Python Framework - Low Kian Seong, Developer
Linuxmalaysia Malaysia
 

Similar to What is Swagger? (20)

Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)
 
No sql injection in meteor.js application
No sql injection in meteor.js applicationNo sql injection in meteor.js application
No sql injection in meteor.js application
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
 
Struts,Jsp,Servlet
Struts,Jsp,ServletStruts,Jsp,Servlet
Struts,Jsp,Servlet
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
 
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptxWRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
 
Paper trail gem
Paper trail gemPaper trail gem
Paper trail gem
 
Web 2.0 Lessonplan Day1
Web 2.0 Lessonplan Day1Web 2.0 Lessonplan Day1
Web 2.0 Lessonplan Day1
 
cdac@parag.gajbhiye@test123
cdac@parag.gajbhiye@test123cdac@parag.gajbhiye@test123
cdac@parag.gajbhiye@test123
 
Graphql
GraphqlGraphql
Graphql
 
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesJBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
 
Apache Aries Blog Sample
Apache Aries Blog SampleApache Aries Blog Sample
Apache Aries Blog Sample
 
NamingConvention
NamingConventionNamingConvention
NamingConvention
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 
Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4
 
Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overview
 
iOS Swift application architecture
iOS Swift application architectureiOS Swift application architecture
iOS Swift application architecture
 
* DJANGO - The Python Framework - Low Kian Seong, Developer
    * DJANGO - The Python Framework - Low Kian Seong, Developer    * DJANGO - The Python Framework - Low Kian Seong, Developer
* DJANGO - The Python Framework - Low Kian Seong, Developer
 

Recently uploaded

By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 

Recently uploaded (20)

By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 

What is Swagger?

  • 1. S What is Swagger? An introduction to a popular framework for REST APIs, Proof of Concepts and Rapid Development. An indispensable tool for Software Engineers, Developers and Architects.
  • 2. Intro My name is Philip A Senger, I have been a software developer for over 20 years. Like many of you I have worked with dozens of tools over the years. After using the Swagger Editor and Swagger Markdown, I feel compelled to expand it usage. I now consider it an essential tool for my daily development of REST APIs. This presentation is designed to explain briefly what swagger is and how to use some of the common tools around the specification.
  • 3. What is Swagger S Swagger is a joint open source project by several vendors aimed at providing representational language for RESTful service oriented end points. S It is used by hundred of companies and is supposed by many vendors ( Apigee, Mulesoft, IBM, etc. ) S It has many open source sub supporting projects such as S Swagger UI - an interactive website for your end points. S Swagger Editor - a UI to help you write Mark down S Swagger SDK Generators / Codeine - a SDK and tool to build your api's in a variety of languages ( node js ). Today we will be talking extensively about Swagger and the Swagger Editor.
  • 4. Getting Started S Markdown languages like Swagger typically don't come with an editor ( eg Git markdown, Jade, etc ). Swagger Editor is the exception. It was built roughly the same time and works fairly well. S The Swagger Editor gives you immediate feed back about the endpoint and its syntax. While it is not great feedback it is “good enough”. S Since this is the first tool used by most to get started with Swagger, Im going to go into the details of how to get it going first.
  • 5. Swagger Editor S The best way to get started is with Swagger is with the Swagger Editor. There are two ways to use it. You can either run the online demo or clone the Git repository and run it locally. S The easiest and quickest entry ( without barriers ) is to go to the website here, and use it. http://editor.swagger.io/#/ S If you are a developer, and have node js, git on your desktop, and some patience, you can clone the repo and run the app via this URL git clone https://github.com/swagger-api/swagger-editor.git cd swagger-editor npm start
  • 6. File Format Swagger is a specification, and like http which can transport either SOAP or JSON, the actual content of swagger can be one of two types. YAML ( Yet Another Markdown Language ) or JSON (JavaScript Object Notation). I prefer YAML, because it simply is less typing. However, YAML is tab sensitive, character sensitive, and basically annoying if you are intolerant of this things. The good news is, the Swagger-Editor can read and convert freely between the two formats. So it is possible to keep the whole the team happy.
  • 7. Website you need to book mark S The Main Website http://swagger.io/ S Schema and Specifications of Swagger http://swagger.io/specification/ S Swagger Editor http://editor.swagger.io/#/ S Git Repository for the Swagger Editor https://github.com/swagger-api/swagger-editor.git
  • 8. Basic Layout of a Swagger 2.0 File The top level layout has three major identifiable sections. I use the word identifiable because, the specification does not declare order, but keeping it consistent makes sense. S General Section ( Application settings ) S Paths Section ( End Points specific settings ) S Definitions Section ( Declaration of entities )
  • 9. General Section The General Section contains information that applies to the whole application, Application settings. You will find in this area information such as the version of swagger this file adheres against, basic info such as the version, title, and summary, copyright, security, the supported protocols such as https, the base path of all the end points in this specification. Furthermore, anything that can apply to application as a whole, such as what it consumes, produces and security. Sorry I won't cover the security section it is very complicated and is not critical to getting an API together fast.
  • 10. Sample of the General Section swagger: '2.0' info: version: 1.0.0 title: 'User Profile Maintenance' description: This endpoint is responsible for manage the user profile information schemes: - https basePath: /rest/v2/profile consumes: - application/json produces: - application/json
  • 11. Paths Section S Paths define the endpoints of the application, information, summary, and also declare any specific details for the endpoint such as security, consume or produces. S Paths can contain path parameters. S The stanza that declares the path should be unique to the application. For example you can not contain two copies of /user/remove/{id}: S Within the Path section specifications can be declared for the endpoint. For the purpose of this document we will cover the http verbs.
  • 12. Http Verbs Immediately proceeding the path stanza are the http verbs supported by the endpoint. For example, this is what a fully operational endpoint would look like /user/: <-- this is the endpoint and the following are the http verbs. post: get: delete: patch: put:
  • 13. Summary and Description Within the verb stanza you will find two additional stanzas. They are the summary and description. These fields can be very complicated, containing additional markdown and can span multiple lines. However, I have found that maintenance becomes a little difficult when the structure spans more than a single line. Summary should be a short and one line. While description can contain more detail.
  • 14. Example of Summary and Description paths: /profile: get: summary: List of profiles description: This end point is used to list all the users profile of a the system.
  • 15. Parameters and Responses S Within the same verb stanza you will find two more stanza in addition to the Summary and Description. They are the parameters and responses. These two stanzas are followed by a very complicated structure, which I will go into detail next. S Here is an example from the previous section with the newly added Parameters and Responses added.
  • 16. Example of Parameters and Responses /profile/{userid}: post: summary: Save or update a user profile description: Used to modify and update a user profile associated with the user id. parameters: - name: userid in: path description: User Id of the profile. required: true type: integer format: int32 responses: 200: description: Successfully saved the user profile. schema: $ref: '#/definitions/SavedUserProfileResponse'
  • 17. Parameters Parameters can be found in the body, the path, or the query parameter. This is defined with the in value. While the parameter required can be either true or false and obviously express if the value is required. In this sample the parameter can be found in the path. - name: orderid in: path description: Order Id of the order and is required required: true type: integer format: int32
  • 18. Parameters (continued) S In this sample, the parameter is in the body, and take note that the consumes must indicate what the payload of the body confirms to. for example it could be a standard www form post or a json body. - name: body in: body description: The article you want to post to the blog required: true schema: type: object $ref: "#/definitions/ArticleBody"
  • 19. Parameters (continued) S In this sample the parameter is a query parameter called type. - name: type in: query type: string required: false description: Type of UPC that has been provided. enum: [ 'UPC-A', 'UPC-B', 'UPC-C', 'UPC-E' ]
  • 20. Parameters (continued) S if you notice there are two values type and format these values can be found here. Common Name type format Comments integer integer int32 signed 32 bits long integer int64 signed 64 bits float number float double number double string string byte string byte base64 encoded characters binary string binary any sequence of octets boolean boolean date string date As defined by full-date - RFC3339 dateTime string date-time As defined by date-time - RFC3339 password string password Used to hint UIs the input needs to be obscured.
  • 21. Parameters (continued) Schema or object literals a little more complicated then the primitives. You can choose to do it in line, but i have found it to be very difficult to debug if the Swagger file is invalid. So I usually do this for an array of pets, then define pets in the definitions schema: type: array items: $ref: '#/definitions/pet'
  • 22. Parameters (continued) Or for an Object in place…. schema: type: object items: $ref: '#/definitions/pet'
  • 23. Responses S Responses are similar in nature to the verbs except they correspond to the HTTP status codes. So there is a 200, 400, etc. This is always followed by a description and if appropriate a schema which can be an array, an object or a reference to a definition ( which is what I prefer ). S So in this example, we have a 200 and 404 response defined, each with a schema defined in the definitions.
  • 24. Responses (continued) responses: 200: description: Successfully retained the user's profile. schema: $ref: '#/definitions/SaveProfileResponse' 404: description: Request does not contain any matching user profiles. schema: $ref: '#/definitions/SaveProfileResponse'
  • 25. Definitions The definition section contains all the object definitions for the entire system and looks like the following example. Note that all objects must be uniquely based on the name of the object. The object name is followed by a description and properties which will contain multiple names. Within that name a description and type just like the properties. These definitions can contain sub objects, which would intern be defined in the definitions as well. While it is possible to define sub objects in-line with the parent, I have found the layout to be a challenge to navigate, I advise everyone to keep the definitions flat.
  • 26. Definitions (continued) definitions: ResponseStatusObj: description: Response status properties: message: description: The i18n message regarding to the status type: string orderId: description: the new order id type: integer format: int32 ResponseError: description: An error has occurred, this is the standard object properties: errorCode: description: Error Code, refer error code dictionary type: integer format: int32 message: description: i18n Error message type: string stackTrace: description: Stack Trace type: string errors: description: Errors from Proxy Server type: array items: $ref: '#/definitions/FieldErrorObj' FieldErrorObj: description: Field level errors. properties: field: description: The Field containing the error. type: string message: description: The i18n error message. type: string
  • 27. Conclusion S Swagger = Good S The Swagger Editor isnt a professional piece of software but it is “Good Enough” S Use Swagger, it really makes development easy, a POC can be cranked out really fast, and it allows you to spot problems with your models in advance. S I enjoy walking into the client, putting forth a spec or POC and getting feed back fast. With all the tools available for this specification, it will only get better. Thank you for your time.