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
Consider preserving referential transparency of OpenAPI schemas #888
Comments
Is this behavior present only on |
Definitely existing releases. It isn't a recent regression though - it has been around since |
Your help is definitively welcome! |
It is looking like I won't get to this for at least another week. If someone else wants to pick it up, please feel free to do so. 😄 |
I was able to reproduce this bug in ReferencedSchemaTest.scala by expanding the test fixture a little and adding request body examples to two different endpoints. I think I also found a fix for it, but I have to admit that OpenAPI schemas are fairly new to me. I'll push some results soon so that you can take a look at it. |
- I.e. description, example, title and default - Fixes endpoints4s#888
- I.e. description, example, title and default - Fixes endpoints4s#888
I've been thinking about API evolution around this issue, and am coming to realize that fixing this will probably inadvertently break some existing uses. In particular, I'm thinking about:
Now, more on the implementation side of things and still taking the {
"allOf": [ { "$ref": "#/Rec" } ]
"description": "Rec description"
"title": "Rec title"
"example": { }
} |
In a nutshell: - adds a new `DocumentedRecord` subclass for representing overrides of examples, descriptions, etc. on named schemas - renders that subclass using `allOf` with the base schema Note: this is a prototype - it doesn't solve referential transparency for names anywhere else (and it is likely that doing so would lead to more subclasses for the other documented JSON schema types). See endpoints4s#888
@julienrf more concrete example of how I ended up needing to tweak tests such that the expected output didn't change is in this commit - see in particular the tweaks to how the fixture schemas are created: harpocrates@ef9aaa7. I think this sort of change will be unavoidable if we want referential transparency. 😟 |
Using
withExample
,withTitle
, andwithDescription
combinators on a named OpenAPI schema mutate the schema. I expect that they would just make a new modified copy of the schema, not modify it! Motivating example:However, in the output OpenAPI JSON, the output schema for both endpoints is identical
The example that gets picked up is just whichever one was "seen" first in the schema traversal. In this case, it is
"foo 2"
:If you agree this is an issue, I can put together a fix. This is fixable now that we have #885 merged - the two request schemas could be
and
The text was updated successfully, but these errors were encountered: