Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !4154

[Python-experimental] types now classes, adds additionalProperties handling

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/spacether/issue_1991_uses_class_types into master Oct 14, 2019
  • Overview 0
  • Commits 13
  • Pipelines 0
  • Changes 140

Created by: spacether

This PR changes the type descriptions in model classes from strings to real python classes so what was 'str' now becomes str. This PR also adds the feature where additional properties defined in models can be strictly typed to one type like str, or can allow any type, like (str, float, int, date, datetime, list, dict). Note: I needed to turn on the additionalproperties handling so our tests would pass for string_boolean_map.py This PR also turns on automatic type checking when instantiating a model on the client side or ingesting the model from the server.

  • If the type is incorrect and _check_type=True, an ApiTypeError exception will be raised
  • That type checking can be turned off by setting _check_type=False.

This PR is the final piece implementing the solution in https://github.com/OpenAPITools/openapi-generator/pull/2049

Details

  • Adds support for additionalProperties to the Python generator
  • Fixes inheritance in python when AllOf is used
  • Adds the ability to access and assign values to a model instance using brackets. model_instance['var_name'] = var_val
  • Simplifies model instance variable storage by storing all values in a data dict. This will make it easier to send Nullable value=None items, because items in the data store are correct
  • Switches parameter and discriminator typing to use actual python classes
  • Adds type checking with TypeError/ValueError/KeyError exceptions which tell where in the data the problem is (data is in the exception string and exception.path_to_item)
  • Model instances can be instantiated with type checking with the _check_type variable
  • Endpoint hits now check type before sending out data with the _check_input_type variable
  • Deserialization automatically checks type on all received data
  • If an optional value is accessed like model.optional_var and optional_var was not set when creating the instance we will now raise an ApiKeyError

Issues that will be closed if this is merged:

Inheritance not working: #623 (closed) When model only has allOf, it is blank: #453 (closed) Fixes additionalproperties: #2028 (closed) $ref references to non-object types not working correctly: #1991 (closed)

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before .
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) @Jyhess (2019/01)

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/spacether/issue_1991_uses_class_types