-
Notifications
You must be signed in to change notification settings - Fork 124
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
[FEATURE] Add support for writeOnly and readOnly openAPI 3.0.3 properties #487
Comments
Hi @mfrischbutter, will handle it during week |
@Vovanella95 any updates on this? |
No idea what the status is here, but for the meantime we were able to solve this by finding an option in our swagger generator in the backend to work around this issue. If you have your Swagger API generated as well, you might want to look for it there as well. The generator we use for Angular seems to have the same problem and WriteOnly doesn't seem to be implemented everywhere yet. In our generator for Django, there is an option to generate the API without writeOnly and readOnly. Maybe this helps. |
@mfrischbutter thanks for the information, we use Django as well so this definitely helps. |
Hi @ankit-triomics @mfrischbutter sorry for now answer for long time. This would be great feature, but we already generating all fields final. It's immutable. I don't see how it can break any logic. Write-only fields? Why just not configure fields in correct way and send it? We already generate all fields final, so it's read only. Do you really need write-only fields? It will be really hard to support and from my perspective it's overhead |
For my side we can leave it as it is. Our swagger generator had the option to disable these fields on generation, so this is not an issue anymore. Even the swagger generator for angular that we are using, does not support these fields. So I think we should be fine, if we ignore that for now. |
@mfrischbutter Yes, sorry, but it will be really expensive to support it. we should generate private field and setter for such fields, also reimplement copyWith method and other things. Not now :) |
@mfrischbutter reopening issue. Looks like it's needed one :D |
Hi again @mfrischbutter , I've tried to implement this feature but faced with a problem. I've generated class like this: @JsonSerializable(explicitToJson: true)
class JSONWebToken {
const JSONWebToken(
this._token, {
required this.password,
required this.email,
});
factory JSONWebToken.fromJson(Map<String, dynamic> json) =>
_$JSONWebTokenFromJson(json);
static const toJsonFactory = _$JSONWebTokenToJson;
Map<String, dynamic> toJson() => _$JSONWebTokenToJson(this);
@JsonKey(name: 'password', includeIfNull: false)
final String password;
@JsonKey(name: 'token', includeIfNull: false)
final String _token;
String get token => _token;
@JsonKey(name: 'email', includeIfNull: false)
final String email;
static const fromJsonFactory = _$JSONWebTokenFromJson;
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other is JSONWebToken &&
(identical(other.password, password) ||
const DeepCollectionEquality()
.equals(other.password, password)) &&
(identical(other._token, _token) ||
const DeepCollectionEquality().equals(other._token, _token)) &&
(identical(other.email, email) ||
const DeepCollectionEquality().equals(other.email, email)));
}
@override
String toString() => jsonEncode(this);
@override
int get hashCode =>
const DeepCollectionEquality().hash(password) ^
const DeepCollectionEquality().hash(_token) ^
const DeepCollectionEquality().hash(email) ^
runtimeType.hashCode;
} Looks good, but Could you provide the way of generation of read-only fields? For now, I have no idea how to do this |
@mfrischbutter We decided to generate all |
Hi @ankit-triomics , @mfrischbutter , I've implemented this feature. For now, all readOnly and writeOnly fields will be nullable and not required. It will give you ability to not send and not receive these properties. |
Is your feature request related to a problem? Please describe.
Since openAPI 3.0.3 there is the possibility to use one schema for the response and request at the same time. With the help of the onlyWrite and onlyRead properties, you can specify whether these properties should only be used in the response or in the request.
Our Django Rest Api currently only generates with these properties, since our move to openAPI 3.0.3. This makes this generator unusable in some places.
Describe the solution you'd like
If such properties are used in a schema, then two different models should be generated which end with Response or Request in their class names.
Example swagger.yaml
Swagger specification link
https://swagger.io/specification/
The text was updated successfully, but these errors were encountered: