Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

v3 simplifies validation #185

Merged
merged 36 commits into from
Jul 7, 2023
Merged

v3 simplifies validation #185

merged 36 commits into from
Jul 7, 2023

Conversation

spacether
Copy link
Contributor

@spacether spacether commented Jun 15, 2023

simplifes validation

  • separate python classes are now written for OpenapiSchemas and their json schema type object and array output types
    • output classes are no longer generated for type: null/string/number/integer/bool
    • nested Schema_ class has been removed and its data is now in a non-nested schema class
    • it should be possible to implement this same pattern in statically typed languages
  • __new__ method becomes the validate method
  • no more use of generics when handling null/boolean/string/number/integer. Schema Classes use generics to set return types for object (dict) and array (tuple) types
  • returned frozendict and tuple classes are now only instances of one class, instances no longer subclass all validated schemas
  • frozendict changed to immutabledict to use generic type definitions in ouput class definitions
  • all schema base classes and mixins deleted
  • schema module refactored into submodules
  • format helper methods as_date_/as_datetime/as_decimal_/as_uuid_ changed to functions in the schemas.format module, this allows string instances to be vanilla strings, which allows string literals to be returned when string enums are defined
  • enums now stored by name in Schema.enums, this prevents collision with other json schema info
  • server variables changed to DictSchema w/ validation
  • request query/header/path/cookie/_params changed to DictSchema w/ validation
  • response headers changed to DictSchema w/ validation
  • json schema type object + array python output classes with names like SomeSchemaDict and SomeSchemaTuple will always run validation on inputs, even if instantiated directly like SomeSchemaDict(...), not from the schema validation method SomeSchema.validate(...)

Note

initially I defined Schema.output_type and output_types to define the output types that a schema generates
and I used that reference for property and __getitem__ return types, but pycharm did not see through to the type defined in output_type/output_types. It described the type as output_type
So instead I fully inspect each schema and write its output types for properties + __getitem__ return types

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/python*.
    For Windows users, please run the script in Git BASH.

@spacether spacether closed this Jun 26, 2023
@spacether spacether reopened this Jun 26, 2023
@spacether spacether force-pushed the v3_simplifies_validation branch 2 times, most recently from f183080 to f5ccbe3 Compare June 29, 2023 18:57
@spacether spacether force-pushed the v3_simplifies_validation branch 6 times, most recently from 70676c0 to d204f17 Compare July 4, 2023 14:40
@spacether spacether force-pushed the v3_simplifies_validation branch from d204f17 to ff52894 Compare July 4, 2023 14:43
@spacether spacether merged commit 38e8560 into 3_0_0 Jul 7, 2023
@spacether spacether deleted the v3_simplifies_validation branch July 7, 2023 18:48
spacether added a commit that referenced this pull request Aug 16, 2023
* Schema mixnins and base classes removed, validate added, output classes written for dict + tuple types

* Updates passed types in api_client and api_response

* Does not run validation twice for unstances of ouput clas for object and array

* Adds tests that verify that array and object validations are not run twice

* Fixes schema ouput class instantiation to use super new

* Renames two new templates to validate

* Renames two last new templates to _helper_prefix_ref_property_value_type + _helper_prefix_property_value_type

* Removes two unused templates

* Adds new method to array output class

* Adds new method to object output classes

* Adds test_dict_validate_using_output_class

* Adds test_list_validate_using_output_class

* Replaces immutabledict.immutabledict with schemas.immutabledict

* Removes unneeded init methods for dict output classes

* Removes unneeded immutabledict imports

* Fixes operation code samples in docs

* Silences schema not found warnings

* Adds requestBodySchemas to codegenOperation

* Updates RequestBodySchemas jsonPathPiece names

* Adds request body schema imports

* Shortens request body schema imports in operation.py

* Reverts content schema imports to be direct

* Fixes response ApiRespinse body definition

* Removes content and content type init imports

* Fixes testResponseWithNoSchemaInHeaders

* Fixes bug in detecting param required that broke two java tests

* Samples regenerated

* Fixes test of noncomplintdisc sample

* Fixes some tests

* Fixes path test validate typo

* Allows int or float into int schemas because values like 1.0 need to be accepted

* Adds Bool class and uses it during validation only

* Fixes the last of the unit test sample tests

* Samples updated

* Fixes two python tests

* Fixes last broken test in petstore
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REQ] Add overload type hints for model new [REQ] Add overload type hints for from_openapi_data_
1 participant