-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[REQ] OAS 3.0 support of readOnly/writeOnly modeling #4190
Comments
I would also love to see this feature. We will definitely first have to rewrite the typescript generator, in order not to have to implement it in all of them. |
FYI, the python-experimental client does serialize read-only properties. I think it should skip serialization of the readOnly properties.
|
@sebastien-rosset this could be added to python-experimental the following way:
I have a general question though. Don't codegen parameters include the readonly and writeonly properties? Why do we need the new lists in Codegenmodel if we already have this info? |
One consideration is attributes beyond read only and write-only, maybe through vendor extensions. For example, we use read-on-create for cases such as when the backend generates an API key secret and returns the value only when the resource is created. We also have create-only for properties that can be set during creation but cannot subsequently be modified. Instead of creating lists of readonly_vars and writeonly_vars, can this be done using meta-data for each property? I.e. in the case of python, you already generate the "openapitype" meta-data for each property. Couldn't we add one more type of meta-data there? |
Thanks for sharing that context. I wasn't aware of those use cases. So far each CodegenProperty metadata has been stored separately. A helpful refactor in python-experimental would be to create some class like CodegenProperty and gather all the data for each parameter there. Then in ModelNormal/ModelComposed we can store a dict where the key is the variable name and the value is the CodegenProperty class instance. One could also do this with just a dict to begin with. Wouldn't that read on create and create only vendor extension need to be individually handled by generators? I am worried about us adding too many lists of vars in CodegenModel. |
Though looking at CodegenModel we already have readOnlyVars, so sure, let's add writeOnlyVars if we have already started going down this path. |
I like this.
It seems that instead of maintaining separate lists, each property could have a list of meta-data attributes, and the generated code could look up the meta-data. For example, it could decide what to do for the serialization. If we want to get fancy, we could also expose a callback to the application such that app developers can insert their custom serialization logic.
|
Is there any roadmap for this issue? I'm using typescript-axios generator and it generates invalid code, which requires read-only params for request. |
Is there any update on this issue? As mentioned by @last-partizan this generates invalid code. |
Need this :( |
I need this too! |
One can also do this with composition instead of readonly/writeOnly. One can have non deterministic behavior by using readonly. Here is an example: A: B: C:
Is C.a readonly or writeOnly? |
Readonly and writeonly flags are now implemented for properties with simple types like |
@bodograumann I believe this would be crucial for many projects as well. |
This will be helpful for many developers!! |
Damn, thought it was already good and found this issue :( |
Need this too please :) |
Any progress on this issue? |
I think it is a very important feature. Is this on the roadmap? @wing328 @jimschubert |
Any news on this issue? |
Any progress on this issue? |
Any progress on this issue? |
I am new to this and I have a question. I have |
Is your feature request related to a problem? Please describe.
Yes, missing support for OAS 3.0 feature of
readOnly
andwriteOnly
properties within a model.Discussion came up on Slack, and I'm documenting it here since we need to implement this for full OAS 3.0 support.
Describe the solution you'd like
Provide a
writeOnlyVars
to match other vars in our codegen model. Support differentiation between request models and response models.Describe alternatives you've considered
Early discussions about
writeOnly
on OAI suggest domain modeling around usage ofallOf
. See OAI/OpenAPI-Specification/issues/425.Additional context
OAS 3.x Schema Object supports two properties,
readOnly
andwriteOnly
. These properties are defined as:boolean
"properties"
definitions. Declares the property as "read only". This means that it MAY be sent as part of a response but SHOULD NOT be sent as part of the request. If the property is marked asreadOnly
beingtrue
and is in therequired
list, therequired
will take effect on the response only. A property MUST NOT be marked as bothreadOnly
andwriteOnly
beingtrue
. Default value isfalse
.boolean
"properties"
definitions. Declares the property as "write only". Therefore, it MAY be sent as part of a request but SHOULD NOT be sent as part of the response. If the property is marked aswriteOnly
beingtrue
and is in therequired
list, therequired
will take effect on the request only. A property MUST NOT be marked as bothreadOnly
andwriteOnly
beingtrue
. Default value isfalse
.We should validate that a property is not both
readOnly=true
andwriteOnly=true
. This validation should be excluded fromstrict spec
skipping as having a property bothreadOnly
andwriteOnly
should be a logical error with undefined behavior.The use of
SHOULD NOT
in the spec is defined via rfc2119:So, we're not technically out of compliance with the spec in relation to
readOnly
andwriteOnly
since our use case to support OpenAPI 2.0 and OpenAPI 3.0 functionality in the same generator + template combinations could be considered a "particular circumstance". However, the we are out of compliance with the clause regardingrequired
because this makes the property required only in a request or response structure, and not both.My proposal is to do multiple passes on models defined in the OpenAPI result object and sort these into an array of "RequestModels" and an array of "ResponseModels", leaving our current "models" collection as a raw collection for backward compatibility. This would allow us to have the same schema definition defined appropriately (according to the specification), without hacky workarounds like adding arbitrary prefixes or suffixes to differentiate.
We may be tempted to suggest that users split their schemas, similar to the recommendation linked above (OAI/OpenAPI-Specification/issues/425), but this will only address the issue for those users who own/manage their specifications. To allow code generation from external systems which follow OpenAPI 3.0 specification, we'd need to support this use case.
The text was updated successfully, but these errors were encountered: