Skip to content

Latest commit

 

History

History
128 lines (71 loc) · 3.47 KB

python_generator.md

File metadata and controls

128 lines (71 loc) · 3.47 KB

Python Code Generator

Requirements

  • autopep8 for automatic code formatting

Server

Generated server code use these libraries:

Client

Generated client library use requests or aiohttp as http library.

Type

RAML Object is mapped to python class

Scalar Type Mapping

Enum

RAML Enum become python enum as described in https://docs.python.org/3/library/enum.html

Input Validation

Except for builtin types, generated server use python-jsonschema for request body validation.

Validation Status
minLength v
maxLength v
pattern v
minimum v
maximum v
format x
multipleOf v
array field minItems v
array field maxItems v
array field uniqueItems x
array Type minItems x
array Type maxItems x
array Type uniqueItems x

Bodies

Request and response body are mapped into structs and following the same rules as types.

struct name = [Resource name][Method name][ReqBody|RespBody].

Resources and Nested Resources

Server

Resources in the server are mapped to:

  • a flask blueprint module

The generated server contains a handlers directory, the python handlers files are the only files that are not overwritten by a regeneration. Each api method has a generated handler file, this is where the user should add the implementation for each method.

Client

Resourcess in the client are implemented as services.

Let's say we have two root resources:

  • /users
  • /network

Client library is going to have two services:

  • users
  • network

Each service will have it's own methods

Methods

Header

Code related to Requests Headers are only generated in the Client lib. All functions have arguments to send any request header, the current client lib will not check the headers against the RAML specifications.

Query Strings and Query Parameters

All client library functions have arguments to send query strings and query Parameters, the current client lib will not check it against the RAML specifications.

Responses

Resource Types and Traits

Resource Types and Traits already parsed by the parser. So, the generator need to know nothing about it.

Security Schemes

go-raml only supports OAuth2.0.

  • client : it currently able to get oauth2 token with client credentials.
  • server : it currently only support JWT token from itsyou.online

Annotations

Modularization

Includes

Includes should work properly

Libraries

Libraries should work properly except the apidocs web page (REST UI).

Overlays and Extensions