Beispiel #1
0
def __extractOpenApiContentSectionAndAppend(contentDict, contentHost, modelTypes, modelFileContainer):
    if contentDict is None:
        return
    for contentDictKey in contentDict.keys():
        content = contentDict[contentDictKey]
        contentEntry = openapi.ContentEntry()
        contentEntry.mimeType = contentDictKey
        schema = content.get('schema', None)
        __getTypeFromSchemaDictAndAsignId(schema, contentEntry, modelTypes, modelFileContainer)
        contentHost.content.append(contentEntry)
Beispiel #2
0
def __extractOpenApiCommandResponses(command, responsesDict, modelTypes, modelFileContainer):
    if responsesDict is None:
        return
    for key in responsesDict.keys():
        responseDict = responsesDict[key]
        response = openapi.Response()
        command.responses.append(response)
        response.returnCode = key
        response.description = responseDict.get('description', None)
        contentDict = responseDict.get('content', None)
        if contentDict is not None:
            __extractOpenApiContentSectionAndAppend(contentDict, response, modelTypes, modelFileContainer)
        else:
            # swagger v2
            schema = responseDict.get('schema', None)
            if schema is not None:
                contentEntry = openapi.ContentEntry()
                response.content.append(contentEntry)
                __getTypeFromSchemaDictAndAsignId(schema, contentEntry, modelTypes, modelFileContainer)
Beispiel #3
0
def __extractOpenApiCommandParameters(command, parametersList, modelTypes, modelFileContainer):
    for param in parametersList:
        originalInType = param.get('in', None)
        if originalInType == 'body':
            # swagger v2
            requestBody = openapi.RequestBody()
            command.requestBody = requestBody
            requestBody.description = param.get('description', None)
            requestBody.required = param.get('required', 'True')
            schema = param.get('schema', None)
            if schema is not None:
                contentEntry = openapi.ContentEntry()
                requestBody.content.append(contentEntry)
                __getTypeFromSchemaDictAndAsignId(schema, contentEntry, modelTypes, modelFileContainer)
        else:
            parameter = openapi.Parameter()
            command.parameters.append(parameter)
            parameter.inType = openapi.ParameterInTypeEnum.valueForString(originalInType)
            parameter.name = param.get('name', None)
            parameter.description = param.get('description', None)
            parameter.required = param.get('required', False)
            paramSchema = param.get('schema', None)
            paramType = param.get('type', None)
            if (paramSchema is None) and (paramType is None):
                logging.error(
                    "modelFile: %s, path=%s: missing schema or type entry" %
                    (modelFileContainer.fileName, command.path))
                continue
            if paramSchema is not None:
                parameter.type = _extractAttribType(
                    command.operationId.capitalize(),
                    parameter,
                    paramSchema,
                    modelTypes,
                    modelFileContainer)
            elif paramType is not None:
                parameter.type = _extractAttribType(
                    command.operationId.capitalize(),
                    parameter,
                    param,
                    modelTypes,
                    modelFileContainer)