OpenAPITools / OpenAPITools/openapi-generator
[BUG] [dart-dio-next] `readOnly: true` is not considered for required fields
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
BuiltValues are validating for null if the field is added to required fields list. But if the field is readOnly: true, built value should not throw error if we are using the data for write operation. Any suggestions on how to achieve this?
openapi-generator version
openapi-generator-cli 5.2.1
commit : 8403e59
OpenAPI declaration file content or url
If you post the code inline, please wrap it with
components:
schemas:
RefreshCredentials:
type: object
properties:
access:
type: string
readOnly: true
expires_in:
type: number
format: float
readOnly: true
refresh:
type: string
writeOnly: true
required:
- access
- expires_in
- refresh
Generation Details
generator: dart-dio-next
Steps to reproduce
run generator, then run build runner.
refreh_credentials.dart looks fine
@BuiltValueField(wireName: r'access')
String get access;
@BuiltValueField(wireName: r'expires_in')
double get expiresIn;
@BuiltValueField(wireName: r'refresh')
String get refresh;
but generated refresh_credentials.g.dart doesn't:
...
@override
_$RefreshCredentials build() {
final _$result = _$v ??
new _$RefreshCredentials._(
access: BuiltValueNullFieldError.checkNotNull(
access, 'RefreshCredentials', 'access'), // <----- THIS LINE
expiresIn: BuiltValueNullFieldError.checkNotNull(
expiresIn, 'RefreshCredentials', 'expiresIn'), // <----- THIS LINE
refresh: BuiltValueNullFieldError.checkNotNull(
refresh, 'RefreshCredentials', 'refresh'));
replace(_$result);
return _$result;
}
Lines pointed above are to ensure access/expiresIn are not null while they are supposed to be when building the value for write.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided OpenAPI declaration using the dart-dio-next generator, then run build runner and compare refresh_credentials.dart with refresh_credentials.g.dart. Trace how required and readOnly fields become BuiltValueNullFieldError checks. Done means readOnly required fields no longer fail validation when building the value for a write operation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, openapi
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100