Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema gets weird \" escapes from Yaml parsing #53

Closed
lawik opened this issue Oct 31, 2023 · 8 comments
Closed

Schema gets weird \" escapes from Yaml parsing #53

lawik opened this issue Oct 31, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@lawik
Copy link
Contributor

lawik commented Oct 31, 2023

I have no idea why this happens on my schema and not on the github-spec.json. But it is consistent:

{
  "components": {
    "responses": {},
    "schemas": {}
  },
  "info": {
    "title": "Sample",
    "version": "0.1"
  },
  "openapi": "3.0.0",
  "paths": {},
  "security": [],
  "servers": [],
  "tags": []
}

Removing the option for yaml and forcing a simple Json.decode works great.

Running the code as is gives this:

-- CUSTOM ERROR --------------- 
Problem with the value at json.openapi:

    "\"3.0.0\""

Invalid version format
@lawik
Copy link
Contributor Author

lawik commented Oct 31, 2023

Okay, I've confirmed that if the yaml parser fails (as it does on the github example), then everything goes well. If the yaml parser succeeds it escapes my strings.

@lawik
Copy link
Contributor Author

lawik commented Oct 31, 2023

The github example fails on:

Parsing "Line 24, column 83: Encountered an unexpected character\nLine 24, column 83: Problem: I was parsing an inline record, when I ran into an invalid property. It is missing the \":\"!"

Mine clears as yaml just fine unfortunately and gets escaped.

@lawik
Copy link
Contributor Author

lawik commented Oct 31, 2023

Or rather, the quotes are kept around for some reason. The quotes are there inside of Yaml.Decode.String which is used in yamlToJsonDecoder.

lawik added a commit to lawik/elm-open-api-cli that referenced this issue Oct 31, 2023
Now checks if the input filepath ends with .json giving the user
a way to avoid the Yaml parser as it can do very strange things to
the JSON values as noted in issue wolfadex#53.
@wolfadex wolfadex added the bug Something isn't working label Oct 31, 2023
@wolfadex
Copy link
Owner

This definitely is a weird bug. By chance would you be able to see if https://package.elm-lang.org/packages/MaybeJustJames/yaml/latest/ has the same parsing issue? I'm looking to switch to it as part of issue #38. Being able to resolve 2 bugs with 1 fix would be nice.

@lawik
Copy link
Contributor Author

lawik commented Oct 31, 2023

Oh yeah, it reproduces up to latest main on the yaml-package. But I think my PR is a reasonably harmless fix.

lawik added a commit to lawik/elm-open-api-cli that referenced this issue Nov 1, 2023
Now checks if the input filepath ends with .json giving the user
a way to avoid the Yaml parser as it can do very strange things to
the JSON values as noted in issue wolfadex#53.
@lawik lawik closed this as completed Nov 5, 2023
@lawik
Copy link
Contributor Author

lawik commented Nov 13, 2023

Release version 0.1.1 does not seem to have built the actual code into it.

Looking through the build in dist it does not contain the string ".json" which it does if I force a build locally. @wolfadex probably something to look at :)

@lawik lawik reopened this Nov 13, 2023
@wolfadex
Copy link
Owner

Release version 0.1.1 does not seem to have built the actual code into it.

Looking through the build in dist it does not contain the string ".json" which it does if I force a build locally. @wolfadex probably something to look at :)

Sorry about that. I forgot to build before publishing (I should set that up so I don't forget again in the future). I've published 0.1.2 which should contain the fix. I'll leave this open till you let me know it's working for you.

@lawik
Copy link
Contributor Author

lawik commented Nov 14, 2023

Sweet, thanks. Confirmed working.

@lawik lawik closed this as completed Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants