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

Ability to be used as a general parser #190

Open
lispyclouds opened this issue Nov 5, 2023 · 3 comments
Open

Ability to be used as a general parser #190

lispyclouds opened this issue Nov 5, 2023 · 3 comments

Comments

@lispyclouds
Copy link
Contributor

Hello!

Thanks a lot for making and maintaining this great tool, has helped me out quite a lot!

I have a few use cases wherein I have a need to just parse OpenAPI/Swagger docs into data for me to walk that tree and infer/transform it:

I use the quite heavy and clunky to use standard java parser for OpenAPI in these and was wondering if martian could be used just for this:

  • Read an OpenAPI or Swagger Spec
  • Resolve all the refs including remote ones
  • Return a plain data structure for further consumption

I tried playing with it and reading the docs but wasn't sure if this could be done? Apologies if this already works and I didn't see it!

Thanks again!

@lispyclouds lispyclouds changed the title Abitlity to be used as a general parser Ability to be used as a general parser Nov 5, 2023
@oliyh
Copy link
Owner

oliyh commented Nov 5, 2023

Hi,

Thanks for your kind words!
You could use this function

(defn openapi->handlers [openapi-json content-types]

It will return a normalised list of handlers with the parameters described using plumatic schema. The shape is defined by the spec here:

(s/def ::handler

I thought Malli had a json schema / openapi parser but it seems maybe not.

@lispyclouds
Copy link
Contributor Author

lispyclouds commented Nov 5, 2023

Thanks a lot!

I tried parsing this spec with this code with my limited understanding:

(-> "api.yaml"
    (slurp)
    (clj-yaml.core/parse-string)
    (martian.openapi/openapi->handlers {}))

But I still see the refs in the content types etc. Am I doing this right?

@oliyh
Copy link
Owner

oliyh commented Jan 27, 2024

Hi,

Apologies for the delayed reply.

Martian does not have the ability to parse remote refs. It would not be impossible to add it as an additional resolver function here, but that would make it less pure. Alternatively the schema could be pre-walked to resolved remote refs first, and then this function would remain pure.

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

No branches or pull requests

2 participants