Skip to content

BL-2190 resolve app-relative paths for YAML references - #28

Open
LivinKevin wants to merge 3 commits into
coldbox-modules:developmentfrom
LivinKevin:BL-2190-combined-fix
Open

LivinKevin wants to merge 3 commits into
coldbox-modules:developmentfrom
LivinKevin:BL-2190-combined-fix

Conversation

@LivinKevin

Copy link
Copy Markdown

BL-2190 - cbSwagger/BoxLang filepath issue

Jira: https://ortussolutions.atlassian.net/browse/BL-2190

Implementation Questions

1. Problem Statement

  • What issue are we solving?
    On BoxLang, cbSwagger fails to load sample files referenced with app-relative paths (e.g. /resources/api/auth/authenticate.response.yml). fileExists() returns true, but java.io.FileInputStream fails on the same path.
    • cbSwagger calls OpenAPIParser.parse( struct ), which never sets baseDocumentPath.
    • fetchDocumentReference() builds getDirectoryFromPath( getBaseDocumentPath() ) & FilePath. In BoxLang, getDirectoryFromPath("") returns /, so the path becomes //resources/....
    • BoxLang file functions resolve that path through mappings, so fileExists() passes; Java takes it literally and can't find it.
    • Scope: the ticket mentions "a few places". We searched both repos: Parser.cfc has three fileExists() guards (lines 31, 307, 311) that all lead into init(), which has the only java.io.File/FileInputStream (lines 59–60). cbSwagger has no FileInputStream or java.io.File usage.
    • The reporter's setup (compat-cfml, orm) has no bx-yaml, which is exactly when the Java read runs.

2. Proposed Solution

  • What changes will be made and why? Both in models/OpenAPI/Parser.cfc:
    • YAML loading (init()): always read the file with fileRead(), then parse the text with yamlDeserialize() (when bx-yaml is installed) or SnakeYAML's load( String ). Java never opens the file, so the existence check and the read always agree on every engine. This also removes a FileInputStream that was never closed.
    • $ref resolution (fetchDocumentReference()): only prefix the base document's directory when a base path is set, so //resources/... is never built.
  • The fix belongs in swagger-sdk rather than BoxLang core: resolving paths through mappings is intended CFML behavior, and the bug is a library passing a CFML-style path to a Java API.

3. Implementation Steps

  • Step 1: Reproduced in BoxLang 1.19.0 (snapshot): fileExists/fileRead succeed, FileInputStream(rawPath) fails, FileInputStream(expandPath(path)) works; getDirectoryFromPath("") returns /.
  • Step 2: Searched cbSwagger and swagger-sdk for every fileExists() guard and FileInputStream use.
  • Step 3: Replaced the java.io.File/FileInputStream YAML read with fileRead() + parse from text.
  • Step 4: Added a baseDirectory variable in fetchDocumentReference() that is empty when there is no base document.
  • Step 5: Added a test that parses a struct with an app-relative $ref, the way cbSwagger does.
  • Step 6: Ran the suite on BoxLang with and without bx-yaml, on the old and new code.

4. Validation Plan

  • Tests added: Loads a YAML $ref from an app-relative path when parsing a struct (BL-2190) in ParserSpec.cfc.

  • Verification steps:

    • BoxLang with bx-yaml (server-boxlang@1.json): box testbox run runner=http://localhost:60299/tests/runner.cfm
    • BoxLang without bx-yaml (the reporter's setup): a local copy of that config without bx-yaml, run on the old and new Parser.cfc.
  • Results (BoxLang 1.18.0, TestBox 7.2.0, ColdBox 8):

    Server Code Passed Errored
    with bx-yaml old 9 0
    with bx-yaml fixed 9 0
    without bx-yaml old 6 3
    without bx-yaml fixed 8 1

    Without bx-yaml, the old code's YAML parser test and the BL-2190 test error with Function [yamlDeserialize] not found; with the fix, both pass. With bx-yaml, the old code already used fileRead(), so the new test passes before and after there.

  • Success criteria:

    • All existing tests pass on BoxLang with bx-yaml
    • YAML loading errors on the old code and passes with the fix on BoxLang without bx-yaml
    • No FileInputStream left in swagger-sdk or cbSwagger
    • CI passes on Lucee and Adobe ColdFusion

Related finding: without bx-yaml, DocumentSpec's "can be coverted to yaml" test errors with Function [yamlSerialize] not found, both before and after this fix. That test covers Document.cfc's asYAML() (line 77), which writes YAML using yamlSerialize() without checking whether bx-yaml is installed. This PR changes only how Parser.cfc reads YAML, so this result is unchanged by it.

Setup note: test-harness/box.json pins ColdBox ^6, which fails on plain BoxLang ("The key [COLDFUSION] was not found"); local runs need ColdBox 8.

JOALUR and others added 3 commits October 19, 2026 17:36
Parses a struct with no base document and a $ref to a YAML file, which resolves to a "//tests/..." path, the same shape that crashed cbSwagger users.

Without bx-yaml on BoxLang, this test fails on the previous code (yamlDeserialize not found) and passes with the fileRead()-based fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants