Skip to content
GitLab
    • Explore Projects Groups Snippets
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
  • !13252

[python-experimental] move validations into cls

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/spacether/python_exp_move_validations_into_cls into master 2 years ago
  • Overview 1
  • Commits 10
  • Pipelines 0
  • Changes 121

Created by: spacether

[python-experimental] move validations into cls I am doing this because there are many types of validations and I want them all to be accessible at the same place This paves the way to moving this data into SomeClass.MetaOapg like django does here to prevent collisions with property names

Todo In the future move composed schema definitions into the cls level also

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/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (6.1.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Compare
  • master (base)

and
  • latest version
    26da51da
    10 commits, 2 years ago

121 files
+ 1083
- 1267

    Preferences

    File browser
    Compare changes
modules/…/…/…/…/p‎ython-experimental‎
model_t‎emplates‎
schema_composed_or‎_anytype.handlebars‎ +5 -5
schema_dict‎.handlebars‎ +3 -3
schema_list‎.handlebars‎ +3 -3
schema_simpl‎e.handlebars‎ +3 -3
validations‎.handlebars‎ +35 -37
schemas.h‎andlebars‎ +260 -272
samples/ope‎napi3/client‎
3_0_3_unit_test‎/…/unit_test_api‎
mo‎del‎
additionalproperties_ar‎e_allowed_by_default.py‎ +1 -1
additionalproperties_should‎_not_look_in_applicators.py‎ +2 -2
allo‎f.py‎ +3 -3
allof_combined_wi‎th_anyof_oneof.py‎ +7 -13
allof_simp‎le_types.py‎ +5 -9
allof_with_b‎ase_schema.py‎ +3 -3
allof_with_one_‎empty_schema.py‎ +1 -1
allof_with_the_fir‎st_empty_schema.py‎ +1 -1
allof_with_the_la‎st_empty_schema.py‎ +1 -1
allof_with_two_‎empty_schemas.py‎ +1 -1
anyo‎f.py‎ +3 -5
anyof_compl‎ex_types.py‎ +3 -3
anyof_with_b‎ase_schema.py‎ +4 -8
anyof_with_one_‎empty_schema.py‎ +1 -1
by_i‎nt.py‎ +2 -4
by_num‎ber.py‎ +2 -4
by_small_‎number.py‎ +2 -4
forbidden_‎property.py‎ +2 -2
invalid_instance_should_not_raise‎_error_when_float_division_inf.py‎ +1 -3
invalid_string_va‎lue_for_default.py‎ +2 -4
maximum_va‎lidation.py‎ +2 -4
maximum_validation_wi‎th_unsigned_integer.py‎ +2 -4
maxitems_va‎lidation.py‎ +2 -4
maxlength_v‎alidation.py‎ +2 -4
maxproperties0_means_‎the_object_is_empty.py‎ +2 -4
maxproperties‎_validation.py‎ +2 -4
minimum_va‎lidation.py‎ +2 -4
minimum_validation_w‎ith_signed_integer.py‎ +2 -4
minitems_va‎lidation.py‎ +2 -4
minlength_v‎alidation.py‎ +2 -4
minproperties‎_validation.py‎ +2 -4
model_‎not.py‎ +1 -1
nested_allof_to_check_‎validation_semantics.py‎ +2 -2
nested_anyof_to_check_‎validation_semantics.py‎ +2 -2
nested_oneof_to_check_‎validation_semantics.py‎ +2 -2
not_more_comp‎lex_schema.py‎ +1 -1
object_properti‎es_validation.py‎ +1 -1
oneo‎f.py‎ +3 -5
oneof_compl‎ex_types.py‎ +3 -3
oneof_with_b‎ase_schema.py‎ +4 -8
oneof_with_em‎pty_schema.py‎ +1 -1
oneof_with_‎required.py‎ +2 -2
pattern_is_no‎t_anchored.py‎ +4 -6
pattern_va‎lidation.py‎ +4 -6
properties_with_es‎caped_characters.py‎ +1 -1
property_named_ref_tha‎t_is_not_a_reference.py‎ +1 -1
ref_in_‎allof.py‎ +1 -1
ref_in_‎anyof.py‎ +1 -1
ref_in‎_not.py‎ +1 -1
ref_in_‎oneof.py‎ +1 -1
ref_in_pr‎operty.py‎ +1 -1
required_defaul‎t_validation.py‎ +1 -1
required_va‎lidation.py‎ +1 -1
required_with_‎empty_array.py‎ +1 -1
required_with_esc‎aped_characters.py‎ +1 -1
the_default_keyword_does_not_do_any‎thing_if_the_property_is_missing.py‎ +1 -3
uniqueitems_fal‎se_validation.py‎ +1 -3
uniqueitems_‎validation.py‎ +2 -4
pa‎ths‎
request_body_post_not_more_‎complex_schema_request_body‎
pos‎t.py‎ +1 -1
request_body_post‎_not_request_body‎
pos‎t.py‎ +1 -1
request_body_post_re‎f_in_not_request_body‎
pos‎t.py‎ +1 -1
request_body_post_required_with‎_escaped_characters_request_body‎
pos‎t.py‎ +1 -1
response_body_post_not_more_complex_s‎chema_response_body_for_content_types‎
pos‎t.py‎ +1 -1
response_body_post_not_resp‎onse_body_for_content_types‎
pos‎t.py‎ +1 -1
response_body_post_ref_in_not_‎response_body_for_content_types‎
pos‎t.py‎ +1 -1
response_body_post_required_with_escaped_‎characters_response_body_for_content_types‎
pos‎t.py‎ +1 -1
schem‎as.py‎ +260 -272
petstore/pytho‎n-experimental‎
petsto‎re_api‎
mo‎del‎
any_type_no‎t_string.py‎ +1 -1
appl‎e.py‎ +9 -13
array_with_valida‎tions_in_items.py‎ +2 -6
cat‎.py‎ +1 -1
child_‎cat.py‎ +1 -1
class_m‎odel.py‎ +1 -1
complex_quad‎rilateral.py‎ +1 -1
composed_any_of_differen‎t_types_no_validations.py‎ +1 -1
composed_one_of_d‎ifferent_types.py‎ +8 -14
date_time_with‎_validations.py‎ +3 -5
date_with_va‎lidations.py‎ +3 -5
dog‎.py‎ +1 -1
equilateral‎_triangle.py‎ +1 -1
format_‎test.py‎ +30 -50
frui‎t.py‎ +1 -1
fruit_‎req.py‎ +1 -1
gm_fr‎uit.py‎ +1 -1
integer_‎max10.py‎ +1 -3
integer_‎min15.py‎ +1 -3
isosceles_‎triangle.py‎ +1 -1
mamm‎al.py‎ +1 -1
model200_r‎esponse.py‎ +1 -1
model_r‎eturn.py‎ +1 -1
nam‎e.py‎ +1 -1
nullable‎_shape.py‎ +1 -1
number_with_v‎alidations.py‎ +2 -4
object_with_inline_co‎mposition_property.py‎ +2 -4
object_with_v‎alidations.py‎ +1 -3
pig‎.py‎ +1 -1
quadrila‎teral.py‎ +1 -1
quadrilateral‎_interface.py‎ +1 -1
scalene_t‎riangle.py‎ +1 -1
shap‎e.py‎ +1 -1
shape_or‎_null.py‎ +1 -1
simple_quad‎rilateral.py‎ +1 -1
some_ob‎ject.py‎ +1 -1
string_with_‎validation.py‎ +1 -3
trian‎gle.py‎ +1 -1
triangle_i‎nterface.py‎ +1 -1
use‎r.py‎ +1 -1
uuid_st‎ring.py‎ +1 -3
pa‎ths‎
fak‎e_1‎
pos‎t.py‎ +20 -36
fake_inline_‎composition_‎
pos‎t.py‎ +12 -24
store_order‎_order_id_1‎
get‎.py‎ +2 -4
schem‎as.py‎ +260 -272
tests_‎manual‎
test_date_time_wi‎th_validations.py‎ +1 -1
test_date_with‎_validations.py‎ +1 -1
test_val‎idate.py‎ +4 -4
modules/openapi-generator/src/main/resources/python-experimental/model_templates/schema_composed_or_anytype.handlebars
+ 5
- 5
  • View file @ 26da51da

  • Edit in single-file editor

  • Open in Web IDE


class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}{{/if}}(
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
{{#if getIsAnyType}}
{{#if composedSchemas}}
schemas.ComposedSchema
schemas.ComposedSchema,
{{else}}
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
{{/if}}
{{else}}
{{#if getHasMultipleTypes}}
@@ -34,6 +31,9 @@ class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}
{{/if}}
"""
{{/if}}
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
{{#or isMap isAnyType}}
{{> model_templates/dict_partial }}
{{/or}}
modules/openapi-generator/src/main/resources/python-experimental/model_templates/schema_dict.handlebars
+ 3
- 3
  • View file @ 26da51da

  • Edit in single-file editor

  • Open in Web IDE


class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}{{/if}}(
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
schemas.DictSchema
):
{{#if this.classname}}
@@ -17,6 +14,9 @@ class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}
{{/if}}
"""
{{/if}}
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
{{> model_templates/dict_partial }}
modules/openapi-generator/src/main/resources/python-experimental/model_templates/schema_list.handlebars
+ 3
- 3
  • View file @ 26da51da

  • Edit in single-file editor

  • Open in Web IDE


class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}{{/if}}(
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
schemas.ListSchema
):
{{#if this.classname}}
@@ -17,6 +14,9 @@ class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}
{{/if}}
"""
{{/if}}
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
{{#with items}}
{{#if complexType}}
modules/openapi-generator/src/main/resources/python-experimental/model_templates/schema_simple.handlebars
+ 3
- 3
  • View file @ 26da51da

  • Edit in single-file editor

  • Open in Web IDE


class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}{{/if}}(
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
{{#if isEnum}}
{{> model_templates/enum_value_to_name }}
{{/if}}
@@ -20,6 +17,9 @@ class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}
{{/if}}
"""
{{/if}}
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
{{#if isEnum}}
{{> model_templates/enums }}
{{else}}
modules/openapi-generator/src/main/resources/python-experimental/model_templates/validations.handlebars
+ 35
- 37
  • View file @ 26da51da

  • Edit in single-file editor

  • Open in Web IDE

schemas.SchemaValidatorClsFactory(
{{#if getUniqueItems}}
unique_items=True,
{{/if}}
{{#if maxLength}}
max_length={{maxLength}},
{{/if}}
{{#if minLength}}
min_length={{minLength}},
{{/if}}
{{#if maxItems}}
max_items={{maxItems}},
{{/if}}
{{#if minItems}}
min_items={{minItems}},
_unique_items=True
{{/if}}
{{#neq maxLength null}}
_max_length={{maxLength}}
{{/neq}}
{{#neq minLength null}}
_min_length={{minLength}}
{{/neq}}
{{#neq maxItems null}}
_max_items={{maxItems}}
{{/neq}}
{{#neq minItems null}}
_min_items={{minItems}}
{{/neq}}
{{#neq maxProperties null }}
max_properties={{maxProperties}},
_max_properties={{maxProperties}}
{{/neq}}
{{#if minProperties}}
min_properties={{minProperties}},
{{/if}}
{{#if maximum}}
{{#if exclusiveMaximum}}exclusive_maximum{{/if}}inclusive_maximum{{#unless exclusiveMaximum}}{{/unless}}={{maximum}},
{{/if}}
{{#if minimum}}
{{#if exclusiveMinimum}}exclusive_minimum{{/if}}inclusive_minimum{{#unless exclusiveMinimum}}{{/unless}}={{minimum}},
{{/if}}
{{#if pattern}}
regex=[{
{{#neq minProperties null}}
_min_properties={{minProperties}}
{{/neq}}
{{#neq maximum null}}
_{{#if exclusiveMaximum}}exclusive_maximum{{/if}}inclusive_maximum{{#unless exclusiveMaximum}}{{/unless}}={{maximum}}
{{/neq}}
{{#neq minimum null}}
_{{#if exclusiveMinimum}}exclusive_minimum{{/if}}inclusive_minimum{{#unless exclusiveMinimum}}{{/unless}}={{minimum}}
{{/neq}}
{{#neq pattern null}}
_regex=[{
{{#if vendorExtensions.x-regex}}
'pattern': r'{{{vendorExtensions.x-regex}}}', # noqa: E501
'pattern': r'{{{vendorExtensions.x-regex}}}', # noqa: E501
{{else}}
'pattern': r'{{{pattern}}}', # noqa: E501
'pattern': r'{{{pattern}}}', # noqa: E501
{{/if}}
{{#each vendorExtensions.x-modifiers}}
{{#if @first}}
'flags': (
'flags': (
{{/if}}
{{#unless @first}}| {{/unless}}re.{{.}}
{{#unless @first}}| {{/unless}}re.{{.}}
{{#if @last}}
)
)
{{/if}}
{{/each}}
}],
{{/if}}
{{#if multipleOf}}
multiple_of={{multipleOf}},
{{/if}}
),
}]
{{/neq}}
{{#neq multipleOf null}}
_multiple_of={{multipleOf}}
{{/neq}}
modules/openapi-generator/src/main/resources/python-experimental/schemas.handlebars
+ 260
- 272
  • View file @ 26da51da

  • Edit in single-file editor

  • Open in Web IDE

Files with large changes are collapsed by default.

samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_are_allowed_by_default.py
+ 1
- 1
  • View file @ 26da51da

  • Edit in single-file editor

  • Open in Web IDE


@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AdditionalpropertiesAreAllowedByDefault(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_should_not_look_in_applicators.py
+ 2
- 2
  • View file @ 26da51da

  • Edit in single-file editor

  • Open in Web IDE


@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AdditionalpropertiesShouldNotLookInApplicators(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -47,7 +47,7 @@ class AdditionalpropertiesShouldNotLookInApplicators(
class all_of_0(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
foo = schemas.AnyTypeSchema
samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/allof.py
+ 3
- 3
  • View file @ 26da51da

  • Edit in single-file editor

  • Open in Web IDE


@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class Allof(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -46,7 +46,7 @@ class Allof(
class all_of_0(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"bar",
@@ -70,7 +70,7 @@ class Allof(
class all_of_1(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"foo",
samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/allof_combined_with_anyof_oneof.py
+ 7
- 13
  • View file @ 26da51da

  • Edit in single-file editor

  • Open in Web IDE


@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AllofCombinedWithAnyofOneof(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -46,11 +46,9 @@ class AllofCombinedWithAnyofOneof(
class all_of_0(
schemas.SchemaValidatorClsFactory(
multiple_of=2,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_multiple_of=2
def __new__(
cls,
@@ -67,11 +65,9 @@ class AllofCombinedWithAnyofOneof(
class one_of_0(
schemas.SchemaValidatorClsFactory(
multiple_of=5,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_multiple_of=5
def __new__(
cls,
@@ -88,11 +84,9 @@ class AllofCombinedWithAnyofOneof(
class any_of_0(
schemas.SchemaValidatorClsFactory(
multiple_of=3,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_multiple_of=3
def __new__(
cls,
samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/allof_simple_types.py
+ 5
- 9
  • View file @ 26da51da

  • Edit in single-file editor

  • Open in Web IDE


@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AllofSimpleTypes(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -46,11 +46,9 @@ class AllofSimpleTypes(
class all_of_0(
schemas.SchemaValidatorClsFactory(
inclusive_maximum=30,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_inclusive_maximum=30
def __new__(
cls,
@@ -67,11 +65,9 @@ class AllofSimpleTypes(
class all_of_1(
schemas.SchemaValidatorClsFactory(
inclusive_minimum=20,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_inclusive_minimum=20
def __new__(
cls,
samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/allof_with_base_schema.py
+ 3
- 3
  • View file @ 26da51da

  • Edit in single-file editor

  • Open in Web IDE


@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AllofWithBaseSchema(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -50,7 +50,7 @@ class AllofWithBaseSchema(
class all_of_0(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"foo",
@@ -74,7 +74,7 @@ class AllofWithBaseSchema(
class all_of_1(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"baz",
0 Assignees
None
Assign to
0 Reviewers
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
Lock merge request
Unlocked
participants
Reference:
Source branch: github/fork/spacether/python_exp_move_validations_into_cls

Menu

Explore Projects Groups Snippets