@@ -113,8 +113,19 @@ public void execute(ToolContext toolContext) {
113113 ImmutablePair <OASClientConfig , OASServiceMetadata > codeGeneratorConfig ;
114114 TomlNodeLocation location = toolContext .currentPackage ().ballerinaToml ().get ().tomlAstNode ().location ();
115115 try {
116+ // Check the file path
117+ String oasPath = toolContext .filePath ();
118+ if (Objects .isNull (oasPath )) {
119+ DiagnosticMessages error = DiagnosticMessages .CONTRACT_PATH_NOT_PROVIDED ;
120+ createDiagnostics (toolContext , error , location );
121+ return ;
122+ }
123+ if (oasPath .isBlank ()) {
124+ DiagnosticMessages error = DiagnosticMessages .EMPTY_CONTRACT_PATH ;
125+ createDiagnostics (toolContext , error , location );
126+ }
116127 // Validate the OAS file whether we can handle within OpenAPI tool
117- if (!canHandle (toolContext )) {
128+ if (!canHandle (oasPath )) {
118129 DiagnosticMessages error = DiagnosticMessages .WARNING_FOR_UNSUPPORTED_CONTRACT ;
119130 createDiagnostics (toolContext , error , location );
120131 return ;
@@ -199,14 +210,7 @@ private void handleCodeGenerationMode(ToolContext toolContext,
199210 * This method uses to check whether given specification can be handled via the openapi client generation tool.
200211 * This includes basic requirements like file extension check.
201212 */
202- private boolean canHandle (ToolContext toolContext ) {
203- String oasPath = toolContext .filePath ();
204- if (oasPath .isBlank ()) {
205- TomlNodeLocation location = toolContext .currentPackage ().ballerinaToml ().get ().tomlAstNode ().location ();
206- DiagnosticMessages error = DiagnosticMessages .EMPTY_CONTRACT_PATH ;
207- createDiagnostics (toolContext , error , location );
208- return false ;
209- }
213+ private boolean canHandle (String oasPath ) {
210214 return (oasPath .endsWith (YAML_EXTENSION ) || oasPath .endsWith (JSON_EXTENSION ) ||
211215 oasPath .endsWith (YML_EXTENSION ));
212216 }
0 commit comments