From a9f6b6c69ba23f6696d958abfc5132a2df4cee51 Mon Sep 17 00:00:00 2001 From: Vincent Bailleau Date: Wed, 25 Oct 2017 13:15:33 +0200 Subject: [PATCH] Allow a wided range of text content types --- lib/components/SchemaSample/schema-sample.html | 4 ++-- lib/components/SchemaSample/schema-sample.ts | 7 ++++++- lib/utils/helpers.ts | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/components/SchemaSample/schema-sample.html b/lib/components/SchemaSample/schema-sample.html index 27357ef8..baaa3055 100644 --- a/lib/components/SchemaSample/schema-sample.html +++ b/lib/components/SchemaSample/schema-sample.html @@ -11,7 +11,7 @@ - + @@ -23,7 +23,7 @@

     
   
-  
+  
     
Copy diff --git a/lib/components/SchemaSample/schema-sample.ts b/lib/components/SchemaSample/schema-sample.ts index 4bbbe4d9..16737737 100644 --- a/lib/components/SchemaSample/schema-sample.ts +++ b/lib/components/SchemaSample/schema-sample.ts @@ -22,6 +22,7 @@ export class SchemaSample extends BaseComponent implements OnInit { sample: any; xmlSample: string; textSample: string; + textSampleType: string; enableButtons: boolean = false; private _normalizer:SchemaNormalizer; @@ -53,7 +54,11 @@ export class SchemaSample extends BaseComponent implements OnInit { } this.xmlSample = base.examples && getXmlLikeSample(base.examples); - this.textSample = base.examples && getTextLikeSample(base.examples); + let textResult = base.examples && getTextLikeSample(base.examples); + if( textResult ) { + this.textSample = textResult.sample; + this.textSampleType = textResult.type; + } let jsonLikeSample = base.examples && getJsonLikeSample(base.examples); if (jsonLikeSample) { diff --git a/lib/utils/helpers.ts b/lib/utils/helpers.ts index 44f8e4df..e37f602d 100644 --- a/lib/utils/helpers.ts +++ b/lib/utils/helpers.ts @@ -148,7 +148,7 @@ export function isXmlLike(contentType: string): boolean { } export function isTextLike(contentType: string): boolean { - return contentType.search(/text\/plain/i) !== -1; + return contentType.search(/text/i) !== -1; } export function getJsonLikeSample(samples: Object = {}) { @@ -179,5 +179,5 @@ export function getTextLikeSample(samples: Object = {}) { return false; } - return samples[textLikeKeys[0]]; + return { type:textLikeKeys[0], sample: samples[textLikeKeys[0]]}; }