[dart-dio] handle polymorphism + discriminator serialization (#12295)

* return structured serializer

* generate samples

* implmented postProcessAllModels to fix assignment of inherited models

* Templates now respect inheritance

* regen dart samples

* only built value support for now

* ignore unused elements

* fixed tests

* new configs to test oneOf

* add some helper vendorextensions for oneOf support

* update templates

* regen samples

* resolve conflicts

* fix missing serializers

* Updated samples and fixed merge conflict

* updated samples

* Follow java conventions

* Follow java conventions

* updated samples

* update sampels 2

* update samples 3 ...

* fix underscores

* fixed missing imports from java code

* update config names

* updated samples

* updated built_value deps

* regen samples

* workaround built_value abstract builders google/built_value.dart#1180

* regen samples

* updated test pubspec

* temp fix rewriteImports for Lists and maps

* Add new samples to CI

* Improve white spaces & formatting

* fix enums not getting assigned correctly

* update samples

* fixed typo

* regen samples

* remove repeating imports

* regen samples

* ignore unused_element warning

* updated tests

* regen samples

Co-authored-by: Peter Leibiger <kuhnroyal@gmail.com>
This commit is contained in:
Ahmed Fwela 2022-09-05 10:44:04 +02:00 committed by GitHub
parent 2fc9264ac8
commit 2a8ea162d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
252 changed files with 13229 additions and 3208 deletions

View File

@ -0,0 +1,11 @@
generatorName: dart-dio
outputDir: samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance
inputSpec: modules/openapi-generator/src/test/resources/3_0/oneof_polymorphism_and_inheritance.yaml
templateDir: modules/openapi-generator/src/main/resources/dart/libraries/dio
typeMappings:
Client: "ModelClient"
File: "ModelFile"
EnumClass: "ModelEnumClass"
additionalProperties:
hideGenerationTimestamp: "true"
enumUnknownDefaultCase: "true"

View File

@ -0,0 +1,11 @@
generatorName: dart-dio
outputDir: samples/openapi3/client/petstore/dart-dio/oneof_primitive
inputSpec: modules/openapi-generator/src/test/resources/3_0/oneOf_primitive.yaml
templateDir: modules/openapi-generator/src/main/resources/dart/libraries/dio
typeMappings:
Client: "ModelClient"
File: "ModelFile"
EnumClass: "ModelEnumClass"
additionalProperties:
hideGenerationTimestamp: "true"
enumUnknownDefaultCase: "true"

View File

@ -0,0 +1,11 @@
generatorName: dart-dio
outputDir: samples/openapi3/client/petstore/dart-dio/oneof
inputSpec: modules/openapi-generator/src/test/resources/3_0/oneOf.yaml
templateDir: modules/openapi-generator/src/main/resources/dart/libraries/dio
typeMappings:
Client: "ModelClient"
File: "ModelFile"
EnumClass: "ModelEnumClass"
additionalProperties:
hideGenerationTimestamp: "true"
enumUnknownDefaultCase: "true"

View File

@ -20,6 +20,7 @@ import com.google.common.collect.Sets;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import io.swagger.v3.oas.models.media.Schema;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.api.TemplatePathLocator;
@ -27,6 +28,7 @@ import org.openapitools.codegen.config.GlobalSettings;
import org.openapitools.codegen.meta.GeneratorMetadata;
import org.openapitools.codegen.meta.Stability;
import org.openapitools.codegen.meta.features.ClientModificationFeature;
import org.openapitools.codegen.meta.features.SchemaSupportFeature;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.ModelsMap;
import org.openapitools.codegen.model.OperationMap;
@ -43,6 +45,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.openapitools.codegen.utils.StringUtils.underscore;
@ -78,6 +81,13 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
.includeClientModificationFeatures(
ClientModificationFeature.Authorizations,
ClientModificationFeature.UserAgent
).includeSchemaSupportFeatures(
SchemaSupportFeature.Polymorphism,
SchemaSupportFeature.Union,
SchemaSupportFeature.Composite,
SchemaSupportFeature.allOf,
SchemaSupportFeature.oneOf,
SchemaSupportFeature.anyOf
)
);
generatorMetadata = GeneratorMetadata.newBuilder()
@ -150,6 +160,9 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
LOGGER.debug("Serialization library not set, using default {}", SERIALIZATION_LIBRARY_DEFAULT);
}
setLibrary(additionalProperties.get(CodegenConstants.SERIALIZATION_LIBRARY).toString());
if (SERIALIZATION_LIBRARY_BUILT_VALUE.equals(library)) {
this.setLegacyDiscriminatorBehavior(false);
}
if (!additionalProperties.containsKey(DATE_LIBRARY)) {
additionalProperties.put(DATE_LIBRARY, DATE_LIBRARY_DEFAULT);
@ -331,6 +344,213 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
return objs;
}
/// Gets all ancestors of a given model, and puts it in accumulator
private void getAncestors(CodegenModel cm, Map<String, CodegenModel> allModels, Set<String> accumulator) {
// get direct parents
Set<String> directParentNames = cm.allOf;
if (directParentNames != null && !directParentNames.isEmpty()) {
for (String directParentName : directParentNames) {
if (accumulator.add(directParentName)) {
CodegenModel parent = allModels.get(directParentName);
getAncestors(parent, allModels, accumulator);
}
}
}
}
private void syncRootTypesWithInnerVars(Map<String, ModelsMap> objs) {
Map<String, CodegenModel> allModels = new HashMap<>();
for (ModelsMap modelsEntries : objs.values()) {
for (ModelMap modelsMap : modelsEntries.getModels()) {
CodegenModel model = modelsMap.getModel();
allModels.put(model.getClassname(), model);
}
}
for (CodegenModel model : allModels.values()) {
syncRootTypesWithInnerVars(allModels, model);
}
}
private void syncRootTypesWithInnerVars(Map<String, CodegenModel> objs, CodegenModel model) {
List<CodegenProperty> allVars = new ArrayList<>();
allVars.addAll(((Collection<CodegenProperty>) model.vendorExtensions.get(kSelfAndAncestorOnlyProps)));
allVars.addAll(((Collection<CodegenProperty>) model.vendorExtensions.get(kSelfOnlyProps)));
allVars.addAll(((Collection<CodegenProperty>) model.vendorExtensions.get(kAncestorOnlyProps)));
for (CodegenProperty prop : allVars) {
//check if type exists in parent map
String type = prop.openApiType;
if (objs.containsKey(type)) {
//get the type
CodegenModel relatedModel = objs.get(type);
//fill the property's VendorExtensions with the type's VendorExtensions
prop.getVendorExtensions().put(kIsParent, relatedModel.getVendorExtensions().get(kIsParent));
prop.isEnum = relatedModel.isEnum;
}
}
}
private final String kIsChild = "x-is-child";
private final String kIsParent = "x-is-parent";
private final String kIsPure = "x-is-pure";
private final String kSelfOnlyProps = "x-self-only-props";
private final String kHasSelfOnlyProps = "x-has-self-only-props";
private final String kAncestorOnlyProps = "x-ancestor-only-props";
private final String kHasAncestorOnlyProps = "x-has-ancestor-only-props";
private final String kSelfAndAncestorOnlyProps = "x-self-and-ancestor-only-props";
private final String kHasSelfAndAncestorOnlyProps = "x-has-self-and-ancestor-only-props";
// adapts codegen models and property to dart rules of inheritance
private void adaptToDartInheritance(Map<String, ModelsMap> objs) {
// get all models
Map<String, CodegenModel> allModels = new HashMap<>();
for (ModelsMap modelsEntries : objs.values()) {
for (ModelMap modelsMap : modelsEntries.getModels()) {
CodegenModel model = modelsMap.getModel();
allModels.put(model.getClassname(), model);
}
}
// all ancestors
Set<String> allAncestorsForAllModelsFlat = new HashSet<>();
// maps a model to its ancestors
Map<String, Set<String>> allAncestorsForAllModels = new HashMap<>();
for (java.util.Map.Entry<String, CodegenModel> cm : allModels.entrySet()) {
Set<String> allAncestors = new HashSet<>();
// get all ancestors
// TODO: optimize this logic ?
getAncestors(cm.getValue(), allModels, allAncestors);
// just in case, a model can't be its own ancestor
allAncestors.remove(cm.getKey());
allAncestorsForAllModels.put(cm.getKey(), allAncestors);
allAncestorsForAllModelsFlat.addAll(allAncestors);
}
Set<String> allPureClasses = new HashSet<>();
// set isChild,isParent,isPure
for (java.util.Map.Entry<String, CodegenModel> cmEntry : allModels.entrySet()) {
String key = cmEntry.getKey();
CodegenModel cm = cmEntry.getValue();
// get all ancestors
Set<String> allAncestors = allAncestorsForAllModels.get(key);
// a class is a parent when it's an ancestor to another class
boolean isParent = allAncestorsForAllModelsFlat.contains(key);
// a class is a child when it has any ancestor
boolean isChild = !allAncestors.isEmpty();
// a class is pure when it's not a child, and has no oneOf nor anyOf
boolean isPure = !isChild && (cm.oneOf == null || cm.oneOf.isEmpty())
&& (cm.anyOf == null || cm.anyOf.isEmpty());
cm.vendorExtensions.put(kIsChild, isChild);
cm.vendorExtensions.put(kIsParent, isParent);
cm.vendorExtensions.put(kIsPure, isPure);
// when pure:
// vars = allVars = selfOnlyProperties = kSelfAndAncestorOnlyProps
// ancestorOnlyProps = empty
if (isPure) {
cm.vendorExtensions.put(kSelfOnlyProps, new ArrayList<>(cm.getVars()));
cm.vendorExtensions.put(kHasSelfOnlyProps, !cm.getVars().isEmpty());
cm.vendorExtensions.put(kAncestorOnlyProps, new ArrayList<CodegenProperty>());
cm.vendorExtensions.put(kHasAncestorOnlyProps, false);
cm.vendorExtensions.put(kSelfAndAncestorOnlyProps, new ArrayList<>(cm.getVars()));
cm.vendorExtensions.put(kHasSelfAndAncestorOnlyProps, !cm.getVars().isEmpty());
allPureClasses.add(key);
}
}
// handle impure models
for (java.util.Map.Entry<String, CodegenModel> cmEntry : allModels.entrySet()) {
String key = cmEntry.getKey();
CodegenModel cm = cmEntry.getValue();
if (allPureClasses.contains(key)) {
continue;
}
// get all ancestors
Set<String> allAncestors = allAncestorsForAllModels.get(key);
// get direct parents
// Set<String> directParentNames = cm.allOf == null ? new HashSet<>() :
// cm.allOf;
Set<String> compositeProperties = new HashSet<>();
Set<String> compositeModelNames = new HashSet<String>();
compositeModelNames.addAll(ObjectUtils.firstNonNull(cm.oneOf, new HashSet<>()));
compositeModelNames.addAll(ObjectUtils.firstNonNull(cm.anyOf, new HashSet<>()));
compositeModelNames.addAll(allAncestors);
for (String compositeModelName : compositeModelNames) {
CodegenModel model = allModels.get(compositeModelName);
if (model == null)
continue;
List<CodegenProperty> allVars = ObjectUtils.firstNonNull(model.getAllVars(), new ArrayList<>());
for (CodegenProperty prop : allVars) {
compositeProperties.add(prop.getName());
}
}
// dart classes declare selfOnlyProperties as direct members (they exist in
// "vars")
// for pure models, this will equal vars
Map<String, CodegenProperty> selfOnlyProperties = new HashMap<>();
// ancestorOnlyProperties are properties defined by all ancestors
// NOTE: oneOf,anyOf are NOT considered ancestors
// since a child in dart must implment ALL OF the parent (using implements)
Map<String, CodegenProperty> ancestorOnlyProperties = new HashMap<>();
// combines both selfOnlyProperties and ancestorOnlyProperties
// this will be used by the custom serializer as "x-handled-vars" and
// "x-has-handled-vars"
Map<String, CodegenProperty> selfAndAncestorOnlyProperties = new HashMap<>();
// STEP 1: calculating selfOnlyProperties
// get all vars of all ancestors and add them to ancestorPropNames
// Set<String> _ancestorPropNames = new HashSet<>();
for (String ancestorKey : allAncestors) {
CodegenModel ancestorCM = allModels.get(ancestorKey);
for (CodegenProperty prop : ancestorCM.getVars()) {
ancestorOnlyProperties.put(prop.getName(), prop);
}
}
for (CodegenProperty p : cm.getVars()) {
p.isInherited = ancestorOnlyProperties.containsKey(p.getName());
if (!p.isInherited && !compositeProperties.contains(p.getName())) {
selfOnlyProperties.put(p.getName(), p);
}
}
selfAndAncestorOnlyProperties.putAll(selfOnlyProperties);
selfAndAncestorOnlyProperties.putAll(ancestorOnlyProperties);
cm.vendorExtensions.put(kSelfOnlyProps, new ArrayList<>(selfOnlyProperties.values()));
cm.vendorExtensions.put(kHasSelfOnlyProps, !selfOnlyProperties.isEmpty());
cm.vendorExtensions.put(kAncestorOnlyProps, new ArrayList<>(ancestorOnlyProperties.values()));
cm.vendorExtensions.put(kHasAncestorOnlyProps, !ancestorOnlyProperties.isEmpty());
cm.vendorExtensions.put(kSelfAndAncestorOnlyProps, new ArrayList<>(selfAndAncestorOnlyProperties.values()));
cm.vendorExtensions.put(kHasSelfAndAncestorOnlyProps, !selfAndAncestorOnlyProperties.isEmpty());
// fixes missing imports
Set<String> interfaceImports = new HashSet<String>();
interfaceImports.addAll(cm.allOf);
interfaceImports.addAll(cm.oneOf);
interfaceImports.addAll(cm.anyOf);
cm.imports.addAll(rewriteImports(interfaceImports, true));
}
}
@Override
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
objs = super.postProcessAllModels(objs);
if (SERIALIZATION_LIBRARY_BUILT_VALUE.equals(library)) {
adaptToDartInheritance(objs);
syncRootTypesWithInnerVars(objs);
}
return objs;
}
@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
super.postProcessModelProperty(model, property);
@ -361,7 +581,7 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
super.postProcessOperationsWithModels(objs, allModels);
OperationMap operations = objs.getOperations();
List<CodegenOperation> operationList = operations.getOperation();
List<CodegenOperation> operationList = operations.getOperation();
Set<String> resultImports = new HashSet<>();
@ -403,7 +623,7 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
for (CodegenParameter param : op.allParams) {
// Generate serializer factories for all container type parameters.
// But skip binary and file parameters, JSON serializers don't make sense there.
if (param.isContainer && !(param.isBinary || param.isFile )) {
if (param.isContainer && !(param.isBinary || param.isFile)) {
addBuiltValueSerializer(new BuiltValueSerializer(
param.isArray,
param.uniqueItems,
@ -459,6 +679,14 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
private Set<String> rewriteImports(Set<String> originalImports, boolean isModel) {
Set<String> resultImports = Sets.newHashSet();
for (String modelImport : originalImports) {
if (modelImport.startsWith("BuiltList", 0)) {
modelImport = "BuiltList";
} else if (modelImport.startsWith("BuiltSet", 0)) {
modelImport = "BuiltSet";
} else if (modelImport.startsWith("BuiltMap", 0)) {
modelImport = "BuiltMap";
}
if (imports.containsKey(modelImport)) {
String i = imports.get(modelImport);
if (Objects.equals(i, DIO_IMPORT) && !isModel) {

View File

@ -1,4 +1,5 @@
{{>header}}
// ignore_for_file: unused_element
{{#models}}
{{#model}}
{{#imports}}

View File

@ -14,8 +14,10 @@ environment:
dependencies:
dio: '>=4.0.1 <5.0.0'
{{#useBuiltValue}}
built_value: '>=8.1.0 <9.0.0'
built_collection: '>=5.1.0 <6.0.0'
one_of: '>=1.5.0 <2.0.0'
one_of_serializer: '>=1.5.0 <2.0.0'
built_value: '>=8.4.0 <9.0.0'
built_collection: '>=5.1.1 <6.0.0'
{{/useBuiltValue}}
{{#useJsonSerializable}}
json_annotation: '^4.4.0'
@ -26,7 +28,7 @@ dependencies:
dev_dependencies:
{{#useBuiltValue}}
built_value_generator: '>=8.1.0 <9.0.0'
built_value_generator: '>=8.4.0 <9.0.0'
build_runner: any
{{/useBuiltValue}}
{{#useJsonSerializable}}

View File

@ -1,154 +1,17 @@
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/serializer.dart';{{#oneOf}}{{#-first}}
import 'package:one_of/one_of.dart';{{/-first}}{{/oneOf}}{{#anyOf}}{{#-first}}
import 'package:one_of/any_of.dart';{{/-first}}{{/anyOf}}
{{#imports}}
{{/imports}}
part '{{classFilename}}.g.dart';
{{!
Classes with polymorphism or composition may generate unused imports,
these need to be ignored for said classes so that there are no lint errors.
}}
{{#parentModel}}
// ignore_for_file: unused_import
{{/parentModel}}
/// {{{description}}}{{^description}}{{classname}}{{/description}}
{{#hasVars}}
///
/// Properties:
{{#allVars}}
/// * [{{{name}}}] {{#description}}- {{{.}}}{{/description}}
{{/allVars}}
{{/hasVars}}
abstract class {{classname}} implements Built<{{classname}}, {{classname}}Builder> {
{{#vars}}
{{#description}}
/// {{{.}}}
{{/description}}
@BuiltValueField(wireName: r'{{baseName}}')
{{>serialization/built_value/variable_type}}{{^isNullable}}{{^required}}?{{/required}}{{/isNullable}} get {{name}};
{{#allowableValues}}
// {{#min}}range from {{{min}}} to {{{max}}}{{/min}}{{^min}}enum {{name}}Enum { {{#values}} {{{.}}}, {{/values}} };{{/min}}
{{/allowableValues}}
{{/vars}}
{{classname}}._();
@BuiltValueHook(initializeBuilder: true)
static void _defaults({{{classname}}}Builder b) => b{{#vars}}{{#defaultValue}}
..{{{name}}} = {{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}}{{/vars}};
factory {{classname}}([void updates({{classname}}Builder b)]) = _${{classname}};
@BuiltValueSerializer(custom: true)
static Serializer<{{classname}}> get serializer => _${{classname}}Serializer();
{{>serialization/built_value/class_header}} {
{{>serialization/built_value/class_members}}
}
{{!
Generate a custom serializer in order to support combinations of required and nullable.
By default built_value does not serialize null fields.
}}
class _${{classname}}Serializer implements StructuredSerializer<{{classname}}> {
@override
final Iterable<Type> types = const [{{classname}}, _${{classname}}];
{{>serialization/built_value/class_serializer}}{{#vendorExtensions.x-is-parent}}
@override
final String wireName = r'{{classname}}';
@override
Iterable<Object?> serialize(Serializers serializers, {{{classname}}} object,
{FullType specifiedType = FullType.unspecified}) {
final result = <Object?>[];
{{#vars}}
{{#required}}
{{!
A required property need to always be part of the serialized output.
When it is nullable, null is serialized, otherwise it is an error if it is null.
}}
result
..add(r'{{baseName}}')
..add({{#isNullable}}object.{{{name}}} == null ? null : {{/isNullable}}serializers.serialize(object.{{{name}}},
specifiedType: const {{>serialization/built_value/variable_serializer_type}}));
{{/required}}
{{^required}}
if (object.{{{name}}} != null) {
{{! Non-required properties are only serialized if not null. }}
result
..add(r'{{baseName}}')
..add(serializers.serialize(object.{{{name}}},
specifiedType: const {{>serialization/built_value/variable_serializer_type}}));
}
{{/required}}
{{/vars}}
return result;
}
@override
{{classname}} deserialize(Serializers serializers, Iterable<Object?> serialized,
{FullType specifiedType = FullType.unspecified}) {
final result = {{classname}}Builder();
final iterator = serialized.iterator;
while (iterator.moveNext()) {
final key = iterator.current as String;
iterator.moveNext();
final Object? value = iterator.current;
switch (key) {
{{#vars}}
case r'{{baseName}}':
final valueDes = serializers.deserialize(value,
specifiedType: const {{>serialization/built_value/variable_serializer_type}}) as {{>serialization/built_value/variable_type}};
{{#isNullable}}
if (valueDes == null) continue;
{{/isNullable}}
{{#isContainer}}
result.{{{name}}}.replace(valueDes);
{{/isContainer}}
{{^isContainer}}
{{#isEnum}}
result.{{{name}}} = valueDes;
{{/isEnum}}
{{^isEnum}}
{{#isModel}}
{{#isPrimitiveType}}
{{! These are models that have been manually marked as primitive via generator param. }}
result.{{{name}}} = valueDes;
{{/isPrimitiveType}}
{{^isPrimitiveType}}
result.{{{name}}}.replace(valueDes);
{{/isPrimitiveType}}
{{/isModel}}
{{^isModel}}
result.{{{name}}} = valueDes;
{{/isModel}}
{{/isEnum}}
{{/isContainer}}
break;
{{/vars}}
}
}
return result.build();
}
}
{{!
Generate an enum for any variables that are declared as inline enums
isEnum is only true for inline variables that are enums.
If an enum is declared as a definition, isEnum is false and the enum is generated from the
enum.mustache template.
}}
{{#vars}}
{{^isModel}}
{{#isEnum}}
{{^isContainer}}
{{>serialization/built_value/enum_inline}}
{{/isContainer}}
{{#isContainer}}
{{#mostInnerItems}}
{{>serialization/built_value/enum_inline}}
{{/mostInnerItems}}
{{/isContainer}}
{{/isEnum}}
{{/isModel}}
{{/vars}}
{{>serialization/built_value/class_concrete}}{{/vendorExtensions.x-is-parent}}
{{>serialization/built_value/class_inline_enums}}

View File

@ -0,0 +1,56 @@
/// a concrete implementation of [{{classname}}], since [{{classname}}] is not instantiable
@BuiltValue(instantiable: true)
abstract class ${{classname}} implements {{classname}}, Built<${{classname}}, ${{classname}}Builder> {
${{classname}}._();
factory ${{classname}}([void Function(${{classname}}Builder)? updates]) = _$${{classname}};
@BuiltValueHook(initializeBuilder: true)
static void _defaults(${{classname}}Builder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<${{classname}}> get serializer => _$${{classname}}Serializer();
}
class _$${{classname}}Serializer implements PrimitiveSerializer<${{classname}}> {
@override
final Iterable<Type> types = const [${{classname}}, _$${{classname}}];
@override
final String wireName = r'${{classname}}';
@override
Object serialize(
Serializers serializers,
${{{classname}}} object, {
FullType specifiedType = FullType.unspecified,
}) {
return serializers.serialize(object, specifiedType: FullType({{classname}}))!;
}
{{#vendorExtensions.x-has-self-and-ancestor-only-props}}{{>serialization/built_value/deserialize_properties}}
{{/vendorExtensions.x-has-self-and-ancestor-only-props}}
@override
${{classname}} deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = ${{classname}}Builder();
{{#vendorExtensions.x-has-self-and-ancestor-only-props}}
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
{{/vendorExtensions.x-has-self-and-ancestor-only-props}}
{{! when discriminator is involved, read it, then return based on value }}
return result.build();
}
}

View File

@ -0,0 +1,10 @@
/// {{{description}}}{{^description}}{{classname}}{{/description}}
{{#hasVars}}
///
/// Properties:
{{#allVars}}
/// * [{{{name}}}] {{#description}}- {{{.}}}{{/description}}
{{/allVars}}
{{/hasVars}}
@BuiltValue({{#vendorExtensions.x-is-parent}}instantiable: false{{/vendorExtensions.x-is-parent}})
abstract class {{classname}} {{^allOf}}{{^vendorExtensions.x-is-parent}}implements {{/vendorExtensions.x-is-parent}}{{/allOf}}{{#allOf}}{{#-first}}implements {{/-first}}{{/allOf}}{{#allOf}}{{{.}}}{{^-last}}, {{/-last}}{{/allOf}}{{^vendorExtensions.x-is-parent}}{{#allOf}}{{#-first}}, {{/-first}}{{/allOf}}{{/vendorExtensions.x-is-parent}}{{^vendorExtensions.x-is-parent}}Built<{{classname}}, {{classname}}Builder>{{/vendorExtensions.x-is-parent}}

View File

@ -0,0 +1,23 @@
{{!
Generate an enum for any variables that are declared as inline enums
isEnum is only true for inline variables that are enums.
If an enum is declared as a definition, isEnum is false and the enum is generated from the
enum.mustache template.
enumName only exists for inline enums
}}
{{#vars}}
{{^isModel}}
{{#enumName}}
{{^isContainer}}
{{>serialization/built_value/enum_inline}}
{{/isContainer}}
{{#isContainer}}
{{#mostInnerItems}}
{{>serialization/built_value/enum_inline}}
{{/mostInnerItems}}
{{/isContainer}}
{{/enumName}}
{{/isModel}}
{{/vars}}

View File

@ -0,0 +1,35 @@
{{! define variables that aren't inherited from allOf/anyOf/oneOf }}
{{#vendorExtensions.x-self-only-props}}
{{#description}}
/// {{{.}}}
{{/description}}
@BuiltValueField(wireName: r'{{baseName}}')
{{>serialization/built_value/variable_type}}{{^isNullable}}{{^required}}?{{/required}}{{/isNullable}} get {{name}};
{{#allowableValues}}
// {{#min}}range from {{{min}}} to {{{max}}}{{/min}}{{^min}}enum {{name}}Enum { {{#values}} {{{.}}}, {{/values}} };{{/min}}
{{/allowableValues}}
{{/vendorExtensions.x-self-only-props}}{{#anyOf}}{{#-first}} /// Any Of {{#anyOf}}[{{{.}}}]{{^-last}}, {{/-last}}{{/anyOf}}
AnyOf get anyOf;
{{/-first}}{{/anyOf}}{{#oneOf}}{{#-first}} /// One Of {{#oneOf}}[{{{.}}}]{{^-last}}, {{/-last}}{{/oneOf}}
OneOf get oneOf;
{{/-first}}{{/oneOf}}{{#discriminator}} static const String discriminatorFieldName = r'{{propertyName}}';{{#hasDiscriminatorWithNonEmptyMapping}}
static const Map<String, Type> discriminatorMapping = {
{{#mappedModels}}
r'{{mappingName}}': {{modelName}},
{{/mappedModels}}
};{{/hasDiscriminatorWithNonEmptyMapping}}
{{/discriminator}}{{^vendorExtensions.x-is-parent}} {{classname}}._();
factory {{classname}}([void updates({{classname}}Builder b)]) = _${{classname}};
@BuiltValueHook(initializeBuilder: true)
static void _defaults({{{classname}}}Builder b) => b{{#vendorExtensions.x-self-and-ancestor-only-props}}{{#defaultValue}}
..{{{name}}} = {{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}}{{/vendorExtensions.x-self-and-ancestor-only-props}};
{{/vendorExtensions.x-is-parent}} @BuiltValueSerializer(custom: true)
static Serializer<{{classname}}> get serializer => _${{classname}}Serializer();

View File

@ -0,0 +1,306 @@
class _${{classname}}Serializer implements PrimitiveSerializer<{{classname}}> {
@override
final Iterable<Type> types = const [{{classname}}{{^vendorExtensions.x-is-parent}}, _${{classname}}{{/vendorExtensions.x-is-parent}}];
@override
final String wireName = r'{{classname}}';
Iterable<Object?> _serializeProperties(
Serializers serializers,
{{{classname}}} object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
{{#vendorExtensions.x-self-and-ancestor-only-props}}
{{#required}}
{{!
A required property need to always be part of the serialized output.
When it is nullable, null is serialized, otherwise it is an error if it is null.
}}
yield r'{{baseName}}';
yield {{#isNullable}}object.{{{name}}} == null ? null : {{/isNullable}}serializers.serialize(
object.{{{name}}},
specifiedType: const {{>serialization/built_value/variable_serializer_type}},
);
{{/required}}
{{^required}}
if (object.{{{name}}} != null) {
{{! Non-required properties are only serialized if not null. }}
yield r'{{baseName}}';
yield serializers.serialize(
object.{{{name}}},
specifiedType: const {{>serialization/built_value/variable_serializer_type}},
);
}
{{/required}}
{{/vendorExtensions.x-self-and-ancestor-only-props}}
}
@override
Object serialize(
Serializers serializers,
{{{classname}}} object, {
FullType specifiedType = FullType.unspecified,
}) {
{{! oneOf }}
{{#oneOf}}
{{#-first}}
final oneOf = object.oneOf;
{{#vendorExtensions.x-self-and-ancestor-only-props}}
final result = _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
result.addAll(serializers.serialize(oneOf.value, specifiedType: FullType(oneOf.valueType)) as Iterable<Object?>);
return result;
{{/vendorExtensions.x-self-and-ancestor-only-props}}
{{^vendorExtensions.x-self-and-ancestor-only-props}}
return serializers.serialize(oneOf.value, specifiedType: FullType(oneOf.valueType))!;
{{/vendorExtensions.x-self-and-ancestor-only-props}}
{{/-first}}
{{/oneOf}}
{{! anyOf }}
{{#anyOf}}
{{#-first}}
final anyOf = object.anyOf;
final result = {{^vendorExtensions.x-has-self-and-ancestor-only-props}}<Object?>[]{{/vendorExtensions.x-has-self-and-ancestor-only-props}}{{#vendorExtensions.x-has-self-and-ancestor-only-props}}_serializeProperties(serializers, object, specifiedType: specifiedType).toList(){{/vendorExtensions.x-has-self-and-ancestor-only-props}};
for (var _valueEntry in anyOf.values.entries) {
final _typeIndex = _valueEntry.key;
final _type = anyOf.types[_typeIndex];
final _value = _valueEntry.value;
result.addAll(serializers.serialize(_value, specifiedType: FullType(_type)) as Iterable<Object?>);
}
return result;
{{/-first}}
{{/anyOf}}
{{^oneOf}}
{{^anyOf}}
{{#hasDiscriminatorWithNonEmptyMapping}}
{{#discriminator}}
{{! handle discriminator }}
{{#mappedModels}}
if (object is {{modelName}}) {
return serializers.serialize(object, specifiedType: FullType({{modelName}}))!;
}
{{/mappedModels}}
{{/discriminator}}
{{/hasDiscriminatorWithNonEmptyMapping}}
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
{{/anyOf}}
{{/oneOf}}
}
{{#vendorExtensions.x-has-self-and-ancestor-only-props}}{{^vendorExtensions.x-is-parent}}{{>serialization/built_value/deserialize_properties}}
{{/vendorExtensions.x-is-parent}}{{/vendorExtensions.x-has-self-and-ancestor-only-props}} @override
{{classname}} deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
{{! oneOf }}
{{#oneOf}}
{{#-first}}
final result = {{#vendorExtensions.x-is-parent}}${{/vendorExtensions.x-is-parent}}{{classname}}Builder();
Object? oneOfDataSrc;
{{#hasDiscriminatorWithNonEmptyMapping}}
{{#discriminator}}
{{! has props, assign them to result, and extract unhandled }}
final serializedList = (serialized as Iterable<Object?>).toList();
final discIndex = serializedList.indexOf({{classname}}.discriminatorFieldName) + 1;
final discValue = serializers.deserialize(serializedList[discIndex], specifiedType: FullType(String)) as String;
{{#vendorExtensions.x-has-self-and-ancestor-only-props}}
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result
);
{{! only deserialize unhandled props }}
oneOfDataSrc = unhandled;
{{/vendorExtensions.x-has-self-and-ancestor-only-props}}
{{^vendorExtensions.x-has-self-and-ancestor-only-props}}
oneOfDataSrc = serialized;
{{! has no probs at all, pass the serialized as is }}
{{/vendorExtensions.x-has-self-and-ancestor-only-props}}
final oneOfTypes = [{{#mappedModels}}{{modelName}}, {{/mappedModels}}{{#vendorExtensions.x-is-parent}}${{classname}}{{/vendorExtensions.x-is-parent}}];
Object oneOfResult;
Type oneOfType;
switch (discValue) {
{{#mappedModels}}
case '{{mappingName}}':
oneOfResult = serializers.deserialize(
oneOfDataSrc,
specifiedType: FullType({{modelName}}),
) as {{modelName}};
oneOfType = {{modelName}};
break;
{{/mappedModels}}
default:
{{#vendorExtensions.x-is-parent}}
oneOfResult = serializers.deserialize(
oneOfDataSrc,
specifiedType: FullType(${{classname}}),
) as ${{classname}};
oneOfType = ${{classname}};
{{/vendorExtensions.x-is-parent}}
{{^vendorExtensions.x-is-parent}}
throw UnsupportedError("Couldn't deserialize oneOf for the discriminator value: ${discValue}");
{{/vendorExtensions.x-is-parent}}
}
result.oneOf = OneOfDynamic(typeIndex: oneOfTypes.indexOf(oneOfType), types: oneOfTypes, value: oneOfResult);
{{/discriminator}}
{{/hasDiscriminatorWithNonEmptyMapping}}
{{^hasDiscriminatorWithNonEmptyMapping}}
{{! use the OneOfSerializer when there is no discriminator }}
final targetType = const FullType(OneOf, [{{#composedSchemas}}{{#oneOf}}{{>serialization/built_value/variable_serializer_type}}, {{/oneOf}}{{/composedSchemas}}]);
{{#vendorExtensions.x-has-self-and-ancestor-only-props}}
{{! has props, assign them to result, and extract unhandled }}
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
{{! only deserialize unhandled props }}
oneOfDataSrc = unhandled;
{{/vendorExtensions.x-has-self-and-ancestor-only-props}}
{{^vendorExtensions.x-has-self-and-ancestor-only-props}}
{{! has no probs at all, pass the serialized as is }}
oneOfDataSrc = serialized;
{{/vendorExtensions.x-has-self-and-ancestor-only-props}}
result.oneOf = serializers.deserialize(oneOfDataSrc, specifiedType: targetType) as OneOf;
{{/hasDiscriminatorWithNonEmptyMapping}}
return result.build();
{{/-first}}
{{/oneOf}}
{{! anyOf }}
{{#anyOf}}
{{#-first}}
final result = {{#vendorExtensions.x-is-parent}}${{/vendorExtensions.x-is-parent}}{{classname}}Builder();
Object? anyOfDataSrc;
{{#hasDiscriminatorWithNonEmptyMapping}}
{{#discriminator}}
{{! has props, assign them to result, and extract unhandled }}
final serializedList = (serialized as Iterable<Object?>).toList();
final discIndex = serializedList.indexOf({{classname}}.discriminatorFieldName) + 1;
final discValue = serializers.deserialize(serializedList[discIndex], specifiedType: FullType(String)) as String;
{{#vendorExtensions.x-has-self-and-ancestor-only-props}}
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
{{! only deserialize unhandled props }}
anyOfDataSrc = unhandled;
{{/vendorExtensions.x-has-self-and-ancestor-only-props}}
{{^vendorExtensions.x-has-self-and-ancestor-only-props}}
anyOfDataSrc = serialized;
{{! has no probs at all, pass the serialized as is }}
{{/vendorExtensions.x-has-self-and-ancestor-only-props}}
final anyOfTypes = [{{#mappedModels}}{{modelName}}, {{/mappedModels}}{{#vendorExtensions.x-is-parent}}${{classname}}{{/vendorExtensions.x-is-parent}}];
Object anyOfResult;
Type anyOfType;
switch (discValue) {
{{#mappedModels}}
case '{{mappingName}}':
anyOfResult = serializers.deserialize(anyOfDataSrc, specifiedType: FullType({{modelName}})) as {{modelName}};
anyOfType = {{modelName}};
break;
{{/mappedModels}}
default:
{{#vendorExtensions.x-is-parent}}
anyOfResult = serializers.deserialize(anyOfDataSrc, specifiedType: FullType(${{classname}})) as ${{classname}};
anyOfType = ${{classname}};
{{/vendorExtensions.x-is-parent}}
{{^vendorExtensions.x-is-parent}}
throw UnsupportedError("Couldn't deserialize anyOf for the discriminator value: ${discValue}");
{{/vendorExtensions.x-is-parent}}
}
result.anyOf = AnyOfDynamic(values: {anyOfTypes.indexOf(anyOfType): anyOfResult}, types: anyOfTypes);
{{/discriminator}}
{{/hasDiscriminatorWithNonEmptyMapping}}
{{^hasDiscriminatorWithNonEmptyMapping}}
{{! use the OneOfSerializer when there is no discriminator }}
final targetType = const FullType(AnyOf, [{{#composedSchemas}}{{#anyOf}}{{>serialization/built_value/variable_serializer_type}}, {{/anyOf}}{{/composedSchemas}}]);
{{#vendorExtensions.x-has-self-and-ancestor-only-props}}
{{! has props, assign them to result, and extract unhandled }}
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
{{! only deserialize unhandled props }}
anyOfDataSrc = unhandled;
{{/vendorExtensions.x-has-self-and-ancestor-only-props}}
{{^vendorExtensions.x-has-self-and-ancestor-only-props}}
{{! has no probs at all, pass the serialized as is }}
anyOfDataSrc = serialized;
{{/vendorExtensions.x-has-self-and-ancestor-only-props}}
result.anyOf = serializers.deserialize(anyOfDataSrc, specifiedType: targetType) as AnyOf;
{{/hasDiscriminatorWithNonEmptyMapping}}
return result.build();
{{/-first}}
{{/anyOf}}
{{! no anyOf nor oneOf, handles allOf trees }}
{{^oneOf}}
{{^anyOf}}
{{#vendorExtensions.x-is-parent}}
{{!
parent classes don't have builder
so they must delegate to another serializer using
1) discriminator + mapping
2) concrete implmentation ($classname)
}}
{{#hasDiscriminatorWithNonEmptyMapping}}
{{#discriminator}}
final serializedList = (serialized as Iterable<Object?>).toList();
final discIndex = serializedList.indexOf({{classname}}.discriminatorFieldName) + 1;
final discValue = serializers.deserialize(serializedList[discIndex], specifiedType: FullType(String)) as String;
switch (discValue) {
{{#mappedModels}}
case '{{mappingName}}':
return serializers.deserialize(serialized, specifiedType: FullType({{modelName}})) as {{modelName}};
{{/mappedModels}}
default:
return serializers.deserialize(serialized, specifiedType: FullType(${{classname}})) as ${{classname}};
}
{{/discriminator}}
{{/hasDiscriminatorWithNonEmptyMapping}}
{{^hasDiscriminatorWithNonEmptyMapping}}
return serializers.deserialize(serialized, specifiedType: FullType(${{classname}})) as ${{classname}};
{{/hasDiscriminatorWithNonEmptyMapping}}
{{/vendorExtensions.x-is-parent}}
{{^vendorExtensions.x-is-parent}}
final result = {{classname}}Builder();
final serializedList = (serialized as Iterable<Object?>).toList();
{{#vendorExtensions.x-has-self-and-ancestor-only-props}}
{{! has props, assign them to result, and extract unhandled }}
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
{{/vendorExtensions.x-has-self-and-ancestor-only-props}}
return result.build();
{{/vendorExtensions.x-is-parent}}
{{/anyOf}}
{{/oneOf}}
}
}

View File

@ -0,0 +1,57 @@
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required {{classname}}Builder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
{{#vendorExtensions.x-self-and-ancestor-only-props}}
case r'{{baseName}}':
final valueDes = serializers.deserialize(
value,
specifiedType: const {{>serialization/built_value/variable_serializer_type}},
) as {{>serialization/built_value/variable_type}};
{{#isNullable}}
if (valueDes == null) continue;
{{/isNullable}}
{{#isContainer}}
result.{{{name}}}.replace(valueDes);
{{/isContainer}}
{{^isContainer}}
{{#isEnum}}
result.{{{name}}} = valueDes;
{{/isEnum}}
{{^isEnum}}
{{#isModel}}
{{#isPrimitiveType}}
{{! These are models that have been manually marked as primitive via generator param. }}
result.{{{name}}} = valueDes;
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#vendorExtensions.x-is-parent}}
result.{{{name}}} = valueDes;
{{/vendorExtensions.x-is-parent}}
{{^vendorExtensions.x-is-parent}}
result.{{{name}}}.replace(valueDes);
{{/vendorExtensions.x-is-parent}}
{{/isPrimitiveType}}
{{/isModel}}
{{^isModel}}
result.{{{name}}} = valueDes;
{{/isModel}}
{{/isEnum}}
{{/isContainer}}
break;
{{/vendorExtensions.x-self-and-ancestor-only-props}}
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}

View File

@ -1,6 +1,8 @@
{{>header}}
// ignore_for_file: unused_import
import 'package:one_of_serializer/any_of_serializer.dart';
import 'package:one_of_serializer/one_of_serializer.dart';
import 'package:built_collection/built_collection.dart';
import 'package:built_value/json_object.dart';
import 'package:built_value/serializer.dart';
@ -17,7 +19,7 @@ import 'package:{{pubName}}/{{sourceFolder}}/offset_date_serializer.dart';{{/use
part 'serializers.g.dart';
@SerializersFor([{{#models}}{{#model}}
{{classname}},{{/model}}{{/models}}
{{classname}},{{#vendorExtensions.x-is-parent}}${{classname}},{{/vendorExtensions.x-is-parent}}{{/model}}{{/models}}
])
Serializers serializers = (_$serializers.toBuilder(){{#builtValueSerializers}}
..addBuilderFactory(
@ -29,7 +31,10 @@ Serializers serializers = (_$serializers.toBuilder(){{#builtValueSerializers}}
const FullType(BuiltMap, [FullType(String), FullType{{#isNullable}}.nullable{{/isNullable}}({{dataType}})]),
() => MapBuilder<String, {{dataType}}>(),
{{/isMap}}
){{/builtValueSerializers}}{{#useDateLibTimeMachine}}
){{/builtValueSerializers}}
{{#models}}{{#model}}{{#vendorExtensions.x-is-parent}}..add({{classname}}.serializer)
{{/vendorExtensions.x-is-parent}}{{/model}}{{/models}}..add(const OneOfSerializer())
..add(const AnyOfSerializer()){{#useDateLibTimeMachine}}
..add(const OffsetDateSerializer())
..add(const OffsetDateTimeSerializer()){{/useDateLibTimeMachine}}{{#useDateLibCore}}
..add(const DateSerializer())

View File

@ -1,2 +1,2 @@
final instance = {{{classname}}}Builder();
{{#vendorExtensions.x-is-parent}}//{{/vendorExtensions.x-is-parent}}final instance = {{{classname}}}Builder();
// TODO add properties to the builder and call build()

View File

@ -1325,6 +1325,9 @@
</activation>
<modules>
<module>samples/openapi3/client/petstore/dart2/petstore_client_lib</module>
<module>samples/openapi3/client/petstore/dart-dio/oneof</module>
<module>samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance</module>
<module>samples/openapi3/client/petstore/dart-dio/oneof_primitive</module>
<module>samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake</module>
<module>samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable</module>
</modules>

View File

@ -0,0 +1,41 @@
# See https://dart.dev/guides/libraries/private-files
# Files and directories created by pub
.dart_tool/
.buildlog
.packages
.project
.pub/
build/
**/packages/
# Files created by dart2js
# (Most Dart developers will use pub build to compile Dart, use/modify these
# rules if you intend to use dart2js directly
# Convention is to use extension '.dart.js' for Dart compiled to Javascript to
# differentiate from explicit Javascript files)
*.dart.js
*.part.js
*.js.deps
*.js.map
*.info.json
# Directory created by dartdoc
doc/api/
# Don't commit pubspec lock file
# (Library packages only! Remove pattern if developing an application package)
pubspec.lock
# Dont commit files and directories created by other development environments.
# For example, if your development environment creates any of the following files,
# consider putting them in a global ignore file:
# IntelliJ
*.iml
*.ipr
*.iws
.idea/
# Mac
.DS_Store

View File

@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

View File

@ -0,0 +1,23 @@
.gitignore
README.md
analysis_options.yaml
doc/Apple.md
doc/Banana.md
doc/DefaultApi.md
doc/Fruit.md
lib/openapi.dart
lib/src/api.dart
lib/src/api/default_api.dart
lib/src/api_util.dart
lib/src/auth/api_key_auth.dart
lib/src/auth/auth.dart
lib/src/auth/basic_auth.dart
lib/src/auth/bearer_auth.dart
lib/src/auth/oauth.dart
lib/src/date_serializer.dart
lib/src/model/apple.dart
lib/src/model/banana.dart
lib/src/model/date.dart
lib/src/model/fruit.dart
lib/src/serializers.dart
pubspec.yaml

View File

@ -0,0 +1 @@
6.1.0-SNAPSHOT

View File

@ -0,0 +1,84 @@
# openapi (EXPERIMENTAL)
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
This Dart package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
- API version: 0.0.1
- Build package: org.openapitools.codegen.languages.DartDioClientCodegen
## Requirements
* Dart 2.12.0 or later OR Flutter 1.26.0 or later
* Dio 4.0.0+
## Installation & Usage
### pub.dev
To use the package from [pub.dev](https://pub.dev), please include the following in pubspec.yaml
```yaml
dependencies:
openapi: 1.0.0
```
### Github
If this Dart package is published to Github, please include the following in pubspec.yaml
```yaml
dependencies:
openapi:
git:
url: https://github.com/GIT_USER_ID/GIT_REPO_ID.git
#ref: main
```
### Local development
To use the package from your local drive, please include the following in pubspec.yaml
```yaml
dependencies:
openapi:
path: /path/to/openapi
```
## Getting Started
Please follow the [installation procedure](#installation--usage) and then run the following:
```dart
import 'package:openapi/openapi.dart';
final api = Openapi().getDefaultApi();
try {
final response = await api.rootGet();
print(response);
} catch on DioError (e) {
print("Exception when calling DefaultApi->rootGet: $e\n");
}
```
## Documentation for API Endpoints
All URIs are relative to *http://localhost*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
[*DefaultApi*](doc/DefaultApi.md) | [**rootGet**](doc/DefaultApi.md#rootget) | **GET** / |
## Documentation For Models
- [Apple](doc/Apple.md)
- [Banana](doc/Banana.md)
- [Fruit](doc/Fruit.md)
## Documentation For Authorization
All endpoints do not require authorization.
## Author

View File

@ -0,0 +1,9 @@
analyzer:
language:
strict-inference: true
strict-raw-types: true
strong-mode:
implicit-dynamic: false
implicit-casts: false
exclude:
- test/*.dart

View File

@ -0,0 +1,15 @@
# openapi.model.Apple
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**kind** | **String** | | [optional]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,15 @@
# openapi.model.Banana
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**count** | **num** | | [optional]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,51 @@
# openapi.api.DefaultApi
## Load the API package
```dart
import 'package:openapi/api.dart';
```
All URIs are relative to *http://localhost*
Method | HTTP request | Description
------------- | ------------- | -------------
[**rootGet**](DefaultApi.md#rootget) | **GET** / |
# **rootGet**
> Fruit rootGet()
### Example
```dart
import 'package:openapi/api.dart';
final api = Openapi().getDefaultApi();
try {
final response = api.rootGet();
print(response);
} catch on DioError (e) {
print('Exception when calling DefaultApi->rootGet: $e\n');
}
```
### Parameters
This endpoint does not need any parameter.
### Return type
[**Fruit**](Fruit.md)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/json
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

View File

@ -0,0 +1,17 @@
# openapi.model.Fruit
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**color** | **String** | | [optional]
**kind** | **String** | | [optional]
**count** | **num** | | [optional]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,16 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
export 'package:openapi/src/api.dart';
export 'package:openapi/src/auth/api_key_auth.dart';
export 'package:openapi/src/auth/basic_auth.dart';
export 'package:openapi/src/auth/oauth.dart';
export 'package:openapi/src/serializers.dart';
export 'package:openapi/src/model/date.dart';
export 'package:openapi/src/api/default_api.dart';
export 'package:openapi/src/model/apple.dart';
export 'package:openapi/src/model/banana.dart';
export 'package:openapi/src/model/fruit.dart';

View File

@ -0,0 +1,73 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'package:dio/dio.dart';
import 'package:built_value/serializer.dart';
import 'package:openapi/src/serializers.dart';
import 'package:openapi/src/auth/api_key_auth.dart';
import 'package:openapi/src/auth/basic_auth.dart';
import 'package:openapi/src/auth/bearer_auth.dart';
import 'package:openapi/src/auth/oauth.dart';
import 'package:openapi/src/api/default_api.dart';
class Openapi {
static const String basePath = r'http://localhost';
final Dio dio;
final Serializers serializers;
Openapi({
Dio? dio,
Serializers? serializers,
String? basePathOverride,
List<Interceptor>? interceptors,
}) : this.serializers = serializers ?? standardSerializers,
this.dio = dio ??
Dio(BaseOptions(
baseUrl: basePathOverride ?? basePath,
connectTimeout: 5000,
receiveTimeout: 3000,
)) {
if (interceptors == null) {
this.dio.interceptors.addAll([
OAuthInterceptor(),
BasicAuthInterceptor(),
BearerAuthInterceptor(),
ApiKeyAuthInterceptor(),
]);
} else {
this.dio.interceptors.addAll(interceptors);
}
}
void setOAuthToken(String name, String token) {
if (this.dio.interceptors.any((i) => i is OAuthInterceptor)) {
(this.dio.interceptors.firstWhere((i) => i is OAuthInterceptor) as OAuthInterceptor).tokens[name] = token;
}
}
void setBearerAuth(String name, String token) {
if (this.dio.interceptors.any((i) => i is BearerAuthInterceptor)) {
(this.dio.interceptors.firstWhere((i) => i is BearerAuthInterceptor) as BearerAuthInterceptor).tokens[name] = token;
}
}
void setBasicAuth(String name, String username, String password) {
if (this.dio.interceptors.any((i) => i is BasicAuthInterceptor)) {
(this.dio.interceptors.firstWhere((i) => i is BasicAuthInterceptor) as BasicAuthInterceptor).authInfo[name] = BasicAuthInfo(username, password);
}
}
void setApiKey(String name, String apiKey) {
if (this.dio.interceptors.any((i) => i is ApiKeyAuthInterceptor)) {
(this.dio.interceptors.firstWhere((element) => element is ApiKeyAuthInterceptor) as ApiKeyAuthInterceptor).apiKeys[name] = apiKey;
}
}
/// Get DefaultApi instance, base route and serializer can be overridden by a given but be careful,
/// by doing that all interceptors will not be executed
DefaultApi getDefaultApi() {
return DefaultApi(dio, serializers);
}
}

View File

@ -0,0 +1,92 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'dart:async';
import 'package:built_value/serializer.dart';
import 'package:dio/dio.dart';
import 'package:openapi/src/model/fruit.dart';
class DefaultApi {
final Dio _dio;
final Serializers _serializers;
const DefaultApi(this._dio, this._serializers);
/// rootGet
///
///
/// Parameters:
/// * [cancelToken] - A [CancelToken] that can be used to cancel the operation
/// * [headers] - Can be used to add additional headers to the request
/// * [extras] - Can be used to add flags to the request
/// * [validateStatus] - A [ValidateStatus] callback that can be used to determine request success based on the HTTP status of the response
/// * [onSendProgress] - A [ProgressCallback] that can be used to get the send progress
/// * [onReceiveProgress] - A [ProgressCallback] that can be used to get the receive progress
///
/// Returns a [Future] containing a [Response] with a [Fruit] as data
/// Throws [DioError] if API call or serialization fails
Future<Response<Fruit>> rootGet({
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) async {
final _path = r'/';
final _options = Options(
method: r'GET',
headers: <String, dynamic>{
...?headers,
},
extra: <String, dynamic>{
'secure': <Map<String, String>>[],
...?extra,
},
validateStatus: validateStatus,
);
final _response = await _dio.request<Object>(
_path,
options: _options,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
Fruit _responseData;
try {
const _responseType = FullType(Fruit);
_responseData = _serializers.deserialize(
_response.data!,
specifiedType: _responseType,
) as Fruit;
} catch (error, stackTrace) {
throw DioError(
requestOptions: _response.requestOptions,
response: _response,
type: DioErrorType.other,
error: error,
)..stackTrace = stackTrace;
}
return Response<Fruit>(
data: _responseData,
headers: _response.headers,
isRedirect: _response.isRedirect,
requestOptions: _response.requestOptions,
redirects: _response.redirects,
statusCode: _response.statusCode,
statusMessage: _response.statusMessage,
extra: _response.extra,
);
}
}

View File

@ -0,0 +1,77 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'dart:convert';
import 'dart:typed_data';
import 'package:built_collection/built_collection.dart';
import 'package:built_value/serializer.dart';
import 'package:dio/dio.dart';
/// Format the given form parameter object into something that Dio can handle.
/// Returns primitive or String.
/// Returns List/Map if the value is BuildList/BuiltMap.
dynamic encodeFormParameter(Serializers serializers, dynamic value, FullType type) {
if (value == null) {
return '';
}
if (value is String || value is num || value is bool) {
return value;
}
final serialized = serializers.serialize(
value as Object,
specifiedType: type,
);
if (serialized is String) {
return serialized;
}
if (value is BuiltList || value is BuiltSet || value is BuiltMap) {
return serialized;
}
return json.encode(serialized);
}
dynamic encodeQueryParameter(
Serializers serializers,
dynamic value,
FullType type,
) {
if (value == null) {
return '';
}
if (value is String || value is num || value is bool) {
return value;
}
if (value is Uint8List) {
// Currently not sure how to serialize this
return value;
}
final serialized = serializers.serialize(
value as Object,
specifiedType: type,
);
if (serialized == null) {
return '';
}
if (serialized is String) {
return serialized;
}
return serialized;
}
ListParam<Object?> encodeCollectionQueryParameter<T>(
Serializers serializers,
dynamic value,
FullType type, {
ListFormat format = ListFormat.multi,
}) {
final serialized = serializers.serialize(
value as Object,
specifiedType: type,
);
if (value is BuiltList<T> || value is BuiltSet<T>) {
return ListParam(List.of((serialized as Iterable<Object?>).cast()), format);
}
throw ArgumentError('Invalid value passed to encodeCollectionQueryParameter');
}

View File

@ -0,0 +1,30 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'package:dio/dio.dart';
import 'package:openapi/src/auth/auth.dart';
class ApiKeyAuthInterceptor extends AuthInterceptor {
final Map<String, String> apiKeys = {};
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
final authInfo = getAuthInfo(options, (secure) => secure['type'] == 'apiKey');
for (final info in authInfo) {
final authName = info['name'] as String;
final authKeyName = info['keyName'] as String;
final authWhere = info['where'] as String;
final apiKey = apiKeys[authName];
if (apiKey != null) {
if (authWhere == 'query') {
options.queryParameters[authKeyName] = apiKey;
} else {
options.headers[authKeyName] = apiKey;
}
}
}
super.onRequest(options, handler);
}
}

View File

@ -0,0 +1,18 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'package:dio/dio.dart';
abstract class AuthInterceptor extends Interceptor {
/// Get auth information on given route for the given type.
/// Can return an empty list if type is not present on auth data or
/// if route doesn't need authentication.
List<Map<String, String>> getAuthInfo(RequestOptions route, bool Function(Map<String, String> secure) handles) {
if (route.extra.containsKey('secure')) {
final auth = route.extra['secure'] as List<Map<String, String>>;
return auth.where((secure) => handles(secure)).toList();
}
return [];
}
}

View File

@ -0,0 +1,37 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:openapi/src/auth/auth.dart';
class BasicAuthInfo {
final String username;
final String password;
const BasicAuthInfo(this.username, this.password);
}
class BasicAuthInterceptor extends AuthInterceptor {
final Map<String, BasicAuthInfo> authInfo = {};
@override
void onRequest(
RequestOptions options,
RequestInterceptorHandler handler,
) {
final metadataAuthInfo = getAuthInfo(options, (secure) => (secure['type'] == 'http' && secure['scheme'] == 'basic') || secure['type'] == 'basic');
for (final info in metadataAuthInfo) {
final authName = info['name'] as String;
final basicAuthInfo = authInfo[authName];
if (basicAuthInfo != null) {
final basicAuth = 'Basic ${base64Encode(utf8.encode('${basicAuthInfo.username}:${basicAuthInfo.password}'))}';
options.headers['Authorization'] = basicAuth;
break;
}
}
super.onRequest(options, handler);
}
}

View File

@ -0,0 +1,26 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'package:dio/dio.dart';
import 'package:openapi/src/auth/auth.dart';
class BearerAuthInterceptor extends AuthInterceptor {
final Map<String, String> tokens = {};
@override
void onRequest(
RequestOptions options,
RequestInterceptorHandler handler,
) {
final authInfo = getAuthInfo(options, (secure) => secure['type'] == 'http' && secure['scheme'] == 'bearer');
for (final info in authInfo) {
final token = tokens[info['name']];
if (token != null) {
options.headers['Authorization'] = 'Bearer ${token}';
break;
}
}
super.onRequest(options, handler);
}
}

View File

@ -0,0 +1,26 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'package:dio/dio.dart';
import 'package:openapi/src/auth/auth.dart';
class OAuthInterceptor extends AuthInterceptor {
final Map<String, String> tokens = {};
@override
void onRequest(
RequestOptions options,
RequestInterceptorHandler handler,
) {
final authInfo = getAuthInfo(options, (secure) => secure['type'] == 'oauth' || secure['type'] == 'oauth2');
for (final info in authInfo) {
final token = tokens[info['name']];
if (token != null) {
options.headers['Authorization'] = 'Bearer ${token}';
break;
}
}
super.onRequest(options, handler);
}
}

View File

@ -0,0 +1,31 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'package:built_collection/built_collection.dart';
import 'package:built_value/serializer.dart';
import 'package:openapi/src/model/date.dart';
class DateSerializer implements PrimitiveSerializer<Date> {
const DateSerializer();
@override
Iterable<Type> get types => BuiltList.of([Date]);
@override
String get wireName => 'Date';
@override
Date deserialize(Serializers serializers, Object serialized,
{FullType specifiedType = FullType.unspecified}) {
final parsed = DateTime.parse(serialized as String);
return Date(parsed.year, parsed.month, parsed.day);
}
@override
Object serialize(Serializers serializers, Date date,
{FullType specifiedType = FullType.unspecified}) {
return date.toString();
}
}

View File

@ -0,0 +1,108 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'apple.g.dart';
/// Apple
///
/// Properties:
/// * [kind]
@BuiltValue()
abstract class Apple implements Built<Apple, AppleBuilder> {
@BuiltValueField(wireName: r'kind')
String? get kind;
Apple._();
factory Apple([void updates(AppleBuilder b)]) = _$Apple;
@BuiltValueHook(initializeBuilder: true)
static void _defaults(AppleBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<Apple> get serializer => _$AppleSerializer();
}
class _$AppleSerializer implements PrimitiveSerializer<Apple> {
@override
final Iterable<Type> types = const [Apple, _$Apple];
@override
final String wireName = r'Apple';
Iterable<Object?> _serializeProperties(
Serializers serializers,
Apple object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
if (object.kind != null) {
yield r'kind';
yield serializers.serialize(
object.kind,
specifiedType: const FullType(String),
);
}
}
@override
Object serialize(
Serializers serializers,
Apple object, {
FullType specifiedType = FullType.unspecified,
}) {
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
}
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required AppleBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'kind':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.kind = valueDes;
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
@override
Apple deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = AppleBuilder();
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
return result.build();
}
}

View File

@ -0,0 +1,108 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'banana.g.dart';
/// Banana
///
/// Properties:
/// * [count]
@BuiltValue()
abstract class Banana implements Built<Banana, BananaBuilder> {
@BuiltValueField(wireName: r'count')
num? get count;
Banana._();
factory Banana([void updates(BananaBuilder b)]) = _$Banana;
@BuiltValueHook(initializeBuilder: true)
static void _defaults(BananaBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<Banana> get serializer => _$BananaSerializer();
}
class _$BananaSerializer implements PrimitiveSerializer<Banana> {
@override
final Iterable<Type> types = const [Banana, _$Banana];
@override
final String wireName = r'Banana';
Iterable<Object?> _serializeProperties(
Serializers serializers,
Banana object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
if (object.count != null) {
yield r'count';
yield serializers.serialize(
object.count,
specifiedType: const FullType(num),
);
}
}
@override
Object serialize(
Serializers serializers,
Banana object, {
FullType specifiedType = FullType.unspecified,
}) {
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
}
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required BananaBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'count':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(num),
) as num;
result.count = valueDes;
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
@override
Banana deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = BananaBuilder();
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
return result.build();
}
}

View File

@ -0,0 +1,70 @@
/// A gregorian calendar date generated by
/// OpenAPI generator to differentiate
/// between [DateTime] and [Date] formats.
class Date implements Comparable<Date> {
final int year;
/// January is 1.
final int month;
/// First day is 1.
final int day;
Date(this.year, this.month, this.day);
/// The current date
static Date now({bool utc = false}) {
var now = DateTime.now();
if (utc) {
now = now.toUtc();
}
return now.toDate();
}
/// Convert to a [DateTime].
DateTime toDateTime({bool utc = false}) {
if (utc) {
return DateTime.utc(year, month, day);
} else {
return DateTime(year, month, day);
}
}
@override
int compareTo(Date other) {
int d = year.compareTo(other.year);
if (d != 0) {
return d;
}
d = month.compareTo(other.month);
if (d != 0) {
return d;
}
return day.compareTo(other.day);
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Date &&
runtimeType == other.runtimeType &&
year == other.year &&
month == other.month &&
day == other.day;
@override
int get hashCode => year.hashCode ^ month.hashCode ^ day.hashCode;
@override
String toString() {
final yyyy = year.toString();
final mm = month.toString().padLeft(2, '0');
final dd = day.toString().padLeft(2, '0');
return '$yyyy-$mm-$dd';
}
}
extension DateTimeToDate on DateTime {
Date toDate() => Date(year, month, day);
}

View File

@ -0,0 +1,123 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:openapi/src/model/apple.dart';
import 'package:openapi/src/model/banana.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:one_of/one_of.dart';
part 'fruit.g.dart';
/// Fruit
///
/// Properties:
/// * [color]
/// * [kind]
/// * [count]
@BuiltValue()
abstract class Fruit implements Built<Fruit, FruitBuilder> {
@BuiltValueField(wireName: r'color')
String? get color;
/// One Of [Apple], [Banana]
OneOf get oneOf;
Fruit._();
factory Fruit([void updates(FruitBuilder b)]) = _$Fruit;
@BuiltValueHook(initializeBuilder: true)
static void _defaults(FruitBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<Fruit> get serializer => _$FruitSerializer();
}
class _$FruitSerializer implements PrimitiveSerializer<Fruit> {
@override
final Iterable<Type> types = const [Fruit, _$Fruit];
@override
final String wireName = r'Fruit';
Iterable<Object?> _serializeProperties(
Serializers serializers,
Fruit object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
if (object.color != null) {
yield r'color';
yield serializers.serialize(
object.color,
specifiedType: const FullType(String),
);
}
}
@override
Object serialize(
Serializers serializers,
Fruit object, {
FullType specifiedType = FullType.unspecified,
}) {
final oneOf = object.oneOf;
final result = _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
result.addAll(serializers.serialize(oneOf.value, specifiedType: FullType(oneOf.valueType)) as Iterable<Object?>);
return result;
}
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required FruitBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'color':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.color = valueDes;
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
@override
Fruit deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = FruitBuilder();
Object? oneOfDataSrc;
final targetType = const FullType(OneOf, [FullType(Apple), FullType(Banana), ]);
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
oneOfDataSrc = unhandled;
result.oneOf = serializers.deserialize(oneOfDataSrc, specifiedType: targetType) as OneOf;
return result.build();
}
}

View File

@ -0,0 +1,36 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_import
import 'package:one_of_serializer/any_of_serializer.dart';
import 'package:one_of_serializer/one_of_serializer.dart';
import 'package:built_collection/built_collection.dart';
import 'package:built_value/json_object.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:built_value/iso_8601_date_time_serializer.dart';
import 'package:openapi/src/date_serializer.dart';
import 'package:openapi/src/model/date.dart';
import 'package:openapi/src/model/apple.dart';
import 'package:openapi/src/model/banana.dart';
import 'package:openapi/src/model/fruit.dart';
part 'serializers.g.dart';
@SerializersFor([
Apple,
Banana,
Fruit,
])
Serializers serializers = (_$serializers.toBuilder()
..add(const OneOfSerializer())
..add(const AnyOfSerializer())
..add(const DateSerializer())
..add(Iso8601DateTimeSerializer()))
.build();
Serializers standardSerializers =
(serializers.toBuilder()..addPlugin(StandardJsonPlugin())).build();

View File

@ -0,0 +1,88 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.openapitools</groupId>
<artifactId>DartDioOneOf</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>DartDio OneOf</name>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>pub-get</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>pub</executable>
<arguments>
<argument>get</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>pub-run-build-runner</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>pub</executable>
<arguments>
<argument>run</argument>
<argument>build_runner</argument>
<argument>build</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>dart-analyze</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>dart</executable>
<arguments>
<argument>analyze</argument>
<argument>--fatal-infos</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>dart-test</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>dart</executable>
<arguments>
<argument>test</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,19 @@
name: openapi
version: 1.0.0
description: OpenAPI API client
homepage: homepage
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
dio: '>=4.0.1 <5.0.0'
one_of: '>=1.5.0 <2.0.0'
one_of_serializer: '>=1.5.0 <2.0.0'
built_value: '>=8.4.0 <9.0.0'
built_collection: '>=5.1.1 <6.0.0'
dev_dependencies:
built_value_generator: '>=8.4.0 <9.0.0'
build_runner: any
test: ^1.16.0

View File

@ -0,0 +1,16 @@
import 'package:test/test.dart';
import 'package:openapi/openapi.dart';
// tests for Apple
void main() {
final instance = AppleBuilder();
// TODO add properties to the builder and call build()
group(Apple, () {
// String kind
test('to test the property `kind`', () async {
// TODO
});
});
}

View File

@ -0,0 +1,16 @@
import 'package:test/test.dart';
import 'package:openapi/openapi.dart';
// tests for Banana
void main() {
final instance = BananaBuilder();
// TODO add properties to the builder and call build()
group(Banana, () {
// num count
test('to test the property `count`', () async {
// TODO
});
});
}

View File

@ -0,0 +1,16 @@
import 'package:test/test.dart';
import 'package:openapi/openapi.dart';
/// tests for DefaultApi
void main() {
final instance = Openapi().getDefaultApi();
group(DefaultApi, () {
//Future<Fruit> rootGet() async
test('test rootGet', () async {
// TODO
});
});
}

View File

@ -0,0 +1,26 @@
import 'package:test/test.dart';
import 'package:openapi/openapi.dart';
// tests for Fruit
void main() {
final instance = FruitBuilder();
// TODO add properties to the builder and call build()
group(Fruit, () {
// String color
test('to test the property `color`', () async {
// TODO
});
// String kind
test('to test the property `kind`', () async {
// TODO
});
// num count
test('to test the property `count`', () async {
// TODO
});
});
}

View File

@ -0,0 +1,41 @@
# See https://dart.dev/guides/libraries/private-files
# Files and directories created by pub
.dart_tool/
.buildlog
.packages
.project
.pub/
build/
**/packages/
# Files created by dart2js
# (Most Dart developers will use pub build to compile Dart, use/modify these
# rules if you intend to use dart2js directly
# Convention is to use extension '.dart.js' for Dart compiled to Javascript to
# differentiate from explicit Javascript files)
*.dart.js
*.part.js
*.js.deps
*.js.map
*.info.json
# Directory created by dartdoc
doc/api/
# Don't commit pubspec lock file
# (Library packages only! Remove pattern if developing an application package)
pubspec.lock
# Dont commit files and directories created by other development environments.
# For example, if your development environment creates any of the following files,
# consider putting them in a global ignore file:
# IntelliJ
*.iml
*.ipr
*.iws
.idea/
# Mac
.DS_Store

View File

@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

View File

@ -0,0 +1,47 @@
.gitignore
README.md
analysis_options.yaml
doc/Addressable.md
doc/Bar.md
doc/BarApi.md
doc/BarCreate.md
doc/BarRef.md
doc/BarRefOrValue.md
doc/Entity.md
doc/EntityRef.md
doc/Extensible.md
doc/Foo.md
doc/FooApi.md
doc/FooRef.md
doc/FooRefOrValue.md
doc/Pasta.md
doc/Pizza.md
doc/PizzaSpeziale.md
lib/openapi.dart
lib/src/api.dart
lib/src/api/bar_api.dart
lib/src/api/foo_api.dart
lib/src/api_util.dart
lib/src/auth/api_key_auth.dart
lib/src/auth/auth.dart
lib/src/auth/basic_auth.dart
lib/src/auth/bearer_auth.dart
lib/src/auth/oauth.dart
lib/src/date_serializer.dart
lib/src/model/addressable.dart
lib/src/model/bar.dart
lib/src/model/bar_create.dart
lib/src/model/bar_ref.dart
lib/src/model/bar_ref_or_value.dart
lib/src/model/date.dart
lib/src/model/entity.dart
lib/src/model/entity_ref.dart
lib/src/model/extensible.dart
lib/src/model/foo.dart
lib/src/model/foo_ref.dart
lib/src/model/foo_ref_or_value.dart
lib/src/model/pasta.dart
lib/src/model/pizza.dart
lib/src/model/pizza_speziale.dart
lib/src/serializers.dart
pubspec.yaml

View File

@ -0,0 +1,99 @@
# openapi (EXPERIMENTAL)
This tests for a oneOf interface representation
This Dart package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
- API version: 0.0.1
- Build package: org.openapitools.codegen.languages.DartDioClientCodegen
## Requirements
* Dart 2.12.0 or later OR Flutter 1.26.0 or later
* Dio 4.0.0+
## Installation & Usage
### pub.dev
To use the package from [pub.dev](https://pub.dev), please include the following in pubspec.yaml
```yaml
dependencies:
openapi: 1.0.0
```
### Github
If this Dart package is published to Github, please include the following in pubspec.yaml
```yaml
dependencies:
openapi:
git:
url: https://github.com/GIT_USER_ID/GIT_REPO_ID.git
#ref: main
```
### Local development
To use the package from your local drive, please include the following in pubspec.yaml
```yaml
dependencies:
openapi:
path: /path/to/openapi
```
## Getting Started
Please follow the [installation procedure](#installation--usage) and then run the following:
```dart
import 'package:openapi/openapi.dart';
final api = Openapi().getBarApi();
final BarCreate barCreate = ; // BarCreate |
try {
final response = await api.createBar(barCreate);
print(response);
} catch on DioError (e) {
print("Exception when calling BarApi->createBar: $e\n");
}
```
## Documentation for API Endpoints
All URIs are relative to *http://localhost:8080*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
[*BarApi*](doc/BarApi.md) | [**createBar**](doc/BarApi.md#createbar) | **POST** /bar | Create a Bar
[*FooApi*](doc/FooApi.md) | [**createFoo**](doc/FooApi.md#createfoo) | **POST** /foo | Create a Foo
[*FooApi*](doc/FooApi.md) | [**getAllFoos**](doc/FooApi.md#getallfoos) | **GET** /foo | GET all Foos
## Documentation For Models
- [Addressable](doc/Addressable.md)
- [Bar](doc/Bar.md)
- [BarCreate](doc/BarCreate.md)
- [BarRef](doc/BarRef.md)
- [BarRefOrValue](doc/BarRefOrValue.md)
- [Entity](doc/Entity.md)
- [EntityRef](doc/EntityRef.md)
- [Extensible](doc/Extensible.md)
- [Foo](doc/Foo.md)
- [FooRef](doc/FooRef.md)
- [FooRefOrValue](doc/FooRefOrValue.md)
- [Pasta](doc/Pasta.md)
- [Pizza](doc/Pizza.md)
- [PizzaSpeziale](doc/PizzaSpeziale.md)
## Documentation For Authorization
All endpoints do not require authorization.
## Author

View File

@ -0,0 +1,9 @@
analyzer:
language:
strict-inference: true
strict-raw-types: true
strong-mode:
implicit-dynamic: false
implicit-casts: false
exclude:
- test/*.dart

View File

@ -0,0 +1,16 @@
# openapi.model.Addressable
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,22 @@
# openapi.model.Bar
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **String** | |
**barPropA** | **String** | | [optional]
**fooPropB** | **String** | | [optional]
**foo** | [**FooRefOrValue**](FooRefOrValue.md) | | [optional]
**href** | **String** | Hyperlink reference | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,55 @@
# openapi.api.BarApi
## Load the API package
```dart
import 'package:openapi/api.dart';
```
All URIs are relative to *http://localhost:8080*
Method | HTTP request | Description
------------- | ------------- | -------------
[**createBar**](BarApi.md#createbar) | **POST** /bar | Create a Bar
# **createBar**
> Bar createBar(barCreate)
Create a Bar
### Example
```dart
import 'package:openapi/api.dart';
final api = Openapi().getBarApi();
final BarCreate barCreate = ; // BarCreate |
try {
final response = api.createBar(barCreate);
print(response);
} catch on DioError (e) {
print('Exception when calling BarApi->createBar: $e\n');
}
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**barCreate** | [**BarCreate**](BarCreate.md)| |
### Return type
[**Bar**](Bar.md)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: application/json
- **Accept**: application/json
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

View File

@ -0,0 +1,22 @@
# openapi.model.BarCreate
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**barPropA** | **String** | | [optional]
**fooPropB** | **String** | | [optional]
**foo** | [**FooRefOrValue**](FooRefOrValue.md) | | [optional]
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,19 @@
# openapi.model.BarRef
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,19 @@
# openapi.model.BarRefOrValue
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier |
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,19 @@
# openapi.model.Entity
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,21 @@
# openapi.model.EntityRef
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **String** | Name of the related entity. | [optional]
**atReferredType** | **String** | The actual type of the target instance when needed for disambiguation. | [optional]
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,17 @@
# openapi.model.Extensible
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,21 @@
# openapi.model.Foo
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**fooPropA** | **String** | | [optional]
**fooPropB** | **String** | | [optional]
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,93 @@
# openapi.api.FooApi
## Load the API package
```dart
import 'package:openapi/api.dart';
```
All URIs are relative to *http://localhost:8080*
Method | HTTP request | Description
------------- | ------------- | -------------
[**createFoo**](FooApi.md#createfoo) | **POST** /foo | Create a Foo
[**getAllFoos**](FooApi.md#getallfoos) | **GET** /foo | GET all Foos
# **createFoo**
> FooRefOrValue createFoo(foo)
Create a Foo
### Example
```dart
import 'package:openapi/api.dart';
final api = Openapi().getFooApi();
final Foo foo = ; // Foo | The Foo to be created
try {
final response = api.createFoo(foo);
print(response);
} catch on DioError (e) {
print('Exception when calling FooApi->createFoo: $e\n');
}
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**foo** | [**Foo**](Foo.md)| The Foo to be created | [optional]
### Return type
[**FooRefOrValue**](FooRefOrValue.md)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: application/json;charset=utf-8
- **Accept**: application/json
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **getAllFoos**
> BuiltList<FooRefOrValue> getAllFoos()
GET all Foos
### Example
```dart
import 'package:openapi/api.dart';
final api = Openapi().getFooApi();
try {
final response = api.getAllFoos();
print(response);
} catch on DioError (e) {
print('Exception when calling FooApi->getAllFoos: $e\n');
}
```
### Parameters
This endpoint does not need any parameter.
### Return type
[**BuiltList&lt;FooRefOrValue&gt;**](FooRefOrValue.md)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/json;charset=utf-8
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

View File

@ -0,0 +1,20 @@
# openapi.model.FooRef
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**foorefPropA** | **String** | | [optional]
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,19 @@
# openapi.model.FooRefOrValue
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,19 @@
# openapi.model.FooRefOrValueWithProperties
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,20 @@
# openapi.model.Pasta
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**vendor** | **String** | | [optional]
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,20 @@
# openapi.model.Pizza
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**pizzaSize** | **num** | | [optional]
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,20 @@
# openapi.model.PizzaSpeziale
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**toppings** | **String** | | [optional]
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,28 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
export 'package:openapi/src/api.dart';
export 'package:openapi/src/auth/api_key_auth.dart';
export 'package:openapi/src/auth/basic_auth.dart';
export 'package:openapi/src/auth/oauth.dart';
export 'package:openapi/src/serializers.dart';
export 'package:openapi/src/model/date.dart';
export 'package:openapi/src/api/bar_api.dart';
export 'package:openapi/src/api/foo_api.dart';
export 'package:openapi/src/model/addressable.dart';
export 'package:openapi/src/model/bar.dart';
export 'package:openapi/src/model/bar_create.dart';
export 'package:openapi/src/model/bar_ref.dart';
export 'package:openapi/src/model/bar_ref_or_value.dart';
export 'package:openapi/src/model/entity.dart';
export 'package:openapi/src/model/entity_ref.dart';
export 'package:openapi/src/model/extensible.dart';
export 'package:openapi/src/model/foo.dart';
export 'package:openapi/src/model/foo_ref.dart';
export 'package:openapi/src/model/foo_ref_or_value.dart';
export 'package:openapi/src/model/pasta.dart';
export 'package:openapi/src/model/pizza.dart';
export 'package:openapi/src/model/pizza_speziale.dart';

View File

@ -0,0 +1,80 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'package:dio/dio.dart';
import 'package:built_value/serializer.dart';
import 'package:openapi/src/serializers.dart';
import 'package:openapi/src/auth/api_key_auth.dart';
import 'package:openapi/src/auth/basic_auth.dart';
import 'package:openapi/src/auth/bearer_auth.dart';
import 'package:openapi/src/auth/oauth.dart';
import 'package:openapi/src/api/bar_api.dart';
import 'package:openapi/src/api/foo_api.dart';
class Openapi {
static const String basePath = r'http://localhost:8080';
final Dio dio;
final Serializers serializers;
Openapi({
Dio? dio,
Serializers? serializers,
String? basePathOverride,
List<Interceptor>? interceptors,
}) : this.serializers = serializers ?? standardSerializers,
this.dio = dio ??
Dio(BaseOptions(
baseUrl: basePathOverride ?? basePath,
connectTimeout: 5000,
receiveTimeout: 3000,
)) {
if (interceptors == null) {
this.dio.interceptors.addAll([
OAuthInterceptor(),
BasicAuthInterceptor(),
BearerAuthInterceptor(),
ApiKeyAuthInterceptor(),
]);
} else {
this.dio.interceptors.addAll(interceptors);
}
}
void setOAuthToken(String name, String token) {
if (this.dio.interceptors.any((i) => i is OAuthInterceptor)) {
(this.dio.interceptors.firstWhere((i) => i is OAuthInterceptor) as OAuthInterceptor).tokens[name] = token;
}
}
void setBearerAuth(String name, String token) {
if (this.dio.interceptors.any((i) => i is BearerAuthInterceptor)) {
(this.dio.interceptors.firstWhere((i) => i is BearerAuthInterceptor) as BearerAuthInterceptor).tokens[name] = token;
}
}
void setBasicAuth(String name, String username, String password) {
if (this.dio.interceptors.any((i) => i is BasicAuthInterceptor)) {
(this.dio.interceptors.firstWhere((i) => i is BasicAuthInterceptor) as BasicAuthInterceptor).authInfo[name] = BasicAuthInfo(username, password);
}
}
void setApiKey(String name, String apiKey) {
if (this.dio.interceptors.any((i) => i is ApiKeyAuthInterceptor)) {
(this.dio.interceptors.firstWhere((element) => element is ApiKeyAuthInterceptor) as ApiKeyAuthInterceptor).apiKeys[name] = apiKey;
}
}
/// Get BarApi instance, base route and serializer can be overridden by a given but be careful,
/// by doing that all interceptors will not be executed
BarApi getBarApi() {
return BarApi(dio, serializers);
}
/// Get FooApi instance, base route and serializer can be overridden by a given but be careful,
/// by doing that all interceptors will not be executed
FooApi getFooApi() {
return FooApi(dio, serializers);
}
}

View File

@ -0,0 +1,114 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'dart:async';
import 'package:built_value/serializer.dart';
import 'package:dio/dio.dart';
import 'package:openapi/src/model/bar.dart';
import 'package:openapi/src/model/bar_create.dart';
class BarApi {
final Dio _dio;
final Serializers _serializers;
const BarApi(this._dio, this._serializers);
/// Create a Bar
///
///
/// Parameters:
/// * [barCreate]
/// * [cancelToken] - A [CancelToken] that can be used to cancel the operation
/// * [headers] - Can be used to add additional headers to the request
/// * [extras] - Can be used to add flags to the request
/// * [validateStatus] - A [ValidateStatus] callback that can be used to determine request success based on the HTTP status of the response
/// * [onSendProgress] - A [ProgressCallback] that can be used to get the send progress
/// * [onReceiveProgress] - A [ProgressCallback] that can be used to get the receive progress
///
/// Returns a [Future] containing a [Response] with a [Bar] as data
/// Throws [DioError] if API call or serialization fails
Future<Response<Bar>> createBar({
required BarCreate barCreate,
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) async {
final _path = r'/bar';
final _options = Options(
method: r'POST',
headers: <String, dynamic>{
...?headers,
},
extra: <String, dynamic>{
'secure': <Map<String, String>>[],
...?extra,
},
contentType: 'application/json',
validateStatus: validateStatus,
);
dynamic _bodyData;
try {
const _type = FullType(BarCreate);
_bodyData = _serializers.serialize(barCreate, specifiedType: _type);
} catch(error, stackTrace) {
throw DioError(
requestOptions: _options.compose(
_dio.options,
_path,
),
type: DioErrorType.other,
error: error,
)..stackTrace = stackTrace;
}
final _response = await _dio.request<Object>(
_path,
data: _bodyData,
options: _options,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
Bar _responseData;
try {
const _responseType = FullType(Bar);
_responseData = _serializers.deserialize(
_response.data!,
specifiedType: _responseType,
) as Bar;
} catch (error, stackTrace) {
throw DioError(
requestOptions: _response.requestOptions,
response: _response,
type: DioErrorType.other,
error: error,
)..stackTrace = stackTrace;
}
return Response<Bar>(
data: _responseData,
headers: _response.headers,
isRedirect: _response.isRedirect,
requestOptions: _response.requestOptions,
redirects: _response.redirects,
statusCode: _response.statusCode,
statusMessage: _response.statusMessage,
extra: _response.extra,
);
}
}

View File

@ -0,0 +1,187 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'dart:async';
import 'package:built_value/serializer.dart';
import 'package:dio/dio.dart';
import 'package:built_collection/built_collection.dart';
import 'package:openapi/src/model/foo.dart';
import 'package:openapi/src/model/foo_ref_or_value.dart';
class FooApi {
final Dio _dio;
final Serializers _serializers;
const FooApi(this._dio, this._serializers);
/// Create a Foo
///
///
/// Parameters:
/// * [foo] - The Foo to be created
/// * [cancelToken] - A [CancelToken] that can be used to cancel the operation
/// * [headers] - Can be used to add additional headers to the request
/// * [extras] - Can be used to add flags to the request
/// * [validateStatus] - A [ValidateStatus] callback that can be used to determine request success based on the HTTP status of the response
/// * [onSendProgress] - A [ProgressCallback] that can be used to get the send progress
/// * [onReceiveProgress] - A [ProgressCallback] that can be used to get the receive progress
///
/// Returns a [Future] containing a [Response] with a [FooRefOrValue] as data
/// Throws [DioError] if API call or serialization fails
Future<Response<FooRefOrValue>> createFoo({
Foo? foo,
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) async {
final _path = r'/foo';
final _options = Options(
method: r'POST',
headers: <String, dynamic>{
...?headers,
},
extra: <String, dynamic>{
'secure': <Map<String, String>>[],
...?extra,
},
contentType: 'application/json;charset=utf-8',
validateStatus: validateStatus,
);
dynamic _bodyData;
try {
const _type = FullType(Foo);
_bodyData = foo == null ? null : _serializers.serialize(foo, specifiedType: _type);
} catch(error, stackTrace) {
throw DioError(
requestOptions: _options.compose(
_dio.options,
_path,
),
type: DioErrorType.other,
error: error,
)..stackTrace = stackTrace;
}
final _response = await _dio.request<Object>(
_path,
data: _bodyData,
options: _options,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
FooRefOrValue _responseData;
try {
const _responseType = FullType(FooRefOrValue);
_responseData = _serializers.deserialize(
_response.data!,
specifiedType: _responseType,
) as FooRefOrValue;
} catch (error, stackTrace) {
throw DioError(
requestOptions: _response.requestOptions,
response: _response,
type: DioErrorType.other,
error: error,
)..stackTrace = stackTrace;
}
return Response<FooRefOrValue>(
data: _responseData,
headers: _response.headers,
isRedirect: _response.isRedirect,
requestOptions: _response.requestOptions,
redirects: _response.redirects,
statusCode: _response.statusCode,
statusMessage: _response.statusMessage,
extra: _response.extra,
);
}
/// GET all Foos
///
///
/// Parameters:
/// * [cancelToken] - A [CancelToken] that can be used to cancel the operation
/// * [headers] - Can be used to add additional headers to the request
/// * [extras] - Can be used to add flags to the request
/// * [validateStatus] - A [ValidateStatus] callback that can be used to determine request success based on the HTTP status of the response
/// * [onSendProgress] - A [ProgressCallback] that can be used to get the send progress
/// * [onReceiveProgress] - A [ProgressCallback] that can be used to get the receive progress
///
/// Returns a [Future] containing a [Response] with a [BuiltList<FooRefOrValue>] as data
/// Throws [DioError] if API call or serialization fails
Future<Response<BuiltList<FooRefOrValue>>> getAllFoos({
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) async {
final _path = r'/foo';
final _options = Options(
method: r'GET',
headers: <String, dynamic>{
...?headers,
},
extra: <String, dynamic>{
'secure': <Map<String, String>>[],
...?extra,
},
validateStatus: validateStatus,
);
final _response = await _dio.request<Object>(
_path,
options: _options,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
BuiltList<FooRefOrValue> _responseData;
try {
const _responseType = FullType(BuiltList, [FullType(FooRefOrValue)]);
_responseData = _serializers.deserialize(
_response.data!,
specifiedType: _responseType,
) as BuiltList<FooRefOrValue>;
} catch (error, stackTrace) {
throw DioError(
requestOptions: _response.requestOptions,
response: _response,
type: DioErrorType.other,
error: error,
)..stackTrace = stackTrace;
}
return Response<BuiltList<FooRefOrValue>>(
data: _responseData,
headers: _response.headers,
isRedirect: _response.isRedirect,
requestOptions: _response.requestOptions,
redirects: _response.redirects,
statusCode: _response.statusCode,
statusMessage: _response.statusMessage,
extra: _response.extra,
);
}
}

View File

@ -0,0 +1,77 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'dart:convert';
import 'dart:typed_data';
import 'package:built_collection/built_collection.dart';
import 'package:built_value/serializer.dart';
import 'package:dio/dio.dart';
/// Format the given form parameter object into something that Dio can handle.
/// Returns primitive or String.
/// Returns List/Map if the value is BuildList/BuiltMap.
dynamic encodeFormParameter(Serializers serializers, dynamic value, FullType type) {
if (value == null) {
return '';
}
if (value is String || value is num || value is bool) {
return value;
}
final serialized = serializers.serialize(
value as Object,
specifiedType: type,
);
if (serialized is String) {
return serialized;
}
if (value is BuiltList || value is BuiltSet || value is BuiltMap) {
return serialized;
}
return json.encode(serialized);
}
dynamic encodeQueryParameter(
Serializers serializers,
dynamic value,
FullType type,
) {
if (value == null) {
return '';
}
if (value is String || value is num || value is bool) {
return value;
}
if (value is Uint8List) {
// Currently not sure how to serialize this
return value;
}
final serialized = serializers.serialize(
value as Object,
specifiedType: type,
);
if (serialized == null) {
return '';
}
if (serialized is String) {
return serialized;
}
return serialized;
}
ListParam<Object?> encodeCollectionQueryParameter<T>(
Serializers serializers,
dynamic value,
FullType type, {
ListFormat format = ListFormat.multi,
}) {
final serialized = serializers.serialize(
value as Object,
specifiedType: type,
);
if (value is BuiltList<T> || value is BuiltSet<T>) {
return ListParam(List.of((serialized as Iterable<Object?>).cast()), format);
}
throw ArgumentError('Invalid value passed to encodeCollectionQueryParameter');
}

View File

@ -0,0 +1,30 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'package:dio/dio.dart';
import 'package:openapi/src/auth/auth.dart';
class ApiKeyAuthInterceptor extends AuthInterceptor {
final Map<String, String> apiKeys = {};
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
final authInfo = getAuthInfo(options, (secure) => secure['type'] == 'apiKey');
for (final info in authInfo) {
final authName = info['name'] as String;
final authKeyName = info['keyName'] as String;
final authWhere = info['where'] as String;
final apiKey = apiKeys[authName];
if (apiKey != null) {
if (authWhere == 'query') {
options.queryParameters[authKeyName] = apiKey;
} else {
options.headers[authKeyName] = apiKey;
}
}
}
super.onRequest(options, handler);
}
}

View File

@ -0,0 +1,18 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'package:dio/dio.dart';
abstract class AuthInterceptor extends Interceptor {
/// Get auth information on given route for the given type.
/// Can return an empty list if type is not present on auth data or
/// if route doesn't need authentication.
List<Map<String, String>> getAuthInfo(RequestOptions route, bool Function(Map<String, String> secure) handles) {
if (route.extra.containsKey('secure')) {
final auth = route.extra['secure'] as List<Map<String, String>>;
return auth.where((secure) => handles(secure)).toList();
}
return [];
}
}

View File

@ -0,0 +1,37 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:openapi/src/auth/auth.dart';
class BasicAuthInfo {
final String username;
final String password;
const BasicAuthInfo(this.username, this.password);
}
class BasicAuthInterceptor extends AuthInterceptor {
final Map<String, BasicAuthInfo> authInfo = {};
@override
void onRequest(
RequestOptions options,
RequestInterceptorHandler handler,
) {
final metadataAuthInfo = getAuthInfo(options, (secure) => (secure['type'] == 'http' && secure['scheme'] == 'basic') || secure['type'] == 'basic');
for (final info in metadataAuthInfo) {
final authName = info['name'] as String;
final basicAuthInfo = authInfo[authName];
if (basicAuthInfo != null) {
final basicAuth = 'Basic ${base64Encode(utf8.encode('${basicAuthInfo.username}:${basicAuthInfo.password}'))}';
options.headers['Authorization'] = basicAuth;
break;
}
}
super.onRequest(options, handler);
}
}

View File

@ -0,0 +1,26 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'package:dio/dio.dart';
import 'package:openapi/src/auth/auth.dart';
class BearerAuthInterceptor extends AuthInterceptor {
final Map<String, String> tokens = {};
@override
void onRequest(
RequestOptions options,
RequestInterceptorHandler handler,
) {
final authInfo = getAuthInfo(options, (secure) => secure['type'] == 'http' && secure['scheme'] == 'bearer');
for (final info in authInfo) {
final token = tokens[info['name']];
if (token != null) {
options.headers['Authorization'] = 'Bearer ${token}';
break;
}
}
super.onRequest(options, handler);
}
}

View File

@ -0,0 +1,26 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'package:dio/dio.dart';
import 'package:openapi/src/auth/auth.dart';
class OAuthInterceptor extends AuthInterceptor {
final Map<String, String> tokens = {};
@override
void onRequest(
RequestOptions options,
RequestInterceptorHandler handler,
) {
final authInfo = getAuthInfo(options, (secure) => secure['type'] == 'oauth' || secure['type'] == 'oauth2');
for (final info in authInfo) {
final token = tokens[info['name']];
if (token != null) {
options.headers['Authorization'] = 'Bearer ${token}';
break;
}
}
super.onRequest(options, handler);
}
}

View File

@ -0,0 +1,31 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
import 'package:built_collection/built_collection.dart';
import 'package:built_value/serializer.dart';
import 'package:openapi/src/model/date.dart';
class DateSerializer implements PrimitiveSerializer<Date> {
const DateSerializer();
@override
Iterable<Type> get types => BuiltList.of([Date]);
@override
String get wireName => 'Date';
@override
Date deserialize(Serializers serializers, Object serialized,
{FullType specifiedType = FullType.unspecified}) {
final parsed = DateTime.parse(serialized as String);
return Date(parsed.year, parsed.month, parsed.day);
}
@override
Object serialize(Serializers serializers, Date date,
{FullType specifiedType = FullType.unspecified}) {
return date.toString();
}
}

View File

@ -0,0 +1,161 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'addressable.g.dart';
/// Base schema for adressable entities
///
/// Properties:
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
@BuiltValue(instantiable: false)
abstract class Addressable {
/// Hyperlink reference
@BuiltValueField(wireName: r'href')
String? get href;
/// unique identifier
@BuiltValueField(wireName: r'id')
String? get id;
@BuiltValueSerializer(custom: true)
static Serializer<Addressable> get serializer => _$AddressableSerializer();
}
class _$AddressableSerializer implements PrimitiveSerializer<Addressable> {
@override
final Iterable<Type> types = const [Addressable];
@override
final String wireName = r'Addressable';
Iterable<Object?> _serializeProperties(
Serializers serializers,
Addressable object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
if (object.href != null) {
yield r'href';
yield serializers.serialize(
object.href,
specifiedType: const FullType(String),
);
}
if (object.id != null) {
yield r'id';
yield serializers.serialize(
object.id,
specifiedType: const FullType(String),
);
}
}
@override
Object serialize(
Serializers serializers,
Addressable object, {
FullType specifiedType = FullType.unspecified,
}) {
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
}
@override
Addressable deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
return serializers.deserialize(serialized, specifiedType: FullType($Addressable)) as $Addressable;
}
}
/// a concrete implementation of [Addressable], since [Addressable] is not instantiable
@BuiltValue(instantiable: true)
abstract class $Addressable implements Addressable, Built<$Addressable, $AddressableBuilder> {
$Addressable._();
factory $Addressable([void Function($AddressableBuilder)? updates]) = _$$Addressable;
@BuiltValueHook(initializeBuilder: true)
static void _defaults($AddressableBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<$Addressable> get serializer => _$$AddressableSerializer();
}
class _$$AddressableSerializer implements PrimitiveSerializer<$Addressable> {
@override
final Iterable<Type> types = const [$Addressable, _$$Addressable];
@override
final String wireName = r'$Addressable';
@override
Object serialize(
Serializers serializers,
$Addressable object, {
FullType specifiedType = FullType.unspecified,
}) {
return serializers.serialize(object, specifiedType: FullType(Addressable))!;
}
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required AddressableBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'href':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.href = valueDes;
break;
case r'id':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.id = valueDes;
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
@override
$Addressable deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = $AddressableBuilder();
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
return result.build();
}
}

View File

@ -0,0 +1,221 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:openapi/src/model/foo_ref_or_value.dart';
import 'package:openapi/src/model/entity.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'bar.g.dart';
/// Bar
///
/// Properties:
/// * [id]
/// * [barPropA]
/// * [fooPropB]
/// * [foo]
/// * [href] - Hyperlink reference
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
/// * [atBaseType] - When sub-classing, this defines the super-class
/// * [atType] - When sub-classing, this defines the sub-class Extensible name
@BuiltValue()
abstract class Bar implements Entity, Built<Bar, BarBuilder> {
@BuiltValueField(wireName: r'foo')
FooRefOrValue? get foo;
@BuiltValueField(wireName: r'fooPropB')
String? get fooPropB;
@BuiltValueField(wireName: r'barPropA')
String? get barPropA;
static const String discriminatorFieldName = r'atType';
Bar._();
factory Bar([void updates(BarBuilder b)]) = _$Bar;
@BuiltValueHook(initializeBuilder: true)
static void _defaults(BarBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<Bar> get serializer => _$BarSerializer();
}
class _$BarSerializer implements PrimitiveSerializer<Bar> {
@override
final Iterable<Type> types = const [Bar, _$Bar];
@override
final String wireName = r'Bar';
Iterable<Object?> _serializeProperties(
Serializers serializers,
Bar object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
if (object.atSchemaLocation != null) {
yield r'@schemaLocation';
yield serializers.serialize(
object.atSchemaLocation,
specifiedType: const FullType(String),
);
}
if (object.foo != null) {
yield r'foo';
yield serializers.serialize(
object.foo,
specifiedType: const FullType(FooRefOrValue),
);
}
if (object.atBaseType != null) {
yield r'@baseType';
yield serializers.serialize(
object.atBaseType,
specifiedType: const FullType(String),
);
}
if (object.fooPropB != null) {
yield r'fooPropB';
yield serializers.serialize(
object.fooPropB,
specifiedType: const FullType(String),
);
}
if (object.href != null) {
yield r'href';
yield serializers.serialize(
object.href,
specifiedType: const FullType(String),
);
}
if (object.id != null) {
yield r'id';
yield serializers.serialize(
object.id,
specifiedType: const FullType(String),
);
}
yield r'@type';
yield serializers.serialize(
object.atType,
specifiedType: const FullType(String),
);
if (object.barPropA != null) {
yield r'barPropA';
yield serializers.serialize(
object.barPropA,
specifiedType: const FullType(String),
);
}
}
@override
Object serialize(
Serializers serializers,
Bar object, {
FullType specifiedType = FullType.unspecified,
}) {
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
}
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required BarBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'@schemaLocation':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atSchemaLocation = valueDes;
break;
case r'foo':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(FooRefOrValue),
) as FooRefOrValue;
result.foo.replace(valueDes);
break;
case r'@baseType':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atBaseType = valueDes;
break;
case r'fooPropB':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.fooPropB = valueDes;
break;
case r'href':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.href = valueDes;
break;
case r'id':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.id = valueDes;
break;
case r'@type':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atType = valueDes;
break;
case r'barPropA':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.barPropA = valueDes;
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
@override
Bar deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = BarBuilder();
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
return result.build();
}
}

View File

@ -0,0 +1,221 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:openapi/src/model/foo_ref_or_value.dart';
import 'package:openapi/src/model/entity.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'bar_create.g.dart';
/// BarCreate
///
/// Properties:
/// * [barPropA]
/// * [fooPropB]
/// * [foo]
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
/// * [atBaseType] - When sub-classing, this defines the super-class
/// * [atType] - When sub-classing, this defines the sub-class Extensible name
@BuiltValue()
abstract class BarCreate implements Entity, Built<BarCreate, BarCreateBuilder> {
@BuiltValueField(wireName: r'foo')
FooRefOrValue? get foo;
@BuiltValueField(wireName: r'fooPropB')
String? get fooPropB;
@BuiltValueField(wireName: r'barPropA')
String? get barPropA;
static const String discriminatorFieldName = r'atType';
BarCreate._();
factory BarCreate([void updates(BarCreateBuilder b)]) = _$BarCreate;
@BuiltValueHook(initializeBuilder: true)
static void _defaults(BarCreateBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<BarCreate> get serializer => _$BarCreateSerializer();
}
class _$BarCreateSerializer implements PrimitiveSerializer<BarCreate> {
@override
final Iterable<Type> types = const [BarCreate, _$BarCreate];
@override
final String wireName = r'BarCreate';
Iterable<Object?> _serializeProperties(
Serializers serializers,
BarCreate object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
if (object.atSchemaLocation != null) {
yield r'@schemaLocation';
yield serializers.serialize(
object.atSchemaLocation,
specifiedType: const FullType(String),
);
}
if (object.foo != null) {
yield r'foo';
yield serializers.serialize(
object.foo,
specifiedType: const FullType(FooRefOrValue),
);
}
if (object.atBaseType != null) {
yield r'@baseType';
yield serializers.serialize(
object.atBaseType,
specifiedType: const FullType(String),
);
}
if (object.fooPropB != null) {
yield r'fooPropB';
yield serializers.serialize(
object.fooPropB,
specifiedType: const FullType(String),
);
}
if (object.href != null) {
yield r'href';
yield serializers.serialize(
object.href,
specifiedType: const FullType(String),
);
}
if (object.id != null) {
yield r'id';
yield serializers.serialize(
object.id,
specifiedType: const FullType(String),
);
}
yield r'@type';
yield serializers.serialize(
object.atType,
specifiedType: const FullType(String),
);
if (object.barPropA != null) {
yield r'barPropA';
yield serializers.serialize(
object.barPropA,
specifiedType: const FullType(String),
);
}
}
@override
Object serialize(
Serializers serializers,
BarCreate object, {
FullType specifiedType = FullType.unspecified,
}) {
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
}
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required BarCreateBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'@schemaLocation':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atSchemaLocation = valueDes;
break;
case r'foo':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(FooRefOrValue),
) as FooRefOrValue;
result.foo.replace(valueDes);
break;
case r'@baseType':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atBaseType = valueDes;
break;
case r'fooPropB':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.fooPropB = valueDes;
break;
case r'href':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.href = valueDes;
break;
case r'id':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.id = valueDes;
break;
case r'@type':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atType = valueDes;
break;
case r'barPropA':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.barPropA = valueDes;
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
@override
BarCreate deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = BarCreateBuilder();
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
return result.build();
}
}

View File

@ -0,0 +1,194 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:openapi/src/model/entity_ref.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'bar_ref.g.dart';
/// BarRef
///
/// Properties:
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
/// * [atBaseType] - When sub-classing, this defines the super-class
/// * [atType] - When sub-classing, this defines the sub-class Extensible name
@BuiltValue()
abstract class BarRef implements EntityRef, Built<BarRef, BarRefBuilder> {
static const String discriminatorFieldName = r'atType';
BarRef._();
factory BarRef([void updates(BarRefBuilder b)]) = _$BarRef;
@BuiltValueHook(initializeBuilder: true)
static void _defaults(BarRefBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<BarRef> get serializer => _$BarRefSerializer();
}
class _$BarRefSerializer implements PrimitiveSerializer<BarRef> {
@override
final Iterable<Type> types = const [BarRef, _$BarRef];
@override
final String wireName = r'BarRef';
Iterable<Object?> _serializeProperties(
Serializers serializers,
BarRef object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
if (object.atSchemaLocation != null) {
yield r'@schemaLocation';
yield serializers.serialize(
object.atSchemaLocation,
specifiedType: const FullType(String),
);
}
if (object.atReferredType != null) {
yield r'@referredType';
yield serializers.serialize(
object.atReferredType,
specifiedType: const FullType(String),
);
}
if (object.name != null) {
yield r'name';
yield serializers.serialize(
object.name,
specifiedType: const FullType(String),
);
}
if (object.atBaseType != null) {
yield r'@baseType';
yield serializers.serialize(
object.atBaseType,
specifiedType: const FullType(String),
);
}
if (object.href != null) {
yield r'href';
yield serializers.serialize(
object.href,
specifiedType: const FullType(String),
);
}
if (object.id != null) {
yield r'id';
yield serializers.serialize(
object.id,
specifiedType: const FullType(String),
);
}
yield r'@type';
yield serializers.serialize(
object.atType,
specifiedType: const FullType(String),
);
}
@override
Object serialize(
Serializers serializers,
BarRef object, {
FullType specifiedType = FullType.unspecified,
}) {
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
}
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required BarRefBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'@schemaLocation':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atSchemaLocation = valueDes;
break;
case r'@referredType':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atReferredType = valueDes;
break;
case r'name':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.name = valueDes;
break;
case r'@baseType':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atBaseType = valueDes;
break;
case r'href':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.href = valueDes;
break;
case r'id':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.id = valueDes;
break;
case r'@type':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atType = valueDes;
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
@override
BarRef deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = BarRefBuilder();
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
return result.build();
}
}

View File

@ -0,0 +1,106 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:openapi/src/model/bar_ref.dart';
import 'package:openapi/src/model/bar.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:one_of/one_of.dart';
part 'bar_ref_or_value.g.dart';
/// BarRefOrValue
///
/// Properties:
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
/// * [atBaseType] - When sub-classing, this defines the super-class
/// * [atType] - When sub-classing, this defines the sub-class Extensible name
@BuiltValue()
abstract class BarRefOrValue implements Built<BarRefOrValue, BarRefOrValueBuilder> {
/// One Of [Bar], [BarRef]
OneOf get oneOf;
static const String discriminatorFieldName = r'atType';
static const Map<String, Type> discriminatorMapping = {
r'Bar': Bar,
r'BarRef': BarRef,
};
BarRefOrValue._();
factory BarRefOrValue([void updates(BarRefOrValueBuilder b)]) = _$BarRefOrValue;
@BuiltValueHook(initializeBuilder: true)
static void _defaults(BarRefOrValueBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<BarRefOrValue> get serializer => _$BarRefOrValueSerializer();
}
class _$BarRefOrValueSerializer implements PrimitiveSerializer<BarRefOrValue> {
@override
final Iterable<Type> types = const [BarRefOrValue, _$BarRefOrValue];
@override
final String wireName = r'BarRefOrValue';
Iterable<Object?> _serializeProperties(
Serializers serializers,
BarRefOrValue object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
}
@override
Object serialize(
Serializers serializers,
BarRefOrValue object, {
FullType specifiedType = FullType.unspecified,
}) {
final oneOf = object.oneOf;
return serializers.serialize(oneOf.value, specifiedType: FullType(oneOf.valueType))!;
}
@override
BarRefOrValue deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = BarRefOrValueBuilder();
Object? oneOfDataSrc;
final serializedList = (serialized as Iterable<Object?>).toList();
final discIndex = serializedList.indexOf(BarRefOrValue.discriminatorFieldName) + 1;
final discValue = serializers.deserialize(serializedList[discIndex], specifiedType: FullType(String)) as String;
oneOfDataSrc = serialized;
final oneOfTypes = [Bar, BarRef, ];
Object oneOfResult;
Type oneOfType;
switch (discValue) {
case 'Bar':
oneOfResult = serializers.deserialize(
oneOfDataSrc,
specifiedType: FullType(Bar),
) as Bar;
oneOfType = Bar;
break;
case 'BarRef':
oneOfResult = serializers.deserialize(
oneOfDataSrc,
specifiedType: FullType(BarRef),
) as BarRef;
oneOfType = BarRef;
break;
default:
throw UnsupportedError("Couldn't deserialize oneOf for the discriminator value: ${discValue}");
}
result.oneOf = OneOfDynamic(typeIndex: oneOfTypes.indexOf(oneOfType), types: oneOfTypes, value: oneOfResult);
return result.build();
}
}

View File

@ -0,0 +1,70 @@
/// A gregorian calendar date generated by
/// OpenAPI generator to differentiate
/// between [DateTime] and [Date] formats.
class Date implements Comparable<Date> {
final int year;
/// January is 1.
final int month;
/// First day is 1.
final int day;
Date(this.year, this.month, this.day);
/// The current date
static Date now({bool utc = false}) {
var now = DateTime.now();
if (utc) {
now = now.toUtc();
}
return now.toDate();
}
/// Convert to a [DateTime].
DateTime toDateTime({bool utc = false}) {
if (utc) {
return DateTime.utc(year, month, day);
} else {
return DateTime(year, month, day);
}
}
@override
int compareTo(Date other) {
int d = year.compareTo(other.year);
if (d != 0) {
return d;
}
d = month.compareTo(other.month);
if (d != 0) {
return d;
}
return day.compareTo(other.day);
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Date &&
runtimeType == other.runtimeType &&
year == other.year &&
month == other.month &&
day == other.day;
@override
int get hashCode => year.hashCode ^ month.hashCode ^ day.hashCode;
@override
String toString() {
final yyyy = year.toString();
final mm = month.toString().padLeft(2, '0');
final dd = day.toString().padLeft(2, '0');
return '$yyyy-$mm-$dd';
}
}
extension DateTimeToDate on DateTime {
Date toDate() => Date(year, month, day);
}

View File

@ -0,0 +1,251 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:openapi/src/model/extensible.dart';
import 'package:openapi/src/model/pizza_speziale.dart';
import 'package:openapi/src/model/foo.dart';
import 'package:openapi/src/model/pizza.dart';
import 'package:openapi/src/model/addressable.dart';
import 'package:openapi/src/model/pasta.dart';
import 'package:openapi/src/model/bar_create.dart';
import 'package:openapi/src/model/bar.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'entity.g.dart';
/// Entity
///
/// Properties:
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
/// * [atBaseType] - When sub-classing, this defines the super-class
/// * [atType] - When sub-classing, this defines the sub-class Extensible name
@BuiltValue(instantiable: false)
abstract class Entity implements Addressable, Extensible {
static const String discriminatorFieldName = r'atType';
static const Map<String, Type> discriminatorMapping = {
r'Bar': Bar,
r'Bar_Create': BarCreate,
r'Foo': Foo,
r'Pasta': Pasta,
r'Pizza': Pizza,
r'PizzaSpeziale': PizzaSpeziale,
};
@BuiltValueSerializer(custom: true)
static Serializer<Entity> get serializer => _$EntitySerializer();
}
class _$EntitySerializer implements PrimitiveSerializer<Entity> {
@override
final Iterable<Type> types = const [Entity];
@override
final String wireName = r'Entity';
Iterable<Object?> _serializeProperties(
Serializers serializers,
Entity object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
if (object.atSchemaLocation != null) {
yield r'@schemaLocation';
yield serializers.serialize(
object.atSchemaLocation,
specifiedType: const FullType(String),
);
}
if (object.atBaseType != null) {
yield r'@baseType';
yield serializers.serialize(
object.atBaseType,
specifiedType: const FullType(String),
);
}
if (object.href != null) {
yield r'href';
yield serializers.serialize(
object.href,
specifiedType: const FullType(String),
);
}
if (object.id != null) {
yield r'id';
yield serializers.serialize(
object.id,
specifiedType: const FullType(String),
);
}
yield r'@type';
yield serializers.serialize(
object.atType,
specifiedType: const FullType(String),
);
}
@override
Object serialize(
Serializers serializers,
Entity object, {
FullType specifiedType = FullType.unspecified,
}) {
if (object is Bar) {
return serializers.serialize(object, specifiedType: FullType(Bar))!;
}
if (object is BarCreate) {
return serializers.serialize(object, specifiedType: FullType(BarCreate))!;
}
if (object is Foo) {
return serializers.serialize(object, specifiedType: FullType(Foo))!;
}
if (object is Pasta) {
return serializers.serialize(object, specifiedType: FullType(Pasta))!;
}
if (object is Pizza) {
return serializers.serialize(object, specifiedType: FullType(Pizza))!;
}
if (object is PizzaSpeziale) {
return serializers.serialize(object, specifiedType: FullType(PizzaSpeziale))!;
}
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
}
@override
Entity deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final serializedList = (serialized as Iterable<Object?>).toList();
final discIndex = serializedList.indexOf(Entity.discriminatorFieldName) + 1;
final discValue = serializers.deserialize(serializedList[discIndex], specifiedType: FullType(String)) as String;
switch (discValue) {
case 'Bar':
return serializers.deserialize(serialized, specifiedType: FullType(Bar)) as Bar;
case 'Bar_Create':
return serializers.deserialize(serialized, specifiedType: FullType(BarCreate)) as BarCreate;
case 'Foo':
return serializers.deserialize(serialized, specifiedType: FullType(Foo)) as Foo;
case 'Pasta':
return serializers.deserialize(serialized, specifiedType: FullType(Pasta)) as Pasta;
case 'Pizza':
return serializers.deserialize(serialized, specifiedType: FullType(Pizza)) as Pizza;
case 'PizzaSpeziale':
return serializers.deserialize(serialized, specifiedType: FullType(PizzaSpeziale)) as PizzaSpeziale;
default:
return serializers.deserialize(serialized, specifiedType: FullType($Entity)) as $Entity;
}
}
}
/// a concrete implementation of [Entity], since [Entity] is not instantiable
@BuiltValue(instantiable: true)
abstract class $Entity implements Entity, Built<$Entity, $EntityBuilder> {
$Entity._();
factory $Entity([void Function($EntityBuilder)? updates]) = _$$Entity;
@BuiltValueHook(initializeBuilder: true)
static void _defaults($EntityBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<$Entity> get serializer => _$$EntitySerializer();
}
class _$$EntitySerializer implements PrimitiveSerializer<$Entity> {
@override
final Iterable<Type> types = const [$Entity, _$$Entity];
@override
final String wireName = r'$Entity';
@override
Object serialize(
Serializers serializers,
$Entity object, {
FullType specifiedType = FullType.unspecified,
}) {
return serializers.serialize(object, specifiedType: FullType(Entity))!;
}
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required EntityBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'@schemaLocation':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atSchemaLocation = valueDes;
break;
case r'@baseType':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atBaseType = valueDes;
break;
case r'href':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.href = valueDes;
break;
case r'id':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.id = valueDes;
break;
case r'@type':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atType = valueDes;
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
@override
$Entity deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = $EntityBuilder();
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
return result.build();
}
}

View File

@ -0,0 +1,261 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:openapi/src/model/extensible.dart';
import 'package:openapi/src/model/bar_ref.dart';
import 'package:openapi/src/model/addressable.dart';
import 'package:openapi/src/model/foo_ref.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'entity_ref.g.dart';
/// Entity reference schema to be use for all entityRef class.
///
/// Properties:
/// * [name] - Name of the related entity.
/// * [atReferredType] - The actual type of the target instance when needed for disambiguation.
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
/// * [atBaseType] - When sub-classing, this defines the super-class
/// * [atType] - When sub-classing, this defines the sub-class Extensible name
@BuiltValue(instantiable: false)
abstract class EntityRef implements Addressable, Extensible {
/// The actual type of the target instance when needed for disambiguation.
@BuiltValueField(wireName: r'@referredType')
String? get atReferredType;
/// Name of the related entity.
@BuiltValueField(wireName: r'name')
String? get name;
static const String discriminatorFieldName = r'atType';
static const Map<String, Type> discriminatorMapping = {
r'BarRef': BarRef,
r'FooRef': FooRef,
};
@BuiltValueSerializer(custom: true)
static Serializer<EntityRef> get serializer => _$EntityRefSerializer();
}
class _$EntityRefSerializer implements PrimitiveSerializer<EntityRef> {
@override
final Iterable<Type> types = const [EntityRef];
@override
final String wireName = r'EntityRef';
Iterable<Object?> _serializeProperties(
Serializers serializers,
EntityRef object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
if (object.atSchemaLocation != null) {
yield r'@schemaLocation';
yield serializers.serialize(
object.atSchemaLocation,
specifiedType: const FullType(String),
);
}
if (object.atReferredType != null) {
yield r'@referredType';
yield serializers.serialize(
object.atReferredType,
specifiedType: const FullType(String),
);
}
if (object.name != null) {
yield r'name';
yield serializers.serialize(
object.name,
specifiedType: const FullType(String),
);
}
if (object.atBaseType != null) {
yield r'@baseType';
yield serializers.serialize(
object.atBaseType,
specifiedType: const FullType(String),
);
}
if (object.href != null) {
yield r'href';
yield serializers.serialize(
object.href,
specifiedType: const FullType(String),
);
}
if (object.id != null) {
yield r'id';
yield serializers.serialize(
object.id,
specifiedType: const FullType(String),
);
}
yield r'@type';
yield serializers.serialize(
object.atType,
specifiedType: const FullType(String),
);
}
@override
Object serialize(
Serializers serializers,
EntityRef object, {
FullType specifiedType = FullType.unspecified,
}) {
if (object is BarRef) {
return serializers.serialize(object, specifiedType: FullType(BarRef))!;
}
if (object is FooRef) {
return serializers.serialize(object, specifiedType: FullType(FooRef))!;
}
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
}
@override
EntityRef deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final serializedList = (serialized as Iterable<Object?>).toList();
final discIndex = serializedList.indexOf(EntityRef.discriminatorFieldName) + 1;
final discValue = serializers.deserialize(serializedList[discIndex], specifiedType: FullType(String)) as String;
switch (discValue) {
case 'BarRef':
return serializers.deserialize(serialized, specifiedType: FullType(BarRef)) as BarRef;
case 'FooRef':
return serializers.deserialize(serialized, specifiedType: FullType(FooRef)) as FooRef;
default:
return serializers.deserialize(serialized, specifiedType: FullType($EntityRef)) as $EntityRef;
}
}
}
/// a concrete implementation of [EntityRef], since [EntityRef] is not instantiable
@BuiltValue(instantiable: true)
abstract class $EntityRef implements EntityRef, Built<$EntityRef, $EntityRefBuilder> {
$EntityRef._();
factory $EntityRef([void Function($EntityRefBuilder)? updates]) = _$$EntityRef;
@BuiltValueHook(initializeBuilder: true)
static void _defaults($EntityRefBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<$EntityRef> get serializer => _$$EntityRefSerializer();
}
class _$$EntityRefSerializer implements PrimitiveSerializer<$EntityRef> {
@override
final Iterable<Type> types = const [$EntityRef, _$$EntityRef];
@override
final String wireName = r'$EntityRef';
@override
Object serialize(
Serializers serializers,
$EntityRef object, {
FullType specifiedType = FullType.unspecified,
}) {
return serializers.serialize(object, specifiedType: FullType(EntityRef))!;
}
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required EntityRefBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'@schemaLocation':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atSchemaLocation = valueDes;
break;
case r'@referredType':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atReferredType = valueDes;
break;
case r'name':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.name = valueDes;
break;
case r'@baseType':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atBaseType = valueDes;
break;
case r'href':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.href = valueDes;
break;
case r'id':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.id = valueDes;
break;
case r'@type':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atType = valueDes;
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
@override
$EntityRef deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = $EntityRefBuilder();
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
return result.build();
}
}

View File

@ -0,0 +1,178 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'extensible.g.dart';
/// Extensible
///
/// Properties:
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
/// * [atBaseType] - When sub-classing, this defines the super-class
/// * [atType] - When sub-classing, this defines the sub-class Extensible name
@BuiltValue(instantiable: false)
abstract class Extensible {
/// A URI to a JSON-Schema file that defines additional attributes and relationships
@BuiltValueField(wireName: r'@schemaLocation')
String? get atSchemaLocation;
/// When sub-classing, this defines the super-class
@BuiltValueField(wireName: r'@baseType')
String? get atBaseType;
/// When sub-classing, this defines the sub-class Extensible name
@BuiltValueField(wireName: r'@type')
String get atType;
@BuiltValueSerializer(custom: true)
static Serializer<Extensible> get serializer => _$ExtensibleSerializer();
}
class _$ExtensibleSerializer implements PrimitiveSerializer<Extensible> {
@override
final Iterable<Type> types = const [Extensible];
@override
final String wireName = r'Extensible';
Iterable<Object?> _serializeProperties(
Serializers serializers,
Extensible object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
if (object.atSchemaLocation != null) {
yield r'@schemaLocation';
yield serializers.serialize(
object.atSchemaLocation,
specifiedType: const FullType(String),
);
}
if (object.atBaseType != null) {
yield r'@baseType';
yield serializers.serialize(
object.atBaseType,
specifiedType: const FullType(String),
);
}
yield r'@type';
yield serializers.serialize(
object.atType,
specifiedType: const FullType(String),
);
}
@override
Object serialize(
Serializers serializers,
Extensible object, {
FullType specifiedType = FullType.unspecified,
}) {
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
}
@override
Extensible deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
return serializers.deserialize(serialized, specifiedType: FullType($Extensible)) as $Extensible;
}
}
/// a concrete implementation of [Extensible], since [Extensible] is not instantiable
@BuiltValue(instantiable: true)
abstract class $Extensible implements Extensible, Built<$Extensible, $ExtensibleBuilder> {
$Extensible._();
factory $Extensible([void Function($ExtensibleBuilder)? updates]) = _$$Extensible;
@BuiltValueHook(initializeBuilder: true)
static void _defaults($ExtensibleBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<$Extensible> get serializer => _$$ExtensibleSerializer();
}
class _$$ExtensibleSerializer implements PrimitiveSerializer<$Extensible> {
@override
final Iterable<Type> types = const [$Extensible, _$$Extensible];
@override
final String wireName = r'$Extensible';
@override
Object serialize(
Serializers serializers,
$Extensible object, {
FullType specifiedType = FullType.unspecified,
}) {
return serializers.serialize(object, specifiedType: FullType(Extensible))!;
}
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required ExtensibleBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'@schemaLocation':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atSchemaLocation = valueDes;
break;
case r'@baseType':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atBaseType = valueDes;
break;
case r'@type':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atType = valueDes;
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
@override
$Extensible deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = $ExtensibleBuilder();
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
return result.build();
}
}

View File

@ -0,0 +1,202 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:openapi/src/model/entity.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'foo.g.dart';
/// Foo
///
/// Properties:
/// * [fooPropA]
/// * [fooPropB]
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
/// * [atBaseType] - When sub-classing, this defines the super-class
/// * [atType] - When sub-classing, this defines the sub-class Extensible name
@BuiltValue()
abstract class Foo implements Entity, Built<Foo, FooBuilder> {
@BuiltValueField(wireName: r'fooPropA')
String? get fooPropA;
@BuiltValueField(wireName: r'fooPropB')
String? get fooPropB;
static const String discriminatorFieldName = r'atType';
Foo._();
factory Foo([void updates(FooBuilder b)]) = _$Foo;
@BuiltValueHook(initializeBuilder: true)
static void _defaults(FooBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<Foo> get serializer => _$FooSerializer();
}
class _$FooSerializer implements PrimitiveSerializer<Foo> {
@override
final Iterable<Type> types = const [Foo, _$Foo];
@override
final String wireName = r'Foo';
Iterable<Object?> _serializeProperties(
Serializers serializers,
Foo object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
if (object.atSchemaLocation != null) {
yield r'@schemaLocation';
yield serializers.serialize(
object.atSchemaLocation,
specifiedType: const FullType(String),
);
}
if (object.fooPropA != null) {
yield r'fooPropA';
yield serializers.serialize(
object.fooPropA,
specifiedType: const FullType(String),
);
}
if (object.atBaseType != null) {
yield r'@baseType';
yield serializers.serialize(
object.atBaseType,
specifiedType: const FullType(String),
);
}
if (object.fooPropB != null) {
yield r'fooPropB';
yield serializers.serialize(
object.fooPropB,
specifiedType: const FullType(String),
);
}
if (object.href != null) {
yield r'href';
yield serializers.serialize(
object.href,
specifiedType: const FullType(String),
);
}
if (object.id != null) {
yield r'id';
yield serializers.serialize(
object.id,
specifiedType: const FullType(String),
);
}
yield r'@type';
yield serializers.serialize(
object.atType,
specifiedType: const FullType(String),
);
}
@override
Object serialize(
Serializers serializers,
Foo object, {
FullType specifiedType = FullType.unspecified,
}) {
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
}
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required FooBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'@schemaLocation':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atSchemaLocation = valueDes;
break;
case r'fooPropA':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.fooPropA = valueDes;
break;
case r'@baseType':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atBaseType = valueDes;
break;
case r'fooPropB':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.fooPropB = valueDes;
break;
case r'href':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.href = valueDes;
break;
case r'id':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.id = valueDes;
break;
case r'@type':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atType = valueDes;
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
@override
Foo deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = FooBuilder();
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
return result.build();
}
}

View File

@ -0,0 +1,212 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:openapi/src/model/entity_ref.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'foo_ref.g.dart';
/// FooRef
///
/// Properties:
/// * [foorefPropA]
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
/// * [atBaseType] - When sub-classing, this defines the super-class
/// * [atType] - When sub-classing, this defines the sub-class Extensible name
@BuiltValue()
abstract class FooRef implements EntityRef, Built<FooRef, FooRefBuilder> {
@BuiltValueField(wireName: r'foorefPropA')
String? get foorefPropA;
static const String discriminatorFieldName = r'atType';
FooRef._();
factory FooRef([void updates(FooRefBuilder b)]) = _$FooRef;
@BuiltValueHook(initializeBuilder: true)
static void _defaults(FooRefBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<FooRef> get serializer => _$FooRefSerializer();
}
class _$FooRefSerializer implements PrimitiveSerializer<FooRef> {
@override
final Iterable<Type> types = const [FooRef, _$FooRef];
@override
final String wireName = r'FooRef';
Iterable<Object?> _serializeProperties(
Serializers serializers,
FooRef object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
if (object.atSchemaLocation != null) {
yield r'@schemaLocation';
yield serializers.serialize(
object.atSchemaLocation,
specifiedType: const FullType(String),
);
}
if (object.atReferredType != null) {
yield r'@referredType';
yield serializers.serialize(
object.atReferredType,
specifiedType: const FullType(String),
);
}
if (object.foorefPropA != null) {
yield r'foorefPropA';
yield serializers.serialize(
object.foorefPropA,
specifiedType: const FullType(String),
);
}
if (object.name != null) {
yield r'name';
yield serializers.serialize(
object.name,
specifiedType: const FullType(String),
);
}
if (object.atBaseType != null) {
yield r'@baseType';
yield serializers.serialize(
object.atBaseType,
specifiedType: const FullType(String),
);
}
if (object.href != null) {
yield r'href';
yield serializers.serialize(
object.href,
specifiedType: const FullType(String),
);
}
if (object.id != null) {
yield r'id';
yield serializers.serialize(
object.id,
specifiedType: const FullType(String),
);
}
yield r'@type';
yield serializers.serialize(
object.atType,
specifiedType: const FullType(String),
);
}
@override
Object serialize(
Serializers serializers,
FooRef object, {
FullType specifiedType = FullType.unspecified,
}) {
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
}
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required FooRefBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'@schemaLocation':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atSchemaLocation = valueDes;
break;
case r'@referredType':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atReferredType = valueDes;
break;
case r'foorefPropA':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.foorefPropA = valueDes;
break;
case r'name':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.name = valueDes;
break;
case r'@baseType':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atBaseType = valueDes;
break;
case r'href':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.href = valueDes;
break;
case r'id':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.id = valueDes;
break;
case r'@type':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atType = valueDes;
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
@override
FooRef deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = FooRefBuilder();
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
return result.build();
}
}

View File

@ -0,0 +1,106 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:openapi/src/model/foo.dart';
import 'package:openapi/src/model/foo_ref.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:one_of/one_of.dart';
part 'foo_ref_or_value.g.dart';
/// FooRefOrValue
///
/// Properties:
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
/// * [atBaseType] - When sub-classing, this defines the super-class
/// * [atType] - When sub-classing, this defines the sub-class Extensible name
@BuiltValue()
abstract class FooRefOrValue implements Built<FooRefOrValue, FooRefOrValueBuilder> {
/// One Of [Foo], [FooRef]
OneOf get oneOf;
static const String discriminatorFieldName = r'atType';
static const Map<String, Type> discriminatorMapping = {
r'Foo': Foo,
r'FooRef': FooRef,
};
FooRefOrValue._();
factory FooRefOrValue([void updates(FooRefOrValueBuilder b)]) = _$FooRefOrValue;
@BuiltValueHook(initializeBuilder: true)
static void _defaults(FooRefOrValueBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<FooRefOrValue> get serializer => _$FooRefOrValueSerializer();
}
class _$FooRefOrValueSerializer implements PrimitiveSerializer<FooRefOrValue> {
@override
final Iterable<Type> types = const [FooRefOrValue, _$FooRefOrValue];
@override
final String wireName = r'FooRefOrValue';
Iterable<Object?> _serializeProperties(
Serializers serializers,
FooRefOrValue object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
}
@override
Object serialize(
Serializers serializers,
FooRefOrValue object, {
FullType specifiedType = FullType.unspecified,
}) {
final oneOf = object.oneOf;
return serializers.serialize(oneOf.value, specifiedType: FullType(oneOf.valueType))!;
}
@override
FooRefOrValue deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = FooRefOrValueBuilder();
Object? oneOfDataSrc;
final serializedList = (serialized as Iterable<Object?>).toList();
final discIndex = serializedList.indexOf(FooRefOrValue.discriminatorFieldName) + 1;
final discValue = serializers.deserialize(serializedList[discIndex], specifiedType: FullType(String)) as String;
oneOfDataSrc = serialized;
final oneOfTypes = [Foo, FooRef, ];
Object oneOfResult;
Type oneOfType;
switch (discValue) {
case 'Foo':
oneOfResult = serializers.deserialize(
oneOfDataSrc,
specifiedType: FullType(Foo),
) as Foo;
oneOfType = Foo;
break;
case 'FooRef':
oneOfResult = serializers.deserialize(
oneOfDataSrc,
specifiedType: FullType(FooRef),
) as FooRef;
oneOfType = FooRef;
break;
default:
throw UnsupportedError("Couldn't deserialize oneOf for the discriminator value: ${discValue}");
}
result.oneOf = OneOfDynamic(typeIndex: oneOfTypes.indexOf(oneOfType), types: oneOfTypes, value: oneOfResult);
return result.build();
}
}

View File

@ -0,0 +1,184 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:openapi/src/model/entity.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'pasta.g.dart';
/// Pasta
///
/// Properties:
/// * [vendor]
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
/// * [atBaseType] - When sub-classing, this defines the super-class
/// * [atType] - When sub-classing, this defines the sub-class Extensible name
@BuiltValue()
abstract class Pasta implements Entity, Built<Pasta, PastaBuilder> {
@BuiltValueField(wireName: r'vendor')
String? get vendor;
static const String discriminatorFieldName = r'atType';
Pasta._();
factory Pasta([void updates(PastaBuilder b)]) = _$Pasta;
@BuiltValueHook(initializeBuilder: true)
static void _defaults(PastaBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<Pasta> get serializer => _$PastaSerializer();
}
class _$PastaSerializer implements PrimitiveSerializer<Pasta> {
@override
final Iterable<Type> types = const [Pasta, _$Pasta];
@override
final String wireName = r'Pasta';
Iterable<Object?> _serializeProperties(
Serializers serializers,
Pasta object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
if (object.atSchemaLocation != null) {
yield r'@schemaLocation';
yield serializers.serialize(
object.atSchemaLocation,
specifiedType: const FullType(String),
);
}
if (object.atBaseType != null) {
yield r'@baseType';
yield serializers.serialize(
object.atBaseType,
specifiedType: const FullType(String),
);
}
if (object.href != null) {
yield r'href';
yield serializers.serialize(
object.href,
specifiedType: const FullType(String),
);
}
if (object.id != null) {
yield r'id';
yield serializers.serialize(
object.id,
specifiedType: const FullType(String),
);
}
yield r'@type';
yield serializers.serialize(
object.atType,
specifiedType: const FullType(String),
);
if (object.vendor != null) {
yield r'vendor';
yield serializers.serialize(
object.vendor,
specifiedType: const FullType(String),
);
}
}
@override
Object serialize(
Serializers serializers,
Pasta object, {
FullType specifiedType = FullType.unspecified,
}) {
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
}
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required PastaBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'@schemaLocation':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atSchemaLocation = valueDes;
break;
case r'@baseType':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atBaseType = valueDes;
break;
case r'href':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.href = valueDes;
break;
case r'id':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.id = valueDes;
break;
case r'@type':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atType = valueDes;
break;
case r'vendor':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.vendor = valueDes;
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
@override
Pasta deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = PastaBuilder();
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
return result.build();
}
}

View File

@ -0,0 +1,233 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:openapi/src/model/pizza_speziale.dart';
import 'package:openapi/src/model/entity.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'pizza.g.dart';
/// Pizza
///
/// Properties:
/// * [pizzaSize]
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
/// * [atBaseType] - When sub-classing, this defines the super-class
/// * [atType] - When sub-classing, this defines the sub-class Extensible name
@BuiltValue(instantiable: false)
abstract class Pizza implements Entity {
@BuiltValueField(wireName: r'pizzaSize')
num? get pizzaSize;
static const String discriminatorFieldName = r'atType';
static const Map<String, Type> discriminatorMapping = {
r'PizzaSpeziale': PizzaSpeziale,
};
@BuiltValueSerializer(custom: true)
static Serializer<Pizza> get serializer => _$PizzaSerializer();
}
class _$PizzaSerializer implements PrimitiveSerializer<Pizza> {
@override
final Iterable<Type> types = const [Pizza];
@override
final String wireName = r'Pizza';
Iterable<Object?> _serializeProperties(
Serializers serializers,
Pizza object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
if (object.pizzaSize != null) {
yield r'pizzaSize';
yield serializers.serialize(
object.pizzaSize,
specifiedType: const FullType(num),
);
}
if (object.atSchemaLocation != null) {
yield r'@schemaLocation';
yield serializers.serialize(
object.atSchemaLocation,
specifiedType: const FullType(String),
);
}
if (object.atBaseType != null) {
yield r'@baseType';
yield serializers.serialize(
object.atBaseType,
specifiedType: const FullType(String),
);
}
if (object.href != null) {
yield r'href';
yield serializers.serialize(
object.href,
specifiedType: const FullType(String),
);
}
if (object.id != null) {
yield r'id';
yield serializers.serialize(
object.id,
specifiedType: const FullType(String),
);
}
yield r'@type';
yield serializers.serialize(
object.atType,
specifiedType: const FullType(String),
);
}
@override
Object serialize(
Serializers serializers,
Pizza object, {
FullType specifiedType = FullType.unspecified,
}) {
if (object is PizzaSpeziale) {
return serializers.serialize(object, specifiedType: FullType(PizzaSpeziale))!;
}
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
}
@override
Pizza deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final serializedList = (serialized as Iterable<Object?>).toList();
final discIndex = serializedList.indexOf(Pizza.discriminatorFieldName) + 1;
final discValue = serializers.deserialize(serializedList[discIndex], specifiedType: FullType(String)) as String;
switch (discValue) {
case 'PizzaSpeziale':
return serializers.deserialize(serialized, specifiedType: FullType(PizzaSpeziale)) as PizzaSpeziale;
default:
return serializers.deserialize(serialized, specifiedType: FullType($Pizza)) as $Pizza;
}
}
}
/// a concrete implementation of [Pizza], since [Pizza] is not instantiable
@BuiltValue(instantiable: true)
abstract class $Pizza implements Pizza, Built<$Pizza, $PizzaBuilder> {
$Pizza._();
factory $Pizza([void Function($PizzaBuilder)? updates]) = _$$Pizza;
@BuiltValueHook(initializeBuilder: true)
static void _defaults($PizzaBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<$Pizza> get serializer => _$$PizzaSerializer();
}
class _$$PizzaSerializer implements PrimitiveSerializer<$Pizza> {
@override
final Iterable<Type> types = const [$Pizza, _$$Pizza];
@override
final String wireName = r'$Pizza';
@override
Object serialize(
Serializers serializers,
$Pizza object, {
FullType specifiedType = FullType.unspecified,
}) {
return serializers.serialize(object, specifiedType: FullType(Pizza))!;
}
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required PizzaBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'pizzaSize':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(num),
) as num;
result.pizzaSize = valueDes;
break;
case r'@schemaLocation':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atSchemaLocation = valueDes;
break;
case r'@baseType':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atBaseType = valueDes;
break;
case r'href':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.href = valueDes;
break;
case r'id':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.id = valueDes;
break;
case r'@type':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atType = valueDes;
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
@override
$Pizza deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = $PizzaBuilder();
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
return result.build();
}
}

View File

@ -0,0 +1,198 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_element
import 'package:openapi/src/model/pizza.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'pizza_speziale.g.dart';
/// PizzaSpeziale
///
/// Properties:
/// * [toppings]
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
/// * [atBaseType] - When sub-classing, this defines the super-class
/// * [atType] - When sub-classing, this defines the sub-class Extensible name
@BuiltValue()
abstract class PizzaSpeziale implements Pizza, Built<PizzaSpeziale, PizzaSpezialeBuilder> {
@BuiltValueField(wireName: r'toppings')
String? get toppings;
static const String discriminatorFieldName = r'atType';
PizzaSpeziale._();
factory PizzaSpeziale([void updates(PizzaSpezialeBuilder b)]) = _$PizzaSpeziale;
@BuiltValueHook(initializeBuilder: true)
static void _defaults(PizzaSpezialeBuilder b) => b;
@BuiltValueSerializer(custom: true)
static Serializer<PizzaSpeziale> get serializer => _$PizzaSpezialeSerializer();
}
class _$PizzaSpezialeSerializer implements PrimitiveSerializer<PizzaSpeziale> {
@override
final Iterable<Type> types = const [PizzaSpeziale, _$PizzaSpeziale];
@override
final String wireName = r'PizzaSpeziale';
Iterable<Object?> _serializeProperties(
Serializers serializers,
PizzaSpeziale object, {
FullType specifiedType = FullType.unspecified,
}) sync* {
if (object.atSchemaLocation != null) {
yield r'@schemaLocation';
yield serializers.serialize(
object.atSchemaLocation,
specifiedType: const FullType(String),
);
}
if (object.pizzaSize != null) {
yield r'pizzaSize';
yield serializers.serialize(
object.pizzaSize,
specifiedType: const FullType(num),
);
}
if (object.toppings != null) {
yield r'toppings';
yield serializers.serialize(
object.toppings,
specifiedType: const FullType(String),
);
}
if (object.atBaseType != null) {
yield r'@baseType';
yield serializers.serialize(
object.atBaseType,
specifiedType: const FullType(String),
);
}
if (object.href != null) {
yield r'href';
yield serializers.serialize(
object.href,
specifiedType: const FullType(String),
);
}
if (object.id != null) {
yield r'id';
yield serializers.serialize(
object.id,
specifiedType: const FullType(String),
);
}
yield r'@type';
yield serializers.serialize(
object.atType,
specifiedType: const FullType(String),
);
}
@override
Object serialize(
Serializers serializers,
PizzaSpeziale object, {
FullType specifiedType = FullType.unspecified,
}) {
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
}
void _deserializeProperties(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
required List<Object?> serializedList,
required PizzaSpezialeBuilder result,
required List<Object?> unhandled,
}) {
for (var i = 0; i < serializedList.length; i += 2) {
final key = serializedList[i] as String;
final value = serializedList[i + 1];
switch (key) {
case r'@schemaLocation':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atSchemaLocation = valueDes;
break;
case r'pizzaSize':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(num),
) as num;
result.pizzaSize = valueDes;
break;
case r'toppings':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.toppings = valueDes;
break;
case r'@baseType':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atBaseType = valueDes;
break;
case r'href':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.href = valueDes;
break;
case r'id':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.id = valueDes;
break;
case r'@type':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(String),
) as String;
result.atType = valueDes;
break;
default:
unhandled.add(key);
unhandled.add(value);
break;
}
}
}
@override
PizzaSpeziale deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
final result = PizzaSpezialeBuilder();
final serializedList = (serialized as Iterable<Object?>).toList();
final unhandled = <Object?>[];
_deserializeProperties(
serializers,
serialized,
specifiedType: specifiedType,
serializedList: serializedList,
unhandled: unhandled,
result: result,
);
return result.build();
}
}

View File

@ -0,0 +1,67 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// ignore_for_file: unused_import
import 'package:one_of_serializer/any_of_serializer.dart';
import 'package:one_of_serializer/one_of_serializer.dart';
import 'package:built_collection/built_collection.dart';
import 'package:built_value/json_object.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:built_value/iso_8601_date_time_serializer.dart';
import 'package:openapi/src/date_serializer.dart';
import 'package:openapi/src/model/date.dart';
import 'package:openapi/src/model/addressable.dart';
import 'package:openapi/src/model/bar.dart';
import 'package:openapi/src/model/bar_create.dart';
import 'package:openapi/src/model/bar_ref.dart';
import 'package:openapi/src/model/bar_ref_or_value.dart';
import 'package:openapi/src/model/entity.dart';
import 'package:openapi/src/model/entity_ref.dart';
import 'package:openapi/src/model/extensible.dart';
import 'package:openapi/src/model/foo.dart';
import 'package:openapi/src/model/foo_ref.dart';
import 'package:openapi/src/model/foo_ref_or_value.dart';
import 'package:openapi/src/model/pasta.dart';
import 'package:openapi/src/model/pizza.dart';
import 'package:openapi/src/model/pizza_speziale.dart';
part 'serializers.g.dart';
@SerializersFor([
Addressable,$Addressable,
Bar,
BarCreate,
BarRef,
BarRefOrValue,
Entity,$Entity,
EntityRef,$EntityRef,
Extensible,$Extensible,
Foo,
FooRef,
FooRefOrValue,
Pasta,
Pizza,$Pizza,
PizzaSpeziale,
])
Serializers serializers = (_$serializers.toBuilder()
..addBuilderFactory(
const FullType(BuiltList, [FullType(FooRefOrValue)]),
() => ListBuilder<FooRefOrValue>(),
)
..add(Addressable.serializer)
..add(Entity.serializer)
..add(EntityRef.serializer)
..add(Extensible.serializer)
..add(Pizza.serializer)
..add(const OneOfSerializer())
..add(const AnyOfSerializer())
..add(const DateSerializer())
..add(Iso8601DateTimeSerializer()))
.build();
Serializers standardSerializers =
(serializers.toBuilder()..addPlugin(StandardJsonPlugin())).build();

View File

@ -0,0 +1,88 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.openapitools</groupId>
<artifactId>DartDioOneOfPolymorphismAndInheritance</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>DartDio OneOf Polymorphism and Inheritance</name>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>pub-get</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>pub</executable>
<arguments>
<argument>get</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>pub-run-build-runner</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>pub</executable>
<arguments>
<argument>run</argument>
<argument>build_runner</argument>
<argument>build</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>dart-analyze</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>dart</executable>
<arguments>
<argument>analyze</argument>
<argument>--fatal-infos</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>dart-test</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>dart</executable>
<arguments>
<argument>test</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,19 @@
name: openapi
version: 1.0.0
description: OpenAPI API client
homepage: homepage
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
dio: '>=4.0.1 <5.0.0'
one_of: '>=1.5.0 <2.0.0'
one_of_serializer: '>=1.5.0 <2.0.0'
built_value: '>=8.4.0 <9.0.0'
built_collection: '>=5.1.1 <6.0.0'
dev_dependencies:
built_value_generator: '>=8.4.0 <9.0.0'
build_runner: any
test: ^1.16.0

View File

@ -0,0 +1,23 @@
import 'package:test/test.dart';
import 'package:openapi/openapi.dart';
// tests for Addressable
void main() {
//final instance = AddressableBuilder();
// TODO add properties to the builder and call build()
group(Addressable, () {
// Hyperlink reference
// String href
test('to test the property `href`', () async {
// TODO
});
// unique identifier
// String id
test('to test the property `id`', () async {
// TODO
});
});
}

Some files were not shown because too many files have changed in this diff Show More