mild-blue / swagger-unittest

Automatically test your swagger API
0 stars 0 forks source link

Add inheritance support #5

Open tomaspavlin opened 3 years ago

tomaspavlin commented 3 years ago

Parsing swagger with allOf does not work properly.

The following model defined in swagger.yaml

    RecipientModelToUpdate:
        allOf:
        -   $ref: '#/definitions/PatientModelToUpdate'
        -   properties:
                acceptable_blood_groups:
                    description: Provide full list of all the acceptable blood groups
                        of the patient, not just the change set
                    items:
                        $ref: '#/definitions/BloodGroupEnum'
                    type: array
                acceptable_blood_groups2:
                    description: Provide full list of all the acceptable blood groups
                        of the patient, not just the change set
                    example:
                    - A
                    - B
                    items:
                        $ref: '#/definitions/BloodGroupEnum'
                    type: array
                cutoff:
                    type: integer
                hla_antibodies:
                    allOf:
                    -   $ref: '#/definitions/HlaAntibodiesToUpdate'
                    description: Provide full list of all the HLA antibodies of the
                        patient, not just the change set
                    example:
                        hla_antibodies_list:
                        -   mfi: 10000
                            raw_code: A*01:02
                hla_types_list_test:
                    items:
                        $ref: '#/definitions/HlaTypeToUpdate'
                    type: array
                previous_transplants:
                    description: Number of previous kidney transplants.
                    type: integer
                recipient_requirements:
                    allOf:
                    -   $ref: '#/definitions/RecipientRequirements'
                    description: Provide the whole recipients requirements object,
                        it will be overwritten
                    example:
                        require_better_match_in_compatibility_index: true
                waiting_since:
                    description: Date since when the patient has been on waiting list.
                        Use format YYYY-MM-DD.
                    example: '2015-01-17'
                    format: date
                    type: string
            required:
            - hla_types_list_test
            type: object

was parsed using

swagger_parser = SwaggerParser(swagger_yaml_path, use_example=True)

with unexpected results in swagger_parser.definitions_example.RecipientModelToUpdate:

image

Most of the defined fields are missing.

tomaspavlin commented 3 years ago

When I implemented swagger validation, I also got the following error:

jsonschema.exceptions.ValidationError: 'A' is not of type 'array'

Failed validating 'type' in schema['allOf'][1]['properties']['acceptable_blood_groups']:
    {'description': '...',
     'example': ['A', '0'],
     'items': {'$ref': '#/definitions/BloodGroupEnum'},
     'type': 'array'}

On instance['acceptable_blood_groups']:
    'A'