Skip to content

Latest commit

 

History

History
28 lines (24 loc) · 2.17 KB

app.md

File metadata and controls

28 lines (24 loc) · 2.17 KB

The initialization of pyswagger starts from App._create_(url), where url could either be a url or a file path. This function returns a App instance, which would be used to initiate Security.

App.op provides a shortcut to access Operation objects, which will produce a set of request/response for SwaggerClient to access API. The way we provide here would help to minimize the possible difference introduced by Swagger2.0 when everything is merged into one file.

# call an API when its nickname is unique
App.op['getPetById']
# call an API when its nickname collid with other resources
App.op['user', 'getById'] # operationId:'getById', tags:'user' (or a user resource in Swagger 1.2)
App.op['pet',  'getById'] # operationId:'getById', tags:'pet'  (or a pet resource in Swagger 1.2)

# utilize App.resolve to do the same thing
App.resolve('#/paths/~1pet~1{petId}').get
# instead of writing JSON-pointers by yourselves, utilize pyswagger.utils.jp_compose
App.resolve(utils.jp_compose('/pet/{petId}', base='#/paths')).get

App.validate(strict=True) provides validation against the loaded Swagger API definition. When passing strict=True, an exception would be raised if validation failed. It returns a list of errors in tuple: (where, type, msg).

App.resolve(JSON_Reference) is a new way to access objects. For example, to access a Schema object 'User':

app.resolve('#/definitions/User')

This function accepts a JSON Reference, which is composed by an url and a JSON Pointer, it is the standard way to access a Swagger document. Since a JSON reference contains an url, this means you can access any external document when you need:

app.resolve('http://another_site.com/apis/swagger.json#/definitions/User')

pyswagger will load that swagger.json, create a new App, and group it with the App you kept (app in code above). Internally, when pyswagger encounter some $ref directs to external documents, we just silently handle it in the same way.

App.dump() dumps the root object(Swagger Object in 2.0, ResourceList Object in 1.2) into a dict.