@@ -9,6 +9,7 @@ const { getServers } = require('./helpers/serversHelper');
99const getExtensions = require ( './helpers/extensionsHelper' ) ;
1010const handleReferencePath = require ( './helpers/handleReferencePath' ) ;
1111const mapJsonSchema = require ( '../reverse_engineering/helpers/adaptJsonSchema/mapJsonSchema' ) ;
12+ const path = require ( 'path' ) ;
1213
1314module . exports = {
1415 generateModelScript ( data , logger , cb ) {
@@ -87,7 +88,7 @@ module.exports = {
8788 parsedScript = JSON . parse ( filteredScript ) ;
8889 }
8990
90- validationHelper . validate ( parsedScript )
91+ validationHelper . validate ( replaceRelativePathByAbsolute ( parsedScript , targetScriptOptions . modelDirectory ) )
9192 . then ( ( messages ) => {
9293 cb ( null , messages ) ;
9394 } )
@@ -150,6 +151,26 @@ const removeCommentLines = (scriptString) => {
150151 . replace ( / ( .* ?) , \s * ( \} | ] ) / g, '$1$2' ) ;
151152}
152153
154+ const replaceRelativePathByAbsolute = ( script , modelDirectory ) => {
155+ if ( ! modelDirectory || typeof modelDirectory !== 'string' ) {
156+ return script ;
157+ }
158+ const stringifiedScript = JSON . stringify ( script ) ;
159+ const fixedScript = stringifiedScript . replace ( / ( " \$ r e f " : \s * ) " ( .* ?(?< ! \\ ) ) " / g, ( match , refGroup , relativePath ) => {
160+ const isAbsolutePath = relativePath . startsWith ( 'file:' ) ;
161+ const isInternetLink = relativePath . startsWith ( 'http:' ) || relativePath . startsWith ( 'https:' ) ;
162+
163+ if ( isAbsolutePath || isInternetLink ) {
164+ return match
165+ }
166+ const absolutePath = path . resolve ( modelDirectory , '..' , relativePath )
167+
168+ return `${ refGroup } "file://${ absolutePath } "`
169+ } ) ;
170+
171+ return JSON . parse ( fixedScript ) ;
172+ }
173+
153174const handleRefInContainers = ( containers , externalDefinitions ) => {
154175 return containers . map ( container => {
155176 try {
0 commit comments