/// <summary> /// Construct a Swagger object. /// </summary> /// <param name="safe">If true, all properties are given none-null values. If false, only Required properties are populated. </param> public Swagger(bool safe) { if (safe) { Version = "2.0"; Host = "localhost"; BasePath = "/"; Schemes = new string[1] { "http" }; Consumes = new string[0]; Produces = new string[0]; ExternalDocs = new ExternalDocumentationObject(); Info = new InfoObject(); Contact = new ContactObject(); License = new LicenseObject(); Tags = new TagObject[0]; } else { Version = "2.0"; Info = new InfoObject(safe); } }
/// <summary> /// Validate an individual tag object. /// </summary> /// <param name="tag"></param> /// <param name="context"></param> /// <param name="nameDescription"></param> /// <param name="result"></param> public static void ValidateTag(TagObject tag, string context, string nameDescription, ViolationCollection result) { if (tag == null) return; var nameValid = tag.Name != null; if (!nameValid) { result.Add(new Violation() { Code = string.Format("{0}.Name", context), Context = string.Format("{0}.Name", context), Description = nameDescription, ViolationLevel = ViolationLevel.Error }); } ValidateExternalDocs(tag.ExternalDocs, string.Format("{0}.ExternalDocs", context), result); }
public void TagValid() { TagObject tag = new TagObject(); Swagger.Tags = new TagObject[] { tag }; var result = SwaggerValidator.Validate(Swagger); Assert.AreEqual(0, result.Count); }
public void TagObjectSafe() { TagObject tag = new TagObject(); Assert.IsNotNull(tag.Name); Assert.IsNotNull(tag.Description); Assert.IsNotNull(tag.ExternalDocs); }
public void TagNameInvalid() { TagObject safeTag = new TagObject(); TagObject nameTag = new TagObject() { Name = null }; Swagger.Tags = new TagObject[] { safeTag, nameTag }; AssertInvalidProperty("Tags[1].Name", ViolationLevel.Error); }
public void TagNameClashCaseInsensitive() { TagObject filler = new TagObject(); TagObject safeTag = new TagObject() { Name = "Dog" }; TagObject clashTag = new TagObject() { Name = "DOG" }; Swagger.Tags = new TagObject[] { filler, safeTag, clashTag }; AssertInvalidProperty("Tags[2].Name", ViolationLevel.Error); }
public void TagExternalDocsValid() { TagObject safeTag = new TagObject(); TagObject docs = new TagObject() { Name = "a", ExternalDocs = new ExternalDocumentationObject() { Url = null } }; Swagger.Tags = new TagObject[] { safeTag, docs }; AssertInvalidProperty("Tags[1].ExternalDocs.Url", ViolationLevel.Error); }