Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,12 @@ class OpenApiCorrector {
(m) => '\\${m[0]}',
);

// In properties blocks, only convert $ref values (not property names)
// In properties blocks, convert $ref values and
// discriminator mapping values (not property names)
restoredBlock = restoredBlock.replaceAllMapped(
RegExp('\\\$ref:\\s*[\'"]#/[^\'"]*/$escapedType[\'"]'),
RegExp(
'(?:\\\$ref:|\\w+):\\s*[\'"]#/[^\'"]*/$escapedType[\'"]',
),
(match) => match[0]!.replaceAll(type, correctType),
);
}
Expand Down
13 changes: 13 additions & 0 deletions swagger_parser/test/e2e/e2e_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,19 @@ void main() {
);
});

test('recursive_schema', () async {
await e2eTest(
'basic/recursive_schema',
(outputDirectory, schemaPath) => SWPConfig(
outputDirectory: outputDirectory,
schemaPath: schemaPath,
jsonSerializer: JsonSerializer.freezed,
putClientsInFolder: true,
),
schemaFileName: 'openapi.yaml',
);
});

test('circular_deps_with_tags', () async {
await e2eTest(
'basic/circular_deps_with_tags',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions swagger_parser/test/e2e/tests/basic/recursive_schema/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
openapi: 3.1.0
info:
title: API with Recursive Schemas
version: 1.0.0
paths:
/api/v1/nodes:
get:
operationId: getNodes
tags:
- nodes
responses:
'200':
description: A node tree
content:
application/json:
schema:
$ref: '#/components/schemas/Node'
/api/v1/groups:
get:
operationId: getGroups
tags:
- groups
responses:
'200':
description: A group list
content:
application/json:
schema:
$ref: '#/components/schemas/ACMEGroupList'
components:
schemas:
Node:
type: object
properties:
id:
type: integer
children:
type: array
items:
$ref: '#/components/schemas/Node'
ACMEGroupList:
type: object
required:
- data
properties:
data:
type: array
items:
oneOf:
- $ref: '#/components/schemas/ACMEGroup'
- $ref: '#/components/schemas/BasicGroup'
discriminator:
propertyName: type
mapping:
ACME: '#/components/schemas/ACMEGroup'
BASIC: '#/components/schemas/BasicGroup'
ACMEGroup:
type: object
required:
- type
- name
properties:
type:
type: string
enum: ['ACME']
name:
type: string
specialField:
type: string
BasicGroup:
type: object
required:
- type
- name
properties:
type:
type: string
enum: ['BASIC']
name:
type: string