-
-
Notifications
You must be signed in to change notification settings - Fork 532
References to arbitrary data #617
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
Comments
I think you’re asking something different of #604, but I also see some overlap there. In your example about required-ness being conditional of response vs PATCH (request), that would be |
Aah, my explanation is pretty bad. Forget about the read-only and write-only, that was the wrong way to explain what I actually want. I want to be able to set properties to required based on if one is reading the property or writing the property.
Yes. In a response I want the type read-only and write-only is good for let's say And I don't really want to use |
This seems like an issue with the standard itself - I've just put together a basic working readOnly / writeOnly support PR which will fix the other issue, but being able to change the From my look at the code, techn ically you could fork and add a custom non-standard schema pattern to https://github.com/drwpow/openapi-typescript/blob/main/src/transform/schema.ts#L36 with |
Indeed
I could. But I don't really want to go outside the standard, as other developers and our partners wouldn't find it in the standard documentation 🙂 |
Added in #626! |
So because of the missing ability in the OpenAPI standard to mark a property to be required independently of it being read-only or write-only, I'm making references to properties directly in cases we need a property that has been marked as required to be optional.
A quick example could be that you have a product with a name. The name is always required in responses. You might want it to be optional in a patch operation because only the given properties should be patched.
So my work-around was to add every writable property as the request body and then don't make them required. Just like so
This is working with all the other tools we're using, but after the
additionalProperties
default has been set tofalse
, then the generated schema fails, as it should because of the missingproperties
object around the properties. This in general might be a problem with the structure of the generated schema types at the moment, because it may not be 1:1 with the provided API specification. I'm not quite sure if this problem might occur in other places as well.I've made a small hack to the utility function
transformRef
but might become a unmaintainable solution moving forward. See it here https://github.com/venue-pos/openapi-typescript/commit/ad6be15bbaeddf93171dbda34683e3d47ad308ccWhat is a better general solution that could actually be implemented?
The text was updated successfully, but these errors were encountered: