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

A couple of enhancements #41

Open
rafalkrupinski opened this issue Sep 1, 2024 · 5 comments
Open

A couple of enhancements #41

rafalkrupinski opened this issue Sep 1, 2024 · 5 comments

Comments

@rafalkrupinski
Copy link

rafalkrupinski commented Sep 1, 2024

Some enhancements I'd be happy port from my project:

Also, Paths could be changed to dict[str, PathItem | Reference], and ref could be removed from PathItem. this is valid

  • validate parameter has no more than one of content and schema
@rafalkrupinski
Copy link
Author

@mike-oakley

@mike-oakley
Copy link
Owner

Hey @rafalkrupinski - apologies for my slow reply here! Commented on the other issues too, but in general i'm happy to accept contributions if its enhancing/within the spirit of openapi/pydantic and maintains support for oas 3.0.x and pydantic 1 + 2.

The only one I'm not sure of in the above is the ref resolver, not sure if it would bloat the surface area of the project too much to be opinionated on it, as we try to defer to Pydantic for most of the heavy lifting on the JSONSchema side. Happy to hear a suggestion if you can suggest an elegant enough API for it 👍🏼

@rafalkrupinski
Copy link
Author

Resolving references is actually quite simple.

  • decode and split path
  • resolve path element in dict or by alias in BaseModel
  • traverse objects starting from OpenAPI instance
  • apply recursively until result is not a Reference itself
  • keep list of resolved json paths to avoid infinite recursion

It could be a method in OpenAPI and a couple of helper functions.
I have the code already in my project, I'll prepare a PR.

@rafalkrupinski
Copy link
Author

@mike-oakley you don't think running mypy on tests is an overkill?

@kgpayne
Copy link

kgpayne commented Dec 13, 2024

+1 for a reference resolver. I am trying to extract a complete schema from a given path-method-response, and was surprised to find refs aren't currently auto-resolved. Especially given the reverse case is true; refs are added to generated json/yaml spec outputs, at least when using the construct_open_api_with_schema_class utility function as per the README. Adding a resolver utility would help, even if it isn't used in the default behavior of parse 🙂

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

3 participants