diff --git a/bin/configs/dart-dio-oneof-polymorphism-and-inheritance.yaml b/bin/configs/dart-dio-oneof-polymorphism-and-inheritance.yaml new file mode 100644 index 00000000000..d3d5b622bc0 --- /dev/null +++ b/bin/configs/dart-dio-oneof-polymorphism-and-inheritance.yaml @@ -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" diff --git a/bin/configs/dart-dio-oneof-primitive.yaml b/bin/configs/dart-dio-oneof-primitive.yaml new file mode 100644 index 00000000000..29130b5dc46 --- /dev/null +++ b/bin/configs/dart-dio-oneof-primitive.yaml @@ -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" diff --git a/bin/configs/dart-dio-oneof.yaml b/bin/configs/dart-dio-oneof.yaml new file mode 100644 index 00000000000..865312cdd49 --- /dev/null +++ b/bin/configs/dart-dio-oneof.yaml @@ -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" diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java index b8ec826fd94..711a111be6a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java @@ -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 allModels, Set accumulator) { + + // get direct parents + Set 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 objs) { + Map 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 objs, CodegenModel model) { + List allVars = new ArrayList<>(); + allVars.addAll(((Collection) model.vendorExtensions.get(kSelfAndAncestorOnlyProps))); + allVars.addAll(((Collection) model.vendorExtensions.get(kSelfOnlyProps))); + allVars.addAll(((Collection) 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 objs) { + // get all models + Map 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 allAncestorsForAllModelsFlat = new HashSet<>(); + // maps a model to its ancestors + Map> allAncestorsForAllModels = new HashMap<>(); + for (java.util.Map.Entry cm : allModels.entrySet()) { + Set 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 allPureClasses = new HashSet<>(); + // set isChild,isParent,isPure + for (java.util.Map.Entry cmEntry : allModels.entrySet()) { + String key = cmEntry.getKey(); + CodegenModel cm = cmEntry.getValue(); + // get all ancestors + Set 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()); + 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 cmEntry : allModels.entrySet()) { + String key = cmEntry.getKey(); + CodegenModel cm = cmEntry.getValue(); + if (allPureClasses.contains(key)) { + continue; + } + // get all ancestors + Set allAncestors = allAncestorsForAllModels.get(key); + + // get direct parents + // Set directParentNames = cm.allOf == null ? new HashSet<>() : + // cm.allOf; + Set compositeProperties = new HashSet<>(); + + Set compositeModelNames = new HashSet(); + 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 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 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 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 selfAndAncestorOnlyProperties = new HashMap<>(); + + // STEP 1: calculating selfOnlyProperties + // get all vars of all ancestors and add them to ancestorPropNames + // Set _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 interfaceImports = new HashSet(); + interfaceImports.addAll(cm.allOf); + interfaceImports.addAll(cm.oneOf); + interfaceImports.addAll(cm.anyOf); + cm.imports.addAll(rewriteImports(interfaceImports, true)); + } + } + + @Override + public Map postProcessAllModels(Map 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 allModels) { super.postProcessOperationsWithModels(objs, allModels); OperationMap operations = objs.getOperations(); - List operationList = operations.getOperation(); + List operationList = operations.getOperation(); Set 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 rewriteImports(Set originalImports, boolean isModel) { Set 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) { diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/model.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/model.mustache index 5fdbb1b77c8..1917decaf6c 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/model.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/model.mustache @@ -1,4 +1,5 @@ {{>header}} +// ignore_for_file: unused_element {{#models}} {{#model}} {{#imports}} diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/pubspec.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/pubspec.mustache index 4a919c21c04..4faed4e3dc4 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/pubspec.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/pubspec.mustache @@ -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}} diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class.mustache index 66fe59788b0..a8a1339c630 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class.mustache @@ -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 types = const [{{classname}}, _${{classname}}]; +{{>serialization/built_value/class_serializer}}{{#vendorExtensions.x-is-parent}} - @override - final String wireName = r'{{classname}}'; - - @override - Iterable serialize(Serializers serializers, {{{classname}}} object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - {{#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 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}} \ No newline at end of file +{{>serialization/built_value/class_concrete}}{{/vendorExtensions.x-is-parent}} +{{>serialization/built_value/class_inline_enums}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_concrete.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_concrete.mustache new file mode 100644 index 00000000000..44cad763010 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_concrete.mustache @@ -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 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).toList(); + final unhandled = []; + _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(); + } +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_header.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_header.mustache new file mode 100644 index 00000000000..e0b80af1dbe --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_header.mustache @@ -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}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_inline_enums.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_inline_enums.mustache new file mode 100644 index 00000000000..1105c1b70b1 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_inline_enums.mustache @@ -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}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_members.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_members.mustache new file mode 100644 index 00000000000..ad2e2b0650b --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_members.mustache @@ -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 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(); \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_serializer.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_serializer.mustache new file mode 100644 index 00000000000..d3b3d8916ca --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_serializer.mustache @@ -0,0 +1,306 @@ +class _${{classname}}Serializer implements PrimitiveSerializer<{{classname}}> { + @override + final Iterable types = const [{{classname}}{{^vendorExtensions.x-is-parent}}, _${{classname}}{{/vendorExtensions.x-is-parent}}]; + + @override + final String wireName = r'{{classname}}'; + + Iterable _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); + 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}}[]{{/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); + } + 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).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 = []; + _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).toList(); + final unhandled = []; + _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).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 = []; + _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).toList(); + final unhandled = []; + _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).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).toList(); + {{#vendorExtensions.x-has-self-and-ancestor-only-props}} + {{! has props, assign them to result, and extract unhandled }} + final unhandled = []; + _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}} + } +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/deserialize_properties.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/deserialize_properties.mustache new file mode 100644 index 00000000000..d64ec8086c3 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/deserialize_properties.mustache @@ -0,0 +1,57 @@ + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required {{classname}}Builder result, + required List 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; + } + } + } \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/serializers.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/serializers.mustache index 7ef191808eb..aa49d9aef9e 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/serializers.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/serializers.mustache @@ -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(), {{/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()) diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/test_instance.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/test_instance.mustache index 4ee29fff3cc..2d92c472df3 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/test_instance.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/test_instance.mustache @@ -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() \ No newline at end of file diff --git a/pom.xml b/pom.xml index df0a4a8f97c..666e811ffaa 100644 --- a/pom.xml +++ b/pom.xml @@ -1325,6 +1325,9 @@ samples/openapi3/client/petstore/dart2/petstore_client_lib + samples/openapi3/client/petstore/dart-dio/oneof + samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance + samples/openapi3/client/petstore/dart-dio/oneof_primitive samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/.gitignore b/samples/openapi3/client/petstore/dart-dio/oneof/.gitignore new file mode 100644 index 00000000000..4298cdcbd1a --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/.gitignore @@ -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 + +# Don’t 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 diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/.openapi-generator-ignore b/samples/openapi3/client/petstore/dart-dio/oneof/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/.openapi-generator-ignore @@ -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 diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/.openapi-generator/FILES b/samples/openapi3/client/petstore/dart-dio/oneof/.openapi-generator/FILES new file mode 100644 index 00000000000..f1ab7b5540a --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/.openapi-generator/FILES @@ -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 diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/.openapi-generator/VERSION b/samples/openapi3/client/petstore/dart-dio/oneof/.openapi-generator/VERSION new file mode 100644 index 00000000000..66672d4e9d3 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/.openapi-generator/VERSION @@ -0,0 +1 @@ +6.1.0-SNAPSHOT \ No newline at end of file diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/README.md b/samples/openapi3/client/petstore/dart-dio/oneof/README.md new file mode 100644 index 00000000000..53bfd08fec4 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/README.md @@ -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 + + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/analysis_options.yaml b/samples/openapi3/client/petstore/dart-dio/oneof/analysis_options.yaml new file mode 100644 index 00000000000..a611887d3ac --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/analysis_options.yaml @@ -0,0 +1,9 @@ +analyzer: + language: + strict-inference: true + strict-raw-types: true + strong-mode: + implicit-dynamic: false + implicit-casts: false + exclude: + - test/*.dart diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/doc/Apple.md b/samples/openapi3/client/petstore/dart-dio/oneof/doc/Apple.md new file mode 100644 index 00000000000..c7f711b87ce --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/doc/Apple.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/doc/Banana.md b/samples/openapi3/client/petstore/dart-dio/oneof/doc/Banana.md new file mode 100644 index 00000000000..bef8a58a427 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/doc/Banana.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/doc/DefaultApi.md b/samples/openapi3/client/petstore/dart-dio/oneof/doc/DefaultApi.md new file mode 100644 index 00000000000..41c9b6f9411 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/doc/DefaultApi.md @@ -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) + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/doc/Fruit.md b/samples/openapi3/client/petstore/dart-dio/oneof/doc/Fruit.md new file mode 100644 index 00000000000..5d48cc6e6d3 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/doc/Fruit.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/lib/openapi.dart b/samples/openapi3/client/petstore/dart-dio/oneof/lib/openapi.dart new file mode 100644 index 00000000000..d85a16fc6ad --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/lib/openapi.dart @@ -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'; diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/api.dart b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/api.dart new file mode 100644 index 00000000000..ba9424a2d2a --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/api.dart @@ -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? 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/api/default_api.dart b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/api/default_api.dart new file mode 100644 index 00000000000..e98b7ae9cae --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/api/default_api.dart @@ -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> rootGet({ + CancelToken? cancelToken, + Map? headers, + Map? extra, + ValidateStatus? validateStatus, + ProgressCallback? onSendProgress, + ProgressCallback? onReceiveProgress, + }) async { + final _path = r'/'; + final _options = Options( + method: r'GET', + headers: { + ...?headers, + }, + extra: { + 'secure': >[], + ...?extra, + }, + validateStatus: validateStatus, + ); + + final _response = await _dio.request( + _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( + data: _responseData, + headers: _response.headers, + isRedirect: _response.isRedirect, + requestOptions: _response.requestOptions, + redirects: _response.redirects, + statusCode: _response.statusCode, + statusMessage: _response.statusMessage, + extra: _response.extra, + ); + } + +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/api_util.dart b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/api_util.dart new file mode 100644 index 00000000000..ed3bb12f25b --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/api_util.dart @@ -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 encodeCollectionQueryParameter( + Serializers serializers, + dynamic value, + FullType type, { + ListFormat format = ListFormat.multi, +}) { + final serialized = serializers.serialize( + value as Object, + specifiedType: type, + ); + if (value is BuiltList || value is BuiltSet) { + return ListParam(List.of((serialized as Iterable).cast()), format); + } + throw ArgumentError('Invalid value passed to encodeCollectionQueryParameter'); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/auth/api_key_auth.dart b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/auth/api_key_auth.dart new file mode 100644 index 00000000000..ee16e3f0f92 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/auth/api_key_auth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/auth/auth.dart b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/auth/auth.dart new file mode 100644 index 00000000000..f7ae9bf3f11 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/auth/auth.dart @@ -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> getAuthInfo(RequestOptions route, bool Function(Map secure) handles) { + if (route.extra.containsKey('secure')) { + final auth = route.extra['secure'] as List>; + return auth.where((secure) => handles(secure)).toList(); + } + return []; + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/auth/basic_auth.dart b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/auth/basic_auth.dart new file mode 100644 index 00000000000..b6e6dce04f9 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/auth/basic_auth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/auth/bearer_auth.dart b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/auth/bearer_auth.dart new file mode 100644 index 00000000000..1d4402b376c --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/auth/bearer_auth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/auth/oauth.dart b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/auth/oauth.dart new file mode 100644 index 00000000000..337cf762b0c --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/auth/oauth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/date_serializer.dart b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/date_serializer.dart new file mode 100644 index 00000000000..db3c5c437db --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/date_serializer.dart @@ -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 { + + const DateSerializer(); + + @override + Iterable 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(); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/model/apple.dart b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/model/apple.dart new file mode 100644 index 00000000000..02ca94190b9 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/model/apple.dart @@ -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 { + @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 get serializer => _$AppleSerializer(); +} + +class _$AppleSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Apple, _$Apple]; + + @override + final String wireName = r'Apple'; + + Iterable _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 serializedList, + required AppleBuilder result, + required List 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).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/model/banana.dart b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/model/banana.dart new file mode 100644 index 00000000000..bf2d632ee11 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/model/banana.dart @@ -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 { + @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 get serializer => _$BananaSerializer(); +} + +class _$BananaSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Banana, _$Banana]; + + @override + final String wireName = r'Banana'; + + Iterable _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 serializedList, + required BananaBuilder result, + required List 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).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/model/date.dart b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/model/date.dart new file mode 100644 index 00000000000..b21c7f544be --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/model/date.dart @@ -0,0 +1,70 @@ +/// A gregorian calendar date generated by +/// OpenAPI generator to differentiate +/// between [DateTime] and [Date] formats. +class Date implements Comparable { + 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); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/model/fruit.dart b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/model/fruit.dart new file mode 100644 index 00000000000..11f8cfa7050 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/model/fruit.dart @@ -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 { + @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 get serializer => _$FruitSerializer(); +} + +class _$FruitSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Fruit, _$Fruit]; + + @override + final String wireName = r'Fruit'; + + Iterable _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); + return result; + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required FruitBuilder result, + required List 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).toList(); + final unhandled = []; + _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(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/serializers.dart b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/serializers.dart new file mode 100644 index 00000000000..ddb1d66a1f5 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/lib/src/serializers.dart @@ -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(); diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/pom.xml b/samples/openapi3/client/petstore/dart-dio/oneof/pom.xml new file mode 100644 index 00000000000..810c7d48d77 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/pom.xml @@ -0,0 +1,88 @@ + + 4.0.0 + org.openapitools + DartDioOneOf + pom + 1.0.0-SNAPSHOT + DartDio OneOf + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory} + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + pub-get + pre-integration-test + + exec + + + pub + + get + + + + + pub-run-build-runner + pre-integration-test + + exec + + + pub + + run + build_runner + build + + + + + dart-analyze + integration-test + + exec + + + dart + + analyze + --fatal-infos + + + + + dart-test + integration-test + + exec + + + dart + + test + + + + + + + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/pubspec.yaml b/samples/openapi3/client/petstore/dart-dio/oneof/pubspec.yaml new file mode 100644 index 00000000000..fb676f65c39 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/pubspec.yaml @@ -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 diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/test/apple_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof/test/apple_test.dart new file mode 100644 index 00000000000..1d542169550 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/test/apple_test.dart @@ -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 + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/test/banana_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof/test/banana_test.dart new file mode 100644 index 00000000000..a883acc0a9e --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/test/banana_test.dart @@ -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 + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/test/default_api_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof/test/default_api_test.dart new file mode 100644 index 00000000000..07d256d2e55 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/test/default_api_test.dart @@ -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 rootGet() async + test('test rootGet', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/test/fruit_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof/test/fruit_test.dart new file mode 100644 index 00000000000..c18790ae956 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof/test/fruit_test.dart @@ -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 + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.gitignore b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.gitignore new file mode 100644 index 00000000000..4298cdcbd1a --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.gitignore @@ -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 + +# Don’t 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 diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator-ignore b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator-ignore @@ -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 diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator/FILES b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator/FILES new file mode 100644 index 00000000000..52a900a1962 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator/FILES @@ -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 diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator/VERSION b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator/VERSION new file mode 100644 index 00000000000..66672d4e9d3 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator/VERSION @@ -0,0 +1 @@ +6.1.0-SNAPSHOT \ No newline at end of file diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/README.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/README.md new file mode 100644 index 00000000000..6a3fea771a1 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/README.md @@ -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 + + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/analysis_options.yaml b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/analysis_options.yaml new file mode 100644 index 00000000000..a611887d3ac --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/analysis_options.yaml @@ -0,0 +1,9 @@ +analyzer: + language: + strict-inference: true + strict-raw-types: true + strong-mode: + implicit-dynamic: false + implicit-casts: false + exclude: + - test/*.dart diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Addressable.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Addressable.md new file mode 100644 index 00000000000..0fcd81b8038 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Addressable.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Bar.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Bar.md new file mode 100644 index 00000000000..4cccc863a48 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Bar.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/BarApi.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/BarApi.md new file mode 100644 index 00000000000..3ef168ecf34 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/BarApi.md @@ -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) + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/BarCreate.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/BarCreate.md new file mode 100644 index 00000000000..c0b4ba6edc9 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/BarCreate.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/BarRef.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/BarRef.md new file mode 100644 index 00000000000..949695f4d36 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/BarRef.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/BarRefOrValue.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/BarRefOrValue.md new file mode 100644 index 00000000000..9dafa2d6b22 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/BarRefOrValue.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Entity.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Entity.md new file mode 100644 index 00000000000..5ba2144b44f --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Entity.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/EntityRef.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/EntityRef.md new file mode 100644 index 00000000000..80eae55f414 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/EntityRef.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Extensible.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Extensible.md new file mode 100644 index 00000000000..7a781e578ea --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Extensible.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Foo.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Foo.md new file mode 100644 index 00000000000..2627691fefe --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Foo.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/FooApi.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/FooApi.md new file mode 100644 index 00000000000..9e8990ebb8b --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/FooApi.md @@ -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 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<FooRefOrValue>**](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) + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/FooRef.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/FooRef.md new file mode 100644 index 00000000000..68104b22729 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/FooRef.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/FooRefOrValue.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/FooRefOrValue.md new file mode 100644 index 00000000000..35e9fd114e1 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/FooRefOrValue.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/FooRefOrValueWithProperties.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/FooRefOrValueWithProperties.md new file mode 100644 index 00000000000..05aa2b0bbc1 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/FooRefOrValueWithProperties.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Pasta.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Pasta.md new file mode 100644 index 00000000000..034ff420d32 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Pasta.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Pizza.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Pizza.md new file mode 100644 index 00000000000..e4b040a6a79 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Pizza.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/PizzaSpeziale.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/PizzaSpeziale.md new file mode 100644 index 00000000000..e1d8434c077 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/PizzaSpeziale.md @@ -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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/openapi.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/openapi.dart new file mode 100644 index 00000000000..ea87a7cb476 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/openapi.dart @@ -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'; diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/api.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/api.dart new file mode 100644 index 00000000000..0bb368eace0 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/api.dart @@ -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? 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/api/bar_api.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/api/bar_api.dart new file mode 100644 index 00000000000..4afe604a557 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/api/bar_api.dart @@ -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> createBar({ + required BarCreate barCreate, + CancelToken? cancelToken, + Map? headers, + Map? extra, + ValidateStatus? validateStatus, + ProgressCallback? onSendProgress, + ProgressCallback? onReceiveProgress, + }) async { + final _path = r'/bar'; + final _options = Options( + method: r'POST', + headers: { + ...?headers, + }, + extra: { + 'secure': >[], + ...?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( + _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( + data: _responseData, + headers: _response.headers, + isRedirect: _response.isRedirect, + requestOptions: _response.requestOptions, + redirects: _response.redirects, + statusCode: _response.statusCode, + statusMessage: _response.statusMessage, + extra: _response.extra, + ); + } + +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/api/foo_api.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/api/foo_api.dart new file mode 100644 index 00000000000..232392c76a7 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/api/foo_api.dart @@ -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> createFoo({ + Foo? foo, + CancelToken? cancelToken, + Map? headers, + Map? extra, + ValidateStatus? validateStatus, + ProgressCallback? onSendProgress, + ProgressCallback? onReceiveProgress, + }) async { + final _path = r'/foo'; + final _options = Options( + method: r'POST', + headers: { + ...?headers, + }, + extra: { + 'secure': >[], + ...?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( + _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( + 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] as data + /// Throws [DioError] if API call or serialization fails + Future>> getAllFoos({ + CancelToken? cancelToken, + Map? headers, + Map? extra, + ValidateStatus? validateStatus, + ProgressCallback? onSendProgress, + ProgressCallback? onReceiveProgress, + }) async { + final _path = r'/foo'; + final _options = Options( + method: r'GET', + headers: { + ...?headers, + }, + extra: { + 'secure': >[], + ...?extra, + }, + validateStatus: validateStatus, + ); + + final _response = await _dio.request( + _path, + options: _options, + cancelToken: cancelToken, + onSendProgress: onSendProgress, + onReceiveProgress: onReceiveProgress, + ); + + BuiltList _responseData; + + try { + const _responseType = FullType(BuiltList, [FullType(FooRefOrValue)]); + _responseData = _serializers.deserialize( + _response.data!, + specifiedType: _responseType, + ) as BuiltList; + + } catch (error, stackTrace) { + throw DioError( + requestOptions: _response.requestOptions, + response: _response, + type: DioErrorType.other, + error: error, + )..stackTrace = stackTrace; + } + + return Response>( + data: _responseData, + headers: _response.headers, + isRedirect: _response.isRedirect, + requestOptions: _response.requestOptions, + redirects: _response.redirects, + statusCode: _response.statusCode, + statusMessage: _response.statusMessage, + extra: _response.extra, + ); + } + +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/api_util.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/api_util.dart new file mode 100644 index 00000000000..ed3bb12f25b --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/api_util.dart @@ -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 encodeCollectionQueryParameter( + Serializers serializers, + dynamic value, + FullType type, { + ListFormat format = ListFormat.multi, +}) { + final serialized = serializers.serialize( + value as Object, + specifiedType: type, + ); + if (value is BuiltList || value is BuiltSet) { + return ListParam(List.of((serialized as Iterable).cast()), format); + } + throw ArgumentError('Invalid value passed to encodeCollectionQueryParameter'); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/auth/api_key_auth.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/auth/api_key_auth.dart new file mode 100644 index 00000000000..ee16e3f0f92 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/auth/api_key_auth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/auth/auth.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/auth/auth.dart new file mode 100644 index 00000000000..f7ae9bf3f11 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/auth/auth.dart @@ -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> getAuthInfo(RequestOptions route, bool Function(Map secure) handles) { + if (route.extra.containsKey('secure')) { + final auth = route.extra['secure'] as List>; + return auth.where((secure) => handles(secure)).toList(); + } + return []; + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/auth/basic_auth.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/auth/basic_auth.dart new file mode 100644 index 00000000000..b6e6dce04f9 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/auth/basic_auth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/auth/bearer_auth.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/auth/bearer_auth.dart new file mode 100644 index 00000000000..1d4402b376c --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/auth/bearer_auth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/auth/oauth.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/auth/oauth.dart new file mode 100644 index 00000000000..337cf762b0c --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/auth/oauth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/date_serializer.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/date_serializer.dart new file mode 100644 index 00000000000..db3c5c437db --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/date_serializer.dart @@ -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 { + + const DateSerializer(); + + @override + Iterable 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(); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/addressable.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/addressable.dart new file mode 100644 index 00000000000..e0311b6595b --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/addressable.dart @@ -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 get serializer => _$AddressableSerializer(); +} + +class _$AddressableSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Addressable]; + + @override + final String wireName = r'Addressable'; + + Iterable _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 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 serializedList, + required AddressableBuilder result, + required List 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).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/bar.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/bar.dart new file mode 100644 index 00000000000..9c52802b84a --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/bar.dart @@ -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 { + @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 get serializer => _$BarSerializer(); +} + +class _$BarSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Bar, _$Bar]; + + @override + final String wireName = r'Bar'; + + Iterable _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 serializedList, + required BarBuilder result, + required List 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).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/bar_create.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/bar_create.dart new file mode 100644 index 00000000000..ebbce357782 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/bar_create.dart @@ -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 { + @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 get serializer => _$BarCreateSerializer(); +} + +class _$BarCreateSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [BarCreate, _$BarCreate]; + + @override + final String wireName = r'BarCreate'; + + Iterable _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 serializedList, + required BarCreateBuilder result, + required List 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).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/bar_ref.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/bar_ref.dart new file mode 100644 index 00000000000..bb4965bea82 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/bar_ref.dart @@ -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 { + 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 get serializer => _$BarRefSerializer(); +} + +class _$BarRefSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [BarRef, _$BarRef]; + + @override + final String wireName = r'BarRef'; + + Iterable _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 serializedList, + required BarRefBuilder result, + required List 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).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/bar_ref_or_value.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/bar_ref_or_value.dart new file mode 100644 index 00000000000..09d7b0b99c6 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/bar_ref_or_value.dart @@ -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 { + /// One Of [Bar], [BarRef] + OneOf get oneOf; + + static const String discriminatorFieldName = r'atType'; + + static const Map 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 get serializer => _$BarRefOrValueSerializer(); +} + +class _$BarRefOrValueSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [BarRefOrValue, _$BarRefOrValue]; + + @override + final String wireName = r'BarRefOrValue'; + + Iterable _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).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(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/date.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/date.dart new file mode 100644 index 00000000000..b21c7f544be --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/date.dart @@ -0,0 +1,70 @@ +/// A gregorian calendar date generated by +/// OpenAPI generator to differentiate +/// between [DateTime] and [Date] formats. +class Date implements Comparable { + 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); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/entity.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/entity.dart new file mode 100644 index 00000000000..1a83a5d6b50 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/entity.dart @@ -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 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 get serializer => _$EntitySerializer(); +} + +class _$EntitySerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Entity]; + + @override + final String wireName = r'Entity'; + + Iterable _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).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 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 serializedList, + required EntityBuilder result, + required List 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).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/entity_ref.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/entity_ref.dart new file mode 100644 index 00000000000..278aa92276c --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/entity_ref.dart @@ -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 discriminatorMapping = { + r'BarRef': BarRef, + r'FooRef': FooRef, + }; + + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$EntityRefSerializer(); +} + +class _$EntityRefSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [EntityRef]; + + @override + final String wireName = r'EntityRef'; + + Iterable _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).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 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 serializedList, + required EntityRefBuilder result, + required List 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).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/extensible.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/extensible.dart new file mode 100644 index 00000000000..2423fb27641 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/extensible.dart @@ -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 get serializer => _$ExtensibleSerializer(); +} + +class _$ExtensibleSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Extensible]; + + @override + final String wireName = r'Extensible'; + + Iterable _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 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 serializedList, + required ExtensibleBuilder result, + required List 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).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/foo.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/foo.dart new file mode 100644 index 00000000000..efb327dd664 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/foo.dart @@ -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 { + @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 get serializer => _$FooSerializer(); +} + +class _$FooSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Foo, _$Foo]; + + @override + final String wireName = r'Foo'; + + Iterable _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 serializedList, + required FooBuilder result, + required List 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).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/foo_ref.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/foo_ref.dart new file mode 100644 index 00000000000..dd05a2d4787 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/foo_ref.dart @@ -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 { + @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 get serializer => _$FooRefSerializer(); +} + +class _$FooRefSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [FooRef, _$FooRef]; + + @override + final String wireName = r'FooRef'; + + Iterable _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 serializedList, + required FooRefBuilder result, + required List 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).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/foo_ref_or_value.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/foo_ref_or_value.dart new file mode 100644 index 00000000000..f512292196a --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/foo_ref_or_value.dart @@ -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 { + /// One Of [Foo], [FooRef] + OneOf get oneOf; + + static const String discriminatorFieldName = r'atType'; + + static const Map 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 get serializer => _$FooRefOrValueSerializer(); +} + +class _$FooRefOrValueSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [FooRefOrValue, _$FooRefOrValue]; + + @override + final String wireName = r'FooRefOrValue'; + + Iterable _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).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(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/pasta.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/pasta.dart new file mode 100644 index 00000000000..5c5ef72537c --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/pasta.dart @@ -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 { + @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 get serializer => _$PastaSerializer(); +} + +class _$PastaSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Pasta, _$Pasta]; + + @override + final String wireName = r'Pasta'; + + Iterable _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 serializedList, + required PastaBuilder result, + required List 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).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/pizza.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/pizza.dart new file mode 100644 index 00000000000..866daab885e --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/pizza.dart @@ -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 discriminatorMapping = { + r'PizzaSpeziale': PizzaSpeziale, + }; + + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$PizzaSerializer(); +} + +class _$PizzaSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Pizza]; + + @override + final String wireName = r'Pizza'; + + Iterable _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).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 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 serializedList, + required PizzaBuilder result, + required List 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).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/pizza_speziale.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/pizza_speziale.dart new file mode 100644 index 00000000000..7f17257e503 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/pizza_speziale.dart @@ -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 { + @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 get serializer => _$PizzaSpezialeSerializer(); +} + +class _$PizzaSpezialeSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [PizzaSpeziale, _$PizzaSpeziale]; + + @override + final String wireName = r'PizzaSpeziale'; + + Iterable _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 serializedList, + required PizzaSpezialeBuilder result, + required List 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).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/serializers.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/serializers.dart new file mode 100644 index 00000000000..55083251e5e --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/serializers.dart @@ -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(), + ) + ..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(); diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/pom.xml b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/pom.xml new file mode 100644 index 00000000000..50f62b7f8da --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/pom.xml @@ -0,0 +1,88 @@ + + 4.0.0 + org.openapitools + DartDioOneOfPolymorphismAndInheritance + pom + 1.0.0-SNAPSHOT + DartDio OneOf Polymorphism and Inheritance + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory} + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + pub-get + pre-integration-test + + exec + + + pub + + get + + + + + pub-run-build-runner + pre-integration-test + + exec + + + pub + + run + build_runner + build + + + + + dart-analyze + integration-test + + exec + + + dart + + analyze + --fatal-infos + + + + + dart-test + integration-test + + exec + + + dart + + test + + + + + + + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/pubspec.yaml b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/pubspec.yaml new file mode 100644 index 00000000000..fb676f65c39 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/pubspec.yaml @@ -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 diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/addressable_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/addressable_test.dart new file mode 100644 index 00000000000..696e26e8e54 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/addressable_test.dart @@ -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 + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/bar_api_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/bar_api_test.dart new file mode 100644 index 00000000000..73be91c446e --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/bar_api_test.dart @@ -0,0 +1,18 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + + +/// tests for BarApi +void main() { + final instance = Openapi().getBarApi(); + + group(BarApi, () { + // Create a Bar + // + //Future createBar(BarCreate barCreate) async + test('test createBar', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/bar_create_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/bar_create_test.dart new file mode 100644 index 00000000000..1bf90151be8 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/bar_create_test.dart @@ -0,0 +1,56 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for BarCreate +void main() { + final instance = BarCreateBuilder(); + // TODO add properties to the builder and call build() + + group(BarCreate, () { + // String barPropA + test('to test the property `barPropA`', () async { + // TODO + }); + + // String fooPropB + test('to test the property `fooPropB`', () async { + // TODO + }); + + // FooRefOrValue foo + test('to test the property `foo`', () async { + // TODO + }); + + // Hyperlink reference + // String href + test('to test the property `href`', () async { + // TODO + }); + + // unique identifier + // String id + test('to test the property `id`', () async { + // TODO + }); + + // A URI to a JSON-Schema file that defines additional attributes and relationships + // String atSchemaLocation + test('to test the property `atSchemaLocation`', () async { + // TODO + }); + + // When sub-classing, this defines the super-class + // String atBaseType + test('to test the property `atBaseType`', () async { + // TODO + }); + + // When sub-classing, this defines the sub-class Extensible name + // String atType + test('to test the property `atType`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/bar_ref_or_value_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/bar_ref_or_value_test.dart new file mode 100644 index 00000000000..c132ac09943 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/bar_ref_or_value_test.dart @@ -0,0 +1,41 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for BarRefOrValue +void main() { + final instance = BarRefOrValueBuilder(); + // TODO add properties to the builder and call build() + + group(BarRefOrValue, () { + // Hyperlink reference + // String href + test('to test the property `href`', () async { + // TODO + }); + + // unique identifier + // String id + test('to test the property `id`', () async { + // TODO + }); + + // A URI to a JSON-Schema file that defines additional attributes and relationships + // String atSchemaLocation + test('to test the property `atSchemaLocation`', () async { + // TODO + }); + + // When sub-classing, this defines the super-class + // String atBaseType + test('to test the property `atBaseType`', () async { + // TODO + }); + + // When sub-classing, this defines the sub-class Extensible name + // String atType + test('to test the property `atType`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/bar_ref_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/bar_ref_test.dart new file mode 100644 index 00000000000..9c410b2b5c5 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/bar_ref_test.dart @@ -0,0 +1,41 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for BarRef +void main() { + final instance = BarRefBuilder(); + // TODO add properties to the builder and call build() + + group(BarRef, () { + // Hyperlink reference + // String href + test('to test the property `href`', () async { + // TODO + }); + + // unique identifier + // String id + test('to test the property `id`', () async { + // TODO + }); + + // A URI to a JSON-Schema file that defines additional attributes and relationships + // String atSchemaLocation + test('to test the property `atSchemaLocation`', () async { + // TODO + }); + + // When sub-classing, this defines the super-class + // String atBaseType + test('to test the property `atBaseType`', () async { + // TODO + }); + + // When sub-classing, this defines the sub-class Extensible name + // String atType + test('to test the property `atType`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/bar_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/bar_test.dart new file mode 100644 index 00000000000..dc6daaa3400 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/bar_test.dart @@ -0,0 +1,55 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for Bar +void main() { + final instance = BarBuilder(); + // TODO add properties to the builder and call build() + + group(Bar, () { + // String id + test('to test the property `id`', () async { + // TODO + }); + + // String barPropA + test('to test the property `barPropA`', () async { + // TODO + }); + + // String fooPropB + test('to test the property `fooPropB`', () async { + // TODO + }); + + // FooRefOrValue foo + test('to test the property `foo`', () async { + // TODO + }); + + // Hyperlink reference + // String href + test('to test the property `href`', () async { + // TODO + }); + + // A URI to a JSON-Schema file that defines additional attributes and relationships + // String atSchemaLocation + test('to test the property `atSchemaLocation`', () async { + // TODO + }); + + // When sub-classing, this defines the super-class + // String atBaseType + test('to test the property `atBaseType`', () async { + // TODO + }); + + // When sub-classing, this defines the sub-class Extensible name + // String atType + test('to test the property `atType`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/entity_ref_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/entity_ref_test.dart new file mode 100644 index 00000000000..836289893fb --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/entity_ref_test.dart @@ -0,0 +1,53 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for EntityRef +void main() { + //final instance = EntityRefBuilder(); + // TODO add properties to the builder and call build() + + group(EntityRef, () { + // Name of the related entity. + // String name + test('to test the property `name`', () async { + // TODO + }); + + // The actual type of the target instance when needed for disambiguation. + // String atReferredType + test('to test the property `atReferredType`', () async { + // TODO + }); + + // Hyperlink reference + // String href + test('to test the property `href`', () async { + // TODO + }); + + // unique identifier + // String id + test('to test the property `id`', () async { + // TODO + }); + + // A URI to a JSON-Schema file that defines additional attributes and relationships + // String atSchemaLocation + test('to test the property `atSchemaLocation`', () async { + // TODO + }); + + // When sub-classing, this defines the super-class + // String atBaseType + test('to test the property `atBaseType`', () async { + // TODO + }); + + // When sub-classing, this defines the sub-class Extensible name + // String atType + test('to test the property `atType`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/entity_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/entity_test.dart new file mode 100644 index 00000000000..30429747562 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/entity_test.dart @@ -0,0 +1,41 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for Entity +void main() { + //final instance = EntityBuilder(); + // TODO add properties to the builder and call build() + + group(Entity, () { + // Hyperlink reference + // String href + test('to test the property `href`', () async { + // TODO + }); + + // unique identifier + // String id + test('to test the property `id`', () async { + // TODO + }); + + // A URI to a JSON-Schema file that defines additional attributes and relationships + // String atSchemaLocation + test('to test the property `atSchemaLocation`', () async { + // TODO + }); + + // When sub-classing, this defines the super-class + // String atBaseType + test('to test the property `atBaseType`', () async { + // TODO + }); + + // When sub-classing, this defines the sub-class Extensible name + // String atType + test('to test the property `atType`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/extensible_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/extensible_test.dart new file mode 100644 index 00000000000..75e6211e074 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/extensible_test.dart @@ -0,0 +1,29 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for Extensible +void main() { + //final instance = ExtensibleBuilder(); + // TODO add properties to the builder and call build() + + group(Extensible, () { + // A URI to a JSON-Schema file that defines additional attributes and relationships + // String atSchemaLocation + test('to test the property `atSchemaLocation`', () async { + // TODO + }); + + // When sub-classing, this defines the super-class + // String atBaseType + test('to test the property `atBaseType`', () async { + // TODO + }); + + // When sub-classing, this defines the sub-class Extensible name + // String atType + test('to test the property `atType`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/foo_api_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/foo_api_test.dart new file mode 100644 index 00000000000..f33986a08b6 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/foo_api_test.dart @@ -0,0 +1,25 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + + +/// tests for FooApi +void main() { + final instance = Openapi().getFooApi(); + + group(FooApi, () { + // Create a Foo + // + //Future createFoo({ Foo foo }) async + test('test createFoo', () async { + // TODO + }); + + // GET all Foos + // + //Future> getAllFoos() async + test('test getAllFoos', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/foo_ref_or_value_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/foo_ref_or_value_test.dart new file mode 100644 index 00000000000..029d030e5e3 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/foo_ref_or_value_test.dart @@ -0,0 +1,41 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for FooRefOrValue +void main() { + final instance = FooRefOrValueBuilder(); + // TODO add properties to the builder and call build() + + group(FooRefOrValue, () { + // Hyperlink reference + // String href + test('to test the property `href`', () async { + // TODO + }); + + // unique identifier + // String id + test('to test the property `id`', () async { + // TODO + }); + + // A URI to a JSON-Schema file that defines additional attributes and relationships + // String atSchemaLocation + test('to test the property `atSchemaLocation`', () async { + // TODO + }); + + // When sub-classing, this defines the super-class + // String atBaseType + test('to test the property `atBaseType`', () async { + // TODO + }); + + // When sub-classing, this defines the sub-class Extensible name + // String atType + test('to test the property `atType`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/foo_ref_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/foo_ref_test.dart new file mode 100644 index 00000000000..a1398787bbc --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/foo_ref_test.dart @@ -0,0 +1,46 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for FooRef +void main() { + final instance = FooRefBuilder(); + // TODO add properties to the builder and call build() + + group(FooRef, () { + // String foorefPropA + test('to test the property `foorefPropA`', () async { + // TODO + }); + + // Hyperlink reference + // String href + test('to test the property `href`', () async { + // TODO + }); + + // unique identifier + // String id + test('to test the property `id`', () async { + // TODO + }); + + // A URI to a JSON-Schema file that defines additional attributes and relationships + // String atSchemaLocation + test('to test the property `atSchemaLocation`', () async { + // TODO + }); + + // When sub-classing, this defines the super-class + // String atBaseType + test('to test the property `atBaseType`', () async { + // TODO + }); + + // When sub-classing, this defines the sub-class Extensible name + // String atType + test('to test the property `atType`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/foo_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/foo_test.dart new file mode 100644 index 00000000000..93a5286e2b4 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/foo_test.dart @@ -0,0 +1,51 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for Foo +void main() { + final instance = FooBuilder(); + // TODO add properties to the builder and call build() + + group(Foo, () { + // String fooPropA + test('to test the property `fooPropA`', () async { + // TODO + }); + + // String fooPropB + test('to test the property `fooPropB`', () async { + // TODO + }); + + // Hyperlink reference + // String href + test('to test the property `href`', () async { + // TODO + }); + + // unique identifier + // String id + test('to test the property `id`', () async { + // TODO + }); + + // A URI to a JSON-Schema file that defines additional attributes and relationships + // String atSchemaLocation + test('to test the property `atSchemaLocation`', () async { + // TODO + }); + + // When sub-classing, this defines the super-class + // String atBaseType + test('to test the property `atBaseType`', () async { + // TODO + }); + + // When sub-classing, this defines the sub-class Extensible name + // String atType + test('to test the property `atType`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/pasta_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/pasta_test.dart new file mode 100644 index 00000000000..6a3ae338eec --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/pasta_test.dart @@ -0,0 +1,46 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for Pasta +void main() { + final instance = PastaBuilder(); + // TODO add properties to the builder and call build() + + group(Pasta, () { + // String vendor + test('to test the property `vendor`', () async { + // TODO + }); + + // Hyperlink reference + // String href + test('to test the property `href`', () async { + // TODO + }); + + // unique identifier + // String id + test('to test the property `id`', () async { + // TODO + }); + + // A URI to a JSON-Schema file that defines additional attributes and relationships + // String atSchemaLocation + test('to test the property `atSchemaLocation`', () async { + // TODO + }); + + // When sub-classing, this defines the super-class + // String atBaseType + test('to test the property `atBaseType`', () async { + // TODO + }); + + // When sub-classing, this defines the sub-class Extensible name + // String atType + test('to test the property `atType`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/pizza_speziale_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/pizza_speziale_test.dart new file mode 100644 index 00000000000..774320231c9 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/pizza_speziale_test.dart @@ -0,0 +1,46 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for PizzaSpeziale +void main() { + final instance = PizzaSpezialeBuilder(); + // TODO add properties to the builder and call build() + + group(PizzaSpeziale, () { + // String toppings + test('to test the property `toppings`', () async { + // TODO + }); + + // Hyperlink reference + // String href + test('to test the property `href`', () async { + // TODO + }); + + // unique identifier + // String id + test('to test the property `id`', () async { + // TODO + }); + + // A URI to a JSON-Schema file that defines additional attributes and relationships + // String atSchemaLocation + test('to test the property `atSchemaLocation`', () async { + // TODO + }); + + // When sub-classing, this defines the super-class + // String atBaseType + test('to test the property `atBaseType`', () async { + // TODO + }); + + // When sub-classing, this defines the sub-class Extensible name + // String atType + test('to test the property `atType`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/pizza_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/pizza_test.dart new file mode 100644 index 00000000000..5c6e1af95a5 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/pizza_test.dart @@ -0,0 +1,46 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for Pizza +void main() { + //final instance = PizzaBuilder(); + // TODO add properties to the builder and call build() + + group(Pizza, () { + // num pizzaSize + test('to test the property `pizzaSize`', () async { + // TODO + }); + + // Hyperlink reference + // String href + test('to test the property `href`', () async { + // TODO + }); + + // unique identifier + // String id + test('to test the property `id`', () async { + // TODO + }); + + // A URI to a JSON-Schema file that defines additional attributes and relationships + // String atSchemaLocation + test('to test the property `atSchemaLocation`', () async { + // TODO + }); + + // When sub-classing, this defines the super-class + // String atBaseType + test('to test the property `atBaseType`', () async { + // TODO + }); + + // When sub-classing, this defines the sub-class Extensible name + // String atType + test('to test the property `atType`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/.gitignore b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/.gitignore new file mode 100644 index 00000000000..4298cdcbd1a --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/.gitignore @@ -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 + +# Don’t 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 diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/.openapi-generator-ignore b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/.openapi-generator-ignore @@ -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 diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/.openapi-generator/FILES b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/.openapi-generator/FILES new file mode 100644 index 00000000000..7f2ac59bf64 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/.openapi-generator/FILES @@ -0,0 +1,21 @@ +.gitignore +README.md +analysis_options.yaml +doc/Child.md +doc/DefaultApi.md +doc/Example.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/child.dart +lib/src/model/date.dart +lib/src/model/example.dart +lib/src/serializers.dart +pubspec.yaml diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/.openapi-generator/VERSION b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/.openapi-generator/VERSION new file mode 100644 index 00000000000..66672d4e9d3 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/.openapi-generator/VERSION @@ -0,0 +1 @@ +6.1.0-SNAPSHOT \ No newline at end of file diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/README.md b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/README.md new file mode 100644 index 00000000000..d73bafd4c64 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/README.md @@ -0,0 +1,83 @@ +# 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: 1.0.0 +- 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.list(); + print(response); +} catch on DioError (e) { + print("Exception when calling DefaultApi->list: $e\n"); +} + +``` + +## Documentation for API Endpoints + +All URIs are relative to *http://api.example.xyz/v1* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +[*DefaultApi*](doc/DefaultApi.md) | [**list**](doc/DefaultApi.md#list) | **GET** /example | + + +## Documentation For Models + + - [Child](doc/Child.md) + - [Example](doc/Example.md) + + +## Documentation For Authorization + + All endpoints do not require authorization. + + +## Author + + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/analysis_options.yaml b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/analysis_options.yaml new file mode 100644 index 00000000000..a611887d3ac --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/analysis_options.yaml @@ -0,0 +1,9 @@ +analyzer: + language: + strict-inference: true + strict-raw-types: true + strong-mode: + implicit-dynamic: false + implicit-casts: false + exclude: + - test/*.dart diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/doc/Child.md b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/doc/Child.md new file mode 100644 index 00000000000..bed0f2feec1 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/doc/Child.md @@ -0,0 +1,15 @@ +# openapi.model.Child + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/doc/DefaultApi.md b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/doc/DefaultApi.md new file mode 100644 index 00000000000..abbf5f07f49 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/doc/DefaultApi.md @@ -0,0 +1,51 @@ +# openapi.api.DefaultApi + +## Load the API package +```dart +import 'package:openapi/api.dart'; +``` + +All URIs are relative to *http://api.example.xyz/v1* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**list**](DefaultApi.md#list) | **GET** /example | + + +# **list** +> Example list() + + + +### Example +```dart +import 'package:openapi/api.dart'; + +final api = Openapi().getDefaultApi(); + +try { + final response = api.list(); + print(response); +} catch on DioError (e) { + print('Exception when calling DefaultApi->list: $e\n'); +} +``` + +### Parameters +This endpoint does not need any parameter. + +### Return type + +[**Example**](Example.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) + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/doc/Example.md b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/doc/Example.md new file mode 100644 index 00000000000..bf49bb137a6 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/doc/Example.md @@ -0,0 +1,15 @@ +# openapi.model.Example + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/openapi.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/openapi.dart new file mode 100644 index 00000000000..220621d6961 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/openapi.dart @@ -0,0 +1,15 @@ +// +// 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/child.dart'; +export 'package:openapi/src/model/example.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/api.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/api.dart new file mode 100644 index 00000000000..776737680d5 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/api.dart @@ -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://api.example.xyz/v1'; + + final Dio dio; + final Serializers serializers; + + Openapi({ + Dio? dio, + Serializers? serializers, + String? basePathOverride, + List? 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/api/default_api.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/api/default_api.dart new file mode 100644 index 00000000000..8d500cb70aa --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/api/default_api.dart @@ -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/example.dart'; + +class DefaultApi { + + final Dio _dio; + + final Serializers _serializers; + + const DefaultApi(this._dio, this._serializers); + + /// list + /// + /// + /// 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 [Example] as data + /// Throws [DioError] if API call or serialization fails + Future> list({ + CancelToken? cancelToken, + Map? headers, + Map? extra, + ValidateStatus? validateStatus, + ProgressCallback? onSendProgress, + ProgressCallback? onReceiveProgress, + }) async { + final _path = r'/example'; + final _options = Options( + method: r'GET', + headers: { + ...?headers, + }, + extra: { + 'secure': >[], + ...?extra, + }, + validateStatus: validateStatus, + ); + + final _response = await _dio.request( + _path, + options: _options, + cancelToken: cancelToken, + onSendProgress: onSendProgress, + onReceiveProgress: onReceiveProgress, + ); + + Example _responseData; + + try { + const _responseType = FullType(Example); + _responseData = _serializers.deserialize( + _response.data!, + specifiedType: _responseType, + ) as Example; + + } catch (error, stackTrace) { + throw DioError( + requestOptions: _response.requestOptions, + response: _response, + type: DioErrorType.other, + error: error, + )..stackTrace = stackTrace; + } + + return Response( + data: _responseData, + headers: _response.headers, + isRedirect: _response.isRedirect, + requestOptions: _response.requestOptions, + redirects: _response.redirects, + statusCode: _response.statusCode, + statusMessage: _response.statusMessage, + extra: _response.extra, + ); + } + +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/api_util.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/api_util.dart new file mode 100644 index 00000000000..ed3bb12f25b --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/api_util.dart @@ -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 encodeCollectionQueryParameter( + Serializers serializers, + dynamic value, + FullType type, { + ListFormat format = ListFormat.multi, +}) { + final serialized = serializers.serialize( + value as Object, + specifiedType: type, + ); + if (value is BuiltList || value is BuiltSet) { + return ListParam(List.of((serialized as Iterable).cast()), format); + } + throw ArgumentError('Invalid value passed to encodeCollectionQueryParameter'); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/auth/api_key_auth.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/auth/api_key_auth.dart new file mode 100644 index 00000000000..ee16e3f0f92 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/auth/api_key_auth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/auth/auth.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/auth/auth.dart new file mode 100644 index 00000000000..f7ae9bf3f11 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/auth/auth.dart @@ -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> getAuthInfo(RequestOptions route, bool Function(Map secure) handles) { + if (route.extra.containsKey('secure')) { + final auth = route.extra['secure'] as List>; + return auth.where((secure) => handles(secure)).toList(); + } + return []; + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/auth/basic_auth.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/auth/basic_auth.dart new file mode 100644 index 00000000000..b6e6dce04f9 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/auth/basic_auth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/auth/bearer_auth.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/auth/bearer_auth.dart new file mode 100644 index 00000000000..1d4402b376c --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/auth/bearer_auth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/auth/oauth.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/auth/oauth.dart new file mode 100644 index 00000000000..337cf762b0c --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/auth/oauth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/date_serializer.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/date_serializer.dart new file mode 100644 index 00000000000..db3c5c437db --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/date_serializer.dart @@ -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 { + + const DateSerializer(); + + @override + Iterable 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(); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/model/child.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/model/child.dart new file mode 100644 index 00000000000..987b52ca724 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/model/child.dart @@ -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 'child.g.dart'; + +/// Child +/// +/// Properties: +/// * [name] +@BuiltValue() +abstract class Child implements Built { + @BuiltValueField(wireName: r'name') + String? get name; + + Child._(); + + factory Child([void updates(ChildBuilder b)]) = _$Child; + + @BuiltValueHook(initializeBuilder: true) + static void _defaults(ChildBuilder b) => b; + + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$ChildSerializer(); +} + +class _$ChildSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Child, _$Child]; + + @override + final String wireName = r'Child'; + + Iterable _serializeProperties( + Serializers serializers, + Child object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.name != null) { + yield r'name'; + yield serializers.serialize( + object.name, + specifiedType: const FullType(String), + ); + } + } + + @override + Object serialize( + Serializers serializers, + Child object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required ChildBuilder result, + required List 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'name': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.name = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + Child deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = ChildBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/model/date.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/model/date.dart new file mode 100644 index 00000000000..b21c7f544be --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/model/date.dart @@ -0,0 +1,70 @@ +/// A gregorian calendar date generated by +/// OpenAPI generator to differentiate +/// between [DateTime] and [Date] formats. +class Date implements Comparable { + 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); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/model/example.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/model/example.dart new file mode 100644 index 00000000000..799b77e4e17 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/model/example.dart @@ -0,0 +1,72 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// + +// ignore_for_file: unused_element +import 'package:openapi/src/model/child.dart'; +import 'dart:core'; +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; +import 'package:one_of/one_of.dart'; + +part 'example.g.dart'; + +/// Example +/// +/// Properties: +/// * [name] +@BuiltValue() +abstract class Example implements Built { + /// One Of [Child], [int] + OneOf get oneOf; + + Example._(); + + factory Example([void updates(ExampleBuilder b)]) = _$Example; + + @BuiltValueHook(initializeBuilder: true) + static void _defaults(ExampleBuilder b) => b; + + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$ExampleSerializer(); +} + +class _$ExampleSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Example, _$Example]; + + @override + final String wireName = r'Example'; + + Iterable _serializeProperties( + Serializers serializers, + Example object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + } + + @override + Object serialize( + Serializers serializers, + Example object, { + FullType specifiedType = FullType.unspecified, + }) { + final oneOf = object.oneOf; + return serializers.serialize(oneOf.value, specifiedType: FullType(oneOf.valueType))!; + } + + @override + Example deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = ExampleBuilder(); + Object? oneOfDataSrc; + final targetType = const FullType(OneOf, [FullType(Child), FullType(int), ]); + oneOfDataSrc = serialized; + result.oneOf = serializers.deserialize(oneOfDataSrc, specifiedType: targetType) as OneOf; + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/serializers.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/serializers.dart new file mode 100644 index 00000000000..cbd8870dc67 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/lib/src/serializers.dart @@ -0,0 +1,34 @@ +// +// 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/child.dart'; +import 'package:openapi/src/model/example.dart'; + +part 'serializers.g.dart'; + +@SerializersFor([ + Child, + Example, +]) +Serializers serializers = (_$serializers.toBuilder() + ..add(const OneOfSerializer()) + ..add(const AnyOfSerializer()) + ..add(const DateSerializer()) + ..add(Iso8601DateTimeSerializer())) + .build(); + +Serializers standardSerializers = + (serializers.toBuilder()..addPlugin(StandardJsonPlugin())).build(); diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/pom.xml b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/pom.xml new file mode 100644 index 00000000000..cceaebd895f --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/pom.xml @@ -0,0 +1,88 @@ + + 4.0.0 + org.openapitools + DartDioOneOfPrimitive + pom + 1.0.0-SNAPSHOT + DartDio OneOf Primitive + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory} + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + pub-get + pre-integration-test + + exec + + + pub + + get + + + + + pub-run-build-runner + pre-integration-test + + exec + + + pub + + run + build_runner + build + + + + + dart-analyze + integration-test + + exec + + + dart + + analyze + --fatal-infos + + + + + dart-test + integration-test + + exec + + + dart + + test + + + + + + + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/pubspec.yaml b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/pubspec.yaml new file mode 100644 index 00000000000..fb676f65c39 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/pubspec.yaml @@ -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 diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/test/child_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/test/child_test.dart new file mode 100644 index 00000000000..d40451a84c2 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/test/child_test.dart @@ -0,0 +1,16 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for Child +void main() { + final instance = ChildBuilder(); + // TODO add properties to the builder and call build() + + group(Child, () { + // String name + test('to test the property `name`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/test/default_api_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/test/default_api_test.dart new file mode 100644 index 00000000000..e4ec5707794 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/test/default_api_test.dart @@ -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 list() async + test('test list', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/test/example_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/test/example_test.dart new file mode 100644 index 00000000000..ccb35121143 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/test/example_test.dart @@ -0,0 +1,16 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for Example +void main() { + final instance = ExampleBuilder(); + // TODO add properties to the builder and call build() + + group(Example, () { + // String name + test('to test the property `name`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/additional_properties_class.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/additional_properties_class.dart index d45eeef83d9..a3d4df084be 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/additional_properties_class.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/additional_properties_class.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'additional_properties_class.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/all_of_with_single_ref.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/all_of_with_single_ref.dart index 7ee9944f7f0..dd3a19e9d93 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/all_of_with_single_ref.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/all_of_with_single_ref.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/single_ref_type.dart'; import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/animal.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/animal.dart index 26090b10920..22a196ce7d7 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/animal.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/animal.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'animal.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/api_response.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/api_response.dart index ac22fd59d69..c6700e2d39c 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/api_response.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/api_response.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'api_response.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/array_of_array_of_number_only.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/array_of_array_of_number_only.dart index dbae180528b..7372be1583f 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/array_of_array_of_number_only.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/array_of_array_of_number_only.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'array_of_array_of_number_only.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/array_of_number_only.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/array_of_number_only.dart index a203361bcc3..d538bb312fd 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/array_of_number_only.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/array_of_number_only.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'array_of_number_only.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/array_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/array_test.dart index 1f1720b2b66..30a6ec8a8b7 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/array_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/array_test.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/read_only_first.dart'; import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/capitalization.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/capitalization.dart index d40127b68a9..707cb05a040 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/capitalization.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/capitalization.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'capitalization.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/cat.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/cat.dart index 9d79ad48220..0b176faf313 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/cat.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/cat.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/animal.dart'; import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/cat_all_of.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/cat_all_of.dart index 55e2a10832f..abb9dbc25e5 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/cat_all_of.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/cat_all_of.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'cat_all_of.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/category.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/category.dart index 6bc66f34418..b94c6157990 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/category.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/category.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'category.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/class_model.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/class_model.dart index 015d2d0297a..01837bfcca9 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/class_model.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/class_model.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'class_model.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/deprecated_object.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/deprecated_object.dart index 9240f1160d0..b97e0637258 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/deprecated_object.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/deprecated_object.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'deprecated_object.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/dog.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/dog.dart index 62527c046b3..a049d0479fb 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/dog.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/dog.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/animal.dart'; import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/dog_all_of.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/dog_all_of.dart index d5ceabdc3a1..19bd4c0267b 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/dog_all_of.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/dog_all_of.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'dog_all_of.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/enum_arrays.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/enum_arrays.dart index 54c9839b9fe..a97d069a3d2 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/enum_arrays.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/enum_arrays.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'enum_arrays.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/enum_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/enum_test.dart index 17a67de347e..80555c14d03 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/enum_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/enum_test.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/outer_enum.dart'; import 'package:openapi/src/model/outer_enum_default_value.dart'; import 'package:openapi/src/model/outer_enum_integer.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/file_schema_test_class.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/file_schema_test_class.dart index 99d4dd3551c..bd2a9dc6f2f 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/file_schema_test_class.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/file_schema_test_class.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/model_file.dart'; import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/foo.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/foo.dart index b21bae484ea..b43572d222c 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/foo.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/foo.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'foo.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/foo_get_default_response.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/foo_get_default_response.dart index 423f93eb779..acc1c60e435 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/foo_get_default_response.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/foo_get_default_response.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/foo.dart'; import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/format_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/format_test.dart index a83f4721d82..91b35595a34 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/format_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/format_test.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:dio/dio.dart'; import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/has_only_read_only.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/has_only_read_only.dart index 25d25ddd06e..84c99fbc188 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/has_only_read_only.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/has_only_read_only.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'has_only_read_only.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/health_check_result.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/health_check_result.dart index 43a07ec7d50..fcb2973b751 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/health_check_result.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/health_check_result.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'health_check_result.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/map_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/map_test.dart index 5c4c3edb70f..7ab19eabd5c 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/map_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/map_test.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'map_test.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/mixed_properties_and_additional_properties_class.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/mixed_properties_and_additional_properties_class.dart index 649f7955806..e2e3cd0b857 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/mixed_properties_and_additional_properties_class.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/mixed_properties_and_additional_properties_class.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/animal.dart'; import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model200_response.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model200_response.dart index f4be2b420f6..346f1257555 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model200_response.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model200_response.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'model200_response.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_client.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_client.dart index 811e2776854..14e22005a16 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_client.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_client.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'model_client.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_enum_class.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_enum_class.dart index e3323e17a18..8abf107d98e 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_enum_class.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_enum_class.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_file.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_file.dart index fa38556a545..fe95e3ff002 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_file.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_file.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'model_file.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_list.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_list.dart index f5ae9fdbd76..543b79ac9f1 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_list.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_list.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'model_list.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_return.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_return.dart index a2b022414fb..192b134d8fc 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_return.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/model_return.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'model_return.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/name.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/name.dart index c361e4397ea..6613fa3afc8 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/name.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/name.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'name.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/nullable_class.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/nullable_class.dart index 3816bb33839..897d489ba45 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/nullable_class.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/nullable_class.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'nullable_class.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/number_only.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/number_only.dart index 8efb55ea167..3ca6bf704b5 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/number_only.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/number_only.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'number_only.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/object_with_deprecated_fields.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/object_with_deprecated_fields.dart index 522ee40e2e0..17361613609 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/object_with_deprecated_fields.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/object_with_deprecated_fields.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/deprecated_object.dart'; import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/order.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/order.dart index 087980a08e8..54134b51131 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/order.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/order.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'order.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_composite.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_composite.dart index f452e4b233d..f2509cb9921 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_composite.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_composite.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'outer_composite.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum.dart index 5b863632d5d..514507968c6 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum_default_value.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum_default_value.dart index f4585362ec8..0c8116edea9 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum_default_value.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum_default_value.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum_integer.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum_integer.dart index c3f134455dc..34268d0e9c5 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum_integer.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum_integer.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum_integer_default_value.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum_integer_default_value.dart index d94f696f81b..97b32593882 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum_integer_default_value.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_enum_integer_default_value.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_object_with_enum_property.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_object_with_enum_property.dart index 80331fe4df4..76d18676a11 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_object_with_enum_property.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/outer_object_with_enum_property.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/outer_enum_integer.dart'; import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/pet.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/pet.dart index f9cf6488384..28d6294bae5 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/pet.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/pet.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/category.dart'; import 'package:openapi/src/model/tag.dart'; import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/read_only_first.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/read_only_first.dart index c79e7df9aea..c71c088f138 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/read_only_first.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/read_only_first.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'read_only_first.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/single_ref_type.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/single_ref_type.dart index 072d072e0bd..ca56d9841a5 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/single_ref_type.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/single_ref_type.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/special_model_name.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/special_model_name.dart index 84332bb1a13..acd3ba09957 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/special_model_name.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/special_model_name.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'special_model_name.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/tag.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/tag.dart index d0372c17422..d8a87eec182 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/tag.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/tag.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'tag.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/user.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/user.dart index 8bb2ae70ce5..62f132ce776 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/user.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/user.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:json_annotation/json_annotation.dart'; part 'user.g.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/additional_properties_class.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/additional_properties_class.dart index 4d45be3abbf..3fdac6d5a44 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/additional_properties_class.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/additional_properties_class.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -13,75 +14,114 @@ part 'additional_properties_class.g.dart'; /// Properties: /// * [mapProperty] /// * [mapOfMapProperty] +@BuiltValue() abstract class AdditionalPropertiesClass implements Built { - @BuiltValueField(wireName: r'map_property') - BuiltMap? get mapProperty; + @BuiltValueField(wireName: r'map_property') + BuiltMap? get mapProperty; - @BuiltValueField(wireName: r'map_of_map_property') - BuiltMap>? get mapOfMapProperty; + @BuiltValueField(wireName: r'map_of_map_property') + BuiltMap>? get mapOfMapProperty; - AdditionalPropertiesClass._(); + AdditionalPropertiesClass._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(AdditionalPropertiesClassBuilder b) => b; + factory AdditionalPropertiesClass([void updates(AdditionalPropertiesClassBuilder b)]) = _$AdditionalPropertiesClass; - factory AdditionalPropertiesClass([void updates(AdditionalPropertiesClassBuilder b)]) = _$AdditionalPropertiesClass; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(AdditionalPropertiesClassBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$AdditionalPropertiesClassSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$AdditionalPropertiesClassSerializer(); } -class _$AdditionalPropertiesClassSerializer implements StructuredSerializer { - @override - final Iterable types = const [AdditionalPropertiesClass, _$AdditionalPropertiesClass]; +class _$AdditionalPropertiesClassSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [AdditionalPropertiesClass, _$AdditionalPropertiesClass]; - @override - final String wireName = r'AdditionalPropertiesClass'; + @override + final String wireName = r'AdditionalPropertiesClass'; - @override - Iterable serialize(Serializers serializers, AdditionalPropertiesClass object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.mapProperty != null) { - result - ..add(r'map_property') - ..add(serializers.serialize(object.mapProperty, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType(String)]))); - } - if (object.mapOfMapProperty != null) { - result - ..add(r'map_of_map_property') - ..add(serializers.serialize(object.mapOfMapProperty, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType(BuiltMap, [FullType(String), FullType(String)])]))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + AdditionalPropertiesClass object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.mapProperty != null) { + yield r'map_property'; + yield serializers.serialize( + object.mapProperty, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType(String)]), + ); } - - @override - AdditionalPropertiesClass deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = AdditionalPropertiesClassBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'map_property': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType(String)])) as BuiltMap; - result.mapProperty.replace(valueDes); - break; - case r'map_of_map_property': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType(BuiltMap, [FullType(String), FullType(String)])])) as BuiltMap>; - result.mapOfMapProperty.replace(valueDes); - break; - } - } - return result.build(); + if (object.mapOfMapProperty != null) { + yield r'map_of_map_property'; + yield serializers.serialize( + object.mapOfMapProperty, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType(BuiltMap, [FullType(String), FullType(String)])]), + ); } + } + + @override + Object serialize( + Serializers serializers, + AdditionalPropertiesClass object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required AdditionalPropertiesClassBuilder result, + required List 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'map_property': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType(String)]), + ) as BuiltMap; + result.mapProperty.replace(valueDes); + break; + case r'map_of_map_property': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType(BuiltMap, [FullType(String), FullType(String)])]), + ) as BuiltMap>; + result.mapOfMapProperty.replace(valueDes); + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + AdditionalPropertiesClass deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = AdditionalPropertiesClassBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/all_of_with_single_ref.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/all_of_with_single_ref.dart index a6955be4a92..04f59d36012 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/all_of_with_single_ref.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/all_of_with_single_ref.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/single_ref_type.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -13,75 +14,114 @@ part 'all_of_with_single_ref.g.dart'; /// Properties: /// * [username] /// * [singleRefType] +@BuiltValue() abstract class AllOfWithSingleRef implements Built { - @BuiltValueField(wireName: r'username') - String? get username; + @BuiltValueField(wireName: r'username') + String? get username; - @BuiltValueField(wireName: r'SingleRefType') - SingleRefType? get singleRefType; + @BuiltValueField(wireName: r'SingleRefType') + SingleRefType? get singleRefType; - AllOfWithSingleRef._(); + AllOfWithSingleRef._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(AllOfWithSingleRefBuilder b) => b; + factory AllOfWithSingleRef([void updates(AllOfWithSingleRefBuilder b)]) = _$AllOfWithSingleRef; - factory AllOfWithSingleRef([void updates(AllOfWithSingleRefBuilder b)]) = _$AllOfWithSingleRef; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(AllOfWithSingleRefBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$AllOfWithSingleRefSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$AllOfWithSingleRefSerializer(); } -class _$AllOfWithSingleRefSerializer implements StructuredSerializer { - @override - final Iterable types = const [AllOfWithSingleRef, _$AllOfWithSingleRef]; +class _$AllOfWithSingleRefSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [AllOfWithSingleRef, _$AllOfWithSingleRef]; - @override - final String wireName = r'AllOfWithSingleRef'; + @override + final String wireName = r'AllOfWithSingleRef'; - @override - Iterable serialize(Serializers serializers, AllOfWithSingleRef object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.username != null) { - result - ..add(r'username') - ..add(serializers.serialize(object.username, - specifiedType: const FullType(String))); - } - if (object.singleRefType != null) { - result - ..add(r'SingleRefType') - ..add(serializers.serialize(object.singleRefType, - specifiedType: const FullType(SingleRefType))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + AllOfWithSingleRef object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.username != null) { + yield r'username'; + yield serializers.serialize( + object.username, + specifiedType: const FullType(String), + ); } - - @override - AllOfWithSingleRef deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = AllOfWithSingleRefBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'username': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.username = valueDes; - break; - case r'SingleRefType': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(SingleRefType)) as SingleRefType; - result.singleRefType = valueDes; - break; - } - } - return result.build(); + if (object.singleRefType != null) { + yield r'SingleRefType'; + yield serializers.serialize( + object.singleRefType, + specifiedType: const FullType(SingleRefType), + ); } + } + + @override + Object serialize( + Serializers serializers, + AllOfWithSingleRef object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required AllOfWithSingleRefBuilder result, + required List 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'username': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.username = valueDes; + break; + case r'SingleRefType': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(SingleRefType), + ) as SingleRefType; + result.singleRefType = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + AllOfWithSingleRef deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = AllOfWithSingleRefBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/animal.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/animal.dart index cd9084ceb28..a8f8aa9c902 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/animal.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/animal.dart @@ -2,6 +2,9 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element +import 'package:openapi/src/model/dog.dart'; +import 'package:openapi/src/model/cat.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -12,74 +15,168 @@ part 'animal.g.dart'; /// Properties: /// * [className] /// * [color] -abstract class Animal implements Built { - @BuiltValueField(wireName: r'className') - String get className; +@BuiltValue(instantiable: false) +abstract class Animal { + @BuiltValueField(wireName: r'className') + String get className; - @BuiltValueField(wireName: r'color') - String? get color; + @BuiltValueField(wireName: r'color') + String? get color; - Animal._(); + static const String discriminatorFieldName = r'className'; - @BuiltValueHook(initializeBuilder: true) - static void _defaults(AnimalBuilder b) => b - ..color = 'red'; + static const Map discriminatorMapping = { + r'Cat': Cat, + r'Dog': Dog, + }; - factory Animal([void updates(AnimalBuilder b)]) = _$Animal; - - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$AnimalSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$AnimalSerializer(); } -class _$AnimalSerializer implements StructuredSerializer { - @override - final Iterable types = const [Animal, _$Animal]; +class _$AnimalSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Animal]; - @override - final String wireName = r'Animal'; + @override + final String wireName = r'Animal'; - @override - Iterable serialize(Serializers serializers, Animal object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - result - ..add(r'className') - ..add(serializers.serialize(object.className, - specifiedType: const FullType(String))); - if (object.color != null) { - result - ..add(r'color') - ..add(serializers.serialize(object.color, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + Animal object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + yield r'className'; + yield serializers.serialize( + object.className, + specifiedType: const FullType(String), + ); + if (object.color != null) { + yield r'color'; + yield serializers.serialize( + object.color, + specifiedType: const FullType(String), + ); } + } - @override - Animal deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = AnimalBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'className': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.className = valueDes; - break; - case r'color': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.color = valueDes; - break; - } - } - return result.build(); + @override + Object serialize( + Serializers serializers, + Animal object, { + FullType specifiedType = FullType.unspecified, + }) { + if (object is Cat) { + return serializers.serialize(object, specifiedType: FullType(Cat))!; } + if (object is Dog) { + return serializers.serialize(object, specifiedType: FullType(Dog))!; + } + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + @override + Animal deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final serializedList = (serialized as Iterable).toList(); + final discIndex = serializedList.indexOf(Animal.discriminatorFieldName) + 1; + final discValue = serializers.deserialize(serializedList[discIndex], specifiedType: FullType(String)) as String; + switch (discValue) { + case 'Cat': + return serializers.deserialize(serialized, specifiedType: FullType(Cat)) as Cat; + case 'Dog': + return serializers.deserialize(serialized, specifiedType: FullType(Dog)) as Dog; + default: + return serializers.deserialize(serialized, specifiedType: FullType($Animal)) as $Animal; + } + } +} + +/// a concrete implementation of [Animal], since [Animal] is not instantiable +@BuiltValue(instantiable: true) +abstract class $Animal implements Animal, Built<$Animal, $AnimalBuilder> { + $Animal._(); + + factory $Animal([void Function($AnimalBuilder)? updates]) = _$$Animal; + + @BuiltValueHook(initializeBuilder: true) + static void _defaults($AnimalBuilder b) => b; + + @BuiltValueSerializer(custom: true) + static Serializer<$Animal> get serializer => _$$AnimalSerializer(); +} + +class _$$AnimalSerializer implements PrimitiveSerializer<$Animal> { + @override + final Iterable types = const [$Animal, _$$Animal]; + + @override + final String wireName = r'$Animal'; + + @override + Object serialize( + Serializers serializers, + $Animal object, { + FullType specifiedType = FullType.unspecified, + }) { + return serializers.serialize(object, specifiedType: FullType(Animal))!; + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required AnimalBuilder result, + required List 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'className': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.className = valueDes; + break; + 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 + $Animal deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = $AnimalBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/api_response.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/api_response.dart index c2ebff7ffea..aadcd792e2b 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/api_response.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/api_response.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -13,89 +14,131 @@ part 'api_response.g.dart'; /// * [code] /// * [type] /// * [message] +@BuiltValue() abstract class ApiResponse implements Built { - @BuiltValueField(wireName: r'code') - int? get code; + @BuiltValueField(wireName: r'code') + int? get code; - @BuiltValueField(wireName: r'type') - String? get type; + @BuiltValueField(wireName: r'type') + String? get type; - @BuiltValueField(wireName: r'message') - String? get message; + @BuiltValueField(wireName: r'message') + String? get message; - ApiResponse._(); + ApiResponse._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(ApiResponseBuilder b) => b; + factory ApiResponse([void updates(ApiResponseBuilder b)]) = _$ApiResponse; - factory ApiResponse([void updates(ApiResponseBuilder b)]) = _$ApiResponse; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(ApiResponseBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$ApiResponseSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$ApiResponseSerializer(); } -class _$ApiResponseSerializer implements StructuredSerializer { - @override - final Iterable types = const [ApiResponse, _$ApiResponse]; +class _$ApiResponseSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [ApiResponse, _$ApiResponse]; - @override - final String wireName = r'ApiResponse'; + @override + final String wireName = r'ApiResponse'; - @override - Iterable serialize(Serializers serializers, ApiResponse object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.code != null) { - result - ..add(r'code') - ..add(serializers.serialize(object.code, - specifiedType: const FullType(int))); - } - if (object.type != null) { - result - ..add(r'type') - ..add(serializers.serialize(object.type, - specifiedType: const FullType(String))); - } - if (object.message != null) { - result - ..add(r'message') - ..add(serializers.serialize(object.message, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + ApiResponse object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.code != null) { + yield r'code'; + yield serializers.serialize( + object.code, + specifiedType: const FullType(int), + ); } - - @override - ApiResponse deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = ApiResponseBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'code': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.code = valueDes; - break; - case r'type': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.type = valueDes; - break; - case r'message': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.message = valueDes; - break; - } - } - return result.build(); + if (object.type != null) { + yield r'type'; + yield serializers.serialize( + object.type, + specifiedType: const FullType(String), + ); } + if (object.message != null) { + yield r'message'; + yield serializers.serialize( + object.message, + specifiedType: const FullType(String), + ); + } + } + + @override + Object serialize( + Serializers serializers, + ApiResponse object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required ApiResponseBuilder result, + required List 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'code': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.code = valueDes; + break; + case r'type': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.type = valueDes; + break; + case r'message': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.message = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + ApiResponse deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = ApiResponseBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/array_of_array_of_number_only.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/array_of_array_of_number_only.dart index 1fa583bccc1..5bc0982b8ab 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/array_of_array_of_number_only.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/array_of_array_of_number_only.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -12,61 +13,97 @@ part 'array_of_array_of_number_only.g.dart'; /// /// Properties: /// * [arrayArrayNumber] +@BuiltValue() abstract class ArrayOfArrayOfNumberOnly implements Built { - @BuiltValueField(wireName: r'ArrayArrayNumber') - BuiltList>? get arrayArrayNumber; + @BuiltValueField(wireName: r'ArrayArrayNumber') + BuiltList>? get arrayArrayNumber; - ArrayOfArrayOfNumberOnly._(); + ArrayOfArrayOfNumberOnly._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(ArrayOfArrayOfNumberOnlyBuilder b) => b; + factory ArrayOfArrayOfNumberOnly([void updates(ArrayOfArrayOfNumberOnlyBuilder b)]) = _$ArrayOfArrayOfNumberOnly; - factory ArrayOfArrayOfNumberOnly([void updates(ArrayOfArrayOfNumberOnlyBuilder b)]) = _$ArrayOfArrayOfNumberOnly; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(ArrayOfArrayOfNumberOnlyBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$ArrayOfArrayOfNumberOnlySerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$ArrayOfArrayOfNumberOnlySerializer(); } -class _$ArrayOfArrayOfNumberOnlySerializer implements StructuredSerializer { - @override - final Iterable types = const [ArrayOfArrayOfNumberOnly, _$ArrayOfArrayOfNumberOnly]; +class _$ArrayOfArrayOfNumberOnlySerializer implements PrimitiveSerializer { + @override + final Iterable types = const [ArrayOfArrayOfNumberOnly, _$ArrayOfArrayOfNumberOnly]; - @override - final String wireName = r'ArrayOfArrayOfNumberOnly'; + @override + final String wireName = r'ArrayOfArrayOfNumberOnly'; - @override - Iterable serialize(Serializers serializers, ArrayOfArrayOfNumberOnly object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.arrayArrayNumber != null) { - result - ..add(r'ArrayArrayNumber') - ..add(serializers.serialize(object.arrayArrayNumber, - specifiedType: const FullType(BuiltList, [FullType(BuiltList, [FullType(num)])]))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + ArrayOfArrayOfNumberOnly object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.arrayArrayNumber != null) { + yield r'ArrayArrayNumber'; + yield serializers.serialize( + object.arrayArrayNumber, + specifiedType: const FullType(BuiltList, [FullType(BuiltList, [FullType(num)])]), + ); } + } - @override - ArrayOfArrayOfNumberOnly deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = ArrayOfArrayOfNumberOnlyBuilder(); + @override + Object serialize( + Serializers serializers, + ArrayOfArrayOfNumberOnly object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'ArrayArrayNumber': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltList, [FullType(BuiltList, [FullType(num)])])) as BuiltList>; - result.arrayArrayNumber.replace(valueDes); - break; - } - } - return result.build(); + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required ArrayOfArrayOfNumberOnlyBuilder result, + required List 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'ArrayArrayNumber': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltList, [FullType(BuiltList, [FullType(num)])]), + ) as BuiltList>; + result.arrayArrayNumber.replace(valueDes); + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } } + } + + @override + ArrayOfArrayOfNumberOnly deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = ArrayOfArrayOfNumberOnlyBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/array_of_number_only.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/array_of_number_only.dart index fcbd7d393be..72239924f5e 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/array_of_number_only.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/array_of_number_only.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -12,61 +13,97 @@ part 'array_of_number_only.g.dart'; /// /// Properties: /// * [arrayNumber] +@BuiltValue() abstract class ArrayOfNumberOnly implements Built { - @BuiltValueField(wireName: r'ArrayNumber') - BuiltList? get arrayNumber; + @BuiltValueField(wireName: r'ArrayNumber') + BuiltList? get arrayNumber; - ArrayOfNumberOnly._(); + ArrayOfNumberOnly._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(ArrayOfNumberOnlyBuilder b) => b; + factory ArrayOfNumberOnly([void updates(ArrayOfNumberOnlyBuilder b)]) = _$ArrayOfNumberOnly; - factory ArrayOfNumberOnly([void updates(ArrayOfNumberOnlyBuilder b)]) = _$ArrayOfNumberOnly; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(ArrayOfNumberOnlyBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$ArrayOfNumberOnlySerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$ArrayOfNumberOnlySerializer(); } -class _$ArrayOfNumberOnlySerializer implements StructuredSerializer { - @override - final Iterable types = const [ArrayOfNumberOnly, _$ArrayOfNumberOnly]; +class _$ArrayOfNumberOnlySerializer implements PrimitiveSerializer { + @override + final Iterable types = const [ArrayOfNumberOnly, _$ArrayOfNumberOnly]; - @override - final String wireName = r'ArrayOfNumberOnly'; + @override + final String wireName = r'ArrayOfNumberOnly'; - @override - Iterable serialize(Serializers serializers, ArrayOfNumberOnly object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.arrayNumber != null) { - result - ..add(r'ArrayNumber') - ..add(serializers.serialize(object.arrayNumber, - specifiedType: const FullType(BuiltList, [FullType(num)]))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + ArrayOfNumberOnly object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.arrayNumber != null) { + yield r'ArrayNumber'; + yield serializers.serialize( + object.arrayNumber, + specifiedType: const FullType(BuiltList, [FullType(num)]), + ); } + } - @override - ArrayOfNumberOnly deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = ArrayOfNumberOnlyBuilder(); + @override + Object serialize( + Serializers serializers, + ArrayOfNumberOnly object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'ArrayNumber': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltList, [FullType(num)])) as BuiltList; - result.arrayNumber.replace(valueDes); - break; - } - } - return result.build(); + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required ArrayOfNumberOnlyBuilder result, + required List 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'ArrayNumber': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltList, [FullType(num)]), + ) as BuiltList; + result.arrayNumber.replace(valueDes); + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } } + } + + @override + ArrayOfNumberOnly deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = ArrayOfNumberOnlyBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/array_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/array_test.dart index 8025d141c12..21f3a5a4c2d 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/array_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/array_test.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:openapi/src/model/read_only_first.dart'; import 'package:built_value/built_value.dart'; @@ -15,89 +16,131 @@ part 'array_test.g.dart'; /// * [arrayOfString] /// * [arrayArrayOfInteger] /// * [arrayArrayOfModel] +@BuiltValue() abstract class ArrayTest implements Built { - @BuiltValueField(wireName: r'array_of_string') - BuiltList? get arrayOfString; + @BuiltValueField(wireName: r'array_of_string') + BuiltList? get arrayOfString; - @BuiltValueField(wireName: r'array_array_of_integer') - BuiltList>? get arrayArrayOfInteger; + @BuiltValueField(wireName: r'array_array_of_integer') + BuiltList>? get arrayArrayOfInteger; - @BuiltValueField(wireName: r'array_array_of_model') - BuiltList>? get arrayArrayOfModel; + @BuiltValueField(wireName: r'array_array_of_model') + BuiltList>? get arrayArrayOfModel; - ArrayTest._(); + ArrayTest._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(ArrayTestBuilder b) => b; + factory ArrayTest([void updates(ArrayTestBuilder b)]) = _$ArrayTest; - factory ArrayTest([void updates(ArrayTestBuilder b)]) = _$ArrayTest; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(ArrayTestBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$ArrayTestSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$ArrayTestSerializer(); } -class _$ArrayTestSerializer implements StructuredSerializer { - @override - final Iterable types = const [ArrayTest, _$ArrayTest]; +class _$ArrayTestSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [ArrayTest, _$ArrayTest]; - @override - final String wireName = r'ArrayTest'; + @override + final String wireName = r'ArrayTest'; - @override - Iterable serialize(Serializers serializers, ArrayTest object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.arrayOfString != null) { - result - ..add(r'array_of_string') - ..add(serializers.serialize(object.arrayOfString, - specifiedType: const FullType(BuiltList, [FullType(String)]))); - } - if (object.arrayArrayOfInteger != null) { - result - ..add(r'array_array_of_integer') - ..add(serializers.serialize(object.arrayArrayOfInteger, - specifiedType: const FullType(BuiltList, [FullType(BuiltList, [FullType(int)])]))); - } - if (object.arrayArrayOfModel != null) { - result - ..add(r'array_array_of_model') - ..add(serializers.serialize(object.arrayArrayOfModel, - specifiedType: const FullType(BuiltList, [FullType(BuiltList, [FullType(ReadOnlyFirst)])]))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + ArrayTest object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.arrayOfString != null) { + yield r'array_of_string'; + yield serializers.serialize( + object.arrayOfString, + specifiedType: const FullType(BuiltList, [FullType(String)]), + ); } - - @override - ArrayTest deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = ArrayTestBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'array_of_string': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltList, [FullType(String)])) as BuiltList; - result.arrayOfString.replace(valueDes); - break; - case r'array_array_of_integer': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltList, [FullType(BuiltList, [FullType(int)])])) as BuiltList>; - result.arrayArrayOfInteger.replace(valueDes); - break; - case r'array_array_of_model': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltList, [FullType(BuiltList, [FullType(ReadOnlyFirst)])])) as BuiltList>; - result.arrayArrayOfModel.replace(valueDes); - break; - } - } - return result.build(); + if (object.arrayArrayOfInteger != null) { + yield r'array_array_of_integer'; + yield serializers.serialize( + object.arrayArrayOfInteger, + specifiedType: const FullType(BuiltList, [FullType(BuiltList, [FullType(int)])]), + ); } + if (object.arrayArrayOfModel != null) { + yield r'array_array_of_model'; + yield serializers.serialize( + object.arrayArrayOfModel, + specifiedType: const FullType(BuiltList, [FullType(BuiltList, [FullType(ReadOnlyFirst)])]), + ); + } + } + + @override + Object serialize( + Serializers serializers, + ArrayTest object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required ArrayTestBuilder result, + required List 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'array_of_string': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltList, [FullType(String)]), + ) as BuiltList; + result.arrayOfString.replace(valueDes); + break; + case r'array_array_of_integer': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltList, [FullType(BuiltList, [FullType(int)])]), + ) as BuiltList>; + result.arrayArrayOfInteger.replace(valueDes); + break; + case r'array_array_of_model': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltList, [FullType(BuiltList, [FullType(ReadOnlyFirst)])]), + ) as BuiltList>; + result.arrayArrayOfModel.replace(valueDes); + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + ArrayTest deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = ArrayTestBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/capitalization.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/capitalization.dart index 15a8f080e9b..75827b9a429 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/capitalization.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/capitalization.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -16,132 +17,183 @@ part 'capitalization.g.dart'; /// * [capitalSnake] /// * [sCAETHFlowPoints] /// * [ATT_NAME] - Name of the pet +@BuiltValue() abstract class Capitalization implements Built { - @BuiltValueField(wireName: r'smallCamel') - String? get smallCamel; + @BuiltValueField(wireName: r'smallCamel') + String? get smallCamel; - @BuiltValueField(wireName: r'CapitalCamel') - String? get capitalCamel; + @BuiltValueField(wireName: r'CapitalCamel') + String? get capitalCamel; - @BuiltValueField(wireName: r'small_Snake') - String? get smallSnake; + @BuiltValueField(wireName: r'small_Snake') + String? get smallSnake; - @BuiltValueField(wireName: r'Capital_Snake') - String? get capitalSnake; + @BuiltValueField(wireName: r'Capital_Snake') + String? get capitalSnake; - @BuiltValueField(wireName: r'SCA_ETH_Flow_Points') - String? get sCAETHFlowPoints; + @BuiltValueField(wireName: r'SCA_ETH_Flow_Points') + String? get sCAETHFlowPoints; - /// Name of the pet - @BuiltValueField(wireName: r'ATT_NAME') - String? get ATT_NAME; + /// Name of the pet + @BuiltValueField(wireName: r'ATT_NAME') + String? get ATT_NAME; - Capitalization._(); + Capitalization._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(CapitalizationBuilder b) => b; + factory Capitalization([void updates(CapitalizationBuilder b)]) = _$Capitalization; - factory Capitalization([void updates(CapitalizationBuilder b)]) = _$Capitalization; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(CapitalizationBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$CapitalizationSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$CapitalizationSerializer(); } -class _$CapitalizationSerializer implements StructuredSerializer { - @override - final Iterable types = const [Capitalization, _$Capitalization]; +class _$CapitalizationSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Capitalization, _$Capitalization]; - @override - final String wireName = r'Capitalization'; + @override + final String wireName = r'Capitalization'; - @override - Iterable serialize(Serializers serializers, Capitalization object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.smallCamel != null) { - result - ..add(r'smallCamel') - ..add(serializers.serialize(object.smallCamel, - specifiedType: const FullType(String))); - } - if (object.capitalCamel != null) { - result - ..add(r'CapitalCamel') - ..add(serializers.serialize(object.capitalCamel, - specifiedType: const FullType(String))); - } - if (object.smallSnake != null) { - result - ..add(r'small_Snake') - ..add(serializers.serialize(object.smallSnake, - specifiedType: const FullType(String))); - } - if (object.capitalSnake != null) { - result - ..add(r'Capital_Snake') - ..add(serializers.serialize(object.capitalSnake, - specifiedType: const FullType(String))); - } - if (object.sCAETHFlowPoints != null) { - result - ..add(r'SCA_ETH_Flow_Points') - ..add(serializers.serialize(object.sCAETHFlowPoints, - specifiedType: const FullType(String))); - } - if (object.ATT_NAME != null) { - result - ..add(r'ATT_NAME') - ..add(serializers.serialize(object.ATT_NAME, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + Capitalization object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.smallCamel != null) { + yield r'smallCamel'; + yield serializers.serialize( + object.smallCamel, + specifiedType: const FullType(String), + ); } - - @override - Capitalization deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = CapitalizationBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'smallCamel': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.smallCamel = valueDes; - break; - case r'CapitalCamel': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.capitalCamel = valueDes; - break; - case r'small_Snake': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.smallSnake = valueDes; - break; - case r'Capital_Snake': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.capitalSnake = valueDes; - break; - case r'SCA_ETH_Flow_Points': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.sCAETHFlowPoints = valueDes; - break; - case r'ATT_NAME': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.ATT_NAME = valueDes; - break; - } - } - return result.build(); + if (object.capitalCamel != null) { + yield r'CapitalCamel'; + yield serializers.serialize( + object.capitalCamel, + specifiedType: const FullType(String), + ); } + if (object.smallSnake != null) { + yield r'small_Snake'; + yield serializers.serialize( + object.smallSnake, + specifiedType: const FullType(String), + ); + } + if (object.capitalSnake != null) { + yield r'Capital_Snake'; + yield serializers.serialize( + object.capitalSnake, + specifiedType: const FullType(String), + ); + } + if (object.sCAETHFlowPoints != null) { + yield r'SCA_ETH_Flow_Points'; + yield serializers.serialize( + object.sCAETHFlowPoints, + specifiedType: const FullType(String), + ); + } + if (object.ATT_NAME != null) { + yield r'ATT_NAME'; + yield serializers.serialize( + object.ATT_NAME, + specifiedType: const FullType(String), + ); + } + } + + @override + Object serialize( + Serializers serializers, + Capitalization object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required CapitalizationBuilder result, + required List 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'smallCamel': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.smallCamel = valueDes; + break; + case r'CapitalCamel': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.capitalCamel = valueDes; + break; + case r'small_Snake': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.smallSnake = valueDes; + break; + case r'Capital_Snake': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.capitalSnake = valueDes; + break; + case r'SCA_ETH_Flow_Points': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.sCAETHFlowPoints = valueDes; + break; + case r'ATT_NAME': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.ATT_NAME = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + Capitalization deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = CapitalizationBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/cat.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/cat.dart index cad5f349dab..31a2b14769c 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/cat.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/cat.dart @@ -2,102 +2,137 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/animal.dart'; +import 'package:openapi/src/model/cat_all_of.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; part 'cat.g.dart'; -// ignore_for_file: unused_import - /// Cat /// /// Properties: /// * [className] /// * [color] /// * [declawed] -abstract class Cat implements Built { - @BuiltValueField(wireName: r'className') - String get className; +@BuiltValue() +abstract class Cat implements Animal, CatAllOf, Built { + static const String discriminatorFieldName = r'className'; - @BuiltValueField(wireName: r'color') - String? get color; + Cat._(); - @BuiltValueField(wireName: r'declawed') - bool? get declawed; + factory Cat([void updates(CatBuilder b)]) = _$Cat; - Cat._(); + @BuiltValueHook(initializeBuilder: true) + static void _defaults(CatBuilder b) => b + ..color = 'red'; - @BuiltValueHook(initializeBuilder: true) - static void _defaults(CatBuilder b) => b - ..color = 'red'; - - factory Cat([void updates(CatBuilder b)]) = _$Cat; - - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$CatSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$CatSerializer(); } -class _$CatSerializer implements StructuredSerializer { - @override - final Iterable types = const [Cat, _$Cat]; +class _$CatSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Cat, _$Cat]; - @override - final String wireName = r'Cat'; + @override + final String wireName = r'Cat'; - @override - Iterable serialize(Serializers serializers, Cat object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - result - ..add(r'className') - ..add(serializers.serialize(object.className, - specifiedType: const FullType(String))); - if (object.color != null) { - result - ..add(r'color') - ..add(serializers.serialize(object.color, - specifiedType: const FullType(String))); - } - if (object.declawed != null) { - result - ..add(r'declawed') - ..add(serializers.serialize(object.declawed, - specifiedType: const FullType(bool))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + Cat object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + yield r'className'; + yield serializers.serialize( + object.className, + specifiedType: const FullType(String), + ); + if (object.color != null) { + yield r'color'; + yield serializers.serialize( + object.color, + specifiedType: const FullType(String), + ); } - - @override - Cat deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = CatBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'className': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.className = valueDes; - break; - case r'color': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.color = valueDes; - break; - case r'declawed': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(bool)) as bool; - result.declawed = valueDes; - break; - } - } - return result.build(); + if (object.declawed != null) { + yield r'declawed'; + yield serializers.serialize( + object.declawed, + specifiedType: const FullType(bool), + ); } + } + + @override + Object serialize( + Serializers serializers, + Cat object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required CatBuilder result, + required List 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'className': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.className = valueDes; + break; + case r'color': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.color = valueDes; + break; + case r'declawed': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(bool), + ) as bool; + result.declawed = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + Cat deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = CatBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/cat_all_of.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/cat_all_of.dart index 1734098fe22..02d9cce0cae 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/cat_all_of.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/cat_all_of.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -11,61 +12,130 @@ part 'cat_all_of.g.dart'; /// /// Properties: /// * [declawed] -abstract class CatAllOf implements Built { - @BuiltValueField(wireName: r'declawed') - bool? get declawed; +@BuiltValue(instantiable: false) +abstract class CatAllOf { + @BuiltValueField(wireName: r'declawed') + bool? get declawed; - CatAllOf._(); - - @BuiltValueHook(initializeBuilder: true) - static void _defaults(CatAllOfBuilder b) => b; - - factory CatAllOf([void updates(CatAllOfBuilder b)]) = _$CatAllOf; - - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$CatAllOfSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$CatAllOfSerializer(); } -class _$CatAllOfSerializer implements StructuredSerializer { - @override - final Iterable types = const [CatAllOf, _$CatAllOf]; +class _$CatAllOfSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [CatAllOf]; - @override - final String wireName = r'CatAllOf'; + @override + final String wireName = r'CatAllOf'; - @override - Iterable serialize(Serializers serializers, CatAllOf object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.declawed != null) { - result - ..add(r'declawed') - ..add(serializers.serialize(object.declawed, - specifiedType: const FullType(bool))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + CatAllOf object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.declawed != null) { + yield r'declawed'; + yield serializers.serialize( + object.declawed, + specifiedType: const FullType(bool), + ); } + } - @override - CatAllOf deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = CatAllOfBuilder(); + @override + Object serialize( + Serializers serializers, + CatAllOf object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'declawed': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(bool)) as bool; - result.declawed = valueDes; - break; - } - } - return result.build(); - } + @override + CatAllOf deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + return serializers.deserialize(serialized, specifiedType: FullType($CatAllOf)) as $CatAllOf; + } +} + +/// a concrete implementation of [CatAllOf], since [CatAllOf] is not instantiable +@BuiltValue(instantiable: true) +abstract class $CatAllOf implements CatAllOf, Built<$CatAllOf, $CatAllOfBuilder> { + $CatAllOf._(); + + factory $CatAllOf([void Function($CatAllOfBuilder)? updates]) = _$$CatAllOf; + + @BuiltValueHook(initializeBuilder: true) + static void _defaults($CatAllOfBuilder b) => b; + + @BuiltValueSerializer(custom: true) + static Serializer<$CatAllOf> get serializer => _$$CatAllOfSerializer(); +} + +class _$$CatAllOfSerializer implements PrimitiveSerializer<$CatAllOf> { + @override + final Iterable types = const [$CatAllOf, _$$CatAllOf]; + + @override + final String wireName = r'$CatAllOf'; + + @override + Object serialize( + Serializers serializers, + $CatAllOf object, { + FullType specifiedType = FullType.unspecified, + }) { + return serializers.serialize(object, specifiedType: FullType(CatAllOf))!; + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required CatAllOfBuilder result, + required List 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'declawed': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(bool), + ) as bool; + result.declawed = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + $CatAllOf deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = $CatAllOfBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/category.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/category.dart index 9ee9a94a3e7..3a541dd1fa9 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/category.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/category.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -12,74 +13,113 @@ part 'category.g.dart'; /// Properties: /// * [id] /// * [name] +@BuiltValue() abstract class Category implements Built { - @BuiltValueField(wireName: r'id') - int? get id; + @BuiltValueField(wireName: r'id') + int? get id; - @BuiltValueField(wireName: r'name') - String get name; + @BuiltValueField(wireName: r'name') + String get name; - Category._(); + Category._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(CategoryBuilder b) => b - ..name = 'default-name'; + factory Category([void updates(CategoryBuilder b)]) = _$Category; - factory Category([void updates(CategoryBuilder b)]) = _$Category; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(CategoryBuilder b) => b + ..name = 'default-name'; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$CategorySerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$CategorySerializer(); } -class _$CategorySerializer implements StructuredSerializer { - @override - final Iterable types = const [Category, _$Category]; +class _$CategorySerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Category, _$Category]; - @override - final String wireName = r'Category'; + @override + final String wireName = r'Category'; - @override - Iterable serialize(Serializers serializers, Category object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.id != null) { - result - ..add(r'id') - ..add(serializers.serialize(object.id, - specifiedType: const FullType(int))); - } - result - ..add(r'name') - ..add(serializers.serialize(object.name, - specifiedType: const FullType(String))); - return result; + Iterable _serializeProperties( + Serializers serializers, + Category object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.id != null) { + yield r'id'; + yield serializers.serialize( + object.id, + specifiedType: const FullType(int), + ); } + yield r'name'; + yield serializers.serialize( + object.name, + specifiedType: const FullType(String), + ); + } - @override - Category deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = CategoryBuilder(); + @override + Object serialize( + Serializers serializers, + Category object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'id': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.id = valueDes; - break; - case r'name': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.name = valueDes; - break; - } - } - return result.build(); + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required CategoryBuilder result, + required List 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'id': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.id = valueDes; + break; + case r'name': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.name = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } } + } + + @override + Category deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = CategoryBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/class_model.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/class_model.dart index 3a000f56cb2..51166943c6c 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/class_model.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/class_model.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -11,61 +12,97 @@ part 'class_model.g.dart'; /// /// Properties: /// * [classField] +@BuiltValue() abstract class ClassModel implements Built { - @BuiltValueField(wireName: r'_class') - String? get classField; + @BuiltValueField(wireName: r'_class') + String? get classField; - ClassModel._(); + ClassModel._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(ClassModelBuilder b) => b; + factory ClassModel([void updates(ClassModelBuilder b)]) = _$ClassModel; - factory ClassModel([void updates(ClassModelBuilder b)]) = _$ClassModel; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(ClassModelBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$ClassModelSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$ClassModelSerializer(); } -class _$ClassModelSerializer implements StructuredSerializer { - @override - final Iterable types = const [ClassModel, _$ClassModel]; +class _$ClassModelSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [ClassModel, _$ClassModel]; - @override - final String wireName = r'ClassModel'; + @override + final String wireName = r'ClassModel'; - @override - Iterable serialize(Serializers serializers, ClassModel object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.classField != null) { - result - ..add(r'_class') - ..add(serializers.serialize(object.classField, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + ClassModel object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.classField != null) { + yield r'_class'; + yield serializers.serialize( + object.classField, + specifiedType: const FullType(String), + ); } + } - @override - ClassModel deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = ClassModelBuilder(); + @override + Object serialize( + Serializers serializers, + ClassModel object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'_class': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.classField = valueDes; - break; - } - } - return result.build(); + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required ClassModelBuilder result, + required List 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'_class': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.classField = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } } + } + + @override + ClassModel deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = ClassModelBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/deprecated_object.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/deprecated_object.dart index 98db39b4f44..91d0b428e9b 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/deprecated_object.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/deprecated_object.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -11,61 +12,97 @@ part 'deprecated_object.g.dart'; /// /// Properties: /// * [name] +@BuiltValue() abstract class DeprecatedObject implements Built { - @BuiltValueField(wireName: r'name') - String? get name; + @BuiltValueField(wireName: r'name') + String? get name; - DeprecatedObject._(); + DeprecatedObject._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(DeprecatedObjectBuilder b) => b; + factory DeprecatedObject([void updates(DeprecatedObjectBuilder b)]) = _$DeprecatedObject; - factory DeprecatedObject([void updates(DeprecatedObjectBuilder b)]) = _$DeprecatedObject; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(DeprecatedObjectBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$DeprecatedObjectSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$DeprecatedObjectSerializer(); } -class _$DeprecatedObjectSerializer implements StructuredSerializer { - @override - final Iterable types = const [DeprecatedObject, _$DeprecatedObject]; +class _$DeprecatedObjectSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [DeprecatedObject, _$DeprecatedObject]; - @override - final String wireName = r'DeprecatedObject'; + @override + final String wireName = r'DeprecatedObject'; - @override - Iterable serialize(Serializers serializers, DeprecatedObject object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.name != null) { - result - ..add(r'name') - ..add(serializers.serialize(object.name, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + DeprecatedObject object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.name != null) { + yield r'name'; + yield serializers.serialize( + object.name, + specifiedType: const FullType(String), + ); } + } - @override - DeprecatedObject deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = DeprecatedObjectBuilder(); + @override + Object serialize( + Serializers serializers, + DeprecatedObject object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'name': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.name = valueDes; - break; - } - } - return result.build(); + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required DeprecatedObjectBuilder result, + required List 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'name': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.name = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } } + } + + @override + DeprecatedObject deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = DeprecatedObjectBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/dog.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/dog.dart index 2ca3df38636..b7cb6bf731f 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/dog.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/dog.dart @@ -2,102 +2,137 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element +import 'package:openapi/src/model/dog_all_of.dart'; import 'package:openapi/src/model/animal.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; part 'dog.g.dart'; -// ignore_for_file: unused_import - /// Dog /// /// Properties: /// * [className] /// * [color] /// * [breed] -abstract class Dog implements Built { - @BuiltValueField(wireName: r'className') - String get className; +@BuiltValue() +abstract class Dog implements Animal, DogAllOf, Built { + static const String discriminatorFieldName = r'className'; - @BuiltValueField(wireName: r'color') - String? get color; + Dog._(); - @BuiltValueField(wireName: r'breed') - String? get breed; + factory Dog([void updates(DogBuilder b)]) = _$Dog; - Dog._(); + @BuiltValueHook(initializeBuilder: true) + static void _defaults(DogBuilder b) => b + ..color = 'red'; - @BuiltValueHook(initializeBuilder: true) - static void _defaults(DogBuilder b) => b - ..color = 'red'; - - factory Dog([void updates(DogBuilder b)]) = _$Dog; - - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$DogSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$DogSerializer(); } -class _$DogSerializer implements StructuredSerializer { - @override - final Iterable types = const [Dog, _$Dog]; +class _$DogSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Dog, _$Dog]; - @override - final String wireName = r'Dog'; + @override + final String wireName = r'Dog'; - @override - Iterable serialize(Serializers serializers, Dog object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - result - ..add(r'className') - ..add(serializers.serialize(object.className, - specifiedType: const FullType(String))); - if (object.color != null) { - result - ..add(r'color') - ..add(serializers.serialize(object.color, - specifiedType: const FullType(String))); - } - if (object.breed != null) { - result - ..add(r'breed') - ..add(serializers.serialize(object.breed, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + Dog object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + yield r'className'; + yield serializers.serialize( + object.className, + specifiedType: const FullType(String), + ); + if (object.color != null) { + yield r'color'; + yield serializers.serialize( + object.color, + specifiedType: const FullType(String), + ); } - - @override - Dog deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = DogBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'className': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.className = valueDes; - break; - case r'color': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.color = valueDes; - break; - case r'breed': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.breed = valueDes; - break; - } - } - return result.build(); + if (object.breed != null) { + yield r'breed'; + yield serializers.serialize( + object.breed, + specifiedType: const FullType(String), + ); } + } + + @override + Object serialize( + Serializers serializers, + Dog object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required DogBuilder result, + required List 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'className': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.className = valueDes; + break; + case r'color': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.color = valueDes; + break; + case r'breed': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.breed = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + Dog deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = DogBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/dog_all_of.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/dog_all_of.dart index 23387e4da75..bd52567fa60 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/dog_all_of.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/dog_all_of.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -11,61 +12,130 @@ part 'dog_all_of.g.dart'; /// /// Properties: /// * [breed] -abstract class DogAllOf implements Built { - @BuiltValueField(wireName: r'breed') - String? get breed; +@BuiltValue(instantiable: false) +abstract class DogAllOf { + @BuiltValueField(wireName: r'breed') + String? get breed; - DogAllOf._(); - - @BuiltValueHook(initializeBuilder: true) - static void _defaults(DogAllOfBuilder b) => b; - - factory DogAllOf([void updates(DogAllOfBuilder b)]) = _$DogAllOf; - - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$DogAllOfSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$DogAllOfSerializer(); } -class _$DogAllOfSerializer implements StructuredSerializer { - @override - final Iterable types = const [DogAllOf, _$DogAllOf]; +class _$DogAllOfSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [DogAllOf]; - @override - final String wireName = r'DogAllOf'; + @override + final String wireName = r'DogAllOf'; - @override - Iterable serialize(Serializers serializers, DogAllOf object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.breed != null) { - result - ..add(r'breed') - ..add(serializers.serialize(object.breed, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + DogAllOf object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.breed != null) { + yield r'breed'; + yield serializers.serialize( + object.breed, + specifiedType: const FullType(String), + ); } + } - @override - DogAllOf deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = DogAllOfBuilder(); + @override + Object serialize( + Serializers serializers, + DogAllOf object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'breed': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.breed = valueDes; - break; - } - } - return result.build(); - } + @override + DogAllOf deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + return serializers.deserialize(serialized, specifiedType: FullType($DogAllOf)) as $DogAllOf; + } +} + +/// a concrete implementation of [DogAllOf], since [DogAllOf] is not instantiable +@BuiltValue(instantiable: true) +abstract class $DogAllOf implements DogAllOf, Built<$DogAllOf, $DogAllOfBuilder> { + $DogAllOf._(); + + factory $DogAllOf([void Function($DogAllOfBuilder)? updates]) = _$$DogAllOf; + + @BuiltValueHook(initializeBuilder: true) + static void _defaults($DogAllOfBuilder b) => b; + + @BuiltValueSerializer(custom: true) + static Serializer<$DogAllOf> get serializer => _$$DogAllOfSerializer(); +} + +class _$$DogAllOfSerializer implements PrimitiveSerializer<$DogAllOf> { + @override + final Iterable types = const [$DogAllOf, _$$DogAllOf]; + + @override + final String wireName = r'$DogAllOf'; + + @override + Object serialize( + Serializers serializers, + $DogAllOf object, { + FullType specifiedType = FullType.unspecified, + }) { + return serializers.serialize(object, specifiedType: FullType(DogAllOf))!; + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required DogAllOfBuilder result, + required List 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'breed': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.breed = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + $DogAllOf deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = $DogAllOfBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/enum_arrays.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/enum_arrays.dart index 2626b354264..b79a175e833 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/enum_arrays.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/enum_arrays.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -13,78 +14,117 @@ part 'enum_arrays.g.dart'; /// Properties: /// * [justSymbol] /// * [arrayEnum] +@BuiltValue() abstract class EnumArrays implements Built { - @BuiltValueField(wireName: r'just_symbol') - EnumArraysJustSymbolEnum? get justSymbol; - // enum justSymbolEnum { >=, $, }; + @BuiltValueField(wireName: r'just_symbol') + EnumArraysJustSymbolEnum? get justSymbol; + // enum justSymbolEnum { >=, $, }; - @BuiltValueField(wireName: r'array_enum') - BuiltList? get arrayEnum; - // enum arrayEnumEnum { fish, crab, }; + @BuiltValueField(wireName: r'array_enum') + BuiltList? get arrayEnum; + // enum arrayEnumEnum { fish, crab, }; - EnumArrays._(); + EnumArrays._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(EnumArraysBuilder b) => b; + factory EnumArrays([void updates(EnumArraysBuilder b)]) = _$EnumArrays; - factory EnumArrays([void updates(EnumArraysBuilder b)]) = _$EnumArrays; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(EnumArraysBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$EnumArraysSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$EnumArraysSerializer(); } -class _$EnumArraysSerializer implements StructuredSerializer { - @override - final Iterable types = const [EnumArrays, _$EnumArrays]; +class _$EnumArraysSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [EnumArrays, _$EnumArrays]; - @override - final String wireName = r'EnumArrays'; + @override + final String wireName = r'EnumArrays'; - @override - Iterable serialize(Serializers serializers, EnumArrays object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.justSymbol != null) { - result - ..add(r'just_symbol') - ..add(serializers.serialize(object.justSymbol, - specifiedType: const FullType(EnumArraysJustSymbolEnum))); - } - if (object.arrayEnum != null) { - result - ..add(r'array_enum') - ..add(serializers.serialize(object.arrayEnum, - specifiedType: const FullType(BuiltList, [FullType(EnumArraysArrayEnumEnum)]))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + EnumArrays object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.justSymbol != null) { + yield r'just_symbol'; + yield serializers.serialize( + object.justSymbol, + specifiedType: const FullType(EnumArraysJustSymbolEnum), + ); } - - @override - EnumArrays deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = EnumArraysBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'just_symbol': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(EnumArraysJustSymbolEnum)) as EnumArraysJustSymbolEnum; - result.justSymbol = valueDes; - break; - case r'array_enum': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltList, [FullType(EnumArraysArrayEnumEnum)])) as BuiltList; - result.arrayEnum.replace(valueDes); - break; - } - } - return result.build(); + if (object.arrayEnum != null) { + yield r'array_enum'; + yield serializers.serialize( + object.arrayEnum, + specifiedType: const FullType(BuiltList, [FullType(EnumArraysArrayEnumEnum)]), + ); } + } + + @override + Object serialize( + Serializers serializers, + EnumArrays object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required EnumArraysBuilder result, + required List 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'just_symbol': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(EnumArraysJustSymbolEnum), + ) as EnumArraysJustSymbolEnum; + result.justSymbol = valueDes; + break; + case r'array_enum': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltList, [FullType(EnumArraysArrayEnumEnum)]), + ) as BuiltList; + result.arrayEnum.replace(valueDes); + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + EnumArrays deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = EnumArraysBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } class EnumArraysJustSymbolEnum extends EnumClass { diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/enum_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/enum_test.dart index ff022e646e8..831f5b9d6d2 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/enum_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/enum_test.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/outer_enum.dart'; import 'package:openapi/src/model/outer_enum_default_value.dart'; import 'package:built_collection/built_collection.dart'; @@ -23,167 +24,224 @@ part 'enum_test.g.dart'; /// * [outerEnumInteger] /// * [outerEnumDefaultValue] /// * [outerEnumIntegerDefaultValue] +@BuiltValue() abstract class EnumTest implements Built { - @BuiltValueField(wireName: r'enum_string') - EnumTestEnumStringEnum? get enumString; - // enum enumStringEnum { UPPER, lower, , }; + @BuiltValueField(wireName: r'enum_string') + EnumTestEnumStringEnum? get enumString; + // enum enumStringEnum { UPPER, lower, , }; - @BuiltValueField(wireName: r'enum_string_required') - EnumTestEnumStringRequiredEnum get enumStringRequired; - // enum enumStringRequiredEnum { UPPER, lower, , }; + @BuiltValueField(wireName: r'enum_string_required') + EnumTestEnumStringRequiredEnum get enumStringRequired; + // enum enumStringRequiredEnum { UPPER, lower, , }; - @BuiltValueField(wireName: r'enum_integer') - EnumTestEnumIntegerEnum? get enumInteger; - // enum enumIntegerEnum { 1, -1, }; + @BuiltValueField(wireName: r'enum_integer') + EnumTestEnumIntegerEnum? get enumInteger; + // enum enumIntegerEnum { 1, -1, }; - @BuiltValueField(wireName: r'enum_number') - EnumTestEnumNumberEnum? get enumNumber; - // enum enumNumberEnum { 1.1, -1.2, }; + @BuiltValueField(wireName: r'enum_number') + EnumTestEnumNumberEnum? get enumNumber; + // enum enumNumberEnum { 1.1, -1.2, }; - @BuiltValueField(wireName: r'outerEnum') - OuterEnum? get outerEnum; - // enum outerEnumEnum { placed, approved, delivered, }; + @BuiltValueField(wireName: r'outerEnum') + OuterEnum? get outerEnum; + // enum outerEnumEnum { placed, approved, delivered, }; - @BuiltValueField(wireName: r'outerEnumInteger') - OuterEnumInteger? get outerEnumInteger; - // enum outerEnumIntegerEnum { 0, 1, 2, }; + @BuiltValueField(wireName: r'outerEnumInteger') + OuterEnumInteger? get outerEnumInteger; + // enum outerEnumIntegerEnum { 0, 1, 2, }; - @BuiltValueField(wireName: r'outerEnumDefaultValue') - OuterEnumDefaultValue? get outerEnumDefaultValue; - // enum outerEnumDefaultValueEnum { placed, approved, delivered, }; + @BuiltValueField(wireName: r'outerEnumDefaultValue') + OuterEnumDefaultValue? get outerEnumDefaultValue; + // enum outerEnumDefaultValueEnum { placed, approved, delivered, }; - @BuiltValueField(wireName: r'outerEnumIntegerDefaultValue') - OuterEnumIntegerDefaultValue? get outerEnumIntegerDefaultValue; - // enum outerEnumIntegerDefaultValueEnum { 0, 1, 2, }; + @BuiltValueField(wireName: r'outerEnumIntegerDefaultValue') + OuterEnumIntegerDefaultValue? get outerEnumIntegerDefaultValue; + // enum outerEnumIntegerDefaultValueEnum { 0, 1, 2, }; - EnumTest._(); + EnumTest._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(EnumTestBuilder b) => b; + factory EnumTest([void updates(EnumTestBuilder b)]) = _$EnumTest; - factory EnumTest([void updates(EnumTestBuilder b)]) = _$EnumTest; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(EnumTestBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$EnumTestSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$EnumTestSerializer(); } -class _$EnumTestSerializer implements StructuredSerializer { - @override - final Iterable types = const [EnumTest, _$EnumTest]; +class _$EnumTestSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [EnumTest, _$EnumTest]; - @override - final String wireName = r'EnumTest'; + @override + final String wireName = r'EnumTest'; - @override - Iterable serialize(Serializers serializers, EnumTest object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.enumString != null) { - result - ..add(r'enum_string') - ..add(serializers.serialize(object.enumString, - specifiedType: const FullType(EnumTestEnumStringEnum))); - } - result - ..add(r'enum_string_required') - ..add(serializers.serialize(object.enumStringRequired, - specifiedType: const FullType(EnumTestEnumStringRequiredEnum))); - if (object.enumInteger != null) { - result - ..add(r'enum_integer') - ..add(serializers.serialize(object.enumInteger, - specifiedType: const FullType(EnumTestEnumIntegerEnum))); - } - if (object.enumNumber != null) { - result - ..add(r'enum_number') - ..add(serializers.serialize(object.enumNumber, - specifiedType: const FullType(EnumTestEnumNumberEnum))); - } - if (object.outerEnum != null) { - result - ..add(r'outerEnum') - ..add(serializers.serialize(object.outerEnum, - specifiedType: const FullType.nullable(OuterEnum))); - } - if (object.outerEnumInteger != null) { - result - ..add(r'outerEnumInteger') - ..add(serializers.serialize(object.outerEnumInteger, - specifiedType: const FullType(OuterEnumInteger))); - } - if (object.outerEnumDefaultValue != null) { - result - ..add(r'outerEnumDefaultValue') - ..add(serializers.serialize(object.outerEnumDefaultValue, - specifiedType: const FullType(OuterEnumDefaultValue))); - } - if (object.outerEnumIntegerDefaultValue != null) { - result - ..add(r'outerEnumIntegerDefaultValue') - ..add(serializers.serialize(object.outerEnumIntegerDefaultValue, - specifiedType: const FullType(OuterEnumIntegerDefaultValue))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + EnumTest object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.enumString != null) { + yield r'enum_string'; + yield serializers.serialize( + object.enumString, + specifiedType: const FullType(EnumTestEnumStringEnum), + ); } - - @override - EnumTest deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = EnumTestBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'enum_string': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(EnumTestEnumStringEnum)) as EnumTestEnumStringEnum; - result.enumString = valueDes; - break; - case r'enum_string_required': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(EnumTestEnumStringRequiredEnum)) as EnumTestEnumStringRequiredEnum; - result.enumStringRequired = valueDes; - break; - case r'enum_integer': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(EnumTestEnumIntegerEnum)) as EnumTestEnumIntegerEnum; - result.enumInteger = valueDes; - break; - case r'enum_number': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(EnumTestEnumNumberEnum)) as EnumTestEnumNumberEnum; - result.enumNumber = valueDes; - break; - case r'outerEnum': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType.nullable(OuterEnum)) as OuterEnum?; - if (valueDes == null) continue; - result.outerEnum = valueDes; - break; - case r'outerEnumInteger': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(OuterEnumInteger)) as OuterEnumInteger; - result.outerEnumInteger = valueDes; - break; - case r'outerEnumDefaultValue': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(OuterEnumDefaultValue)) as OuterEnumDefaultValue; - result.outerEnumDefaultValue = valueDes; - break; - case r'outerEnumIntegerDefaultValue': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(OuterEnumIntegerDefaultValue)) as OuterEnumIntegerDefaultValue; - result.outerEnumIntegerDefaultValue = valueDes; - break; - } - } - return result.build(); + yield r'enum_string_required'; + yield serializers.serialize( + object.enumStringRequired, + specifiedType: const FullType(EnumTestEnumStringRequiredEnum), + ); + if (object.enumInteger != null) { + yield r'enum_integer'; + yield serializers.serialize( + object.enumInteger, + specifiedType: const FullType(EnumTestEnumIntegerEnum), + ); } + if (object.enumNumber != null) { + yield r'enum_number'; + yield serializers.serialize( + object.enumNumber, + specifiedType: const FullType(EnumTestEnumNumberEnum), + ); + } + if (object.outerEnum != null) { + yield r'outerEnum'; + yield serializers.serialize( + object.outerEnum, + specifiedType: const FullType.nullable(OuterEnum), + ); + } + if (object.outerEnumInteger != null) { + yield r'outerEnumInteger'; + yield serializers.serialize( + object.outerEnumInteger, + specifiedType: const FullType(OuterEnumInteger), + ); + } + if (object.outerEnumDefaultValue != null) { + yield r'outerEnumDefaultValue'; + yield serializers.serialize( + object.outerEnumDefaultValue, + specifiedType: const FullType(OuterEnumDefaultValue), + ); + } + if (object.outerEnumIntegerDefaultValue != null) { + yield r'outerEnumIntegerDefaultValue'; + yield serializers.serialize( + object.outerEnumIntegerDefaultValue, + specifiedType: const FullType(OuterEnumIntegerDefaultValue), + ); + } + } + + @override + Object serialize( + Serializers serializers, + EnumTest object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required EnumTestBuilder result, + required List 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'enum_string': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(EnumTestEnumStringEnum), + ) as EnumTestEnumStringEnum; + result.enumString = valueDes; + break; + case r'enum_string_required': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(EnumTestEnumStringRequiredEnum), + ) as EnumTestEnumStringRequiredEnum; + result.enumStringRequired = valueDes; + break; + case r'enum_integer': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(EnumTestEnumIntegerEnum), + ) as EnumTestEnumIntegerEnum; + result.enumInteger = valueDes; + break; + case r'enum_number': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(EnumTestEnumNumberEnum), + ) as EnumTestEnumNumberEnum; + result.enumNumber = valueDes; + break; + case r'outerEnum': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType.nullable(OuterEnum), + ) as OuterEnum?; + if (valueDes == null) continue; + result.outerEnum = valueDes; + break; + case r'outerEnumInteger': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(OuterEnumInteger), + ) as OuterEnumInteger; + result.outerEnumInteger = valueDes; + break; + case r'outerEnumDefaultValue': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(OuterEnumDefaultValue), + ) as OuterEnumDefaultValue; + result.outerEnumDefaultValue = valueDes; + break; + case r'outerEnumIntegerDefaultValue': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(OuterEnumIntegerDefaultValue), + ) as OuterEnumIntegerDefaultValue; + result.outerEnumIntegerDefaultValue = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + EnumTest deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = EnumTestBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } class EnumTestEnumStringEnum extends EnumClass { diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/file_schema_test_class.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/file_schema_test_class.dart index 7a2090e87da..5ab41d14f43 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/file_schema_test_class.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/file_schema_test_class.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:openapi/src/model/model_file.dart'; import 'package:built_value/built_value.dart'; @@ -14,75 +15,114 @@ part 'file_schema_test_class.g.dart'; /// Properties: /// * [file] /// * [files] +@BuiltValue() abstract class FileSchemaTestClass implements Built { - @BuiltValueField(wireName: r'file') - ModelFile? get file; + @BuiltValueField(wireName: r'file') + ModelFile? get file; - @BuiltValueField(wireName: r'files') - BuiltList? get files; + @BuiltValueField(wireName: r'files') + BuiltList? get files; - FileSchemaTestClass._(); + FileSchemaTestClass._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(FileSchemaTestClassBuilder b) => b; + factory FileSchemaTestClass([void updates(FileSchemaTestClassBuilder b)]) = _$FileSchemaTestClass; - factory FileSchemaTestClass([void updates(FileSchemaTestClassBuilder b)]) = _$FileSchemaTestClass; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(FileSchemaTestClassBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$FileSchemaTestClassSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$FileSchemaTestClassSerializer(); } -class _$FileSchemaTestClassSerializer implements StructuredSerializer { - @override - final Iterable types = const [FileSchemaTestClass, _$FileSchemaTestClass]; +class _$FileSchemaTestClassSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [FileSchemaTestClass, _$FileSchemaTestClass]; - @override - final String wireName = r'FileSchemaTestClass'; + @override + final String wireName = r'FileSchemaTestClass'; - @override - Iterable serialize(Serializers serializers, FileSchemaTestClass object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.file != null) { - result - ..add(r'file') - ..add(serializers.serialize(object.file, - specifiedType: const FullType(ModelFile))); - } - if (object.files != null) { - result - ..add(r'files') - ..add(serializers.serialize(object.files, - specifiedType: const FullType(BuiltList, [FullType(ModelFile)]))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + FileSchemaTestClass object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.file != null) { + yield r'file'; + yield serializers.serialize( + object.file, + specifiedType: const FullType(ModelFile), + ); } - - @override - FileSchemaTestClass deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = FileSchemaTestClassBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'file': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(ModelFile)) as ModelFile; - result.file.replace(valueDes); - break; - case r'files': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltList, [FullType(ModelFile)])) as BuiltList; - result.files.replace(valueDes); - break; - } - } - return result.build(); + if (object.files != null) { + yield r'files'; + yield serializers.serialize( + object.files, + specifiedType: const FullType(BuiltList, [FullType(ModelFile)]), + ); } + } + + @override + Object serialize( + Serializers serializers, + FileSchemaTestClass object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required FileSchemaTestClassBuilder result, + required List 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'file': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(ModelFile), + ) as ModelFile; + result.file.replace(valueDes); + break; + case r'files': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltList, [FullType(ModelFile)]), + ) as BuiltList; + result.files.replace(valueDes); + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + FileSchemaTestClass deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = FileSchemaTestClassBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/foo.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/foo.dart index dd3691968d4..57e0992c67c 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/foo.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/foo.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -11,62 +12,98 @@ part 'foo.g.dart'; /// /// Properties: /// * [bar] +@BuiltValue() abstract class Foo implements Built { - @BuiltValueField(wireName: r'bar') - String? get bar; + @BuiltValueField(wireName: r'bar') + String? get bar; - Foo._(); + Foo._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(FooBuilder b) => b - ..bar = 'bar'; + factory Foo([void updates(FooBuilder b)]) = _$Foo; - factory Foo([void updates(FooBuilder b)]) = _$Foo; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(FooBuilder b) => b + ..bar = 'bar'; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$FooSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$FooSerializer(); } -class _$FooSerializer implements StructuredSerializer { - @override - final Iterable types = const [Foo, _$Foo]; +class _$FooSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Foo, _$Foo]; - @override - final String wireName = r'Foo'; + @override + final String wireName = r'Foo'; - @override - Iterable serialize(Serializers serializers, Foo object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.bar != null) { - result - ..add(r'bar') - ..add(serializers.serialize(object.bar, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + Foo object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.bar != null) { + yield r'bar'; + yield serializers.serialize( + object.bar, + specifiedType: const FullType(String), + ); } + } - @override - Foo deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = FooBuilder(); + @override + Object serialize( + Serializers serializers, + Foo object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'bar': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.bar = valueDes; - break; - } - } - return result.build(); + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required FooBuilder result, + required List 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'bar': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.bar = 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).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/foo_get_default_response.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/foo_get_default_response.dart index 655b5f480db..b5903ebd5db 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/foo_get_default_response.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/foo_get_default_response.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/foo.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -12,61 +13,97 @@ part 'foo_get_default_response.g.dart'; /// /// Properties: /// * [string] +@BuiltValue() abstract class FooGetDefaultResponse implements Built { - @BuiltValueField(wireName: r'string') - Foo? get string; + @BuiltValueField(wireName: r'string') + Foo? get string; - FooGetDefaultResponse._(); + FooGetDefaultResponse._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(FooGetDefaultResponseBuilder b) => b; + factory FooGetDefaultResponse([void updates(FooGetDefaultResponseBuilder b)]) = _$FooGetDefaultResponse; - factory FooGetDefaultResponse([void updates(FooGetDefaultResponseBuilder b)]) = _$FooGetDefaultResponse; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(FooGetDefaultResponseBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$FooGetDefaultResponseSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$FooGetDefaultResponseSerializer(); } -class _$FooGetDefaultResponseSerializer implements StructuredSerializer { - @override - final Iterable types = const [FooGetDefaultResponse, _$FooGetDefaultResponse]; +class _$FooGetDefaultResponseSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [FooGetDefaultResponse, _$FooGetDefaultResponse]; - @override - final String wireName = r'FooGetDefaultResponse'; + @override + final String wireName = r'FooGetDefaultResponse'; - @override - Iterable serialize(Serializers serializers, FooGetDefaultResponse object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.string != null) { - result - ..add(r'string') - ..add(serializers.serialize(object.string, - specifiedType: const FullType(Foo))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + FooGetDefaultResponse object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.string != null) { + yield r'string'; + yield serializers.serialize( + object.string, + specifiedType: const FullType(Foo), + ); } + } - @override - FooGetDefaultResponse deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = FooGetDefaultResponseBuilder(); + @override + Object serialize( + Serializers serializers, + FooGetDefaultResponse object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'string': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(Foo)) as Foo; - result.string.replace(valueDes); - break; - } - } - return result.build(); + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required FooGetDefaultResponseBuilder result, + required List 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'string': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(Foo), + ) as Foo; + result.string.replace(valueDes); + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } } + } + + @override + FooGetDefaultResponse deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = FooGetDefaultResponseBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/format_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/format_test.dart index cf1be44ab5b..33775231476 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/format_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/format_test.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'dart:typed_data'; import 'package:openapi/src/model/date.dart'; import 'package:built_value/built_value.dart'; @@ -28,265 +29,346 @@ part 'format_test.g.dart'; /// * [password] /// * [patternWithDigits] - A string that is a 10 digit number. Can have leading zeros. /// * [patternWithDigitsAndDelimiter] - A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. +@BuiltValue() abstract class FormatTest implements Built { - @BuiltValueField(wireName: r'integer') - int? get integer; + @BuiltValueField(wireName: r'integer') + int? get integer; - @BuiltValueField(wireName: r'int32') - int? get int32; + @BuiltValueField(wireName: r'int32') + int? get int32; - @BuiltValueField(wireName: r'int64') - int? get int64; + @BuiltValueField(wireName: r'int64') + int? get int64; - @BuiltValueField(wireName: r'number') - num get number; + @BuiltValueField(wireName: r'number') + num get number; - @BuiltValueField(wireName: r'float') - double? get float; + @BuiltValueField(wireName: r'float') + double? get float; - @BuiltValueField(wireName: r'double') - double? get double_; + @BuiltValueField(wireName: r'double') + double? get double_; - @BuiltValueField(wireName: r'decimal') - double? get decimal; + @BuiltValueField(wireName: r'decimal') + double? get decimal; - @BuiltValueField(wireName: r'string') - String? get string; + @BuiltValueField(wireName: r'string') + String? get string; - @BuiltValueField(wireName: r'byte') - String get byte; + @BuiltValueField(wireName: r'byte') + String get byte; - @BuiltValueField(wireName: r'binary') - Uint8List? get binary; + @BuiltValueField(wireName: r'binary') + Uint8List? get binary; - @BuiltValueField(wireName: r'date') - Date get date; + @BuiltValueField(wireName: r'date') + Date get date; - @BuiltValueField(wireName: r'dateTime') - DateTime? get dateTime; + @BuiltValueField(wireName: r'dateTime') + DateTime? get dateTime; - @BuiltValueField(wireName: r'uuid') - String? get uuid; + @BuiltValueField(wireName: r'uuid') + String? get uuid; - @BuiltValueField(wireName: r'password') - String get password; + @BuiltValueField(wireName: r'password') + String get password; - /// A string that is a 10 digit number. Can have leading zeros. - @BuiltValueField(wireName: r'pattern_with_digits') - String? get patternWithDigits; + /// A string that is a 10 digit number. Can have leading zeros. + @BuiltValueField(wireName: r'pattern_with_digits') + String? get patternWithDigits; - /// A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. - @BuiltValueField(wireName: r'pattern_with_digits_and_delimiter') - String? get patternWithDigitsAndDelimiter; + /// A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. + @BuiltValueField(wireName: r'pattern_with_digits_and_delimiter') + String? get patternWithDigitsAndDelimiter; - FormatTest._(); + FormatTest._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(FormatTestBuilder b) => b; + factory FormatTest([void updates(FormatTestBuilder b)]) = _$FormatTest; - factory FormatTest([void updates(FormatTestBuilder b)]) = _$FormatTest; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(FormatTestBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$FormatTestSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$FormatTestSerializer(); } -class _$FormatTestSerializer implements StructuredSerializer { - @override - final Iterable types = const [FormatTest, _$FormatTest]; +class _$FormatTestSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [FormatTest, _$FormatTest]; - @override - final String wireName = r'FormatTest'; + @override + final String wireName = r'FormatTest'; - @override - Iterable serialize(Serializers serializers, FormatTest object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.integer != null) { - result - ..add(r'integer') - ..add(serializers.serialize(object.integer, - specifiedType: const FullType(int))); - } - if (object.int32 != null) { - result - ..add(r'int32') - ..add(serializers.serialize(object.int32, - specifiedType: const FullType(int))); - } - if (object.int64 != null) { - result - ..add(r'int64') - ..add(serializers.serialize(object.int64, - specifiedType: const FullType(int))); - } - result - ..add(r'number') - ..add(serializers.serialize(object.number, - specifiedType: const FullType(num))); - if (object.float != null) { - result - ..add(r'float') - ..add(serializers.serialize(object.float, - specifiedType: const FullType(double))); - } - if (object.double_ != null) { - result - ..add(r'double') - ..add(serializers.serialize(object.double_, - specifiedType: const FullType(double))); - } - if (object.decimal != null) { - result - ..add(r'decimal') - ..add(serializers.serialize(object.decimal, - specifiedType: const FullType(double))); - } - if (object.string != null) { - result - ..add(r'string') - ..add(serializers.serialize(object.string, - specifiedType: const FullType(String))); - } - result - ..add(r'byte') - ..add(serializers.serialize(object.byte, - specifiedType: const FullType(String))); - if (object.binary != null) { - result - ..add(r'binary') - ..add(serializers.serialize(object.binary, - specifiedType: const FullType(Uint8List))); - } - result - ..add(r'date') - ..add(serializers.serialize(object.date, - specifiedType: const FullType(Date))); - if (object.dateTime != null) { - result - ..add(r'dateTime') - ..add(serializers.serialize(object.dateTime, - specifiedType: const FullType(DateTime))); - } - if (object.uuid != null) { - result - ..add(r'uuid') - ..add(serializers.serialize(object.uuid, - specifiedType: const FullType(String))); - } - result - ..add(r'password') - ..add(serializers.serialize(object.password, - specifiedType: const FullType(String))); - if (object.patternWithDigits != null) { - result - ..add(r'pattern_with_digits') - ..add(serializers.serialize(object.patternWithDigits, - specifiedType: const FullType(String))); - } - if (object.patternWithDigitsAndDelimiter != null) { - result - ..add(r'pattern_with_digits_and_delimiter') - ..add(serializers.serialize(object.patternWithDigitsAndDelimiter, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + FormatTest object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.integer != null) { + yield r'integer'; + yield serializers.serialize( + object.integer, + specifiedType: const FullType(int), + ); } - - @override - FormatTest deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = FormatTestBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'integer': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.integer = valueDes; - break; - case r'int32': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.int32 = valueDes; - break; - case r'int64': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.int64 = valueDes; - break; - case r'number': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(num)) as num; - result.number = valueDes; - break; - case r'float': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(double)) as double; - result.float = valueDes; - break; - case r'double': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(double)) as double; - result.double_ = valueDes; - break; - case r'decimal': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(double)) as double; - result.decimal = valueDes; - break; - case r'string': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.string = valueDes; - break; - case r'byte': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.byte = valueDes; - break; - case r'binary': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(Uint8List)) as Uint8List; - result.binary = valueDes; - break; - case r'date': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(Date)) as Date; - result.date = valueDes; - break; - case r'dateTime': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(DateTime)) as DateTime; - result.dateTime = valueDes; - break; - case r'uuid': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.uuid = valueDes; - break; - case r'password': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.password = valueDes; - break; - case r'pattern_with_digits': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.patternWithDigits = valueDes; - break; - case r'pattern_with_digits_and_delimiter': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.patternWithDigitsAndDelimiter = valueDes; - break; - } - } - return result.build(); + if (object.int32 != null) { + yield r'int32'; + yield serializers.serialize( + object.int32, + specifiedType: const FullType(int), + ); } + if (object.int64 != null) { + yield r'int64'; + yield serializers.serialize( + object.int64, + specifiedType: const FullType(int), + ); + } + yield r'number'; + yield serializers.serialize( + object.number, + specifiedType: const FullType(num), + ); + if (object.float != null) { + yield r'float'; + yield serializers.serialize( + object.float, + specifiedType: const FullType(double), + ); + } + if (object.double_ != null) { + yield r'double'; + yield serializers.serialize( + object.double_, + specifiedType: const FullType(double), + ); + } + if (object.decimal != null) { + yield r'decimal'; + yield serializers.serialize( + object.decimal, + specifiedType: const FullType(double), + ); + } + if (object.string != null) { + yield r'string'; + yield serializers.serialize( + object.string, + specifiedType: const FullType(String), + ); + } + yield r'byte'; + yield serializers.serialize( + object.byte, + specifiedType: const FullType(String), + ); + if (object.binary != null) { + yield r'binary'; + yield serializers.serialize( + object.binary, + specifiedType: const FullType(Uint8List), + ); + } + yield r'date'; + yield serializers.serialize( + object.date, + specifiedType: const FullType(Date), + ); + if (object.dateTime != null) { + yield r'dateTime'; + yield serializers.serialize( + object.dateTime, + specifiedType: const FullType(DateTime), + ); + } + if (object.uuid != null) { + yield r'uuid'; + yield serializers.serialize( + object.uuid, + specifiedType: const FullType(String), + ); + } + yield r'password'; + yield serializers.serialize( + object.password, + specifiedType: const FullType(String), + ); + if (object.patternWithDigits != null) { + yield r'pattern_with_digits'; + yield serializers.serialize( + object.patternWithDigits, + specifiedType: const FullType(String), + ); + } + if (object.patternWithDigitsAndDelimiter != null) { + yield r'pattern_with_digits_and_delimiter'; + yield serializers.serialize( + object.patternWithDigitsAndDelimiter, + specifiedType: const FullType(String), + ); + } + } + + @override + Object serialize( + Serializers serializers, + FormatTest object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required FormatTestBuilder result, + required List 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'integer': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.integer = valueDes; + break; + case r'int32': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.int32 = valueDes; + break; + case r'int64': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.int64 = valueDes; + break; + case r'number': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(num), + ) as num; + result.number = valueDes; + break; + case r'float': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(double), + ) as double; + result.float = valueDes; + break; + case r'double': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(double), + ) as double; + result.double_ = valueDes; + break; + case r'decimal': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(double), + ) as double; + result.decimal = valueDes; + break; + case r'string': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.string = valueDes; + break; + case r'byte': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.byte = valueDes; + break; + case r'binary': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(Uint8List), + ) as Uint8List; + result.binary = valueDes; + break; + case r'date': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(Date), + ) as Date; + result.date = valueDes; + break; + case r'dateTime': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(DateTime), + ) as DateTime; + result.dateTime = valueDes; + break; + case r'uuid': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.uuid = valueDes; + break; + case r'password': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.password = valueDes; + break; + case r'pattern_with_digits': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.patternWithDigits = valueDes; + break; + case r'pattern_with_digits_and_delimiter': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.patternWithDigitsAndDelimiter = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + FormatTest deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = FormatTestBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/has_only_read_only.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/has_only_read_only.dart index 21b44ece26e..9683985cf19 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/has_only_read_only.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/has_only_read_only.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -12,75 +13,114 @@ part 'has_only_read_only.g.dart'; /// Properties: /// * [bar] /// * [foo] +@BuiltValue() abstract class HasOnlyReadOnly implements Built { - @BuiltValueField(wireName: r'bar') - String? get bar; + @BuiltValueField(wireName: r'bar') + String? get bar; - @BuiltValueField(wireName: r'foo') - String? get foo; + @BuiltValueField(wireName: r'foo') + String? get foo; - HasOnlyReadOnly._(); + HasOnlyReadOnly._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(HasOnlyReadOnlyBuilder b) => b; + factory HasOnlyReadOnly([void updates(HasOnlyReadOnlyBuilder b)]) = _$HasOnlyReadOnly; - factory HasOnlyReadOnly([void updates(HasOnlyReadOnlyBuilder b)]) = _$HasOnlyReadOnly; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(HasOnlyReadOnlyBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$HasOnlyReadOnlySerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$HasOnlyReadOnlySerializer(); } -class _$HasOnlyReadOnlySerializer implements StructuredSerializer { - @override - final Iterable types = const [HasOnlyReadOnly, _$HasOnlyReadOnly]; +class _$HasOnlyReadOnlySerializer implements PrimitiveSerializer { + @override + final Iterable types = const [HasOnlyReadOnly, _$HasOnlyReadOnly]; - @override - final String wireName = r'HasOnlyReadOnly'; + @override + final String wireName = r'HasOnlyReadOnly'; - @override - Iterable serialize(Serializers serializers, HasOnlyReadOnly object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.bar != null) { - result - ..add(r'bar') - ..add(serializers.serialize(object.bar, - specifiedType: const FullType(String))); - } - if (object.foo != null) { - result - ..add(r'foo') - ..add(serializers.serialize(object.foo, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + HasOnlyReadOnly object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.bar != null) { + yield r'bar'; + yield serializers.serialize( + object.bar, + specifiedType: const FullType(String), + ); } - - @override - HasOnlyReadOnly deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = HasOnlyReadOnlyBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'bar': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.bar = valueDes; - break; - case r'foo': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.foo = valueDes; - break; - } - } - return result.build(); + if (object.foo != null) { + yield r'foo'; + yield serializers.serialize( + object.foo, + specifiedType: const FullType(String), + ); } + } + + @override + Object serialize( + Serializers serializers, + HasOnlyReadOnly object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required HasOnlyReadOnlyBuilder result, + required List 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'bar': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.bar = valueDes; + break; + case r'foo': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.foo = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + HasOnlyReadOnly deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = HasOnlyReadOnlyBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/health_check_result.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/health_check_result.dart index e589cb7bd35..c092a535f2f 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/health_check_result.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/health_check_result.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -11,62 +12,98 @@ part 'health_check_result.g.dart'; /// /// Properties: /// * [nullableMessage] +@BuiltValue() abstract class HealthCheckResult implements Built { - @BuiltValueField(wireName: r'NullableMessage') - String? get nullableMessage; + @BuiltValueField(wireName: r'NullableMessage') + String? get nullableMessage; - HealthCheckResult._(); + HealthCheckResult._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(HealthCheckResultBuilder b) => b; + factory HealthCheckResult([void updates(HealthCheckResultBuilder b)]) = _$HealthCheckResult; - factory HealthCheckResult([void updates(HealthCheckResultBuilder b)]) = _$HealthCheckResult; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(HealthCheckResultBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$HealthCheckResultSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$HealthCheckResultSerializer(); } -class _$HealthCheckResultSerializer implements StructuredSerializer { - @override - final Iterable types = const [HealthCheckResult, _$HealthCheckResult]; +class _$HealthCheckResultSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [HealthCheckResult, _$HealthCheckResult]; - @override - final String wireName = r'HealthCheckResult'; + @override + final String wireName = r'HealthCheckResult'; - @override - Iterable serialize(Serializers serializers, HealthCheckResult object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.nullableMessage != null) { - result - ..add(r'NullableMessage') - ..add(serializers.serialize(object.nullableMessage, - specifiedType: const FullType.nullable(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + HealthCheckResult object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.nullableMessage != null) { + yield r'NullableMessage'; + yield serializers.serialize( + object.nullableMessage, + specifiedType: const FullType.nullable(String), + ); } + } - @override - HealthCheckResult deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = HealthCheckResultBuilder(); + @override + Object serialize( + Serializers serializers, + HealthCheckResult object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'NullableMessage': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType.nullable(String)) as String?; - if (valueDes == null) continue; - result.nullableMessage = valueDes; - break; - } - } - return result.build(); + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required HealthCheckResultBuilder result, + required List 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'NullableMessage': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType.nullable(String), + ) as String?; + if (valueDes == null) continue; + result.nullableMessage = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } } + } + + @override + HealthCheckResult deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = HealthCheckResultBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/inline_response_default.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/inline_response_default.dart index b611f8beb6a..74d5ed70f1e 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/inline_response_default.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/inline_response_default.dart @@ -5,6 +5,9 @@ import 'package:openapi/src/model/foo.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; +import 'package:one_of/one_of.dart'; +import 'package:one_of/any_of.dart'; +// ignore_for_file: unused_element, unused_import part 'inline_response_default.g.dart'; @@ -12,61 +15,77 @@ part 'inline_response_default.g.dart'; /// /// Properties: /// * [string] +@BuiltValue() abstract class InlineResponseDefault implements Built { @BuiltValueField(wireName: r'string') Foo? get string; + InlineResponseDefault._(); + + factory InlineResponseDefault([void updates(InlineResponseDefaultBuilder b)]) = _$InlineResponseDefault; @BuiltValueHook(initializeBuilder: true) static void _defaults(InlineResponseDefaultBuilder b) => b; - factory InlineResponseDefault([void updates(InlineResponseDefaultBuilder b)]) = _$InlineResponseDefault; - @BuiltValueSerializer(custom: true) static Serializer get serializer => _$InlineResponseDefaultSerializer(); + + } -class _$InlineResponseDefaultSerializer implements StructuredSerializer { +class _$InlineResponseDefaultSerializer implements PrimitiveSerializer { @override final Iterable types = const [InlineResponseDefault, _$InlineResponseDefault]; @override final String wireName = r'InlineResponseDefault'; - @override - Iterable serialize(Serializers serializers, InlineResponseDefault object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; + Iterable _serializeProperties(Serializers serializers, InlineResponseDefault object, + {FullType specifiedType = FullType.unspecified}) sync* { if (object.string != null) { - result - ..add(r'string') - ..add(serializers.serialize(object.string, - specifiedType: const FullType(Foo))); + yield r'string'; + yield serializers.serialize(object.string, + specifiedType: const FullType(Foo)); } - return result; } @override - InlineResponseDefault deserialize(Serializers serializers, Iterable serialized, + Object serialize(Serializers serializers, InlineResponseDefault object, {FullType specifiedType = FullType.unspecified}) { - final result = InlineResponseDefaultBuilder(); + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - + void _deserializeProperties(Serializers serializers, Object serialized, + {FullType specifiedType = FullType.unspecified, required List serializedList,required InlineResponseDefaultBuilder result, required List 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'string': + case r'string': final valueDes = serializers.deserialize(value, specifiedType: const FullType(Foo)) as Foo; result.string.replace(valueDes); break; + default: + unhandled.add(key); + unhandled.add(value); + break; } } + } + + @override + InlineResponseDefault deserialize(Serializers serializers, Object serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = InlineResponseDefaultBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties(serializers, serialized, specifiedType: specifiedType, serializedList: serializedList, unhandled: unhandled, result: result); return result.build(); } } + + + diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/map_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/map_test.dart index 16df0490e16..9fa58677a84 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/map_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/map_test.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -15,105 +16,150 @@ part 'map_test.g.dart'; /// * [mapOfEnumString] /// * [directMap] /// * [indirectMap] +@BuiltValue() abstract class MapTest implements Built { - @BuiltValueField(wireName: r'map_map_of_string') - BuiltMap>? get mapMapOfString; + @BuiltValueField(wireName: r'map_map_of_string') + BuiltMap>? get mapMapOfString; - @BuiltValueField(wireName: r'map_of_enum_string') - BuiltMap? get mapOfEnumString; - // enum mapOfEnumStringEnum { UPPER, lower, }; + @BuiltValueField(wireName: r'map_of_enum_string') + BuiltMap? get mapOfEnumString; + // enum mapOfEnumStringEnum { UPPER, lower, }; - @BuiltValueField(wireName: r'direct_map') - BuiltMap? get directMap; + @BuiltValueField(wireName: r'direct_map') + BuiltMap? get directMap; - @BuiltValueField(wireName: r'indirect_map') - BuiltMap? get indirectMap; + @BuiltValueField(wireName: r'indirect_map') + BuiltMap? get indirectMap; - MapTest._(); + MapTest._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(MapTestBuilder b) => b; + factory MapTest([void updates(MapTestBuilder b)]) = _$MapTest; - factory MapTest([void updates(MapTestBuilder b)]) = _$MapTest; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(MapTestBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$MapTestSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$MapTestSerializer(); } -class _$MapTestSerializer implements StructuredSerializer { - @override - final Iterable types = const [MapTest, _$MapTest]; +class _$MapTestSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [MapTest, _$MapTest]; - @override - final String wireName = r'MapTest'; + @override + final String wireName = r'MapTest'; - @override - Iterable serialize(Serializers serializers, MapTest object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.mapMapOfString != null) { - result - ..add(r'map_map_of_string') - ..add(serializers.serialize(object.mapMapOfString, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType(BuiltMap, [FullType(String), FullType(String)])]))); - } - if (object.mapOfEnumString != null) { - result - ..add(r'map_of_enum_string') - ..add(serializers.serialize(object.mapOfEnumString, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType(MapTestMapOfEnumStringEnum)]))); - } - if (object.directMap != null) { - result - ..add(r'direct_map') - ..add(serializers.serialize(object.directMap, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType(bool)]))); - } - if (object.indirectMap != null) { - result - ..add(r'indirect_map') - ..add(serializers.serialize(object.indirectMap, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType(bool)]))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + MapTest object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.mapMapOfString != null) { + yield r'map_map_of_string'; + yield serializers.serialize( + object.mapMapOfString, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType(BuiltMap, [FullType(String), FullType(String)])]), + ); } - - @override - MapTest deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = MapTestBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'map_map_of_string': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType(BuiltMap, [FullType(String), FullType(String)])])) as BuiltMap>; - result.mapMapOfString.replace(valueDes); - break; - case r'map_of_enum_string': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType(MapTestMapOfEnumStringEnum)])) as BuiltMap; - result.mapOfEnumString.replace(valueDes); - break; - case r'direct_map': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType(bool)])) as BuiltMap; - result.directMap.replace(valueDes); - break; - case r'indirect_map': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType(bool)])) as BuiltMap; - result.indirectMap.replace(valueDes); - break; - } - } - return result.build(); + if (object.mapOfEnumString != null) { + yield r'map_of_enum_string'; + yield serializers.serialize( + object.mapOfEnumString, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType(MapTestMapOfEnumStringEnum)]), + ); } + if (object.directMap != null) { + yield r'direct_map'; + yield serializers.serialize( + object.directMap, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType(bool)]), + ); + } + if (object.indirectMap != null) { + yield r'indirect_map'; + yield serializers.serialize( + object.indirectMap, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType(bool)]), + ); + } + } + + @override + Object serialize( + Serializers serializers, + MapTest object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required MapTestBuilder result, + required List 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'map_map_of_string': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType(BuiltMap, [FullType(String), FullType(String)])]), + ) as BuiltMap>; + result.mapMapOfString.replace(valueDes); + break; + case r'map_of_enum_string': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType(MapTestMapOfEnumStringEnum)]), + ) as BuiltMap; + result.mapOfEnumString.replace(valueDes); + break; + case r'direct_map': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType(bool)]), + ) as BuiltMap; + result.directMap.replace(valueDes); + break; + case r'indirect_map': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType(bool)]), + ) as BuiltMap; + result.indirectMap.replace(valueDes); + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + MapTest deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = MapTestBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } class MapTestMapOfEnumStringEnum extends EnumClass { diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/mixed_properties_and_additional_properties_class.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/mixed_properties_and_additional_properties_class.dart index 27c6993cc70..76b5933ae5a 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/mixed_properties_and_additional_properties_class.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/mixed_properties_and_additional_properties_class.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:openapi/src/model/animal.dart'; import 'package:built_value/built_value.dart'; @@ -15,89 +16,131 @@ part 'mixed_properties_and_additional_properties_class.g.dart'; /// * [uuid] /// * [dateTime] /// * [map] +@BuiltValue() abstract class MixedPropertiesAndAdditionalPropertiesClass implements Built { - @BuiltValueField(wireName: r'uuid') - String? get uuid; + @BuiltValueField(wireName: r'uuid') + String? get uuid; - @BuiltValueField(wireName: r'dateTime') - DateTime? get dateTime; + @BuiltValueField(wireName: r'dateTime') + DateTime? get dateTime; - @BuiltValueField(wireName: r'map') - BuiltMap? get map; + @BuiltValueField(wireName: r'map') + BuiltMap? get map; - MixedPropertiesAndAdditionalPropertiesClass._(); + MixedPropertiesAndAdditionalPropertiesClass._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(MixedPropertiesAndAdditionalPropertiesClassBuilder b) => b; + factory MixedPropertiesAndAdditionalPropertiesClass([void updates(MixedPropertiesAndAdditionalPropertiesClassBuilder b)]) = _$MixedPropertiesAndAdditionalPropertiesClass; - factory MixedPropertiesAndAdditionalPropertiesClass([void updates(MixedPropertiesAndAdditionalPropertiesClassBuilder b)]) = _$MixedPropertiesAndAdditionalPropertiesClass; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(MixedPropertiesAndAdditionalPropertiesClassBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$MixedPropertiesAndAdditionalPropertiesClassSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$MixedPropertiesAndAdditionalPropertiesClassSerializer(); } -class _$MixedPropertiesAndAdditionalPropertiesClassSerializer implements StructuredSerializer { - @override - final Iterable types = const [MixedPropertiesAndAdditionalPropertiesClass, _$MixedPropertiesAndAdditionalPropertiesClass]; +class _$MixedPropertiesAndAdditionalPropertiesClassSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [MixedPropertiesAndAdditionalPropertiesClass, _$MixedPropertiesAndAdditionalPropertiesClass]; - @override - final String wireName = r'MixedPropertiesAndAdditionalPropertiesClass'; + @override + final String wireName = r'MixedPropertiesAndAdditionalPropertiesClass'; - @override - Iterable serialize(Serializers serializers, MixedPropertiesAndAdditionalPropertiesClass object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.uuid != null) { - result - ..add(r'uuid') - ..add(serializers.serialize(object.uuid, - specifiedType: const FullType(String))); - } - if (object.dateTime != null) { - result - ..add(r'dateTime') - ..add(serializers.serialize(object.dateTime, - specifiedType: const FullType(DateTime))); - } - if (object.map != null) { - result - ..add(r'map') - ..add(serializers.serialize(object.map, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType(Animal)]))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + MixedPropertiesAndAdditionalPropertiesClass object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.uuid != null) { + yield r'uuid'; + yield serializers.serialize( + object.uuid, + specifiedType: const FullType(String), + ); } - - @override - MixedPropertiesAndAdditionalPropertiesClass deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = MixedPropertiesAndAdditionalPropertiesClassBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'uuid': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.uuid = valueDes; - break; - case r'dateTime': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(DateTime)) as DateTime; - result.dateTime = valueDes; - break; - case r'map': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType(Animal)])) as BuiltMap; - result.map.replace(valueDes); - break; - } - } - return result.build(); + if (object.dateTime != null) { + yield r'dateTime'; + yield serializers.serialize( + object.dateTime, + specifiedType: const FullType(DateTime), + ); } + if (object.map != null) { + yield r'map'; + yield serializers.serialize( + object.map, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType(Animal)]), + ); + } + } + + @override + Object serialize( + Serializers serializers, + MixedPropertiesAndAdditionalPropertiesClass object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required MixedPropertiesAndAdditionalPropertiesClassBuilder result, + required List 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'uuid': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.uuid = valueDes; + break; + case r'dateTime': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(DateTime), + ) as DateTime; + result.dateTime = valueDes; + break; + case r'map': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType(Animal)]), + ) as BuiltMap; + result.map.replace(valueDes); + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + MixedPropertiesAndAdditionalPropertiesClass deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = MixedPropertiesAndAdditionalPropertiesClassBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model200_response.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model200_response.dart index 1e7b31e2af6..0a2cfb4411a 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model200_response.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model200_response.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -12,75 +13,114 @@ part 'model200_response.g.dart'; /// Properties: /// * [name] /// * [classField] +@BuiltValue() abstract class Model200Response implements Built { - @BuiltValueField(wireName: r'name') - int? get name; + @BuiltValueField(wireName: r'name') + int? get name; - @BuiltValueField(wireName: r'class') - String? get classField; + @BuiltValueField(wireName: r'class') + String? get classField; - Model200Response._(); + Model200Response._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(Model200ResponseBuilder b) => b; + factory Model200Response([void updates(Model200ResponseBuilder b)]) = _$Model200Response; - factory Model200Response([void updates(Model200ResponseBuilder b)]) = _$Model200Response; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(Model200ResponseBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$Model200ResponseSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$Model200ResponseSerializer(); } -class _$Model200ResponseSerializer implements StructuredSerializer { - @override - final Iterable types = const [Model200Response, _$Model200Response]; +class _$Model200ResponseSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Model200Response, _$Model200Response]; - @override - final String wireName = r'Model200Response'; + @override + final String wireName = r'Model200Response'; - @override - Iterable serialize(Serializers serializers, Model200Response object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.name != null) { - result - ..add(r'name') - ..add(serializers.serialize(object.name, - specifiedType: const FullType(int))); - } - if (object.classField != null) { - result - ..add(r'class') - ..add(serializers.serialize(object.classField, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + Model200Response object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.name != null) { + yield r'name'; + yield serializers.serialize( + object.name, + specifiedType: const FullType(int), + ); } - - @override - Model200Response deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = Model200ResponseBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'name': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.name = valueDes; - break; - case r'class': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.classField = valueDes; - break; - } - } - return result.build(); + if (object.classField != null) { + yield r'class'; + yield serializers.serialize( + object.classField, + specifiedType: const FullType(String), + ); } + } + + @override + Object serialize( + Serializers serializers, + Model200Response object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required Model200ResponseBuilder result, + required List 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'name': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.name = valueDes; + break; + case r'class': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.classField = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + Model200Response deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = Model200ResponseBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_client.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_client.dart index 23c30a77f2b..36690977421 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_client.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_client.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -11,61 +12,97 @@ part 'model_client.g.dart'; /// /// Properties: /// * [client] +@BuiltValue() abstract class ModelClient implements Built { - @BuiltValueField(wireName: r'client') - String? get client; + @BuiltValueField(wireName: r'client') + String? get client; - ModelClient._(); + ModelClient._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(ModelClientBuilder b) => b; + factory ModelClient([void updates(ModelClientBuilder b)]) = _$ModelClient; - factory ModelClient([void updates(ModelClientBuilder b)]) = _$ModelClient; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(ModelClientBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$ModelClientSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$ModelClientSerializer(); } -class _$ModelClientSerializer implements StructuredSerializer { - @override - final Iterable types = const [ModelClient, _$ModelClient]; +class _$ModelClientSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [ModelClient, _$ModelClient]; - @override - final String wireName = r'ModelClient'; + @override + final String wireName = r'ModelClient'; - @override - Iterable serialize(Serializers serializers, ModelClient object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.client != null) { - result - ..add(r'client') - ..add(serializers.serialize(object.client, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + ModelClient object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.client != null) { + yield r'client'; + yield serializers.serialize( + object.client, + specifiedType: const FullType(String), + ); } + } - @override - ModelClient deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = ModelClientBuilder(); + @override + Object serialize( + Serializers serializers, + ModelClient object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'client': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.client = valueDes; - break; - } - } - return result.build(); + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required ModelClientBuilder result, + required List 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'client': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.client = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } } + } + + @override + ModelClient deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = ModelClientBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_enum_class.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_enum_class.dart index f49be90d2bb..ac609bfd15a 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_enum_class.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_enum_class.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_file.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_file.dart index aa7b5ecfedd..2702c21d36f 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_file.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_file.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -11,62 +12,98 @@ part 'model_file.g.dart'; /// /// Properties: /// * [sourceURI] - Test capitalization +@BuiltValue() abstract class ModelFile implements Built { - /// Test capitalization - @BuiltValueField(wireName: r'sourceURI') - String? get sourceURI; + /// Test capitalization + @BuiltValueField(wireName: r'sourceURI') + String? get sourceURI; - ModelFile._(); + ModelFile._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(ModelFileBuilder b) => b; + factory ModelFile([void updates(ModelFileBuilder b)]) = _$ModelFile; - factory ModelFile([void updates(ModelFileBuilder b)]) = _$ModelFile; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(ModelFileBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$ModelFileSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$ModelFileSerializer(); } -class _$ModelFileSerializer implements StructuredSerializer { - @override - final Iterable types = const [ModelFile, _$ModelFile]; +class _$ModelFileSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [ModelFile, _$ModelFile]; - @override - final String wireName = r'ModelFile'; + @override + final String wireName = r'ModelFile'; - @override - Iterable serialize(Serializers serializers, ModelFile object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.sourceURI != null) { - result - ..add(r'sourceURI') - ..add(serializers.serialize(object.sourceURI, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + ModelFile object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.sourceURI != null) { + yield r'sourceURI'; + yield serializers.serialize( + object.sourceURI, + specifiedType: const FullType(String), + ); } + } - @override - ModelFile deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = ModelFileBuilder(); + @override + Object serialize( + Serializers serializers, + ModelFile object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'sourceURI': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.sourceURI = valueDes; - break; - } - } - return result.build(); + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required ModelFileBuilder result, + required List 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'sourceURI': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.sourceURI = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } } + } + + @override + ModelFile deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = ModelFileBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_list.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_list.dart index 87e10153b1a..579853258f8 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_list.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_list.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -11,61 +12,97 @@ part 'model_list.g.dart'; /// /// Properties: /// * [n123list] +@BuiltValue() abstract class ModelList implements Built { - @BuiltValueField(wireName: r'123-list') - String? get n123list; + @BuiltValueField(wireName: r'123-list') + String? get n123list; - ModelList._(); + ModelList._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(ModelListBuilder b) => b; + factory ModelList([void updates(ModelListBuilder b)]) = _$ModelList; - factory ModelList([void updates(ModelListBuilder b)]) = _$ModelList; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(ModelListBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$ModelListSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$ModelListSerializer(); } -class _$ModelListSerializer implements StructuredSerializer { - @override - final Iterable types = const [ModelList, _$ModelList]; +class _$ModelListSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [ModelList, _$ModelList]; - @override - final String wireName = r'ModelList'; + @override + final String wireName = r'ModelList'; - @override - Iterable serialize(Serializers serializers, ModelList object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.n123list != null) { - result - ..add(r'123-list') - ..add(serializers.serialize(object.n123list, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + ModelList object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.n123list != null) { + yield r'123-list'; + yield serializers.serialize( + object.n123list, + specifiedType: const FullType(String), + ); } + } - @override - ModelList deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = ModelListBuilder(); + @override + Object serialize( + Serializers serializers, + ModelList object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'123-list': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.n123list = valueDes; - break; - } - } - return result.build(); + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required ModelListBuilder result, + required List 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'123-list': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.n123list = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } } + } + + @override + ModelList deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = ModelListBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_return.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_return.dart index c63e0464faa..45a2f67f8a4 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_return.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/model_return.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -11,61 +12,97 @@ part 'model_return.g.dart'; /// /// Properties: /// * [return_] +@BuiltValue() abstract class ModelReturn implements Built { - @BuiltValueField(wireName: r'return') - int? get return_; + @BuiltValueField(wireName: r'return') + int? get return_; - ModelReturn._(); + ModelReturn._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(ModelReturnBuilder b) => b; + factory ModelReturn([void updates(ModelReturnBuilder b)]) = _$ModelReturn; - factory ModelReturn([void updates(ModelReturnBuilder b)]) = _$ModelReturn; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(ModelReturnBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$ModelReturnSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$ModelReturnSerializer(); } -class _$ModelReturnSerializer implements StructuredSerializer { - @override - final Iterable types = const [ModelReturn, _$ModelReturn]; +class _$ModelReturnSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [ModelReturn, _$ModelReturn]; - @override - final String wireName = r'ModelReturn'; + @override + final String wireName = r'ModelReturn'; - @override - Iterable serialize(Serializers serializers, ModelReturn object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.return_ != null) { - result - ..add(r'return') - ..add(serializers.serialize(object.return_, - specifiedType: const FullType(int))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + ModelReturn object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.return_ != null) { + yield r'return'; + yield serializers.serialize( + object.return_, + specifiedType: const FullType(int), + ); } + } - @override - ModelReturn deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = ModelReturnBuilder(); + @override + Object serialize( + Serializers serializers, + ModelReturn object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'return': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.return_ = valueDes; - break; - } - } - return result.build(); + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required ModelReturnBuilder result, + required List 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'return': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.return_ = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } } + } + + @override + ModelReturn deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = ModelReturnBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/name.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/name.dart index 78f9f8e545e..10fa99e6a5f 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/name.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/name.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -14,101 +15,146 @@ part 'name.g.dart'; /// * [snakeCase] /// * [property] /// * [n123number] +@BuiltValue() abstract class Name implements Built { - @BuiltValueField(wireName: r'name') - int get name; + @BuiltValueField(wireName: r'name') + int get name; - @BuiltValueField(wireName: r'snake_case') - int? get snakeCase; + @BuiltValueField(wireName: r'snake_case') + int? get snakeCase; - @BuiltValueField(wireName: r'property') - String? get property; + @BuiltValueField(wireName: r'property') + String? get property; - @BuiltValueField(wireName: r'123Number') - int? get n123number; + @BuiltValueField(wireName: r'123Number') + int? get n123number; - Name._(); + Name._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(NameBuilder b) => b; + factory Name([void updates(NameBuilder b)]) = _$Name; - factory Name([void updates(NameBuilder b)]) = _$Name; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(NameBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$NameSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$NameSerializer(); } -class _$NameSerializer implements StructuredSerializer { - @override - final Iterable types = const [Name, _$Name]; +class _$NameSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Name, _$Name]; - @override - final String wireName = r'Name'; + @override + final String wireName = r'Name'; - @override - Iterable serialize(Serializers serializers, Name object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - result - ..add(r'name') - ..add(serializers.serialize(object.name, - specifiedType: const FullType(int))); - if (object.snakeCase != null) { - result - ..add(r'snake_case') - ..add(serializers.serialize(object.snakeCase, - specifiedType: const FullType(int))); - } - if (object.property != null) { - result - ..add(r'property') - ..add(serializers.serialize(object.property, - specifiedType: const FullType(String))); - } - if (object.n123number != null) { - result - ..add(r'123Number') - ..add(serializers.serialize(object.n123number, - specifiedType: const FullType(int))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + Name object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + yield r'name'; + yield serializers.serialize( + object.name, + specifiedType: const FullType(int), + ); + if (object.snakeCase != null) { + yield r'snake_case'; + yield serializers.serialize( + object.snakeCase, + specifiedType: const FullType(int), + ); } - - @override - Name deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = NameBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'name': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.name = valueDes; - break; - case r'snake_case': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.snakeCase = valueDes; - break; - case r'property': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.property = valueDes; - break; - case r'123Number': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.n123number = valueDes; - break; - } - } - return result.build(); + if (object.property != null) { + yield r'property'; + yield serializers.serialize( + object.property, + specifiedType: const FullType(String), + ); } + if (object.n123number != null) { + yield r'123Number'; + yield serializers.serialize( + object.n123number, + specifiedType: const FullType(int), + ); + } + } + + @override + Object serialize( + Serializers serializers, + Name object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required NameBuilder result, + required List 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'name': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.name = valueDes; + break; + case r'snake_case': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.snakeCase = valueDes; + break; + case r'property': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.property = valueDes; + break; + case r'123Number': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.n123number = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + Name deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = NameBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/nullable_class.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/nullable_class.dart index efddc42e307..c993a41303f 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/nullable_class.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/nullable_class.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:openapi/src/model/date.dart'; import 'package:built_value/json_object.dart'; @@ -25,225 +26,294 @@ part 'nullable_class.g.dart'; /// * [objectNullableProp] /// * [objectAndItemsNullableProp] /// * [objectItemsNullable] +@BuiltValue() abstract class NullableClass implements Built { - @BuiltValueField(wireName: r'integer_prop') - int? get integerProp; + @BuiltValueField(wireName: r'integer_prop') + int? get integerProp; - @BuiltValueField(wireName: r'number_prop') - num? get numberProp; + @BuiltValueField(wireName: r'number_prop') + num? get numberProp; - @BuiltValueField(wireName: r'boolean_prop') - bool? get booleanProp; + @BuiltValueField(wireName: r'boolean_prop') + bool? get booleanProp; - @BuiltValueField(wireName: r'string_prop') - String? get stringProp; + @BuiltValueField(wireName: r'string_prop') + String? get stringProp; - @BuiltValueField(wireName: r'date_prop') - Date? get dateProp; + @BuiltValueField(wireName: r'date_prop') + Date? get dateProp; - @BuiltValueField(wireName: r'datetime_prop') - DateTime? get datetimeProp; + @BuiltValueField(wireName: r'datetime_prop') + DateTime? get datetimeProp; - @BuiltValueField(wireName: r'array_nullable_prop') - BuiltList? get arrayNullableProp; + @BuiltValueField(wireName: r'array_nullable_prop') + BuiltList? get arrayNullableProp; - @BuiltValueField(wireName: r'array_and_items_nullable_prop') - BuiltList? get arrayAndItemsNullableProp; + @BuiltValueField(wireName: r'array_and_items_nullable_prop') + BuiltList? get arrayAndItemsNullableProp; - @BuiltValueField(wireName: r'array_items_nullable') - BuiltList? get arrayItemsNullable; + @BuiltValueField(wireName: r'array_items_nullable') + BuiltList? get arrayItemsNullable; - @BuiltValueField(wireName: r'object_nullable_prop') - BuiltMap? get objectNullableProp; + @BuiltValueField(wireName: r'object_nullable_prop') + BuiltMap? get objectNullableProp; - @BuiltValueField(wireName: r'object_and_items_nullable_prop') - BuiltMap? get objectAndItemsNullableProp; + @BuiltValueField(wireName: r'object_and_items_nullable_prop') + BuiltMap? get objectAndItemsNullableProp; - @BuiltValueField(wireName: r'object_items_nullable') - BuiltMap? get objectItemsNullable; + @BuiltValueField(wireName: r'object_items_nullable') + BuiltMap? get objectItemsNullable; - NullableClass._(); + NullableClass._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(NullableClassBuilder b) => b; + factory NullableClass([void updates(NullableClassBuilder b)]) = _$NullableClass; - factory NullableClass([void updates(NullableClassBuilder b)]) = _$NullableClass; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(NullableClassBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$NullableClassSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$NullableClassSerializer(); } -class _$NullableClassSerializer implements StructuredSerializer { - @override - final Iterable types = const [NullableClass, _$NullableClass]; +class _$NullableClassSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [NullableClass, _$NullableClass]; - @override - final String wireName = r'NullableClass'; + @override + final String wireName = r'NullableClass'; - @override - Iterable serialize(Serializers serializers, NullableClass object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.integerProp != null) { - result - ..add(r'integer_prop') - ..add(serializers.serialize(object.integerProp, - specifiedType: const FullType.nullable(int))); - } - if (object.numberProp != null) { - result - ..add(r'number_prop') - ..add(serializers.serialize(object.numberProp, - specifiedType: const FullType.nullable(num))); - } - if (object.booleanProp != null) { - result - ..add(r'boolean_prop') - ..add(serializers.serialize(object.booleanProp, - specifiedType: const FullType.nullable(bool))); - } - if (object.stringProp != null) { - result - ..add(r'string_prop') - ..add(serializers.serialize(object.stringProp, - specifiedType: const FullType.nullable(String))); - } - if (object.dateProp != null) { - result - ..add(r'date_prop') - ..add(serializers.serialize(object.dateProp, - specifiedType: const FullType.nullable(Date))); - } - if (object.datetimeProp != null) { - result - ..add(r'datetime_prop') - ..add(serializers.serialize(object.datetimeProp, - specifiedType: const FullType.nullable(DateTime))); - } - if (object.arrayNullableProp != null) { - result - ..add(r'array_nullable_prop') - ..add(serializers.serialize(object.arrayNullableProp, - specifiedType: const FullType.nullable(BuiltList, [FullType(JsonObject)]))); - } - if (object.arrayAndItemsNullableProp != null) { - result - ..add(r'array_and_items_nullable_prop') - ..add(serializers.serialize(object.arrayAndItemsNullableProp, - specifiedType: const FullType.nullable(BuiltList, [FullType.nullable(JsonObject)]))); - } - if (object.arrayItemsNullable != null) { - result - ..add(r'array_items_nullable') - ..add(serializers.serialize(object.arrayItemsNullable, - specifiedType: const FullType(BuiltList, [FullType.nullable(JsonObject)]))); - } - if (object.objectNullableProp != null) { - result - ..add(r'object_nullable_prop') - ..add(serializers.serialize(object.objectNullableProp, - specifiedType: const FullType.nullable(BuiltMap, [FullType(String), FullType(JsonObject)]))); - } - if (object.objectAndItemsNullableProp != null) { - result - ..add(r'object_and_items_nullable_prop') - ..add(serializers.serialize(object.objectAndItemsNullableProp, - specifiedType: const FullType.nullable(BuiltMap, [FullType(String), FullType.nullable(JsonObject)]))); - } - if (object.objectItemsNullable != null) { - result - ..add(r'object_items_nullable') - ..add(serializers.serialize(object.objectItemsNullable, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType.nullable(JsonObject)]))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + NullableClass object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.integerProp != null) { + yield r'integer_prop'; + yield serializers.serialize( + object.integerProp, + specifiedType: const FullType.nullable(int), + ); } - - @override - NullableClass deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = NullableClassBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'integer_prop': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType.nullable(int)) as int?; - if (valueDes == null) continue; - result.integerProp = valueDes; - break; - case r'number_prop': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType.nullable(num)) as num?; - if (valueDes == null) continue; - result.numberProp = valueDes; - break; - case r'boolean_prop': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType.nullable(bool)) as bool?; - if (valueDes == null) continue; - result.booleanProp = valueDes; - break; - case r'string_prop': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType.nullable(String)) as String?; - if (valueDes == null) continue; - result.stringProp = valueDes; - break; - case r'date_prop': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType.nullable(Date)) as Date?; - if (valueDes == null) continue; - result.dateProp = valueDes; - break; - case r'datetime_prop': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType.nullable(DateTime)) as DateTime?; - if (valueDes == null) continue; - result.datetimeProp = valueDes; - break; - case r'array_nullable_prop': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType.nullable(BuiltList, [FullType(JsonObject)])) as BuiltList?; - if (valueDes == null) continue; - result.arrayNullableProp.replace(valueDes); - break; - case r'array_and_items_nullable_prop': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType.nullable(BuiltList, [FullType.nullable(JsonObject)])) as BuiltList?; - if (valueDes == null) continue; - result.arrayAndItemsNullableProp.replace(valueDes); - break; - case r'array_items_nullable': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltList, [FullType.nullable(JsonObject)])) as BuiltList; - result.arrayItemsNullable.replace(valueDes); - break; - case r'object_nullable_prop': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType.nullable(BuiltMap, [FullType(String), FullType(JsonObject)])) as BuiltMap?; - if (valueDes == null) continue; - result.objectNullableProp.replace(valueDes); - break; - case r'object_and_items_nullable_prop': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType.nullable(BuiltMap, [FullType(String), FullType.nullable(JsonObject)])) as BuiltMap?; - if (valueDes == null) continue; - result.objectAndItemsNullableProp.replace(valueDes); - break; - case r'object_items_nullable': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltMap, [FullType(String), FullType.nullable(JsonObject)])) as BuiltMap; - result.objectItemsNullable.replace(valueDes); - break; - } - } - return result.build(); + if (object.numberProp != null) { + yield r'number_prop'; + yield serializers.serialize( + object.numberProp, + specifiedType: const FullType.nullable(num), + ); } + if (object.booleanProp != null) { + yield r'boolean_prop'; + yield serializers.serialize( + object.booleanProp, + specifiedType: const FullType.nullable(bool), + ); + } + if (object.stringProp != null) { + yield r'string_prop'; + yield serializers.serialize( + object.stringProp, + specifiedType: const FullType.nullable(String), + ); + } + if (object.dateProp != null) { + yield r'date_prop'; + yield serializers.serialize( + object.dateProp, + specifiedType: const FullType.nullable(Date), + ); + } + if (object.datetimeProp != null) { + yield r'datetime_prop'; + yield serializers.serialize( + object.datetimeProp, + specifiedType: const FullType.nullable(DateTime), + ); + } + if (object.arrayNullableProp != null) { + yield r'array_nullable_prop'; + yield serializers.serialize( + object.arrayNullableProp, + specifiedType: const FullType.nullable(BuiltList, [FullType(JsonObject)]), + ); + } + if (object.arrayAndItemsNullableProp != null) { + yield r'array_and_items_nullable_prop'; + yield serializers.serialize( + object.arrayAndItemsNullableProp, + specifiedType: const FullType.nullable(BuiltList, [FullType.nullable(JsonObject)]), + ); + } + if (object.arrayItemsNullable != null) { + yield r'array_items_nullable'; + yield serializers.serialize( + object.arrayItemsNullable, + specifiedType: const FullType(BuiltList, [FullType.nullable(JsonObject)]), + ); + } + if (object.objectNullableProp != null) { + yield r'object_nullable_prop'; + yield serializers.serialize( + object.objectNullableProp, + specifiedType: const FullType.nullable(BuiltMap, [FullType(String), FullType(JsonObject)]), + ); + } + if (object.objectAndItemsNullableProp != null) { + yield r'object_and_items_nullable_prop'; + yield serializers.serialize( + object.objectAndItemsNullableProp, + specifiedType: const FullType.nullable(BuiltMap, [FullType(String), FullType.nullable(JsonObject)]), + ); + } + if (object.objectItemsNullable != null) { + yield r'object_items_nullable'; + yield serializers.serialize( + object.objectItemsNullable, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType.nullable(JsonObject)]), + ); + } + } + + @override + Object serialize( + Serializers serializers, + NullableClass object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required NullableClassBuilder result, + required List 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'integer_prop': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType.nullable(int), + ) as int?; + if (valueDes == null) continue; + result.integerProp = valueDes; + break; + case r'number_prop': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType.nullable(num), + ) as num?; + if (valueDes == null) continue; + result.numberProp = valueDes; + break; + case r'boolean_prop': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType.nullable(bool), + ) as bool?; + if (valueDes == null) continue; + result.booleanProp = valueDes; + break; + case r'string_prop': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType.nullable(String), + ) as String?; + if (valueDes == null) continue; + result.stringProp = valueDes; + break; + case r'date_prop': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType.nullable(Date), + ) as Date?; + if (valueDes == null) continue; + result.dateProp = valueDes; + break; + case r'datetime_prop': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType.nullable(DateTime), + ) as DateTime?; + if (valueDes == null) continue; + result.datetimeProp = valueDes; + break; + case r'array_nullable_prop': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType.nullable(BuiltList, [FullType(JsonObject)]), + ) as BuiltList?; + if (valueDes == null) continue; + result.arrayNullableProp.replace(valueDes); + break; + case r'array_and_items_nullable_prop': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType.nullable(BuiltList, [FullType.nullable(JsonObject)]), + ) as BuiltList?; + if (valueDes == null) continue; + result.arrayAndItemsNullableProp.replace(valueDes); + break; + case r'array_items_nullable': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltList, [FullType.nullable(JsonObject)]), + ) as BuiltList; + result.arrayItemsNullable.replace(valueDes); + break; + case r'object_nullable_prop': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType.nullable(BuiltMap, [FullType(String), FullType(JsonObject)]), + ) as BuiltMap?; + if (valueDes == null) continue; + result.objectNullableProp.replace(valueDes); + break; + case r'object_and_items_nullable_prop': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType.nullable(BuiltMap, [FullType(String), FullType.nullable(JsonObject)]), + ) as BuiltMap?; + if (valueDes == null) continue; + result.objectAndItemsNullableProp.replace(valueDes); + break; + case r'object_items_nullable': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltMap, [FullType(String), FullType.nullable(JsonObject)]), + ) as BuiltMap; + result.objectItemsNullable.replace(valueDes); + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + NullableClass deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = NullableClassBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/number_only.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/number_only.dart index e90cc9b9340..482a95f3e52 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/number_only.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/number_only.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -11,61 +12,97 @@ part 'number_only.g.dart'; /// /// Properties: /// * [justNumber] +@BuiltValue() abstract class NumberOnly implements Built { - @BuiltValueField(wireName: r'JustNumber') - num? get justNumber; + @BuiltValueField(wireName: r'JustNumber') + num? get justNumber; - NumberOnly._(); + NumberOnly._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(NumberOnlyBuilder b) => b; + factory NumberOnly([void updates(NumberOnlyBuilder b)]) = _$NumberOnly; - factory NumberOnly([void updates(NumberOnlyBuilder b)]) = _$NumberOnly; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(NumberOnlyBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$NumberOnlySerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$NumberOnlySerializer(); } -class _$NumberOnlySerializer implements StructuredSerializer { - @override - final Iterable types = const [NumberOnly, _$NumberOnly]; +class _$NumberOnlySerializer implements PrimitiveSerializer { + @override + final Iterable types = const [NumberOnly, _$NumberOnly]; - @override - final String wireName = r'NumberOnly'; + @override + final String wireName = r'NumberOnly'; - @override - Iterable serialize(Serializers serializers, NumberOnly object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.justNumber != null) { - result - ..add(r'JustNumber') - ..add(serializers.serialize(object.justNumber, - specifiedType: const FullType(num))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + NumberOnly object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.justNumber != null) { + yield r'JustNumber'; + yield serializers.serialize( + object.justNumber, + specifiedType: const FullType(num), + ); } + } - @override - NumberOnly deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = NumberOnlyBuilder(); + @override + Object serialize( + Serializers serializers, + NumberOnly object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'JustNumber': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(num)) as num; - result.justNumber = valueDes; - break; - } - } - return result.build(); + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required NumberOnlyBuilder result, + required List 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'JustNumber': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(num), + ) as num; + result.justNumber = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } } + } + + @override + NumberOnly deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = NumberOnlyBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/object_with_deprecated_fields.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/object_with_deprecated_fields.dart index 881ede54d0d..f59131ea6fb 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/object_with_deprecated_fields.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/object_with_deprecated_fields.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:openapi/src/model/deprecated_object.dart'; import 'package:built_value/built_value.dart'; @@ -16,103 +17,148 @@ part 'object_with_deprecated_fields.g.dart'; /// * [id] /// * [deprecatedRef] /// * [bars] +@BuiltValue() abstract class ObjectWithDeprecatedFields implements Built { - @BuiltValueField(wireName: r'uuid') - String? get uuid; + @BuiltValueField(wireName: r'uuid') + String? get uuid; - @BuiltValueField(wireName: r'id') - num? get id; + @BuiltValueField(wireName: r'id') + num? get id; - @BuiltValueField(wireName: r'deprecatedRef') - DeprecatedObject? get deprecatedRef; + @BuiltValueField(wireName: r'deprecatedRef') + DeprecatedObject? get deprecatedRef; - @BuiltValueField(wireName: r'bars') - BuiltList? get bars; + @BuiltValueField(wireName: r'bars') + BuiltList? get bars; - ObjectWithDeprecatedFields._(); + ObjectWithDeprecatedFields._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(ObjectWithDeprecatedFieldsBuilder b) => b; + factory ObjectWithDeprecatedFields([void updates(ObjectWithDeprecatedFieldsBuilder b)]) = _$ObjectWithDeprecatedFields; - factory ObjectWithDeprecatedFields([void updates(ObjectWithDeprecatedFieldsBuilder b)]) = _$ObjectWithDeprecatedFields; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(ObjectWithDeprecatedFieldsBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$ObjectWithDeprecatedFieldsSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$ObjectWithDeprecatedFieldsSerializer(); } -class _$ObjectWithDeprecatedFieldsSerializer implements StructuredSerializer { - @override - final Iterable types = const [ObjectWithDeprecatedFields, _$ObjectWithDeprecatedFields]; +class _$ObjectWithDeprecatedFieldsSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [ObjectWithDeprecatedFields, _$ObjectWithDeprecatedFields]; - @override - final String wireName = r'ObjectWithDeprecatedFields'; + @override + final String wireName = r'ObjectWithDeprecatedFields'; - @override - Iterable serialize(Serializers serializers, ObjectWithDeprecatedFields object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.uuid != null) { - result - ..add(r'uuid') - ..add(serializers.serialize(object.uuid, - specifiedType: const FullType(String))); - } - if (object.id != null) { - result - ..add(r'id') - ..add(serializers.serialize(object.id, - specifiedType: const FullType(num))); - } - if (object.deprecatedRef != null) { - result - ..add(r'deprecatedRef') - ..add(serializers.serialize(object.deprecatedRef, - specifiedType: const FullType(DeprecatedObject))); - } - if (object.bars != null) { - result - ..add(r'bars') - ..add(serializers.serialize(object.bars, - specifiedType: const FullType(BuiltList, [FullType(String)]))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + ObjectWithDeprecatedFields object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.uuid != null) { + yield r'uuid'; + yield serializers.serialize( + object.uuid, + specifiedType: const FullType(String), + ); } - - @override - ObjectWithDeprecatedFields deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = ObjectWithDeprecatedFieldsBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'uuid': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.uuid = valueDes; - break; - case r'id': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(num)) as num; - result.id = valueDes; - break; - case r'deprecatedRef': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(DeprecatedObject)) as DeprecatedObject; - result.deprecatedRef.replace(valueDes); - break; - case r'bars': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltList, [FullType(String)])) as BuiltList; - result.bars.replace(valueDes); - break; - } - } - return result.build(); + if (object.id != null) { + yield r'id'; + yield serializers.serialize( + object.id, + specifiedType: const FullType(num), + ); } + if (object.deprecatedRef != null) { + yield r'deprecatedRef'; + yield serializers.serialize( + object.deprecatedRef, + specifiedType: const FullType(DeprecatedObject), + ); + } + if (object.bars != null) { + yield r'bars'; + yield serializers.serialize( + object.bars, + specifiedType: const FullType(BuiltList, [FullType(String)]), + ); + } + } + + @override + Object serialize( + Serializers serializers, + ObjectWithDeprecatedFields object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required ObjectWithDeprecatedFieldsBuilder result, + required List 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'uuid': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.uuid = valueDes; + break; + case r'id': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(num), + ) as num; + result.id = valueDes; + break; + case r'deprecatedRef': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(DeprecatedObject), + ) as DeprecatedObject; + result.deprecatedRef.replace(valueDes); + break; + case r'bars': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltList, [FullType(String)]), + ) as BuiltList; + result.bars.replace(valueDes); + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + ObjectWithDeprecatedFields deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = ObjectWithDeprecatedFieldsBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/order.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/order.dart index 507a1e3a98d..a44e1b340c1 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/order.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/order.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -17,135 +18,186 @@ part 'order.g.dart'; /// * [shipDate] /// * [status] - Order Status /// * [complete] +@BuiltValue() abstract class Order implements Built { - @BuiltValueField(wireName: r'id') - int? get id; + @BuiltValueField(wireName: r'id') + int? get id; - @BuiltValueField(wireName: r'petId') - int? get petId; + @BuiltValueField(wireName: r'petId') + int? get petId; - @BuiltValueField(wireName: r'quantity') - int? get quantity; + @BuiltValueField(wireName: r'quantity') + int? get quantity; - @BuiltValueField(wireName: r'shipDate') - DateTime? get shipDate; + @BuiltValueField(wireName: r'shipDate') + DateTime? get shipDate; - /// Order Status - @BuiltValueField(wireName: r'status') - OrderStatusEnum? get status; - // enum statusEnum { placed, approved, delivered, }; + /// Order Status + @BuiltValueField(wireName: r'status') + OrderStatusEnum? get status; + // enum statusEnum { placed, approved, delivered, }; - @BuiltValueField(wireName: r'complete') - bool? get complete; + @BuiltValueField(wireName: r'complete') + bool? get complete; - Order._(); + Order._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(OrderBuilder b) => b - ..complete = false; + factory Order([void updates(OrderBuilder b)]) = _$Order; - factory Order([void updates(OrderBuilder b)]) = _$Order; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(OrderBuilder b) => b + ..complete = false; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$OrderSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$OrderSerializer(); } -class _$OrderSerializer implements StructuredSerializer { - @override - final Iterable types = const [Order, _$Order]; +class _$OrderSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Order, _$Order]; - @override - final String wireName = r'Order'; + @override + final String wireName = r'Order'; - @override - Iterable serialize(Serializers serializers, Order object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.id != null) { - result - ..add(r'id') - ..add(serializers.serialize(object.id, - specifiedType: const FullType(int))); - } - if (object.petId != null) { - result - ..add(r'petId') - ..add(serializers.serialize(object.petId, - specifiedType: const FullType(int))); - } - if (object.quantity != null) { - result - ..add(r'quantity') - ..add(serializers.serialize(object.quantity, - specifiedType: const FullType(int))); - } - if (object.shipDate != null) { - result - ..add(r'shipDate') - ..add(serializers.serialize(object.shipDate, - specifiedType: const FullType(DateTime))); - } - if (object.status != null) { - result - ..add(r'status') - ..add(serializers.serialize(object.status, - specifiedType: const FullType(OrderStatusEnum))); - } - if (object.complete != null) { - result - ..add(r'complete') - ..add(serializers.serialize(object.complete, - specifiedType: const FullType(bool))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + Order object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.id != null) { + yield r'id'; + yield serializers.serialize( + object.id, + specifiedType: const FullType(int), + ); } - - @override - Order deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = OrderBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'id': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.id = valueDes; - break; - case r'petId': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.petId = valueDes; - break; - case r'quantity': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.quantity = valueDes; - break; - case r'shipDate': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(DateTime)) as DateTime; - result.shipDate = valueDes; - break; - case r'status': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(OrderStatusEnum)) as OrderStatusEnum; - result.status = valueDes; - break; - case r'complete': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(bool)) as bool; - result.complete = valueDes; - break; - } - } - return result.build(); + if (object.petId != null) { + yield r'petId'; + yield serializers.serialize( + object.petId, + specifiedType: const FullType(int), + ); } + if (object.quantity != null) { + yield r'quantity'; + yield serializers.serialize( + object.quantity, + specifiedType: const FullType(int), + ); + } + if (object.shipDate != null) { + yield r'shipDate'; + yield serializers.serialize( + object.shipDate, + specifiedType: const FullType(DateTime), + ); + } + if (object.status != null) { + yield r'status'; + yield serializers.serialize( + object.status, + specifiedType: const FullType(OrderStatusEnum), + ); + } + if (object.complete != null) { + yield r'complete'; + yield serializers.serialize( + object.complete, + specifiedType: const FullType(bool), + ); + } + } + + @override + Object serialize( + Serializers serializers, + Order object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required OrderBuilder result, + required List 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'id': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.id = valueDes; + break; + case r'petId': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.petId = valueDes; + break; + case r'quantity': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.quantity = valueDes; + break; + case r'shipDate': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(DateTime), + ) as DateTime; + result.shipDate = valueDes; + break; + case r'status': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(OrderStatusEnum), + ) as OrderStatusEnum; + result.status = valueDes; + break; + case r'complete': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(bool), + ) as bool; + result.complete = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + Order deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = OrderBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } class OrderStatusEnum extends EnumClass { diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_composite.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_composite.dart index 0715bdff305..0d6341cc129 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_composite.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_composite.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -13,89 +14,131 @@ part 'outer_composite.g.dart'; /// * [myNumber] /// * [myString] /// * [myBoolean] +@BuiltValue() abstract class OuterComposite implements Built { - @BuiltValueField(wireName: r'my_number') - num? get myNumber; + @BuiltValueField(wireName: r'my_number') + num? get myNumber; - @BuiltValueField(wireName: r'my_string') - String? get myString; + @BuiltValueField(wireName: r'my_string') + String? get myString; - @BuiltValueField(wireName: r'my_boolean') - bool? get myBoolean; + @BuiltValueField(wireName: r'my_boolean') + bool? get myBoolean; - OuterComposite._(); + OuterComposite._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(OuterCompositeBuilder b) => b; + factory OuterComposite([void updates(OuterCompositeBuilder b)]) = _$OuterComposite; - factory OuterComposite([void updates(OuterCompositeBuilder b)]) = _$OuterComposite; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(OuterCompositeBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$OuterCompositeSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$OuterCompositeSerializer(); } -class _$OuterCompositeSerializer implements StructuredSerializer { - @override - final Iterable types = const [OuterComposite, _$OuterComposite]; +class _$OuterCompositeSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [OuterComposite, _$OuterComposite]; - @override - final String wireName = r'OuterComposite'; + @override + final String wireName = r'OuterComposite'; - @override - Iterable serialize(Serializers serializers, OuterComposite object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.myNumber != null) { - result - ..add(r'my_number') - ..add(serializers.serialize(object.myNumber, - specifiedType: const FullType(num))); - } - if (object.myString != null) { - result - ..add(r'my_string') - ..add(serializers.serialize(object.myString, - specifiedType: const FullType(String))); - } - if (object.myBoolean != null) { - result - ..add(r'my_boolean') - ..add(serializers.serialize(object.myBoolean, - specifiedType: const FullType(bool))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + OuterComposite object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.myNumber != null) { + yield r'my_number'; + yield serializers.serialize( + object.myNumber, + specifiedType: const FullType(num), + ); } - - @override - OuterComposite deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = OuterCompositeBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'my_number': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(num)) as num; - result.myNumber = valueDes; - break; - case r'my_string': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.myString = valueDes; - break; - case r'my_boolean': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(bool)) as bool; - result.myBoolean = valueDes; - break; - } - } - return result.build(); + if (object.myString != null) { + yield r'my_string'; + yield serializers.serialize( + object.myString, + specifiedType: const FullType(String), + ); } + if (object.myBoolean != null) { + yield r'my_boolean'; + yield serializers.serialize( + object.myBoolean, + specifiedType: const FullType(bool), + ); + } + } + + @override + Object serialize( + Serializers serializers, + OuterComposite object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required OuterCompositeBuilder result, + required List 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'my_number': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(num), + ) as num; + result.myNumber = valueDes; + break; + case r'my_string': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.myString = valueDes; + break; + case r'my_boolean': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(bool), + ) as bool; + result.myBoolean = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + OuterComposite deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = OuterCompositeBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum.dart index 882219e06cd..5ad5d8009bd 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum_default_value.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum_default_value.dart index 77353c07711..62c3cefe845 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum_default_value.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum_default_value.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum_integer.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum_integer.dart index 9b179131475..988b30785d3 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum_integer.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum_integer.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum_integer_default_value.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum_integer_default_value.dart index ded5b2c7231..3fe792cedbe 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum_integer_default_value.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_enum_integer_default_value.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_object_with_enum_property.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_object_with_enum_property.dart index 91524a285b8..17332985645 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_object_with_enum_property.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/outer_object_with_enum_property.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:openapi/src/model/outer_enum_integer.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -12,60 +13,96 @@ part 'outer_object_with_enum_property.g.dart'; /// /// Properties: /// * [value] +@BuiltValue() abstract class OuterObjectWithEnumProperty implements Built { - @BuiltValueField(wireName: r'value') - OuterEnumInteger get value; - // enum valueEnum { 0, 1, 2, }; + @BuiltValueField(wireName: r'value') + OuterEnumInteger get value; + // enum valueEnum { 0, 1, 2, }; - OuterObjectWithEnumProperty._(); + OuterObjectWithEnumProperty._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(OuterObjectWithEnumPropertyBuilder b) => b; + factory OuterObjectWithEnumProperty([void updates(OuterObjectWithEnumPropertyBuilder b)]) = _$OuterObjectWithEnumProperty; - factory OuterObjectWithEnumProperty([void updates(OuterObjectWithEnumPropertyBuilder b)]) = _$OuterObjectWithEnumProperty; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(OuterObjectWithEnumPropertyBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$OuterObjectWithEnumPropertySerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$OuterObjectWithEnumPropertySerializer(); } -class _$OuterObjectWithEnumPropertySerializer implements StructuredSerializer { - @override - final Iterable types = const [OuterObjectWithEnumProperty, _$OuterObjectWithEnumProperty]; +class _$OuterObjectWithEnumPropertySerializer implements PrimitiveSerializer { + @override + final Iterable types = const [OuterObjectWithEnumProperty, _$OuterObjectWithEnumProperty]; - @override - final String wireName = r'OuterObjectWithEnumProperty'; + @override + final String wireName = r'OuterObjectWithEnumProperty'; - @override - Iterable serialize(Serializers serializers, OuterObjectWithEnumProperty object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - result - ..add(r'value') - ..add(serializers.serialize(object.value, - specifiedType: const FullType(OuterEnumInteger))); - return result; + Iterable _serializeProperties( + Serializers serializers, + OuterObjectWithEnumProperty object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + yield r'value'; + yield serializers.serialize( + object.value, + specifiedType: const FullType(OuterEnumInteger), + ); + } + + @override + Object serialize( + Serializers serializers, + OuterObjectWithEnumProperty object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required OuterObjectWithEnumPropertyBuilder result, + required List 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'value': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(OuterEnumInteger), + ) as OuterEnumInteger; + result.value = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } } + } - @override - OuterObjectWithEnumProperty deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = OuterObjectWithEnumPropertyBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'value': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(OuterEnumInteger)) as OuterEnumInteger; - result.value = valueDes; - break; - } - } - return result.build(); - } + @override + OuterObjectWithEnumProperty deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = OuterObjectWithEnumPropertyBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/pet.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/pet.dart index 8ed90d104aa..4d6358bef27 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/pet.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/pet.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:openapi/src/model/category.dart'; import 'package:openapi/src/model/tag.dart'; @@ -19,130 +20,181 @@ part 'pet.g.dart'; /// * [photoUrls] /// * [tags] /// * [status] - pet status in the store +@BuiltValue() abstract class Pet implements Built { - @BuiltValueField(wireName: r'id') - int? get id; + @BuiltValueField(wireName: r'id') + int? get id; - @BuiltValueField(wireName: r'category') - Category? get category; + @BuiltValueField(wireName: r'category') + Category? get category; - @BuiltValueField(wireName: r'name') - String get name; + @BuiltValueField(wireName: r'name') + String get name; - @BuiltValueField(wireName: r'photoUrls') - BuiltSet get photoUrls; + @BuiltValueField(wireName: r'photoUrls') + BuiltSet get photoUrls; - @BuiltValueField(wireName: r'tags') - BuiltList? get tags; + @BuiltValueField(wireName: r'tags') + BuiltList? get tags; - /// pet status in the store - @BuiltValueField(wireName: r'status') - PetStatusEnum? get status; - // enum statusEnum { available, pending, sold, }; + /// pet status in the store + @BuiltValueField(wireName: r'status') + PetStatusEnum? get status; + // enum statusEnum { available, pending, sold, }; - Pet._(); + Pet._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(PetBuilder b) => b; + factory Pet([void updates(PetBuilder b)]) = _$Pet; - factory Pet([void updates(PetBuilder b)]) = _$Pet; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(PetBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$PetSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$PetSerializer(); } -class _$PetSerializer implements StructuredSerializer { - @override - final Iterable types = const [Pet, _$Pet]; +class _$PetSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Pet, _$Pet]; - @override - final String wireName = r'Pet'; + @override + final String wireName = r'Pet'; - @override - Iterable serialize(Serializers serializers, Pet object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.id != null) { - result - ..add(r'id') - ..add(serializers.serialize(object.id, - specifiedType: const FullType(int))); - } - if (object.category != null) { - result - ..add(r'category') - ..add(serializers.serialize(object.category, - specifiedType: const FullType(Category))); - } - result - ..add(r'name') - ..add(serializers.serialize(object.name, - specifiedType: const FullType(String))); - result - ..add(r'photoUrls') - ..add(serializers.serialize(object.photoUrls, - specifiedType: const FullType(BuiltSet, [FullType(String)]))); - if (object.tags != null) { - result - ..add(r'tags') - ..add(serializers.serialize(object.tags, - specifiedType: const FullType(BuiltList, [FullType(Tag)]))); - } - if (object.status != null) { - result - ..add(r'status') - ..add(serializers.serialize(object.status, - specifiedType: const FullType(PetStatusEnum))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + Pet object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.id != null) { + yield r'id'; + yield serializers.serialize( + object.id, + specifiedType: const FullType(int), + ); } - - @override - Pet deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = PetBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'id': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.id = valueDes; - break; - case r'category': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(Category)) as Category; - result.category.replace(valueDes); - break; - case r'name': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.name = valueDes; - break; - case r'photoUrls': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltSet, [FullType(String)])) as BuiltSet; - result.photoUrls.replace(valueDes); - break; - case r'tags': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(BuiltList, [FullType(Tag)])) as BuiltList; - result.tags.replace(valueDes); - break; - case r'status': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(PetStatusEnum)) as PetStatusEnum; - result.status = valueDes; - break; - } - } - return result.build(); + if (object.category != null) { + yield r'category'; + yield serializers.serialize( + object.category, + specifiedType: const FullType(Category), + ); } + yield r'name'; + yield serializers.serialize( + object.name, + specifiedType: const FullType(String), + ); + yield r'photoUrls'; + yield serializers.serialize( + object.photoUrls, + specifiedType: const FullType(BuiltSet, [FullType(String)]), + ); + if (object.tags != null) { + yield r'tags'; + yield serializers.serialize( + object.tags, + specifiedType: const FullType(BuiltList, [FullType(Tag)]), + ); + } + if (object.status != null) { + yield r'status'; + yield serializers.serialize( + object.status, + specifiedType: const FullType(PetStatusEnum), + ); + } + } + + @override + Object serialize( + Serializers serializers, + Pet object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required PetBuilder result, + required List 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'id': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.id = valueDes; + break; + case r'category': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(Category), + ) as Category; + result.category.replace(valueDes); + break; + case r'name': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.name = valueDes; + break; + case r'photoUrls': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltSet, [FullType(String)]), + ) as BuiltSet; + result.photoUrls.replace(valueDes); + break; + case r'tags': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(BuiltList, [FullType(Tag)]), + ) as BuiltList; + result.tags.replace(valueDes); + break; + case r'status': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(PetStatusEnum), + ) as PetStatusEnum; + result.status = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + Pet deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = PetBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } class PetStatusEnum extends EnumClass { diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/read_only_first.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/read_only_first.dart index b9f108fb625..b619217ab3c 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/read_only_first.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/read_only_first.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -12,75 +13,114 @@ part 'read_only_first.g.dart'; /// Properties: /// * [bar] /// * [baz] +@BuiltValue() abstract class ReadOnlyFirst implements Built { - @BuiltValueField(wireName: r'bar') - String? get bar; + @BuiltValueField(wireName: r'bar') + String? get bar; - @BuiltValueField(wireName: r'baz') - String? get baz; + @BuiltValueField(wireName: r'baz') + String? get baz; - ReadOnlyFirst._(); + ReadOnlyFirst._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(ReadOnlyFirstBuilder b) => b; + factory ReadOnlyFirst([void updates(ReadOnlyFirstBuilder b)]) = _$ReadOnlyFirst; - factory ReadOnlyFirst([void updates(ReadOnlyFirstBuilder b)]) = _$ReadOnlyFirst; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(ReadOnlyFirstBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$ReadOnlyFirstSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$ReadOnlyFirstSerializer(); } -class _$ReadOnlyFirstSerializer implements StructuredSerializer { - @override - final Iterable types = const [ReadOnlyFirst, _$ReadOnlyFirst]; +class _$ReadOnlyFirstSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [ReadOnlyFirst, _$ReadOnlyFirst]; - @override - final String wireName = r'ReadOnlyFirst'; + @override + final String wireName = r'ReadOnlyFirst'; - @override - Iterable serialize(Serializers serializers, ReadOnlyFirst object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.bar != null) { - result - ..add(r'bar') - ..add(serializers.serialize(object.bar, - specifiedType: const FullType(String))); - } - if (object.baz != null) { - result - ..add(r'baz') - ..add(serializers.serialize(object.baz, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + ReadOnlyFirst object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.bar != null) { + yield r'bar'; + yield serializers.serialize( + object.bar, + specifiedType: const FullType(String), + ); } - - @override - ReadOnlyFirst deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = ReadOnlyFirstBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'bar': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.bar = valueDes; - break; - case r'baz': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.baz = valueDes; - break; - } - } - return result.build(); + if (object.baz != null) { + yield r'baz'; + yield serializers.serialize( + object.baz, + specifiedType: const FullType(String), + ); } + } + + @override + Object serialize( + Serializers serializers, + ReadOnlyFirst object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required ReadOnlyFirstBuilder result, + required List 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'bar': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.bar = valueDes; + break; + case r'baz': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.baz = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + ReadOnlyFirst deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = ReadOnlyFirstBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/single_ref_type.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/single_ref_type.dart index f1e6aef099e..b51e77292e8 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/single_ref_type.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/single_ref_type.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/special_model_name.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/special_model_name.dart index dcfe12bb066..fa860056b45 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/special_model_name.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/special_model_name.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -11,61 +12,97 @@ part 'special_model_name.g.dart'; /// /// Properties: /// * [dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket] +@BuiltValue() abstract class SpecialModelName implements Built { - @BuiltValueField(wireName: r'$special[property.name]') - int? get dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket; + @BuiltValueField(wireName: r'$special[property.name]') + int? get dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket; - SpecialModelName._(); + SpecialModelName._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(SpecialModelNameBuilder b) => b; + factory SpecialModelName([void updates(SpecialModelNameBuilder b)]) = _$SpecialModelName; - factory SpecialModelName([void updates(SpecialModelNameBuilder b)]) = _$SpecialModelName; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(SpecialModelNameBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$SpecialModelNameSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$SpecialModelNameSerializer(); } -class _$SpecialModelNameSerializer implements StructuredSerializer { - @override - final Iterable types = const [SpecialModelName, _$SpecialModelName]; +class _$SpecialModelNameSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [SpecialModelName, _$SpecialModelName]; - @override - final String wireName = r'SpecialModelName'; + @override + final String wireName = r'SpecialModelName'; - @override - Iterable serialize(Serializers serializers, SpecialModelName object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket != null) { - result - ..add(r'$special[property.name]') - ..add(serializers.serialize(object.dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket, - specifiedType: const FullType(int))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + SpecialModelName object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket != null) { + yield r'$special[property.name]'; + yield serializers.serialize( + object.dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket, + specifiedType: const FullType(int), + ); } + } - @override - SpecialModelName deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = SpecialModelNameBuilder(); + @override + Object serialize( + Serializers serializers, + SpecialModelName object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'$special[property.name]': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket = valueDes; - break; - } - } - return result.build(); + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required SpecialModelNameBuilder result, + required List 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'$special[property.name]': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } } + } + + @override + SpecialModelName deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = SpecialModelNameBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/tag.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/tag.dart index 5a7ed38d94c..3be220d8188 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/tag.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/tag.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -12,75 +13,114 @@ part 'tag.g.dart'; /// Properties: /// * [id] /// * [name] +@BuiltValue() abstract class Tag implements Built { - @BuiltValueField(wireName: r'id') - int? get id; + @BuiltValueField(wireName: r'id') + int? get id; - @BuiltValueField(wireName: r'name') - String? get name; + @BuiltValueField(wireName: r'name') + String? get name; - Tag._(); + Tag._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(TagBuilder b) => b; + factory Tag([void updates(TagBuilder b)]) = _$Tag; - factory Tag([void updates(TagBuilder b)]) = _$Tag; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(TagBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$TagSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$TagSerializer(); } -class _$TagSerializer implements StructuredSerializer { - @override - final Iterable types = const [Tag, _$Tag]; +class _$TagSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Tag, _$Tag]; - @override - final String wireName = r'Tag'; + @override + final String wireName = r'Tag'; - @override - Iterable serialize(Serializers serializers, Tag object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.id != null) { - result - ..add(r'id') - ..add(serializers.serialize(object.id, - specifiedType: const FullType(int))); - } - if (object.name != null) { - result - ..add(r'name') - ..add(serializers.serialize(object.name, - specifiedType: const FullType(String))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + Tag object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.id != null) { + yield r'id'; + yield serializers.serialize( + object.id, + specifiedType: const FullType(int), + ); } - - @override - Tag deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = TagBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'id': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.id = valueDes; - break; - case r'name': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.name = valueDes; - break; - } - } - return result.build(); + if (object.name != null) { + yield r'name'; + yield serializers.serialize( + object.name, + specifiedType: const FullType(String), + ); } + } + + @override + Object serialize( + Serializers serializers, + Tag object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required TagBuilder result, + required List 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'id': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.id = valueDes; + break; + case r'name': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.name = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + Tag deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = TagBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/user.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/user.dart index d590c20bdc7..f7577d7e1ee 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/user.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/user.dart @@ -2,6 +2,7 @@ // AUTO-GENERATED FILE, DO NOT MODIFY! // +// ignore_for_file: unused_element import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -18,160 +19,217 @@ part 'user.g.dart'; /// * [password] /// * [phone] /// * [userStatus] - User Status +@BuiltValue() abstract class User implements Built { - @BuiltValueField(wireName: r'id') - int? get id; + @BuiltValueField(wireName: r'id') + int? get id; - @BuiltValueField(wireName: r'username') - String? get username; + @BuiltValueField(wireName: r'username') + String? get username; - @BuiltValueField(wireName: r'firstName') - String? get firstName; + @BuiltValueField(wireName: r'firstName') + String? get firstName; - @BuiltValueField(wireName: r'lastName') - String? get lastName; + @BuiltValueField(wireName: r'lastName') + String? get lastName; - @BuiltValueField(wireName: r'email') - String? get email; + @BuiltValueField(wireName: r'email') + String? get email; - @BuiltValueField(wireName: r'password') - String? get password; + @BuiltValueField(wireName: r'password') + String? get password; - @BuiltValueField(wireName: r'phone') - String? get phone; + @BuiltValueField(wireName: r'phone') + String? get phone; - /// User Status - @BuiltValueField(wireName: r'userStatus') - int? get userStatus; + /// User Status + @BuiltValueField(wireName: r'userStatus') + int? get userStatus; - User._(); + User._(); - @BuiltValueHook(initializeBuilder: true) - static void _defaults(UserBuilder b) => b; + factory User([void updates(UserBuilder b)]) = _$User; - factory User([void updates(UserBuilder b)]) = _$User; + @BuiltValueHook(initializeBuilder: true) + static void _defaults(UserBuilder b) => b; - @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$UserSerializer(); + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$UserSerializer(); } -class _$UserSerializer implements StructuredSerializer { - @override - final Iterable types = const [User, _$User]; +class _$UserSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [User, _$User]; - @override - final String wireName = r'User'; + @override + final String wireName = r'User'; - @override - Iterable serialize(Serializers serializers, User object, - {FullType specifiedType = FullType.unspecified}) { - final result = []; - if (object.id != null) { - result - ..add(r'id') - ..add(serializers.serialize(object.id, - specifiedType: const FullType(int))); - } - if (object.username != null) { - result - ..add(r'username') - ..add(serializers.serialize(object.username, - specifiedType: const FullType(String))); - } - if (object.firstName != null) { - result - ..add(r'firstName') - ..add(serializers.serialize(object.firstName, - specifiedType: const FullType(String))); - } - if (object.lastName != null) { - result - ..add(r'lastName') - ..add(serializers.serialize(object.lastName, - specifiedType: const FullType(String))); - } - if (object.email != null) { - result - ..add(r'email') - ..add(serializers.serialize(object.email, - specifiedType: const FullType(String))); - } - if (object.password != null) { - result - ..add(r'password') - ..add(serializers.serialize(object.password, - specifiedType: const FullType(String))); - } - if (object.phone != null) { - result - ..add(r'phone') - ..add(serializers.serialize(object.phone, - specifiedType: const FullType(String))); - } - if (object.userStatus != null) { - result - ..add(r'userStatus') - ..add(serializers.serialize(object.userStatus, - specifiedType: const FullType(int))); - } - return result; + Iterable _serializeProperties( + Serializers serializers, + User object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.id != null) { + yield r'id'; + yield serializers.serialize( + object.id, + specifiedType: const FullType(int), + ); } - - @override - User deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = UserBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current as String; - iterator.moveNext(); - final Object? value = iterator.current; - - switch (key) { - case r'id': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.id = valueDes; - break; - case r'username': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.username = valueDes; - break; - case r'firstName': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.firstName = valueDes; - break; - case r'lastName': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.lastName = valueDes; - break; - case r'email': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.email = valueDes; - break; - case r'password': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.password = valueDes; - break; - case r'phone': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(String)) as String; - result.phone = valueDes; - break; - case r'userStatus': - final valueDes = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - result.userStatus = valueDes; - break; - } - } - return result.build(); + if (object.username != null) { + yield r'username'; + yield serializers.serialize( + object.username, + specifiedType: const FullType(String), + ); } + if (object.firstName != null) { + yield r'firstName'; + yield serializers.serialize( + object.firstName, + specifiedType: const FullType(String), + ); + } + if (object.lastName != null) { + yield r'lastName'; + yield serializers.serialize( + object.lastName, + specifiedType: const FullType(String), + ); + } + if (object.email != null) { + yield r'email'; + yield serializers.serialize( + object.email, + specifiedType: const FullType(String), + ); + } + if (object.password != null) { + yield r'password'; + yield serializers.serialize( + object.password, + specifiedType: const FullType(String), + ); + } + if (object.phone != null) { + yield r'phone'; + yield serializers.serialize( + object.phone, + specifiedType: const FullType(String), + ); + } + if (object.userStatus != null) { + yield r'userStatus'; + yield serializers.serialize( + object.userStatus, + specifiedType: const FullType(int), + ); + } + } + + @override + Object serialize( + Serializers serializers, + User object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required UserBuilder result, + required List 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'id': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.id = valueDes; + break; + case r'username': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.username = valueDes; + break; + case r'firstName': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.firstName = valueDes; + break; + case r'lastName': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.lastName = valueDes; + break; + case r'email': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.email = valueDes; + break; + case r'password': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.password = valueDes; + break; + case r'phone': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(String), + ) as String; + result.phone = valueDes; + break; + case r'userStatus': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(int), + ) as int; + result.userStatus = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + User deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = UserBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/serializers.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/serializers.dart index 8ac0fc258f9..60f50e5a77f 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/serializers.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/serializers.dart @@ -4,6 +4,8 @@ // 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'; @@ -66,19 +68,19 @@ part 'serializers.g.dart'; @SerializersFor([ AdditionalPropertiesClass, AllOfWithSingleRef, - Animal, + Animal,$Animal, ApiResponse, ArrayOfArrayOfNumberOnly, ArrayOfNumberOnly, ArrayTest, Capitalization, Cat, - CatAllOf, + CatAllOf,$CatAllOf, Category, ClassModel, DeprecatedObject, Dog, - DogAllOf, + DogAllOf,$DogAllOf, EnumArrays, EnumTest, FileSchemaTestClass, @@ -146,6 +148,11 @@ Serializers serializers = (_$serializers.toBuilder() const FullType(BuiltList, [FullType(String)]), () => ListBuilder(), ) + ..add(Animal.serializer) + ..add(CatAllOf.serializer) + ..add(DogAllOf.serializer) + ..add(const OneOfSerializer()) + ..add(const AnyOfSerializer()) ..add(const DateSerializer()) ..add(Iso8601DateTimeSerializer())) .build(); diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/pubspec.yaml b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/pubspec.yaml index 5a3cc4e4df8..fb676f65c39 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/pubspec.yaml +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/pubspec.yaml @@ -8,10 +8,12 @@ environment: dependencies: dio: '>=4.0.1 <5.0.0' - 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' dev_dependencies: - built_value_generator: '>=8.1.0 <9.0.0' + built_value_generator: '>=8.4.0 <9.0.0' build_runner: any test: ^1.16.0 diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/all_of_with_single_ref_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/all_of_with_single_ref_test.dart index 8fdb1603ce3..64e241a4dce 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/all_of_with_single_ref_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/all_of_with_single_ref_test.dart @@ -12,7 +12,7 @@ void main() { // TODO }); - // AllOfWithSingleRefSingleRefType singleRefType + // SingleRefType singleRefType test('to test the property `singleRefType`', () async { // TODO }); diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/animal_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/animal_test.dart index 875bb42a106..39b8b59cdf5 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/animal_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/animal_test.dart @@ -3,7 +3,7 @@ import 'package:openapi/openapi.dart'; // tests for Animal void main() { - final instance = AnimalBuilder(); + //final instance = AnimalBuilder(); // TODO add properties to the builder and call build() group(Animal, () { diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/cat_all_of_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/cat_all_of_test.dart index afdac82ad18..fb7e999bf8d 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/cat_all_of_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/cat_all_of_test.dart @@ -3,7 +3,7 @@ import 'package:openapi/openapi.dart'; // tests for CatAllOf void main() { - final instance = CatAllOfBuilder(); + //final instance = CatAllOfBuilder(); // TODO add properties to the builder and call build() group(CatAllOf, () { diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/class_model_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/class_model_test.dart index 92f95f186c9..89f1d35e556 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/class_model_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/class_model_test.dart @@ -7,8 +7,8 @@ void main() { // TODO add properties to the builder and call build() group(ClassModel, () { - // String class_ - test('to test the property `class_`', () async { + // String classField + test('to test the property `classField`', () async { // TODO }); diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/default_api_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/default_api_test.dart index eef4c41652e..f079565f978 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/default_api_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/default_api_test.dart @@ -7,7 +7,7 @@ void main() { final instance = Openapi().getDefaultApi(); group(DefaultApi, () { - //Future fooGet() async + //Future fooGet() async test('test fooGet', () async { // TODO }); diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/dog_all_of_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/dog_all_of_test.dart index 7b58b3a2755..7b4f4095dc9 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/dog_all_of_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/dog_all_of_test.dart @@ -3,7 +3,7 @@ import 'package:openapi/openapi.dart'; // tests for DogAllOf void main() { - final instance = DogAllOfBuilder(); + //final instance = DogAllOfBuilder(); // TODO add properties to the builder and call build() group(DogAllOf, () { diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/model200_response_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/model200_response_test.dart index 39ff6ec59c0..11bac07fafb 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/model200_response_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/model200_response_test.dart @@ -12,8 +12,8 @@ void main() { // TODO }); - // String class_ - test('to test the property `class_`', () async { + // String classField + test('to test the property `classField`', () async { // TODO }); diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/user_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/user_test.dart index d4555abccc5..1e6a1bc23fa 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/user_test.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/user_test.dart @@ -48,10 +48,5 @@ void main() { // TODO }); - // UserType userType - test('to test the property `userType`', () async { - // TODO - }); - }); } diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/pubspec.yaml b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/pubspec.yaml index 518f45b62eb..80178cb89a9 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/pubspec.yaml +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/pubspec.yaml @@ -8,8 +8,8 @@ environment: sdk: '>=2.10.0 <3.0.0' dev_dependencies: - built_collection: 5.1.0 - built_value: 8.1.0 + built_collection: 5.1.1 + built_value: 8.4.0 dio: 4.0.1 http_mock_adapter: 0.3.2 mockito: 5.0.11 diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/puby.yaml b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/puby.yaml new file mode 100644 index 00000000000..64080c7e80a --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/puby.yaml @@ -0,0 +1,3 @@ +exclude: + - test + - pub run build_runner \ No newline at end of file