Repository navigation
BL-2190 resolve app-relative paths for YAML references - #28
Open
LivinKevin wants to merge 3 commits into
Open
LivinKevin wants to merge 3 commits into
LivinKevin wants to merge 3 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BL-2190 - cbSwagger/BoxLang filepath issue
Jira: https://ortussolutions.atlassian.net/browse/BL-2190
Implementation Questions
1. Problem Statement
On BoxLang, cbSwagger fails to load sample files referenced with app-relative paths (e.g.
/resources/api/auth/authenticate.response.yml).fileExists()returnstrue, butjava.io.FileInputStreamfails on the same path.OpenAPIParser.parse( struct ), which never setsbaseDocumentPath.fetchDocumentReference()buildsgetDirectoryFromPath( getBaseDocumentPath() ) & FilePath. In BoxLang,getDirectoryFromPath("")returns/, so the path becomes//resources/....fileExists()passes; Java takes it literally and can't find it.Parser.cfchas threefileExists()guards (lines 31, 307, 311) that all lead intoinit(), which has the onlyjava.io.File/FileInputStream(lines 59–60). cbSwagger has noFileInputStreamorjava.io.Fileusage.2. Proposed Solution
models/OpenAPI/Parser.cfc:init()): always read the file withfileRead(), then parse the text withyamlDeserialize()(when bx-yaml is installed) or SnakeYAML'sload( String ). Java never opens the file, so the existence check and the read always agree on every engine. This also removes aFileInputStreamthat was never closed.$refresolution (fetchDocumentReference()): only prefix the base document's directory when a base path is set, so//resources/...is never built.3. Implementation Steps
fileExists/fileReadsucceed,FileInputStream(rawPath)fails,FileInputStream(expandPath(path))works;getDirectoryFromPath("")returns/.fileExists()guard andFileInputStreamuse.java.io.File/FileInputStreamYAML read withfileRead()+ parse from text.baseDirectoryvariable infetchDocumentReference()that is empty when there is no base document.$ref, the way cbSwagger does.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:
server-boxlang@1.json):box testbox run runner=http://localhost:60299/tests/runner.cfmParser.cfc.Results (BoxLang 1.18.0, TestBox 7.2.0, ColdBox 8):
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 usedfileRead(), so the new test passes before and after there.Success criteria:
FileInputStreamleft in swagger-sdk or cbSwaggerRelated 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 coversDocument.cfc'sasYAML()(line 77), which writes YAML usingyamlSerialize()without checking whether bx-yaml is installed. This PR changes only howParser.cfcreads YAML, so this result is unchanged by it.Setup note:
test-harness/box.jsonpins ColdBox^6, which fails on plain BoxLang ("The key [COLDFUSION] was not found"); local runs need ColdBox 8.