(section: dict, model_id: str, schema_name: str, errors: List[str])
return (
        openapi_document,
        model_info,
    )
:param section: The section on a config spec: ie: init_config or instances
    :param model_id: The model id, which is either 'shared' or 'instance'
    :param schema_name: The specific model class name which is either SharedConfig or InstanceConfig
    :param errors: Array where to write error messages
    :return: openapi_document, model_info
    :rtype: (dict, ModelInfo)
:param section: The section on a config spec: ie: init_config or instances
    :param model_id: The model id, which is either 'shared' or 'instance'
    :param schema_name: The specific model class name which is either SharedConfig or InstanceConfig
    :param errors: Array where to write error messages
    :return: openapi_document, model_info
    :rtype: (dict, ModelInfo)
: param section : The section on a config spec : ie : init_config or instances : param model_id : The model id which is either shared or instance : param schema_name : The specific model class name which is either SharedConfig or InstanceConfig : param errors : Array where to write error messages : return : openapi_document model_info : rtype : ( dict ModelInfo )
def build_openapi_document(section: dict, model_id: str, schema_name: str, errors: List[str]) -> (dict, ModelInfo):
    """
    :param section: The section on a config spec: ie: init_config or instances
    :param model_id: The model id, which is either 'shared' or 'instance'
    :param schema_name: The specific model class name which is either SharedConfig or InstanceConfig
    :param errors: Array where to write error messages
    :return: openapi_document, model_info
    :rtype: (dict, ModelInfo)
    """
    # We want to create something like:
    #
    # paths:
    #   /instance:
    #     get:
    #       responses:
    #         '200':
    #           content:
    #             application/json:
    #               schema:
    #                 $ref: '#/components/schemas/InstanceConfig'
    # components:
    #   schemas:
    #     InstanceConfig:
    #       required:
    #       - endpoint
    #       properties:
    #         endpoint:
    #           ...
    #         timeout:
    #           ...
    #         ...
    openapi_document = {
        'paths': {
            f'/{model_id}': {
                'get': {
                    'responses': {
                        '200': {
                            'content': {'application/json': {'schema': {'$ref': f'#/components/schemas/{schema_name}'}}}
                        }
                    }
                }
            }
        },
        'components': {'schemas': {}},
    }
    schema = {}
    options = {}
    required_options = []

    schema['properties'] = options
    schema['required'] = required_options
    openapi_document['components']['schemas'][schema_name] = schema

    model_info = ModelInfo()
    options_seen = set()

    for section_option in sorted(section['options'], key=lambda o: (o['name'], o['hidden'])):
        option_name = section_option['name']
        normalized_option_name = _normalize_option_name(option_name)

        if normalized_option_name in options_seen:
            continue
        else:
            options_seen.add(normalized_option_name)

        type_data = _build_type_data(section_option)
        if not type_data:
            errors.append(f'Option `{option_name}` must have a `value` or `options` attribute')
            continue
        options[option_name] = type_data

        if section_option['deprecation']:
            model_info.add_deprecation(model_id, option_name, section_option['deprecation'])

        if section_option['required']:
            required_options.append(option_name)
        else:
            model_info.add_defaults(model_id, normalized_option_name, type_data)

        validator_errors = model_info.add_type_validators(type_data, option_name, normalized_option_name)
        errors.extend(validator_errors)

        # Remove fields that aren't part of the OpenAPI specification
        for extra_field in set(type_data) - ALLOWED_TYPE_FIELDS:
            type_data.pop(extra_field, None)

        _sanitize_openapi_object_properties(type_data)
    return (
        openapi_document,
        model_info,
    )
def build_openapi_document ( section : dict , model_id : str , schema_name : str , errors : List [ str ] ) -> ( dict , ModelInfo ) : # We want to create something like: # # paths: #   /instance: #     get: #       responses: #         '200': #           content: #             application/json: #               schema: #                 $ref: '#/components/schemas/InstanceConfig' # components: #   schemas: #     InstanceConfig: #       required: #       - endpoint #       properties: #         endpoint: #           ... #         timeout: #           ... #         ... openapi_document = { 'paths' : { f'/{model_id}' : { 'get' : { 'responses' : { '200' : { 'content' : { 'application/json' : { 'schema' : { '$ref' : f'#/components/schemas/{schema_name}' } } } } } } } } , 'components' : { 'schemas' : { } } , } schema = { } options = { } required_options = [ ] schema [ 'properties' ] = options schema [ 'required' ] = required_options openapi_document [ 'components' ] [ 'schemas' ] [ schema_name ] = schema model_info = ModelInfo ( ) options_seen = set ( ) for section_option in sorted ( section [ 'options' ] , key = lambda o : ( o [ 'name' ] , o [ 'hidden' ] ) ) : option_name = section_option [ 'name' ] normalized_option_name = _normalize_option_name ( option_name ) if normalized_option_name in options_seen : continue else : options_seen . add ( normalized_option_name ) type_data = _build_type_data ( section_option ) if not type_data : errors . append ( f'Option `{option_name}` must have a `value` or `options` attribute' ) continue options [ option_name ] = type_data if section_option [ 'deprecation' ] : model_info . add_deprecation ( model_id , option_name , section_option [ 'deprecation' ] ) if section_option [ 'required' ] : required_options . append ( option_name ) else : model_info . add_defaults ( model_id , normalized_option_name , type_data ) validator_errors = model_info . add_type_validators ( type_data , option_name , normalized_option_name ) errors . extend ( validator_errors ) # Remove fields that aren't part of the OpenAPI specification for extra_field in set ( type_data ) - ALLOWED_TYPE_FIELDS : type_data . pop ( extra_field , None ) _sanitize_openapi_object_properties ( type_data ) return ( openapi_document , model_info , )