Skip to content

Commit

Permalink
tests: wrote test for additional properties v2 parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Elena Ferro committed Jan 11, 2024
1 parent e85683a commit 769e8f7
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ extension UniversalTypeX on UniversalType {
if (nullable || (!isRequired && defaultValue == null)) {
sb.write('?');
}
print(sb.toString());
return sb.toString();
}

Expand Down
56 changes: 55 additions & 1 deletion swagger_parser/test/parser/data_classes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ void main() {
expect(item2, expectedItem2);
});

test('additionalProperties entity that should not parse to object test',
test('additionalProperties entity that should not parse to object test 3.0',
() async {
final schemaPath = p.join(
'test',
Expand Down Expand Up @@ -508,6 +508,60 @@ void main() {
expect(item2, expectedItem2);
});

test('additionalProperties entity should parse to object test 2.0',
() async {
final schemaPath = p.join(
'test',
'parser',
'schemas',
'additional_properties_class.2.0.json',
);
final configFile = schemaFile(schemaPath);
final schemaContent = configFile!.readAsStringSync();
final parser = OpenApiParser(schemaContent);
final dataClasses = parser.parseDataClasses().toList();
final expectedDataClasses = <UniversalDataClass>[
const UniversalComponentClass(
name: 'ValueClass',
imports: {},
parameters: [
UniversalType(
type: 'string',
name: 'testProp',
jsonKey: 'testProp',
description: 'A test property',
),
],
),
const UniversalComponentClass(
name: 'WrapperClass',
imports: { 'ValueClass' },
parameters: [
UniversalType(
type: 'ValueClass',
name: 'map',
jsonKey: 'map',
mapType: 'string',
),
],
),
];

expect(dataClasses.length, expectedDataClasses.length);
final item1 = dataClasses[0] as UniversalComponentClass;
final item2 = dataClasses[1] as UniversalComponentClass;
final expectedItem1 = expectedDataClasses[0] as UniversalComponentClass;
final expectedItem2 = expectedDataClasses[1] as UniversalComponentClass;
expect(item1.parameters.length, expectedItem1.parameters.length);
for (var i = 0; i < item1.parameters.length; i++) {
expect(
item1.parameters[i],
expectedItem1.parameters[i],
);
}
expect(item2, expectedItem2);
});

test('Enum name test', () async {
final schemaPath = p.join('test', 'parser', 'schemas', 'enum_class.json');
final configFile = schemaFile(schemaPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"swagger": "2.0",
"info": {
"description": "API",
"version": "1.0",
"title": "REST API"
},
"host": "localhost:8081",
"basePath": "/",
"tags": [
{
"name": "Test",
"description": "Test"
}
],
"paths": {
"/test": {
"get": {
"tags": [
"Test"
],
"operationId": "testMethod",
"produces": [
"application/json"
],
"parameters": [
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/WrapperClass"
}
},
"400": {
"description": "Invalid request parameters"
},
"500": {
"description": "Server error"
}
},
"deprecated": false
}
}
},
"definitions": {
"ValueClass": {
"type": "object",
"required": [
"testProp"
],
"properties": {
"testProp": {
"type": "string",
"description": "A test property"
}
},
"title": "ValueClass"
},
"WrapperClass": {
"type": "object",
"required": [
"map"
],
"properties": {
"map": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/ValueClass"
}
}
},
"title": "WrapperClass"
}
}
}

0 comments on commit 769e8f7

Please sign in to comment.