2525import io .harness .pms .pipeline .service .PMSYamlSchemaService ;
2626import io .harness .pms .yaml .SchemaErrorResponse ;
2727import io .harness .pms .yaml .YamlSchemaResponse ;
28+ import io .harness .serializer .JsonUtils ;
2829import io .harness .yaml .schema .YamlSchemaResource ;
2930
3031import com .fasterxml .jackson .databind .JsonNode ;
32+ import com .google .common .io .Resources ;
3133import com .google .inject .Inject ;
34+ import java .io .IOException ;
35+ import java .nio .charset .StandardCharsets ;
36+ import java .util .Objects ;
3237import javax .validation .constraints .NotNull ;
3338import javax .ws .rs .NotSupportedException ;
3439import lombok .AllArgsConstructor ;
@@ -43,6 +48,8 @@ public class PmsYamlSchemaResourceImpl implements YamlSchemaResource, PmsYamlSch
4348 private final NGTriggerYamlSchemaService ngTriggerYamlSchemaService ;
4449
4550 private final String deployMode = System .getenv ().get ("DEPLOY_MODE" );
51+ private final String PIPELINE_JSON_PATH = "static-schema/pipeline.json" ;
52+ private final String TEMPLATE_JSON_PATH = "static-schema/template.json" ;
4653
4754 public ResponseDTO <JsonNode > getYamlSchema (@ NotNull EntityType entityType , String projectIdentifier ,
4855 String orgIdentifier , Scope scope , String identifier , @ NotNull String accountIdentifier ) {
@@ -66,7 +73,8 @@ public ResponseDTO<JsonNode> getStaticYamlSchema(String accountIdentifier, Strin
6673 Currently static schema is not supported for community and onPrem env.
6774 */
6875 if (!validateIfStaticSchemaRequired (entityType , env )) {
69- return getYamlSchema (entityType , projectIdentifier , orgIdentifier , scope , identifier , accountIdentifier );
76+ return getStaticYamlSchemaFromResource (
77+ accountIdentifier , projectIdentifier , orgIdentifier , identifier , entityType , scope );
7078 }
7179
7280 JsonNode staticJson = pmsYamlSchemaService .getStaticSchema (
@@ -78,6 +86,34 @@ public ResponseDTO<JsonNode> getStaticYamlSchema(String accountIdentifier, Strin
7886 : getYamlSchema (entityType , projectIdentifier , orgIdentifier , scope , identifier , accountIdentifier );
7987 }
8088
89+ private ResponseDTO <JsonNode > getStaticYamlSchemaFromResource (String accountIdentifier , String projectIdentifier ,
90+ String orgIdentifier , String identifier , EntityType entityType , Scope scope ) {
91+ String filePath ;
92+ switch (entityType ) {
93+ case PIPELINES :
94+ filePath = PIPELINE_JSON_PATH ;
95+ break ;
96+ case TEMPLATE :
97+ filePath = TEMPLATE_JSON_PATH ;
98+ break ;
99+ default :
100+ return getYamlSchema (entityType , projectIdentifier , orgIdentifier , scope , identifier , accountIdentifier );
101+ }
102+
103+ try {
104+ return ResponseDTO .newResponse (fetchFile (filePath ));
105+ } catch (IOException ex ) {
106+ log .error ("Not able to read json from {} path" , filePath );
107+ }
108+ return getYamlSchema (entityType , projectIdentifier , orgIdentifier , scope , identifier , accountIdentifier );
109+ }
110+ public JsonNode fetchFile (String filePath ) throws IOException {
111+ ClassLoader classLoader = this .getClass ().getClassLoader ();
112+ String staticJson =
113+ Resources .toString (Objects .requireNonNull (classLoader .getResource (filePath )), StandardCharsets .UTF_8 );
114+ return JsonUtils .asObject (staticJson , JsonNode .class );
115+ }
116+
81117 private boolean validateIfStaticSchemaRequired (EntityType entityType , String env ) {
82118 // static schema is not supported for empty env or on-prem env. In entity type currently its supported only for
83119 // Pipelines or Template
0 commit comments