1
Advanced Mocking for Swagger APIs
Speeding Design & Development with Virtualization
2
Today’s Presenters
PJ Stevens
Marketing Manager
Harsh Upreti
Product Marketing Manager
Nathan Wright
Engineer
Mike Hawley
Associate Sales Engineer
3
Agenda
• Swagger with Mocking
• Swagger with Virtualization
• Demo: Swagger & ServiceV Pro
4
What is the OpenAPI Specification?
A common, public contract between services
Independent of language, framework,
deployment technology
YAML or JSON format
Supports both API-first and code-first
approaches to defining, building and
documenting APIs
Bottom-up community and usage driven
evolution
Learn more about OAS: https://swagger.io/specification/
5
Mocks and Sandboxes
Tools available for mocking:
• SoapUI Open Source, Mock-Server
Sandboxing as a Service:
• API Service Providers, WireMocks, GetSandbox
Mocks are static emulation of APIs, these are generally coded in a programming
language
Sandboxes are pre-provisioned instances of API endpoints, often provided for
specific use-cases
6
Problems with mocking and sandboxes
• Hard to create, need scripting experience
• Often owned by other teams, lack of control
• Static, limited to few scenarios, hard to create multiple responses
for scenarios
• Stateless, cannot easily pass parameters from one response to
next
{
"id": "d290f1ee",
"name": “Text Widget",
"manufacturer": {
"name": "ACME Corporation",
"homePage": "https://www.acme-corp.com",
"phone": "408-867-5309"
}
}
Static mock response
Multiple scenarios?
Routing between
scenarios?
State-ful scenarios?
7
Swagger Design With Mocks
Development Test Production
Design and Document
Developers
Testers
Customers
Prototypes
Users
Consumers
8
What is Service Virtualization
Virtualization accurately mimics/simulates behavior of components
that are unavailable or difficult to access during software
development and beyond.
Examples of Components that can be Virtualized:
Devices Database API Network
More about Service Virtualization: https://smartbear.com/learn/software-
testing/what-is-service-virtualization/
9
Virtualization Vs Mocking
Mocking API Calls
Static implementation for specific
situations
State-less, responses do not have
contextual information
100% manual configuration
No re-use
Virtualizing APIs
Full implementation of the service
State-ful, Responses are aware of the
context
No configuration needed
Re-usable artifacts
10
Benefits of Service Virtualization
• Quickly create, edit and use Virtual responses for swagger APIs
• Easily record services, modify them and use them for testing,
development, prototyping
• Make virtual services realistic (real life) by linking them to data
• Get creative with routing and dispatching different responses
• Easily route between virtual and actual service
• Provide access to the team by sharing the virtualized transactions
Time Savings Faster Time to Market Full Control
11
Swagger with Service Virtualization
Design and Document
Virtualization
• Testers
• Developers
• Prototypes
• Managers
• Other Apps
• Customers
TestDevelopment
Refactor
Feedback
Import Final
12
Summary
Mocking is often inadequate for iterative swagger design
Service Virtualization enables ‘real life’ APIs for iterative design
• ServiceV Pro provides easy way to import-refactor Swagger
definitions
• ServiceV Pro provides dynamic responses and full control on APIs
• ServiceV Pro does not require experience with coding
• ServiceV Pro enables sharing of virtual services with the broader
team
13
Thank You!
Learn more with the full webinar: https://smartbear.wistia.com/medias/yav4j5ozfq

Advanced Mocking for Swagger APIs

  • 1.
    1 Advanced Mocking forSwagger APIs Speeding Design & Development with Virtualization
  • 2.
    2 Today’s Presenters PJ Stevens MarketingManager Harsh Upreti Product Marketing Manager Nathan Wright Engineer Mike Hawley Associate Sales Engineer
  • 3.
    3 Agenda • Swagger withMocking • Swagger with Virtualization • Demo: Swagger & ServiceV Pro
  • 4.
    4 What is theOpenAPI Specification? A common, public contract between services Independent of language, framework, deployment technology YAML or JSON format Supports both API-first and code-first approaches to defining, building and documenting APIs Bottom-up community and usage driven evolution Learn more about OAS: https://swagger.io/specification/
  • 5.
    5 Mocks and Sandboxes Toolsavailable for mocking: • SoapUI Open Source, Mock-Server Sandboxing as a Service: • API Service Providers, WireMocks, GetSandbox Mocks are static emulation of APIs, these are generally coded in a programming language Sandboxes are pre-provisioned instances of API endpoints, often provided for specific use-cases
  • 6.
    6 Problems with mockingand sandboxes • Hard to create, need scripting experience • Often owned by other teams, lack of control • Static, limited to few scenarios, hard to create multiple responses for scenarios • Stateless, cannot easily pass parameters from one response to next { "id": "d290f1ee", "name": “Text Widget", "manufacturer": { "name": "ACME Corporation", "homePage": "https://www.acme-corp.com", "phone": "408-867-5309" } } Static mock response Multiple scenarios? Routing between scenarios? State-ful scenarios?
  • 7.
    7 Swagger Design WithMocks Development Test Production Design and Document Developers Testers Customers Prototypes Users Consumers
  • 8.
    8 What is ServiceVirtualization Virtualization accurately mimics/simulates behavior of components that are unavailable or difficult to access during software development and beyond. Examples of Components that can be Virtualized: Devices Database API Network More about Service Virtualization: https://smartbear.com/learn/software- testing/what-is-service-virtualization/
  • 9.
    9 Virtualization Vs Mocking MockingAPI Calls Static implementation for specific situations State-less, responses do not have contextual information 100% manual configuration No re-use Virtualizing APIs Full implementation of the service State-ful, Responses are aware of the context No configuration needed Re-usable artifacts
  • 10.
    10 Benefits of ServiceVirtualization • Quickly create, edit and use Virtual responses for swagger APIs • Easily record services, modify them and use them for testing, development, prototyping • Make virtual services realistic (real life) by linking them to data • Get creative with routing and dispatching different responses • Easily route between virtual and actual service • Provide access to the team by sharing the virtualized transactions Time Savings Faster Time to Market Full Control
  • 11.
    11 Swagger with ServiceVirtualization Design and Document Virtualization • Testers • Developers • Prototypes • Managers • Other Apps • Customers TestDevelopment Refactor Feedback Import Final
  • 12.
    12 Summary Mocking is ofteninadequate for iterative swagger design Service Virtualization enables ‘real life’ APIs for iterative design • ServiceV Pro provides easy way to import-refactor Swagger definitions • ServiceV Pro provides dynamic responses and full control on APIs • ServiceV Pro does not require experience with coding • ServiceV Pro enables sharing of virtual services with the broader team
  • 13.
    13 Thank You! Learn morewith the full webinar: https://smartbear.wistia.com/medias/yav4j5ozfq

Editor's Notes

  • #6 Mocking and Sandboxing is a really popular way of emulating simple Swagger API Describe mocking describe sandboxing Give mocking examples Give sandboxing examples
  • #7 mocking and sandboxing are static difficult to create multiple scenarios do not go much Beyond a single response for a request do not help in coverage of all the possible scenarios not very useful Beyond just giving a high-level idea of the API  sandboxes are often owned by other teams provided to Consumers for very specific purposes They are stateless very hard to have common information passed between different response scenarios it makes it hard to use them for any realistic purpose,  like prototyping functional testing, they do not give a holistic idea of the capabilities of the API
  • #8 with mocking  teams are forced 2 develop at least a basic prototype of the API before it could be used for any purposes it's only after development phase, APIs are available for testers It's only after testing of API that they can be made available for customers it's only after production any API is available for the consumers or users hence its only after api's are available in production or development that they would be used and would provide any sort of valuable feedback to designers of swagger APIs At this point if anything has gone wrong with the design then a lot of re-work will have to be done to fix it through the development and testing phase Mocking would only provide static representation of swagger API and they are not very much usable for testing prototyping or  development of other apps using this api's The feedback loop for the design takes a lot of time as it goes through all the phases, development and testing
  • #12 With virtualization you can import the swagger spec to ServiceV Pro with just a few clicks and use one response to clone and create advanced scenarios Share these advanced scenarios with consumers of your APIs including testers and developers of other apps dependent on your APIs or managers and customers who want to see the prototype of the APIs See the feedback from the consumers of your APIs and incorporate it into your design, after every change of design refactor the changes back into the ServiceV Pro Only after the design is finalized start writing code and start development on the APIs Faster iterative design and development of APIs, coding and testing happens only after the design is finalized