Fix openapi mobile code generation issues

This commit is contained in:
Matthias Rupp 2023-05-02 00:02:03 -11:00
parent 8c79e8e719
commit 44c750cfa4
6 changed files with 53 additions and 142 deletions

View file

@ -8,10 +8,10 @@ import 'package:openapi/api.dart';
## Properties ## Properties
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**type** | [**AssetTypeEnum**](AssetTypeEnum.md) | |
**lat** | **double** | |
**lon** | **double** | |
**id** | **String** | | **id** | **String** | |
**type** | **String** | |
**lat** | **num** | |
**lon** | **num** | |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View file

@ -13,44 +13,44 @@ part of openapi.api;
class MapMarkerResponseDto { class MapMarkerResponseDto {
/// Returns a new [MapMarkerResponseDto] instance. /// Returns a new [MapMarkerResponseDto] instance.
MapMarkerResponseDto({ MapMarkerResponseDto({
required this.id,
required this.type, required this.type,
required this.lat, required this.lat,
required this.lon, required this.lon,
required this.id,
}); });
AssetTypeEnum type;
double lat;
double lon;
String id; String id;
MapMarkerResponseDtoTypeEnum type;
num lat;
num lon;
@override @override
bool operator ==(Object other) => identical(this, other) || other is MapMarkerResponseDto && bool operator ==(Object other) => identical(this, other) || other is MapMarkerResponseDto &&
other.id == id &&
other.type == type && other.type == type &&
other.lat == lat && other.lat == lat &&
other.lon == lon; other.lon == lon &&
other.id == id;
@override @override
int get hashCode => int get hashCode =>
// ignore: unnecessary_parenthesis // ignore: unnecessary_parenthesis
(id.hashCode) +
(type.hashCode) + (type.hashCode) +
(lat.hashCode) + (lat.hashCode) +
(lon.hashCode); (lon.hashCode) +
(id.hashCode);
@override @override
String toString() => 'MapMarkerResponseDto[id=$id, type=$type, lat=$lat, lon=$lon]'; String toString() => 'MapMarkerResponseDto[type=$type, lat=$lat, lon=$lon, id=$id]';
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final json = <String, dynamic>{}; final json = <String, dynamic>{};
json[r'id'] = this.id;
json[r'type'] = this.type; json[r'type'] = this.type;
json[r'lat'] = this.lat; json[r'lat'] = this.lat;
json[r'lon'] = this.lon; json[r'lon'] = this.lon;
json[r'id'] = this.id;
return json; return json;
} }
@ -73,14 +73,10 @@ class MapMarkerResponseDto {
}()); }());
return MapMarkerResponseDto( return MapMarkerResponseDto(
type: AssetTypeEnum.fromJson(json[r'type'])!,
lat: mapValueOfType<double>(json, r'lat')!,
lon: mapValueOfType<double>(json, r'lon')!,
id: mapValueOfType<String>(json, r'id')!, id: mapValueOfType<String>(json, r'id')!,
type: MapMarkerResponseDtoTypeEnum.fromJson(json[r'type'])!,
lat: json[r'lat'] == null
? null
: num.parse(json[r'lat'].toString()),
lon: json[r'lon'] == null
? null
: num.parse(json[r'lon'].toString()),
); );
} }
return null; return null;
@ -130,90 +126,10 @@ class MapMarkerResponseDto {
/// The list of required keys that must be present in a JSON. /// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{ static const requiredKeys = <String>{
'id',
'type', 'type',
'lat', 'lat',
'lon', 'lon',
'id',
}; };
} }
class MapMarkerResponseDtoTypeEnum {
/// Instantiate a new enum with the provided [value].
const MapMarkerResponseDtoTypeEnum._(this.value);
/// The underlying value of this enum member.
final String value;
@override
String toString() => value;
String toJson() => value;
static const IMAGE = MapMarkerResponseDtoTypeEnum._(r'IMAGE');
static const VIDEO = MapMarkerResponseDtoTypeEnum._(r'VIDEO');
static const AUDIO = MapMarkerResponseDtoTypeEnum._(r'AUDIO');
static const OTHER = MapMarkerResponseDtoTypeEnum._(r'OTHER');
/// List of all possible values in this [enum][MapMarkerResponseDtoTypeEnum].
static const values = <MapMarkerResponseDtoTypeEnum>[
IMAGE,
VIDEO,
AUDIO,
OTHER,
];
static MapMarkerResponseDtoTypeEnum? fromJson(dynamic value) => MapMarkerResponseDtoTypeEnumTypeTransformer().decode(value);
static List<MapMarkerResponseDtoTypeEnum>? listFromJson(dynamic json, {bool growable = false,}) {
final result = <MapMarkerResponseDtoTypeEnum>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = MapMarkerResponseDtoTypeEnum.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
}
/// Transformation class that can [encode] an instance of [MapMarkerResponseDtoTypeEnum] to String,
/// and [decode] dynamic data back to [MapMarkerResponseDtoTypeEnum].
class MapMarkerResponseDtoTypeEnumTypeTransformer {
factory MapMarkerResponseDtoTypeEnumTypeTransformer() => _instance ??= const MapMarkerResponseDtoTypeEnumTypeTransformer._();
const MapMarkerResponseDtoTypeEnumTypeTransformer._();
String encode(MapMarkerResponseDtoTypeEnum data) => data.value;
/// Decodes a [dynamic value][data] to a MapMarkerResponseDtoTypeEnum.
///
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
///
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
/// and users are still using an old app with the old code.
MapMarkerResponseDtoTypeEnum? decode(dynamic data, {bool allowNull = true}) {
if (data != null) {
switch (data) {
case r'IMAGE': return MapMarkerResponseDtoTypeEnum.IMAGE;
case r'VIDEO': return MapMarkerResponseDtoTypeEnum.VIDEO;
case r'AUDIO': return MapMarkerResponseDtoTypeEnum.AUDIO;
case r'OTHER': return MapMarkerResponseDtoTypeEnum.OTHER;
default:
if (!allowNull) {
throw ArgumentError('Unknown enum value to decode: $data');
}
}
}
return null;
}
/// Singleton [MapMarkerResponseDtoTypeEnumTypeTransformer] instance.
static MapMarkerResponseDtoTypeEnumTypeTransformer? _instance;
}

View file

@ -16,26 +16,26 @@ void main() {
// final instance = MapMarkerResponseDto(); // final instance = MapMarkerResponseDto();
group('test MapMarkerResponseDto', () { group('test MapMarkerResponseDto', () {
// String id // AssetTypeEnum type
test('to test the property `id`', () async {
// TODO
});
// String type
test('to test the property `type`', () async { test('to test the property `type`', () async {
// TODO // TODO
}); });
// num lat // double lat
test('to test the property `lat`', () async { test('to test the property `lat`', () async {
// TODO // TODO
}); });
// num lon // double lon
test('to test the property `lon`', () async { test('to test the property `lon`', () async {
// TODO // TODO
}); });
// String id
test('to test the property `id`', () async {
// TODO
});
}); });

View file

@ -5248,30 +5248,26 @@
"MapMarkerResponseDto": { "MapMarkerResponseDto": {
"type": "object", "type": "object",
"properties": { "properties": {
"id": {
"type": "string"
},
"type": { "type": {
"type": "string", "$ref": "#/components/schemas/AssetTypeEnum"
"enum": [
"IMAGE",
"VIDEO",
"AUDIO",
"OTHER"
]
}, },
"lat": { "lat": {
"type": "number" "type": "number",
"format": "double"
}, },
"lon": { "lon": {
"type": "number" "type": "number",
"format": "double"
},
"id": {
"type": "string"
} }
}, },
"required": [ "required": [
"id",
"type", "type",
"lat", "lat",
"lon" "lon",
"id"
] ]
}, },
"UpdateAssetDto": { "UpdateAssetDto": {

View file

@ -1,9 +1,16 @@
import { AssetEntity, AssetType } from '@app/infra/entities'; import { AssetEntity, AssetType } from '@app/infra/entities';
import { ApiProperty } from '@nestjs/swagger';
export class MapMarkerResponseDto { export class MapMarkerResponseDto {
id!: string; id!: string;
@ApiProperty({ enumName: 'AssetTypeEnum', enum: AssetType })
type!: AssetType; type!: AssetType;
@ApiProperty({ type: 'number', format: 'double' })
lat!: number; lat!: number;
@ApiProperty({ type: 'number', format: 'double' })
lon!: number; lon!: number;
} }

View file

@ -1446,16 +1446,10 @@ export interface LogoutResponseDto {
export interface MapMarkerResponseDto { export interface MapMarkerResponseDto {
/** /**
* *
* @type {string} * @type {AssetTypeEnum}
* @memberof MapMarkerResponseDto * @memberof MapMarkerResponseDto
*/ */
'id': string; 'type': AssetTypeEnum;
/**
*
* @type {string}
* @memberof MapMarkerResponseDto
*/
'type': MapMarkerResponseDtoTypeEnum;
/** /**
* *
* @type {number} * @type {number}
@ -1468,16 +1462,14 @@ export interface MapMarkerResponseDto {
* @memberof MapMarkerResponseDto * @memberof MapMarkerResponseDto
*/ */
'lon': number; 'lon': number;
/**
*
* @type {string}
* @memberof MapMarkerResponseDto
*/
'id': string;
} }
export const MapMarkerResponseDtoTypeEnum = {
Image: 'IMAGE',
Video: 'VIDEO',
Audio: 'AUDIO',
Other: 'OTHER'
} as const;
export type MapMarkerResponseDtoTypeEnum = typeof MapMarkerResponseDtoTypeEnum[keyof typeof MapMarkerResponseDtoTypeEnum];
/** /**
* *