Browse Source

Merge pull request #133 from provokateurin/feature/additional-properties

dynamite,specs,nextcloud: Support additionalProperties
pull/134/head
Kate 2 years ago committed by GitHub
parent
commit
b4d23a2118
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      packages/dynamite/lib/src/models/schema.dart
  2. 5
      packages/dynamite/lib/src/models/schema.g.dart
  3. 10
      packages/dynamite/lib/src/openapi_builder.dart
  4. 2
      packages/nextcloud/build.yaml
  5. 13
      packages/nextcloud/lib/src/nextcloud.openapi.dart
  6. 1939
      packages/nextcloud/lib/src/nextcloud.openapi.g.dart
  7. 10
      packages/nextcloud/lib/src/nextcloud.openapi.json
  8. 10
      specs/core.json

3
packages/dynamite/lib/src/models/schema.dart

@ -18,6 +18,7 @@ class Schema {
this.properties, this.properties,
this.required, this.required,
this.items, this.items,
this.additionalProperties,
}); });
factory Schema.fromJson(final Map<String, dynamic> json) => _$SchemaFromJson(json); factory Schema.fromJson(final Map<String, dynamic> json) => _$SchemaFromJson(json);
@ -53,4 +54,6 @@ class Schema {
final List<String>? required; final List<String>? required;
final Schema? items; final Schema? items;
final bool? additionalProperties;
} }

5
packages/dynamite/lib/src/models/schema.g.dart

@ -22,7 +22,8 @@ Schema _$SchemaFromJson(Map<String, dynamic> json) {
'enum', 'enum',
'properties', 'properties',
'required', 'required',
'items' 'items',
'additionalProperties'
], ],
); );
return Schema( return Schema(
@ -41,6 +42,7 @@ Schema _$SchemaFromJson(Map<String, dynamic> json) {
), ),
required: (json['required'] as List<dynamic>?)?.map((e) => e as String).toList(), required: (json['required'] as List<dynamic>?)?.map((e) => e as String).toList(),
items: json['items'] == null ? null : Schema.fromJson(json['items'] as Map<String, dynamic>), items: json['items'] == null ? null : Schema.fromJson(json['items'] as Map<String, dynamic>),
additionalProperties: json['additionalProperties'] as bool?,
); );
} }
@ -66,5 +68,6 @@ Map<String, dynamic> _$SchemaToJson(Schema instance) {
writeNotNull('properties', instance.properties?.map((k, e) => MapEntry(k, e.toJson()))); writeNotNull('properties', instance.properties?.map((k, e) => MapEntry(k, e.toJson())));
writeNotNull('required', instance.required); writeNotNull('required', instance.required);
writeNotNull('items', instance.items?.toJson()); writeNotNull('items', instance.items?.toJson());
writeNotNull('additionalProperties', instance.additionalProperties);
return val; return val;
} }

10
packages/dynamite/lib/src/openapi_builder.dart

@ -326,12 +326,7 @@ class OpenAPIBuilder implements Builder {
(final s) => resolveType( (final s) => resolveType(
'$identifier${schema.ofs!.indexOf(s)}', '$identifier${schema.ofs!.indexOf(s)}',
s, s,
extraJsonSerializableValues: { extraJsonSerializableValues: extraJsonSerializableValues,
'disallowUnrecognizedKeys': 'true',
if (extraJsonSerializableValues != null) ...{
...extraJsonSerializableValues,
},
},
), ),
) )
.toList(); .toList();
@ -518,6 +513,9 @@ class OpenAPIBuilder implements Builder {
refer('JsonSerializable').call( refer('JsonSerializable').call(
[], [],
{ {
if (schema.additionalProperties ?? false) ...{
'disallowUnrecognizedKeys': refer('false'),
},
if (extraJsonSerializableValues != null) ...{ if (extraJsonSerializableValues != null) ...{
for (final key in extraJsonSerializableValues.keys) ...{ for (final key in extraJsonSerializableValues.keys) ...{
key: refer(extraJsonSerializableValues[key]!), key: refer(extraJsonSerializableValues[key]!),

2
packages/nextcloud/build.yaml

@ -3,5 +3,5 @@ targets:
builders: builders:
json_serializable: json_serializable:
options: options:
# disallow_unrecognized_keys: true # Uncomment this to check that all the models are correct. We can't enable this because the capabilities contain different keys based on which apps are installed disallow_unrecognized_keys: true
explicit_to_json: true explicit_to_json: true

13
packages/nextcloud/lib/src/nextcloud.openapi.dart

@ -290,13 +290,18 @@ class CoreServerCapabilities_Ocs_Data_Capabilities_Bruteforce {
@JsonSerializable() @JsonSerializable()
class CoreServerCapabilities_Ocs_Data_Capabilities_MetadataAvailable { class CoreServerCapabilities_Ocs_Data_Capabilities_MetadataAvailable {
CoreServerCapabilities_Ocs_Data_Capabilities_MetadataAvailable({required this.size}); CoreServerCapabilities_Ocs_Data_Capabilities_MetadataAvailable({
required this.size,
required this.gps,
});
factory CoreServerCapabilities_Ocs_Data_Capabilities_MetadataAvailable.fromJson(Map<String, dynamic> json) => factory CoreServerCapabilities_Ocs_Data_Capabilities_MetadataAvailable.fromJson(Map<String, dynamic> json) =>
_$CoreServerCapabilities_Ocs_Data_Capabilities_MetadataAvailableFromJson(json); _$CoreServerCapabilities_Ocs_Data_Capabilities_MetadataAvailableFromJson(json);
final List<String> size; final List<String> size;
final List<String> gps;
// coverage:ignore-start // coverage:ignore-start
Map<String, dynamic> toJson() => _$CoreServerCapabilities_Ocs_Data_Capabilities_MetadataAvailableToJson(this); Map<String, dynamic> toJson() => _$CoreServerCapabilities_Ocs_Data_Capabilities_MetadataAvailableToJson(this);
// coverage:ignore-end // coverage:ignore-end
@ -1247,7 +1252,7 @@ class CoreServerCapabilities_Ocs_Data_Capabilities_WeatherStatus {
// coverage:ignore-end // coverage:ignore-end
} }
@JsonSerializable() @JsonSerializable(disallowUnrecognizedKeys: false)
class CoreServerCapabilities_Ocs_Data_Capabilities { class CoreServerCapabilities_Ocs_Data_Capabilities {
CoreServerCapabilities_Ocs_Data_Capabilities({ CoreServerCapabilities_Ocs_Data_Capabilities({
required this.core, required this.core,
@ -3316,7 +3321,7 @@ class UserStatusClearAt_Time {
// coverage:ignore-end // coverage:ignore-end
} }
@JsonSerializable(disallowUnrecognizedKeys: true) @JsonSerializable()
class UserStatusClearAt { class UserStatusClearAt {
UserStatusClearAt({ UserStatusClearAt({
required this.type, required this.type,
@ -3549,7 +3554,7 @@ class UserStatus_ClearAt {
// coverage:ignore-end // coverage:ignore-end
} }
@JsonSerializable(disallowUnrecognizedKeys: true) @JsonSerializable()
class UserStatus { class UserStatus {
UserStatus({ UserStatus({
required this.userId, required this.userId,

1939
packages/nextcloud/lib/src/nextcloud.openapi.g.dart

File diff suppressed because it is too large Load Diff

10
packages/nextcloud/lib/src/nextcloud.openapi.json

@ -190,6 +190,7 @@
}, },
"capabilities": { "capabilities": {
"type": "object", "type": "object",
"additionalProperties": true,
"required": [ "required": [
"core", "core",
"bruteforce", "bruteforce",
@ -236,7 +237,8 @@
"metadataAvailable": { "metadataAvailable": {
"type": "object", "type": "object",
"required": [ "required": [
"size" "size",
"gps"
], ],
"properties": { "properties": {
"size": { "size": {
@ -244,6 +246,12 @@
"items": { "items": {
"type": "string" "type": "string"
} }
},
"gps": {
"type": "array",
"items": {
"type": "string"
}
} }
} }
}, },

10
specs/core.json

@ -176,6 +176,7 @@
}, },
"capabilities": { "capabilities": {
"type": "object", "type": "object",
"additionalProperties": true,
"required": [ "required": [
"core", "core",
"bruteforce", "bruteforce",
@ -222,7 +223,8 @@
"metadataAvailable": { "metadataAvailable": {
"type": "object", "type": "object",
"required": [ "required": [
"size" "size",
"gps"
], ],
"properties": { "properties": {
"size": { "size": {
@ -230,6 +232,12 @@
"items": { "items": {
"type": "string" "type": "string"
} }
},
"gps": {
"type": "array",
"items": {
"type": "string"
}
} }
} }
}, },

Loading…
Cancel
Save