コード例 #1
0
    def testSingleTypeSchema3(self):
        modelFile = 'tests/resources/models/json/examples/model_with_bytes.json'
        modelFileExists = os.path.isfile(modelFile)
        self.assertTrue('model file exists: ' + modelFile, modelFileExists)
        model = config.Model()
        model.schema = modelFile
        modelTypes = getModelFromJson(model, [])
        self.assertIsNotNone(modelTypes)
        self.assertEqual(16, len(modelTypes))
        self._checkUpType(0, 'Job', 6, modelTypes, ['models', 'tasks'])
        self._checkUpType(1, 'Model', 4, modelTypes, [])
        self._checkUpType(2, 'Task', 8, modelTypes, [])
        self._checkUpType(3, 'BlackWhiteListEntry', 2, modelTypes, ['name'])
        self._checkUpType(4, 'BlackWhiteListEntryTypeEnum', 0, modelTypes, [])
        self._checkUpType(5, 'SingleFileTask', 3, modelTypes, [])
        self._checkUpType(6, 'TemplateParam', 6, modelTypes, ['name', 'value'])
        self._checkUpType(7, 'MultiFileTask', 10, modelTypes, [])
        self._checkUpType(8, 'MultiFileTaskFileFilterTypeEnum', 0, modelTypes, [])
        self._checkUpType(9, 'RandomDataTask', 13, modelTypes, [], ('keyProperties', 'valuePools', 'arrays'))
        self.assertEqual('bValues', modelTypes[2].properties[1].name)
        self.assertTrue(modelTypes[2].properties[1].isArray)
        self.assertTrue(isinstance(modelTypes[2].properties[1].type, BytesType))
        self.assertEqual('bValue', modelTypes[6].properties[2].name)
        self.assertFalse(modelTypes[6].properties[2].isArray)
        self.assertTrue(isinstance(modelTypes[6].properties[2].type, BytesType))

        jobType = modelTypes[0]
        self.assertEqual(jobType.properties[4].type.format, NumberTypeFormatEnum.FLOAT)
        self.assertEqual(jobType.properties[5].type.format, NumberTypeFormatEnum.DOUBLE)
コード例 #2
0
    def testOpenApiSchema(self):
        modelFile = 'resources/models/json/yacg_openapi_paths.json'
        modelFileExists = os.path.isfile(modelFile)
        self.assertTrue('model file exists: ' + modelFile, modelFileExists)
        model = config.Model()
        model.schema = modelFile
        modelTypes = getModelFromJson(model, [])
        templateFile = 'resources/templates/examples/pythonBeans.mako'
        template = Template(filename=templateFile)
        templateFileExists = os.path.isfile(modelFile)
        self.assertTrue('template file exists: ' + templateFile, templateFileExists)
        templateParameterDict = {}
        templateParameterDict['baseModelDomain'] = 'yacg.model.openapi'

        blackListList = []
        # all types from the main model should be igrnored ...
        # blacklisted by domain example
        entryTag = config.BlackWhiteListEntry()
        entryTag.name = 'yacgCore'
        entryTag.type = config.BlackWhiteListEntryTypeEnum.DOMAIN
        blackListList.append(entryTag)
        trimmedTypes = generatorHelperFuncs.trimModelTypes(modelTypes, blackListList, None)

        renderResult = template.render(
            modelTypes=trimmedTypes,
            templateParameters=templateParameterDict)
        self.assertIsNotNone(renderResult)

        testOutputFile = "tmp/openapi.py"
        f = open(testOutputFile, "w+")
        f.write(renderResult)
        f.close()
コード例 #3
0
    def testDictionary4(self):
        modelFile = 'tests/resources/models/json/examples/simple_allof_with_dictionary.json'
        modelFileExists = os.path.isfile(modelFile)
        self.assertTrue('model file exists: ' + modelFile, modelFileExists)
        model = config.Model()
        model.schema = modelFile
        modelTypes = getModelFromJson(model, [])
        self.assertIsNotNone(modelTypes)
        self.assertEqual(5, len(modelTypes))
        self.assertTrue(isinstance(modelTypes[0], ComplexType))
        self.assertTrue(isinstance(modelTypes[1], ComplexType))
        self.assertTrue(isinstance(modelTypes[2], EnumType))
        self.assertTrue(isinstance(modelTypes[3], DictionaryType))
        self.assertTrue(isinstance(modelTypes[4], DictionaryType))

        self.assertTrue(isinstance(modelTypes[3].valueType, IntegerType))
        self.assertTrue(isinstance(modelTypes[4].valueType, StringType))

        self.assertTrue(
            isinstance(modelTypes[1].properties[2].type, StringType))
        self.assertTrue(
            isinstance(modelTypes[1].properties[3].type, ObjectType))
        self.assertTrue(
            isinstance(modelTypes[1].properties[4].type, DictionaryType))
        self.assertTrue(
            isinstance(modelTypes[1].properties[4].type.valueType,
                       IntegerType))
        self.assertTrue(
            isinstance(modelTypes[1].properties[5].type, DictionaryType))
        self.assertTrue(
            isinstance(modelTypes[1].properties[5].type.valueType, StringType))
コード例 #4
0
    def testJavaBeanTemplate(self):
        dirpath = Path('tmp', 'javaBeans')
        if dirpath.exists() and dirpath.is_dir():
            shutil.rmtree(dirpath)
        modelFile = 'resources/models/json/yacg_model_schema.json'
        modelFileExists = os.path.isfile(modelFile)
        self.assertTrue('model file exists: ' + modelFile, modelFileExists)
        model = config.Model()
        model.schema = modelFile
        modelTypes = getModelFromJson(model, [])
        templateFile = 'resources/templates/examples/javaBeans.mako'
        templateFileExists = os.path.isfile(templateFile)
        self.assertTrue('template file exists: ' + templateFile,
                        templateFileExists)
        templateParameters = []
        templateParam = config.TemplateParam()
        templateParam.name = 'modelPackage'
        templateParam.value = 'de.test.model'
        templateParameters.append(templateParam)
        multiFileTask = MultiFileTask()
        multiFileTask.template = templateFile
        multiFileTask.destDir = 'tmp/javaBeans/de/test/model'
        multiFileTask.destFileExt = 'java'
        multiFileTask.templateParams = templateParameters

        renderMultiFileTemplate(modelTypes, (), (), multiFileTask)
コード例 #5
0
 def testFlattenByTag(self):
     modelFile = 'tests/resources/models/json/examples/flatten_by_tag.json'
     modelFileExists = os.path.isfile(modelFile)
     self.assertTrue('model file exists: ' + modelFile, modelFileExists)
     model = config.Model()
     model.schema = modelFile
     modelTypes = getModelFromJson(model, [])
     modelTypes = modelFuncs.processYacgTags(modelTypes)
     self.assertIsNotNone(modelTypes)
     self.assertEqual(6, len(modelTypes))
     for t in modelTypes:
         if t.name == 'MoreSophisticatedAllOf':
             self.assertEqual(1, len(t.properties))
             self.assertIsNotNone(t.extendsType)
         if t.name == 'Address':
             # type Address is removed by Tag
             self.assertIsNone(t)
         if t.name == 'MainAdress':
             self.assertEqual(6, len(t.properties))
             self.assertIsNone(t.extendsType)
         if t.name == 'SimpleAllOfSchema':
             self.assertEqual(1, len(t.properties))
             self.assertIsNotNone(t.extendsType)
         if t.name == 'MainAddressComplex':
             self.assertEqual(3, len(t.properties))
             self.assertIsNone(t.extendsType)
コード例 #6
0
    def testNormalized(self):
        modelFile = 'tests/resources/models/json/examples/openapi_v3_example_refs.json'
        modelFileExists = os.path.isfile(modelFile)
        self.assertTrue('model file exists: ' + modelFile, modelFileExists)
        model = config.Model()
        model.schema = modelFile
        modelTypes = getModelFromJson(model, [])
        # tests for enum values

        self.assertTrue(modelTypes[4], EnumType)
        self.assertIsNone(modelTypes[4].valuesMap)

        templateFile = 'resources/templates/examples/normalizedOpenApiJson.mako'
        templateFileExists = os.path.isfile(templateFile)
        self.assertTrue('template file exists: ' + templateFile,
                        templateFileExists)
        templateParameters = {}
        template = Template(filename=templateFile)
        renderResult = template.render(modelTypes=modelTypes,
                                       templateParameters=templateParameters)
        self.assertIsNotNone(renderResult)

        testOutputFile = "tmp/normalizedOpenApiNormalized.json"
        f = open(testOutputFile, "w+")
        f.write(renderResult)
        f.close()
コード例 #7
0
    def testEvilSchema(self):
        modelFile = 'tests/resources/models/json/examples/evil_enum.json'
        modelFileExists = os.path.isfile(modelFile)
        self.assertTrue('model file exists: ' + modelFile, modelFileExists)
        model = config.Model()
        model.schema = modelFile
        modelTypes = getModelFromJson(model, [])

        self.assertTrue(modelTypes[0], EnumType)
        self.assertIsNone(modelTypes[0].valuesMap)

        templateFile = 'resources/templates/examples/pythonBeans.mako'
        template = Template(filename=templateFile)
        templateFileExists = os.path.isfile(modelFile)
        self.assertTrue('template file exists: ' + templateFile,
                        templateFileExists)
        templateParameterDict = {}
        templateParameterDict['baseModelDomain'] = 'yacg.model.model'
        renderResult = template.render(
            modelTypes=modelTypes, templateParameters=templateParameterDict)
        self.assertIsNotNone(renderResult)

        testOutputFile = "tmp/evil_model.py"
        f = open(testOutputFile, "w+")
        f.write(renderResult)
        f.close()
コード例 #8
0
    def testWhiteList(self):
        modelFile = 'tests/resources/models/json/examples/dummy_random_data_model.json'
        modelFileExists = os.path.isfile(modelFile)
        self.assertTrue('model file exists: ' + modelFile, modelFileExists)
        model = config.Model()
        model.schema = modelFile
        modelTypes = getModelFromJson(model, [])
        randomDataTask = RandomDataTask()
        randomDataTask.destDir = 'tmp/randomData3'
        randomDataTask.defaultKeyPropNames = ('id')

        whiteList = []
        whiteListEntry = BlackWhiteListEntry()
        whiteListEntry.name = 'IntegerType'
        whiteListEntry.type = BlackWhiteListEntryTypeEnum.TYPE
        whiteList.append(whiteListEntry)
        whiteListEntry = BlackWhiteListEntry()
        whiteListEntry.name = 'NumberType'
        whiteListEntry.type = BlackWhiteListEntryTypeEnum.TYPE
        whiteList.append(whiteListEntry)

        randomData = randomDataGenerator.renderRandomData(modelTypes, [], whiteList, randomDataTask)
        self.assertEqual(2, len(randomData))
        integerTypeData = randomData['IntegerType']
        self.assertTrue(len(integerTypeData) > 0)
        for d in integerTypeData:
            self.assertIsNotNone(d.get('guid', None))
        numberTypeData = randomData['NumberType']
        self.assertTrue(len(numberTypeData) > 0)
        for d in numberTypeData:
            self.assertIsNotNone(d.get('id', None))
コード例 #9
0
    def testSingleTypeSchema(self):
        modelFile = 'tests/resources/models/json/examples/single_type_schema.json'
        modelFileExists = os.path.isfile(modelFile)
        self.assertTrue('model file exists: ' + modelFile, modelFileExists)
        model = config.Model()
        model.schema = modelFile
        modelTypes = getModelFromJson(model, [])
        self.assertIsNotNone(modelTypes)
        self.assertEqual(4, len(modelTypes))

        mainType = None
        anotherType = None
        innerComplexType = None
        for type in modelTypes:
            if type.name == 'SingleTypeSchema':
                mainType = type
            elif type.name == 'AnotherType':
                anotherType = type
            else:
                innerComplexType = type
        self.assertIsNotNone(mainType)
        self.assertEqual(4, len(mainType.properties))
        self.assertTrue(isinstance(mainType.properties[0].type, StringType))
        self.assertEqual(mainType.properties[0].type.minLength, 2)
        self.assertEqual(mainType.properties[0].type.maxLength, 200)
        self.assertEqual(mainType.properties[0].type.pattern, "^\\d$")

        self.assertTrue(isinstance(mainType.properties[1].type, NumberType))
        self.assertEqual(mainType.properties[1].type.minimum, 0.5)
        self.assertEqual(mainType.properties[1].type.maximum, 1.4)
        self.assertEqual(mainType.properties[1].type.exclusiveMinimum, -1.5)
        self.assertEqual(mainType.properties[1].type.exclusiveMaximum, -10.4)

        self.assertTrue(isinstance(mainType.properties[2].type, EnumType))
        self.assertTrue(isinstance(mainType.properties[3].type, ComplexType))

        self.assertIsNotNone(anotherType)
        self.assertEqual(2, len(anotherType.properties))
        self.assertTrue(
            isinstance(anotherType.properties[0].type, DateTimeType))
        self.assertTrue(isinstance(anotherType.properties[1].type, NumberType))

        self.assertTrue(isinstance(anotherType.properties[1].type, NumberType))
        self.assertIsNone(anotherType.properties[1].type.minimum)
        self.assertIsNone(anotherType.properties[1].type.maximum)
        self.assertIsNone(anotherType.properties[1].type.exclusiveMinimum)
        self.assertIsNone(anotherType.properties[1].type.exclusiveMaximum)

        self.assertIsNotNone(innerComplexType)
        self.assertEqual(3, len(innerComplexType.properties))
        self.assertTrue(
            isinstance(innerComplexType.properties[0].type, StringType))
        self.assertTrue(
            isinstance(innerComplexType.properties[1].type, IntegerType))
        self.assertTrue(
            isinstance(innerComplexType.properties[2].type, ComplexType))
        self.assertEqual(anotherType, innerComplexType.properties[2].type)
コード例 #10
0
 def testGetTypeAndAllChildTypes(self):
     modelFile = 'tests/resources/models/json/examples/nibelheim.json'
     modelFileExists = os.path.isfile(modelFile)
     self.assertTrue('model file exists: ' + modelFile, modelFileExists)
     model = config.Model()
     model.schema = modelFile
     modelTypes = getModelFromJson(model, [])
     mongoTypes = getTypeAndAllChildTypes(modelTypes[0])
     self.assertEqual(len(mongoTypes), 2)
コード例 #11
0
 def testGetRelatedTypesToTag(self):
     modelFile = 'tests/resources/models/json/examples/nibelheim.json'
     modelFileExists = os.path.isfile(modelFile)
     self.assertTrue('model file exists: ' + modelFile, modelFileExists)
     model = config.Model()
     model.schema = modelFile
     modelTypes = getModelFromJson(model, [])
     mongoTypes = getTypesRelatedTagName(modelTypes, "mongodb")
     self.assertEqual(len(mongoTypes), 7)
コード例 #12
0
 def test_openApiV3Json(self):
     modelFile = 'tests/resources/models/json/examples/openapi_v3_example.json'
     modelFileExists = os.path.isfile(modelFile)
     self.assertTrue('model file exists: ' + modelFile, modelFileExists)
     model = config.Model()
     model.schema = modelFile
     ignorePathTypes = True
     modelTypes = getModelFromJson(model, [], ignorePathTypes)
     self._checkUpTypes(modelTypes)
コード例 #13
0
 def testDoesTypeOrAttribContainsType(self):
     modelFile = 'resources/models/json/yacg_config_schema.json'
     modelFileExists = os.path.isfile(modelFile)
     self.assertTrue('model file exists: ' + modelFile, modelFileExists)
     model = config.Model()
     model.schema = modelFile
     modelTypes = getModelFromJson(model, [])
     self.assertTrue(doesTypeOrAttribContainsType(modelTypes[0],
                                                  StringType))
     self.assertFalse(doesTypeOrAttribContainsType(modelTypes[0], UuidType))
コード例 #14
0
    def testEvilEnum2(self):
        modelFile = 'tests/resources/models/json/examples/evil_enum_with_values.json'
        modelFileExists = os.path.isfile(modelFile)
        self.assertTrue('model file exists: ' + modelFile, modelFileExists)
        model = config.Model()
        model.schema = modelFile
        modelTypes = getModelFromJson(model, [])

        self.assertTrue(modelTypes[0], EnumType)
        self.assertIsNotNone(modelTypes[0].valuesMap)
        self.assertEqual('true', modelTypes[0].valuesMap['1'])
コード例 #15
0
 def testExternalEnum(self):
     modelFile = 'tests/resources/models/json/examples/ExternalEnum.json'
     modelFileExists = os.path.isfile(modelFile)
     self.assertTrue('model file exists: ' + modelFile, modelFileExists)
     model = config.Model()
     model.schema = modelFile
     modelTypes = getModelFromJson(model, [])
     self.assertIsNotNone(modelTypes)
     self.assertEqual(1, len(modelTypes))
     self.assertTrue(modelTypes[0], EnumType)
     self.assertIsNone(modelTypes[0].valuesMap)
コード例 #16
0
 def testDictionary2(self):
     modelFile = 'tests/resources/models/json/examples/simple_dictionary2.json'
     modelFileExists = os.path.isfile(modelFile)
     self.assertTrue('model file exists: ' + modelFile, modelFileExists)
     model = config.Model()
     model.schema = modelFile
     modelTypes = getModelFromJson(model, [])
     self.assertIsNotNone(modelTypes)
     self.assertEqual(2, len(modelTypes))
     self.assertTrue(isinstance(modelTypes[0], DictionaryType))
     self.assertIsNotNone(modelTypes[0].valueType)
     self.assertTrue(isinstance(modelTypes[0].valueType, ComplexType))
コード例 #17
0
 def _testSimpleAllOf(self):
     modelFile = 'tests/resources/models/json/examples/simple_allof.json'
     modelFileExists = os.path.isfile(modelFile)
     self.assertTrue('model file exists: ' + modelFile, modelFileExists)
     model = config.Model()
     model.schema = modelFile
     modelTypes = getModelFromJson(model, [])
     self.assertIsNotNone(modelTypes)
     self.assertEqual(3, len(modelTypes))
     self._checkUpType(0, 'SimpleAllOfSchema', 1, modelTypes)
     self._checkUpType(1, 'Address', 3, modelTypes)
     self._checkUpType(2, 'SimpleAllOfSchemaTypeEnum', 0, modelTypes)
コード例 #18
0
ファイル: yacg.py プロジェクト: OkieOth/yacg
def readModels(configJob, flattenInheritance):
    """reads all desired models and build the model object tree from it"""

    loadedTypes = []
    yamlExtensions = set(['.yaml', '.yml'])
    for model in configJob.models:
        fileExt = getFileExt(model.schema)
        if fileExt.lower() in yamlExtensions:
            loadedTypes = getModelFromYaml(model, loadedTypes)
        else:
            loadedTypes = getModelFromJson(model, loadedTypes)
    return _postProcessLoadedModels(loadedTypes, flattenInheritance)
コード例 #19
0
 def _testSchemaWithExternalRef(self):
     modelFile = 'tests/resources/models/json/examples/schema_with_external_ref.json'
     modelFileExists = os.path.isfile(modelFile)
     self.assertTrue('model file exists: ' + modelFile, modelFileExists)
     model = config.Model()
     model.schema = modelFile
     modelTypes = getModelFromJson(model, [])
     self.assertIsNotNone(modelTypes)
     self.assertEqual(3, len(modelTypes))
     self._checkUpType(0, 'OneType', 2, modelTypes)
     self._checkUpType(1, 'TwoType', 3, modelTypes)
     self._checkUpType(2, 'AnotherType', 2, modelTypes)
コード例 #20
0
 def testExternalEnumWithValues2(self):
     modelFile = 'tests/resources/models/json/examples/openapi_v3_example_refs2.json'
     modelFileExists = os.path.isfile(modelFile)
     self.assertTrue('model file exists: ' + modelFile, modelFileExists)
     model = config.Model()
     model.schema = modelFile
     modelTypes = getModelFromJson(model, [])
     self.assertIsNotNone(modelTypes[4].valuesMap)
     keys = modelTypes[4].valuesMap.keys()
     self.assertEqual(3, len(keys))
     self.assertEqual('10', modelTypes[4].valuesMap['A'])
     self.assertEqual('20', modelTypes[4].valuesMap['B'])
     self.assertEqual('30', modelTypes[4].valuesMap['C'])
コード例 #21
0
    def testSchemaWithExternalCircularRefs(self):
        modelFile = 'tests/resources/models/json/examples/schema_with_circular_deps.json'
        modelFileExists = os.path.isfile(modelFile)
        self.assertTrue('model file exists: ' + modelFile, modelFileExists)
        model = config.Model()
        model.schema = modelFile
        modelTypes = getModelFromJson(model, [])
        self.assertIsNotNone(modelTypes)
        self.assertEqual(5, len(modelTypes))

        self._checkUpType(0, 'OneType', 2, modelTypes, [])
        self._checkUpType(1, 'RefBackType', 4, modelTypes, [])
        self._checkUpType(2, 'RefBackType2', 3, modelTypes, [])
        self._checkUpType(3, 'TwoType', 3, modelTypes, [])
        self._checkUpType(4, 'AnotherType', 2, modelTypes, [])
コード例 #22
0
    def testTags(self):
        modelFile = 'resources/models/json/yacg_model_schema.json'
        modelFileExists = os.path.isfile(modelFile)
        self.assertTrue('model file exists: ' + modelFile, modelFileExists)
        model = config.Model()
        model.schema = modelFile
        modelTypes = getModelFromJson(model, [])
        metaModelTypes = []
        self.assertIsNotNone(modelTypes)
        tagType = None
        propertyType = None
        complexTypeType = None
        for type in modelTypes:
            if hasTag('metaModelType', type):
                metaModelTypes.append(type.name)
            if type.name == 'Tag':
                tagType = type
            elif type.name == 'Property':
                propertyType = type
            elif type.name == 'ComplexType':
                complexTypeType = type
            self.assertEqual('yacg.model.model', type.domain)
        self.assertIsNotNone(tagType)
        constructorValueProps1 = getPropertiesThatHasTag('constructorValue', tagType)
        self.assertEqual(2, len(constructorValueProps1))
        self.assertIsNotNone(propertyType)
        constructorValueProps2 = getPropertiesThatHasTag('constructorValue', propertyType)
        self.assertEqual(2, len(constructorValueProps2))
        self.assertIsNotNone(complexTypeType)
        constructorValueProps3 = getPropertiesThatHasTag('constructorValue', complexTypeType)
        self.assertEqual(0, len(constructorValueProps3))

        expectedMetaModelTypes = [
            'Type',
            'ObjectType',
            'IntegerType',
            'NumberType',
            'BooleanType',
            'StringType',
            'UuidType',
            'EnumType',
            'DateType',
            'DateTimeType',
            'BytesType',
            'ComplexType',
            'DictionaryType'
        ]
        self.assertEqual(expectedMetaModelTypes, metaModelTypes)
コード例 #23
0
 def testSophisticatedAllOf(self):
     modelFile = 'tests/resources/models/json/examples/more_sophisticated_allof.json'
     modelFileExists = os.path.isfile(modelFile)
     self.assertTrue('model file exists: ' + modelFile, modelFileExists)
     model = config.Model()
     model.schema = modelFile
     modelTypes = getModelFromJson(model, [])
     self.assertIsNotNone(modelTypes)
     self.assertEqual(7, len(modelTypes))
     type = self._checkUpType(0, 'MoreSophisticatedAllOf', 1, modelTypes, [])
     self.assertIsNotNone(type.extendsType)
     address = self._checkUpType(1, 'Address', 3, modelTypes, [])
     self.assertEqual(type.extendsType, address)
     self._checkUpType(2, 'MoreSophisticatedAllOfTypeEnum', 0, modelTypes, [])
     self._checkUpType(3, 'MainAddress', 2, modelTypes, [])
     self._checkUpType(6, 'MainAddressComplex', 3, modelTypes, [])
コード例 #24
0
 def testSchemaWithExternalRef(self):
     modelFile = 'tests/resources/models/json/examples/schema_with_external_ref.json'
     modelFileExists = os.path.isfile(modelFile)
     self.assertTrue('model file exists: ' + modelFile, modelFileExists)
     model = config.Model()
     model.schema = modelFile
     modelTypes = getModelFromJson(model, [])
     self.assertIsNotNone(modelTypes)
     self.assertEqual(4, len(modelTypes))
     self._checkUpType(0, 'OneType', 2, modelTypes, [])
     self._checkUpType(1, 'TwoType', 4, modelTypes, [])
     # TwoType->implicitRef
     self.assertIsNotNone(modelTypes[1].properties[3].foreignKey)
     self.assertEqual(modelTypes[1].properties[2].type, modelTypes[1].properties[3].foreignKey)
     self._checkUpType(2, 'AnotherType', 2, modelTypes, [])
     self._checkUpType(3, 'DemoEnum', 0, modelTypes, [])
コード例 #25
0
 def testEvilArray(self):
     modelFile = 'tests/resources/models/json/examples/evil_array.json'
     modelFileExists = os.path.isfile(modelFile)
     self.assertTrue('model file exists: ' + modelFile, modelFileExists)
     model = config.Model()
     model.schema = modelFile
     modelTypes = getModelFromJson(model, [])
     self.assertIsNotNone(modelTypes)
     self.assertEqual(len(modelTypes), 3)
     self.assertEqual(len(modelTypes[0].properties), 3)
     self.assertEqual(modelTypes[0].properties[0].arrayDimensions, 1)
     self.assertIsNotNone(modelTypes[0].properties[0].type)
     self.assertEqual(modelTypes[0].properties[1].arrayDimensions, 2)
     self.assertIsNotNone(modelTypes[0].properties[1].type)
     self.assertEqual(modelTypes[0].properties[2].arrayDimensions, 3)
     self.assertIsNotNone(modelTypes[0].properties[2].type)
コード例 #26
0
 def test_compareSwaggerV2(self):
     modelFileJson = 'tests/resources/models/json/examples/swagger_v2_example.json'
     modelJson = config.Model()
     modelJson.schema = modelFileJson
     modelTypesJson = getModelFromJson(modelJson, [], True)
     modelFileYaml = 'tests/resources/models/yaml/examples/swagger_v2_example.yaml'
     modelYaml = config.Model()
     modelYaml.schema = modelFileYaml
     modelTypesYaml = getModelFromYaml(modelYaml, [], True)
     self.assertEqual(len(modelTypesJson), len(modelTypesYaml))
     for i in range(len(modelTypesJson)):
         typeJson = modelTypesJson[i]
         typeYaml = modelTypesYaml[i]
         self.assertEqual(str(type(typeJson)), str(type(typeYaml)))
         if isinstance(typeJson, ComplexType):
             self.assertEqual(len(typeJson.properties),
                              len(typeYaml.properties))
コード例 #27
0
 def testGetPythonValueForTypeStringType(self):
     modelFile = 'tests/resources/models/json/examples/swagger_v2_example.json'
     modelFileExists = os.path.isfile(modelFile)
     self.assertTrue('model file exists: ' + modelFile, modelFileExists)
     model = config.Model()
     model.schema = modelFile
     ignorePathTypes = False
     modelTypes = getModelFromJson(model, [], ignorePathTypes)
     whiteList = []
     whiteListEntry = BlackWhiteListEntry()
     whiteListEntry.name = 'PathType'
     whiteListEntry.type = BlackWhiteListEntryTypeEnum.TYPETYPE
     whiteList.append(whiteListEntry)
     pathTypes = generatorHelper.trimModelTypes(modelTypes, (), whiteList)
     self.assertEqual(14, len(pathTypes))
     multiFileTypes = swaggerFilterByOperationId(pathTypes)
     self.assertEqual(20, len(multiFileTypes))
コード例 #28
0
    def _estFlattenTypes(self):
        modelFile = 'tests/resources/models/json/examples/more_sophisticated_allof.json'
        modelFileExists = os.path.isfile(modelFile)
        self.assertTrue('model file exists: ' + modelFile, modelFileExists)
        model = config.Model()
        model.schema = modelFile
        modelTypes = getModelFromJson(model, [])
        self.assertIsNotNone(modelTypes)
        self.assertEqual(7, len(modelTypes))
        for t in modelTypes:
            if t.name == 'MoreSophisticatedAllOf':
                self.assertEqual(1, len(t.properties))
                self.assertIsNotNone(t.extendsType)
            if t.name == 'Address':
                self.assertEqual(3, len(t.properties))
                self.assertIsNone(t.extendsType)
            if t.name == 'MainAdress':
                self.assertEqual(2, len(t.properties))
                self.assertIsNotNone(t.extendsType)
            if t.name == 'SimpleAllOfSchema':
                self.assertEqual(1, len(t.properties))
                self.assertIsNotNone(t.extendsType)
            if t.name == 'MainAddressComplex':
                self.assertEqual(3, len(t.properties))
                self.assertIsNone(t.extendsType)

        flattenTypes = modelFuncs.flattenTypes(modelTypes)
        self.assertIsNotNone(flattenTypes)
        self.assertEqual(7, len(flattenTypes))
        for t in flattenTypes:
            if t.name == 'MoreSophisticatedAllOf':
                self.assertEqual(4, len(t.properties))
                self.assertIsNone(t.extendsType)
            if t.name == 'Address':
                self.assertEqual(3, len(t.properties))
                self.assertIsNone(t.extendsType)
            if t.name == 'MainAdress':
                self.assertEqual(6, len(t.properties))
                self.assertIsNone(t.extendsType)
            if t.name == 'SimpleAllOfSchema':
                self.assertEqual(4, len(t.properties))
                self.assertIsNone(t.extendsType)
            if t.name == 'MainAddressComplex':
                self.assertEqual(3, len(t.properties))
                self.assertIsNone(t.extendsType)
コード例 #29
0
    def _testSingleTypeSchema2(self):
        modelFile = 'resources/models/json/yacg_config_schema.json'
        modelFileExists = os.path.isfile(modelFile)
        self.assertTrue('model file exists: ' + modelFile, modelFileExists)
        model = config.Model()
        model.schema = modelFile
        modelTypes = getModelFromJson(model, [])
        self.assertIsNotNone(modelTypes)
        self.assertEqual(8, len(modelTypes))

        self._checkUpType(0, 'Job', 4, modelTypes)
        self._checkUpType(1, 'Model', 4, modelTypes)
        self._checkUpType(2, 'Task', 6, modelTypes)
        self._checkUpType(3, 'BlackWhiteListEntry', 2, modelTypes)
        self._checkUpType(4, 'BlackWhiteListEntryTypeEnum', 0, modelTypes)
        self._checkUpType(5, 'SingleFileTask', 3, modelTypes)
        self._checkUpType(6, 'TemplateParam', 2, modelTypes)
        self._checkUpType(7, 'MultiFileTask', 6, modelTypes)
コード例 #30
0
    def testSingleTypeSchema(self):
        modelFile = 'tests/resources/models/json/examples/single_type_schema.json'
        modelFileExists = os.path.isfile(modelFile)
        self.assertTrue('model file exists: ' + modelFile, modelFileExists)
        model = config.Model()
        model.schema = modelFile
        modelTypes = getModelFromJson(model, [])
        templateFile = 'yacg/generators/templates/plantUml.mako'
        template = Template(filename=templateFile)
        templateFileExists = os.path.isfile(modelFile)
        self.assertTrue('template file exists: ' + templateFile,
                        templateFileExists)
        renderResult = template.render(modelTypes=modelTypes)
        self.assertIsNotNone(renderResult)

        testOutputFile = "tmp/singleTypeSchema.puml"
        f = open(testOutputFile, "w+")
        f.write(renderResult)
        f.close()