Example #1
0
        public void TestInitialise()
        {
            _objectParser = new Mock <IOpenApiSpecObjectParser <JsonCatchAllTypeModel> >();

            _service = new OpenApiSpecUmbrellaTypeParser <JsonCatchAllTypeModel>();

            _primitiveModel = new JsonCatchAllTypeModel()
            {
                Type   = "integer",
                Format = "int64"
            };
            _enumValues = new List <string>()
            {
                "One",
                "Two",
                "Three"
            };
            _enumModel = new JsonCatchAllTypeModel()
            {
                Type = "string",
                Enum = _enumValues
            };
            _objectProp  = new JsonCatchAllTypeModel();
            _allOfMember = new JsonCatchAllTypeModel();
            _objectModel = new JsonCatchAllTypeModel()
            {
                Type       = "object",
                Properties = new Dictionary <string, JsonCatchAllTypeModel>()
                {
                    { "Property", _objectProp }
                },
                AllOf = new List <JsonCatchAllTypeModel>()
                {
                    _allOfMember
                }
            };
            _referenceValue = Guid.NewGuid().ToString();
            _referenceModel = new JsonCatchAllTypeModel()
            {
                Reference = _referenceValue
            };
            _arrayItems = new JsonCatchAllTypeModel()
            {
                Type       = "object",
                Properties = new Dictionary <string, JsonCatchAllTypeModel>()
                {
                    { "ArrayMemberProperty", _objectProp }
                }
            };
            _arrayModel = new JsonCatchAllTypeModel()
            {
                Type  = "array",
                Items = _arrayItems
            };

            _objectParser.Setup(s => s.Parse(It.IsAny <JsonCatchAllTypeModel>()))
            .Returns(() => new OpenApiObjectType());
        }
Example #2
0
        protected override void BeginProcessing()
        {
            base.BeginProcessing();

            var filePathFormatService = new FilePathFormattingService();
            var jsonTypeParser        = new OpenApiSpecUmbrellaTypeParser <JsonCatchAllTypeModel>();
            var jsonObjectParser      = new OpenApiSpecObjectParser <JsonCatchAllTypeModel>(jsonTypeParser);
            var yamlTypeParser        = new OpenApiSpecUmbrellaTypeParser <YamlCatchAllTypeModel>();
            var yamlObjectParser      = new OpenApiSpecObjectParser <YamlCatchAllTypeModel>(yamlTypeParser);
            var lastTokenService      = new LastTokenInPathService();
            var enumFromStringService = new EnumFromStringService();
            var shortNameService      = new OpenApiEndpointShortNameService(lastTokenService);

            var moduleBuilderProvider   = new ModuleBuilderProvider();
            var openApiPrimitiveService = new OpenApiPrimitiveToTypeService(new OpenApiEnumToTypeService(moduleBuilderProvider));
            var openApiTypeResolver     = new OpenApiUmbrellaTypeResolver(openApiPrimitiveService,
                                                                          new OpenApiReferenceToTypeService(lastTokenService));
            var openApiObjectToTypeService = new OpenApiObjectToTypeService(openApiTypeResolver,
                                                                            new StealFieldsFromOpenApiObjectTypeService(openApiTypeResolver),
                                                                            moduleBuilderProvider);

            //establish current ps session working directory
            using (var session = PowerShell.Create(RunspaceMode.CurrentRunspace))
            {
                session.AddCommand("get-location");
                _pwd = session.Invoke <PathInfo>()
                       .FirstOrDefault()?.Path;
            }

            _specImportService = new ImportSpecFromFilePathService(filePathFormatService,
                                                                   new JsonFileToOpenApiModelService(jsonObjectParser,
                                                                                                     jsonTypeParser,
                                                                                                     new OpenApiJsonEndpointsParser(jsonTypeParser,
                                                                                                                                    jsonObjectParser,
                                                                                                                                    enumFromStringService),
                                                                                                     shortNameService),
                                                                   new YamlFileToOpenApiModelService(yamlObjectParser,
                                                                                                     yamlTypeParser,
                                                                                                     new OpenApiYamlEndpointsParser(yamlTypeParser,
                                                                                                                                    yamlObjectParser,
                                                                                                                                    enumFromStringService),
                                                                                                     shortNameService),
                                                                   new OpenApiSpecModelToGeneratedTypesService(openApiObjectToTypeService,
                                                                                                               openApiTypeResolver,
                                                                                                               new OpenApiEndpointToEndpointService(openApiTypeResolver,
                                                                                                                                                    openApiPrimitiveService,
                                                                                                                                                    openApiObjectToTypeService)));
        }