Skip to content

Surprising behavior in references: component is resolved only when in a different module? #633

Closed Answered by mbuhot
sphaso asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @sphaso 👋

The short answer to your questions:

  1. No, the reason it is not working is because the caller isn't passing enough information into cast_value for it to resolve the reference. I'm not sure why we have OpenApiSpex.cast_value/2, it will fail as soon as it encounters a %Reference{} to another schema. Prefer to use OpenApiSpex.cast_value/3 which includes the OpenApi struct.

  2. The plug is working because it uses OpenApiSpex.cast_and_validate/5, including the full OpenApi struct, allowing references to be looked up in the components.

(Edited this comment to update the details on point 2)


With more explaining:

In this code:
/~https://github.com/sphaso/api_spec_misunderstanding/blob/…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sphaso
Comment options

Answer selected by sphaso
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #632 on September 02, 2024 04:36.