public override IEnumerable <ComparisonMessage> Compare() { Logger.LogInfo(Resources.ParsingSwagger); if (string.IsNullOrWhiteSpace(Settings.Input) || string.IsNullOrWhiteSpace(Settings.Previous)) { throw ErrorManager.CreateError(Resources.InputRequired); } var oldDefintion = SwaggerParser.Load(Settings.Previous, Settings.FileSystem); var newDefintion = SwaggerParser.Load(Settings.Input, Settings.FileSystem); var context = new ComparisonContext(oldDefintion, newDefintion); // Look for semantic errors and warnings in the new document. var validator = new RecursiveObjectValidator(PropertyNameResolver.JsonName); var validationMessages = validator.GetValidationExceptions(newDefintion).ToList(); // Only compare versions if the new version is correct. var comparisonMessages = !validationMessages.Any(m => m.Severity > LogEntrySeverity.Error) ? newDefintion.Compare(context, oldDefintion) : Enumerable.Empty <ComparisonMessage>(); return(validationMessages .Select(msg => new ComparisonMessage(new MessageTemplate { Id = 0, Message = msg.Message }, string.Join("/", msg.Path), msg.Severity)) .Concat(comparisonMessages)); }
public override IEnumerable <LogMessage> Compare() { var settings = Settings.Instance; Logger.Instance.Log(Category.Info, Resources.ParsingSwagger); if (string.IsNullOrWhiteSpace(Settings.Input) || string.IsNullOrWhiteSpace(Settings.Previous)) { throw ErrorManager.CreateError(Resources.InputRequired); } var oldDefintion = SwaggerParser.Load(settings.Previous, settings.FileSystemInput); var newDefintion = SwaggerParser.Load(settings.Input, settings.FileSystemInput); var context = new ComparisonContext(oldDefintion, newDefintion); // Look for semantic errors and warnings in the new document. var validator = new RecursiveObjectValidator(PropertyNameResolver.JsonName); var LogMessages = validator.GetValidationExceptions(newDefintion.FilePath, newDefintion, new ServiceDefinitionMetadata { ServiceDefinitionDocumentType = ServiceDefinitionDocumentType.ARM, MergeState = ServiceDefinitionDocumentState.Composed }).ToList(); // Only compare versions if the new version is correct. var comparisonMessages = !LogMessages.Any(m => m.Severity > Category.Error) ? newDefintion.Compare(context, oldDefintion) : Enumerable.Empty <ComparisonMessage>(); return(LogMessages .Select(msg => new ComparisonMessage(new MessageTemplate { Id = 0, Message = msg.Message }, msg.Path, msg.Severity)) .Concat(comparisonMessages)); }
/// <summary> /// Builds service model from swagger file. /// </summary> /// <returns></returns> public override CodeModel Build() { Logger.Instance.Log(Category.Info, Resources.ParsingSwagger); if (string.IsNullOrWhiteSpace(Settings.Input)) { throw ErrorManager.CreateError(Resources.InputRequired); } var serviceDefinition = SwaggerParser.Load(Settings.Input, Settings.FileSystemInput); return(Build(serviceDefinition)); }
public override CodeModel Build(out IEnumerable <ValidationMessage> messages) { Logger.LogInfo(Resources.ParsingSwagger); if (string.IsNullOrWhiteSpace(Settings.Input)) { throw ErrorManager.CreateError(Resources.InputRequired); } ServiceDefinition = SwaggerParser.Load(Settings.Input, Settings.FileSystem); // Look for semantic errors and warnings in the document. var validator = new RecursiveObjectValidator(PropertyNameResolver.JsonName); messages = validator.GetValidationExceptions(ServiceDefinition).ToList(); Logger.LogInfo(Resources.GeneratingClient); // Update settings UpdateSettings(); InitializeClientModel(); BuildCompositeTypes(); // Build client parameters foreach (var swaggerParameter in ServiceDefinition.Parameters.Values) { var parameter = ((ParameterBuilder)swaggerParameter.GetBuilder(this)).Build(); var clientProperty = New <Property>(); clientProperty.LoadFrom(parameter); CodeModel.Add(clientProperty); } var methods = new List <Method>(); // Build methods foreach (var path in ServiceDefinition.Paths.Concat(ServiceDefinition.CustomPaths)) { foreach (var verb in path.Value.Keys) { var operation = path.Value[verb]; if (string.IsNullOrWhiteSpace(operation.OperationId)) { throw ErrorManager.CreateError( string.Format(CultureInfo.InvariantCulture, Resources.OperationIdMissing, verb, path.Key)); } var methodName = GetMethodName(operation); var methodGroup = GetMethodGroup(operation); if (verb.ToHttpMethod() != HttpMethod.Options) { string url = path.Key; if (url.Contains("?")) { url = url.Substring(0, url.IndexOf('?')); } var method = BuildMethod(verb.ToHttpMethod(), url, methodName, operation); method.Group = methodGroup; methods.Add(method); if (method.DefaultResponse.Body is CompositeType) { CodeModel.AddError((CompositeType)method.DefaultResponse.Body); } } else { Logger.LogWarning(Resources.OptionsNotSupported); } } } // Set base type foreach (var typeName in GeneratedTypes.Keys) { var objectType = GeneratedTypes[typeName]; if (ExtendedTypes.ContainsKey(typeName)) { objectType.BaseModelType = GeneratedTypes[ExtendedTypes[typeName]]; } CodeModel.Add(objectType); } CodeModel.AddRange(methods); return(CodeModel); }