src/swagger2x.py
def swagger_property_data_schema(json_data, input_path, name):
    """swagger_property_data_schema
    get the value of the property name from the schema that is referenced by the path in get (or post)
    it tries to get first the enum values or the default value.
    if this is not found then it will try to get the value from the example
    :param json_data: the swagger file as json struct
    :param input_path: the path to which the if should be queried
    :return: list of if values
    """
    data_values = []
    schema = None
    example = None
    for path, path_item in json_data["paths"].items():
        if input_path == path:
            # get the schema
            try:
                schema = path_item["get"]["responses"]["200"]["schema"]
            except:
                try:
                    schema = path_item["post"]["responses"]["200"]["schema"]
                except:
                    print("swagger_property_data_schema: could not find schema")
                    pass
            # get the example
            try:
                example = path_item["get"]["responses"]["200"]["x-example"]
            except:
                try:
                    example = path_item["post"]["responses"]["200"]["x-example"]
                except:
                    print("swagger_property_data_schema: could not find x-example")
                    pass

            value_found = False
            if schema is not None:
                def_data = json_data["definitions"]
                for def_name, def_item in def_data.items():
                    full_def_name = "#/definitions/" + def_name
                    if full_def_name == schema["$ref"]:
                        name_block = find_key_link(def_item, name)
                        if name_block is not None:
                            # get it from the schema::enum
                            try:
                                enum_values = name_block["items"]["enum"]
                                for enum_value in enum_values:
                                    data_values.append(enum_value)
                                    value_found = True
                            except:
                                # get it from the schema::default
                                try:
                                    default_values = name_block["default"]
                                    for default_value in default_values:
                                        data_values.append(default_value)
                                        value_found = True

                                except:
                                    # get it from the example
                                    value_found = False
                        else:
                            pass

            else:
                print("swagger_property_data: schema not found:", input_path)

            if value_found is False:
                if example is not None:
                    if isinstance(example, dict):
                        value = example.get(name)
                        if value is not None:
                            value = example[name]
                            if isinstance(value, list):
                                for val in value:
                                    data_values.append(val)
                            else:
                                data_values.append(value)
                    else:
                        print(
                            "swagger_property_data_schema: example could not find:", name)
                        pass
                else:
                    print("swagger_property_data_schema: example is none")
    return data_values
swagger_property_data_schema
    get the value of the property name from the schema that is referenced by the path in get (or post)
    it tries to get first the enum values or the default value.
    if this is not found then it will try to get the value from the example
    :param json_data: the swagger file as json struct
    :param input_path: the path to which the if should be queried
    :return: list of if values
    
swagger_property_data_schema
get the value of the property name from the schema that is referenced by the path in get (or post)
it tries to get first the enum values or the default value.
if this is not found then it will try to get the value from the example
swagger_property_data_schema get the value of the property name from the schema that is referenced by the path in get ( or post ) it tries to get first the enum values or the default value . if this is not found then it will try to get the value from the example
def swagger_property_data_schema(json_data, input_path, name):
    data_values = []
    schema = None
    example = None
    for path, path_item in json_data["paths"].items():
        if input_path == path:
            try:
                schema = path_item["get"]["responses"]["200"]["schema"]
            except:
                try:
                    schema = path_item["post"]["responses"]["200"]["schema"]
                except:
                    print("swagger_property_data_schema: could not find schema")
                    pass
            try:
                example = path_item["get"]["responses"]["200"]["x-example"]
            except:
                try:
                    example = path_item["post"]["responses"]["200"]["x-example"]
                except:
                    print("swagger_property_data_schema: could not find x-example")
                    pass
            value_found = False
            if schema is not None:
                def_data = json_data["definitions"]
                for def_name, def_item in def_data.items():
                    full_def_name = "#/definitions/" + def_name
                    if full_def_name == schema["$ref"]:
                        name_block = find_key_link(def_item, name)
                        if name_block is not None:
                            try:
                                enum_values = name_block["items"]["enum"]
                                for enum_value in enum_values:
                                    data_values.append(enum_value)
                                    value_found = True
                            except:
                                try:
                                    default_values = name_block["default"]
                                    for default_value in default_values:
                                        data_values.append(default_value)
                                        value_found = True
                                except:
                                    value_found = False
                        else:
                            pass
            else:
                print("swagger_property_data: schema not found:", input_path)
            if value_found is False:
                if example is not None:
                    if isinstance(example, dict):
                        value = example.get(name)
                        if value is not None:
                            value = example[name]
                            if isinstance(value, list):
                                for val in value:
                                    data_values.append(val)
                            else:
                                data_values.append(value)
                    else:
                        print(
                            "swagger_property_data_schema: example could not find:", name)
                        pass
                else:
                    print("swagger_property_data_schema: example is none")
    return data_values
def swagger_property_data_schema ( json_data , input_path , name ) : data_values = [ ] schema = None example = None for path , path_item in json_data [ "paths" ] . items ( ) : if input_path == path : try : schema = path_item [ "get" ] [ "responses" ] [ "200" ] [ "schema" ] except : try : schema = path_item [ "post" ] [ "responses" ] [ "200" ] [ "schema" ] except : print ( "swagger_property_data_schema: could not find schema" ) pass try : example = path_item [ "get" ] [ "responses" ] [ "200" ] [ "x-example" ] except : try : example = path_item [ "post" ] [ "responses" ] [ "200" ] [ "x-example" ] except : print ( "swagger_property_data_schema: could not find x-example" ) pass value_found = False if schema is not None : def_data = json_data [ "definitions" ] for def_name , def_item in def_data . items ( ) : full_def_name = "#/definitions/" + def_name if full_def_name == schema [ "$ref" ] : name_block = find_key_link ( def_item , name ) if name_block is not None : try : enum_values = name_block [ "items" ] [ "enum" ] for enum_value in enum_values : data_values . append ( enum_value ) value_found = True except : try : default_values = name_block [ "default" ] for default_value in default_values : data_values . append ( default_value ) value_found = True except : value_found = False else : pass else : print ( "swagger_property_data: schema not found:" , input_path ) if value_found is False : if example is not None : if isinstance ( example , dict ) : value = example . get ( name ) if value is not None : value = example [ name ] if isinstance ( value , list ) : for val in value : data_values . append ( val ) else : data_values . append ( value ) else : print ( "swagger_property_data_schema: example could not find:" , name ) pass else : print ( "swagger_property_data_schema: example is none" ) return data_values
swagger_property_data_schema
get the value of the property name from the schema that is referenced by the path in get (or post)
it tries to get first the enum values or the default value.
swagger_property_data_schema get the value of the property name from the schema that is referenced by the path in get ( or post ) it tries to get first the enum values or the default value .
"""swagger_property_data_schema
    get the value of the property name from the schema that is referenced by the path in get (or post)
    it tries to get first the enum values or the default value.
    if this is not found then it will try to get the value from the example
    :param json_data: the swagger file as json struct
    :param input_path: the path to which the if should be queried
    :return: list of if values
    """ # get the schema
 # get the example
 # get it from the schema::enum
 # get it from the schema::default
 # get it from the example

list of if values
list of if values
json_data
the swagger file as json struct
the swagger file as json struct
input_path
the path to which the if should be queried
the path to which the if should be queried
name