All Projects → pyopenapi → Pyswagger

pyopenapi / Pyswagger

Licence: mit
An OpenAPI (fka Swagger) client & converter in python, which is type-safe, dynamic, spec-compliant.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pyswagger

Light 4j
A fast, lightweight and more productive microservices framework
Stars: ✭ 3,303 (+913.19%)
Mutual labels:  swagger, openapi
tssg-syntax-parser
Parser to generate AST from TSSG Syntax
Stars: ✭ 17 (-94.79%)
Mutual labels:  swagger, openapi
fastify-openapi-glue
A plugin for Fastify to autogenerate a configuration based on a OpenApi(v2/v3) specification.
Stars: ✭ 94 (-71.17%)
Mutual labels:  swagger, openapi
kompendium
Ktor OpenAPI Spec Generator
Stars: ✭ 46 (-85.89%)
Mutual labels:  swagger, openapi
Generator Express No Stress Typescript
🚄 A Yeoman generator for Express.js based 12-factor apps and apis using Typescript
Stars: ✭ 297 (-8.9%)
Mutual labels:  swagger, openapi
openapi-schema-validator
OpenAPI schema validator for Python
Stars: ✭ 35 (-89.26%)
Mutual labels:  swagger, openapi
openapi-schemas
JSON Schemas for every version of the OpenAPI Specification
Stars: ✭ 22 (-93.25%)
Mutual labels:  swagger, openapi
api
🚀 Automatic SDK generation from an OpenAPI definition
Stars: ✭ 127 (-61.04%)
Mutual labels:  swagger, openapi
5gc apis
RESTful APIs of main Network Functions in the 3GPP 5G Core Network
Stars: ✭ 253 (-22.39%)
Mutual labels:  swagger, openapi
json-ref-resolver
[Deprecated] Recursively resolve JSON pointers and remote authorities.
Stars: ✭ 27 (-91.72%)
Mutual labels:  swagger, openapi
Martian
The HTTP abstraction library for Clojure/script, supporting Swagger, Schema, re-frame and more
Stars: ✭ 294 (-9.82%)
Mutual labels:  swagger, openapi
Openapi Typescript Codegen
NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification
Stars: ✭ 249 (-23.62%)
Mutual labels:  swagger, openapi
openapi-generator-for-spring
Open API v3 Generator for Spring Boot applications
Stars: ✭ 54 (-83.44%)
Mutual labels:  swagger, openapi
openapi-assert
Asserting data against OpenAPI docs.
Stars: ✭ 17 (-94.79%)
Mutual labels:  swagger, openapi
shipengine-openapi
The official OpenAPI 3.0 definitions for ShipEngine™
Stars: ✭ 13 (-96.01%)
Mutual labels:  swagger, openapi
oas2
OpenAPI 2.0 (aka Swagger) utils for Golang.
Stars: ✭ 19 (-94.17%)
Mutual labels:  swagger, openapi
Php Crud Api
Single file PHP script that adds a REST API to a SQL database
Stars: ✭ 2,904 (+790.8%)
Mutual labels:  swagger, openapi
fhir-fuel.github.io
Place to prepare proposal to FHIR about JSON, JSON-Schema, Swagger/OpenAPI, JSON native databases and other JSON-frendly formats (yaml, edn, avro, protobuf etc) and technologies
Stars: ✭ 20 (-93.87%)
Mutual labels:  swagger, openapi
gin-swagger
DRY templates for go-swagger
Stars: ✭ 79 (-75.77%)
Mutual labels:  swagger, openapi
Safrs
SqlAlchemy Flask-Restful Swagger Json:API OpenAPI
Stars: ✭ 255 (-21.78%)
Mutual labels:  swagger, openapi

pyswagger

Build Status Coverage Status

A python client for Swagger enabled REST API. It wouldn't be easier to try Swagger REST API by Swagger-UI. However, when it's time to unittest your API, the first option you find would be Swagger-codegen, but the better option is us.

This project is developed after swagger-py, which is a nicely implemented one, and inspired many aspects of this project. Another project is flex, which focuses on parameter validation, try it if you can handle other parts by yourselves. For other projects related to Swagger tools in python, check here.

pyswagger is much easier to use (compared to swagger-codegen, you don't need to prepare a scala environment) and tries hard to fully supports Swagger Spec in all aspects.


Features

  • convert Swagger Document from older version to newer one. (ex. convert from 1.2 to 2.0)
  • support Swagger 1.2, 2.0 on python 2.6, 2.7, 3.3, 3.5, 3.6
  • support YAML via Pretty-YAML
  • support $ref to External Document, multiple swagger.json will be organized into a group of App. And external document with self-describing resource is also supported (refer to issue).
  • type safe, input/output are converted to python types according to Data Type described in Swagger. You don't need to touch any json schema when using pyswagger. Limitations like minimum/maximum or enum are also checked. Model inheritance also supported.
  • provide function App.validate to check validity of the loaded API definition according to spec.
  • builtin client implementation based on various http clients in python. For usage of these clients, please refer to pyswagger.tests.contrib.client for details
  • not implemented parts, fire me a bug if you need it
    • [ ] Swagger 2.0
      • [ ] Schema.pattern
      • [ ] Scheme.patternProperties
      • [ ] Schema.readonly
      • [ ] Schema.allowEmptyValue
      • [ ] A scanner to validate schema
    • [ ] A WebSocket client
    • [ ] dump extension field

Tutorial


Quick Start

Before running this script, please make sure requests is installed on your environment.

from pyswagger import App, Security
from pyswagger.contrib.client.requests import Client
from pyswagger.utils import jp_compose

# load Swagger resource file into App object
app = App._create_('http://petstore.swagger.io/v2/swagger.json')

auth = Security(app)
auth.update_with('api_key', '12312312312312312313q') # api key
auth.update_with('petstore_auth', '12334546556521123fsfss') # oauth2

# init swagger client
client = Client(auth)

# a dict is enough for representing a Model in Swagger
pet_Tom=dict(id=1, name='Tom', photoUrls=['http://test']) 
# a request to create a new pet
client.request(app.op['addPet'](body=pet_Tom))

# - access an Operation object via App.op when operationId is defined
# - a request to get the pet back
req, resp = app.op['getPetById'](petId=1)
# prefer json as response
req.produce('application/json')
pet = client.request((req, resp)).data
assert pet.id == 1
assert pet.name == 'Tom'

# new ways to get Operation object corresponding to 'getPetById'.
# 'jp_compose' stands for JSON-Pointer composition
req, resp = app.resolve(jp_compose('/pet/{petId}', base='#/paths')).get(petId=1)
req.produce('application/json')
pet = client.request((req, resp)).data
assert pet.id == 1

Installation

We support pip installtion.

pip install pyswagger

Additional dependencies must be prepared before firing a request. If you are going to access a remote/local web server, you must install requests first.

pip install requests

If you want to test a local tornado server, please make sure tornado is ready on your environment

pip install tornado

We also provide native client for flask app, but to use it, flask is also required

pip install flask

Reference

All exported API are described in following sections. A diagram about relations between components


Contributors


Contribution Guildeline

report an issue:

  • issues can be reported here
  • include swagger.json if possible
  • turn on logging and report with messages on console
import logging
logger = logging.getLogger('pyswagger')

formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
console.setFormatter(formatter)

logger.addHandler(console)
logger.setLevel(logging.DEBUG)

... your stuff

  • describe expected behavior, or more specific, the input/output

submit a PR

  • test included
  • only PR to develop would be accepted

env preparation

pip install -r requirement-dev.txt

unit testing

python -m pytest -s -v --cov=pyswagger --cov-config=.coveragerc pyswagger/tests
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].