Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !7493

Dart oneof for models

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/wbt-solutions/dart-oneof into dart-oneof 4 years ago
  • Overview 0
  • Commits 5
  • Pipelines 0
  • Changes 4

Created by: sbu-WBT

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.
Compare
  • dart-oneof (base)

and
  • latest version
    4804cfd4
    5 commits, 2 years ago

4 files
+ 56
- 20

    Preferences

    File browser
    Compare changes
modules/openapi-ge‎nerator/…/…/…/dart2‎
class.m‎ustache‎ +6 -0
class_oneo‎f.mustache‎ +22 -10
samples/client/pet‎store/…/…/lib/model‎
one_of_t‎est.dart‎ +24 -10
pet.‎dart‎ +4 -0
modules/openapi-generator/src/main/resources/dart2/class.mustache
+ 6
- 0
  • View file @ 4804cfd4

  • Edit in single-file editor

  • Open in Web IDE


@@ -107,6 +107,12 @@ class {{classname}} {
{{/complexType}}
{{/isDate}}
{{/isDateTime}}
{{#required}}
{{^isNullable}}
if ({{name}} == null)
throw ArgumentError("$json has no {{name}} field which is required for {{classname}}");
{{/isNullable}}
{{/required}}
{{/vars}}
}
modules/openapi-generator/src/main/resources/dart2/class_oneof.mustache
+ 22
- 10
  • View file @ 4804cfd4

  • Edit in single-file editor

  • Open in Web IDE

class {{classname}} {
dynamic instance;
/// Can be {{#oneOf}}[{{{.}}}], {{/oneOf}}
dynamic _instance;
// default constructor
{{classname}}({
});
{{classname}}();
set instance(dynamic instance) {
if (!(instance == null{{#oneOf}} || instance is {{{.}}}{{/oneOf}}))
throw ArgumentError("${instance.runtimeType} is not a valid type for {{classname}}");
_instance = instance;
}
dynamic get instance => _instance;
@override
String toString() {
// TODO
return _instance.toString();
}
{{classname}}.fromJson(Map<String, dynamic> json) {
// TODO
// loop through models/primitive types defined in {{#oneOf}} {{{.}}} {{/oneOf}}
// and make sure the payload `json` deserializes to one and only one schema defined in oneOf
if (json == null) return;
// TODO primitives, lists, maps
{{#oneOf}}
try {
_instance = {{{.}}}.fromJson(json);
} on ArgumentError {
}
{{/oneOf}}
}
Map<String, dynamic> toJson() {
// TOOD there should be a class member/property called "instance"
// which is dynamic type and it stores the actual instance of the schema defined in oneOf
// if oneOf is [Dog, Cat], then the instance can store either an instance of Dog or Cat
// TODO primitives, lists, maps
return _instance.toJson();
}
}
samples/client/petstore/dart2/petstore_client_lib/lib/model/one_of_test.dart
+ 24
- 10
  • View file @ 4804cfd4

  • Edit in single-file editor

  • Open in Web IDE

part of openapi.api;
class OneOfTest {
dynamic instance;
/// Can be [Pet], [User],
dynamic _instance;
// default constructor
OneOfTest({
});
OneOfTest();
set instance(dynamic instance) {
if (!(instance == null || instance is Pet || instance is User))
throw ArgumentError("${instance.runtimeType} is not a valid type for OneOfTest");
_instance = instance;
}
dynamic get instance => _instance;
@override
String toString() {
// TODO
return _instance.toString();
}
OneOfTest.fromJson(Map<String, dynamic> json) {
// TODO
// loop through models/primitive types defined in Pet User
// and make sure the payload `json` deserializes to one and only one schema defined in oneOf
if (json == null) return;
// TODO primitives, lists, maps
try {
_instance = Pet.fromJson(json);
} on ArgumentError {
}
try {
_instance = User.fromJson(json);
} on ArgumentError {
}
}
Map<String, dynamic> toJson() {
// TOOD there should be a class member/property called "instance"
// which is dynamic type and it stores the actual instance of the schema defined in oneOf
// if oneOf is [Dog, Cat], then the instance can store either an instance of Dog or Cat
// TODO primitives, lists, maps
return _instance.toJson();
}
}
samples/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart
+ 4
- 0
  • View file @ 4804cfd4

  • Edit in single-file editor

  • Open in Web IDE


@@ -35,9 +35,13 @@ class Pet {
null :
Category.fromJson(json['category']);
name = json['name'];
if (name == null)
throw ArgumentError("$json has no name field which is required for Pet");
photoUrls = (json['photoUrls'] == null) ?
null :
(json['photoUrls'] as List).cast<String>();
if (photoUrls == null)
throw ArgumentError("$json has no photoUrls field which is required for Pet");
tags = (json['tags'] == null) ?
null :
Tag.listFromJson(json['tags']);
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
3
Client: Dart Enhancement: Feature Feature: OAS 3.0 spec support
3
Client: Dart Enhancement: Feature Feature: OAS 3.0 spec support
    Assign labels
  • Manage project labels

Milestone
5.0.0
5.0.0 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
1
1 participant
Administrator
Reference: OpenAPITools/openapi-generator!7493
Source branch: github/fork/wbt-solutions/dart-oneof

Menu

Explore Projects Groups Snippets