Skip to content

Commit

Permalink
fix jsonschema generator
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Oct 9, 2024
1 parent 557c369 commit c90334e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/Generator/JsonSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ protected function generateType(TypeInterface $type, DefinitionsInterface $defin
}
} elseif ($type instanceof MapTypeInterface) {
$data = $type->toArray();
$data['type'] = 'object';

if (isset($data['schema']) && $data['schema'] instanceof TypeInterface) {
$data['additionalProperties'] = $this->generateType($data['schema'], $definitions, $template);
Expand All @@ -132,6 +133,7 @@ protected function generateType(TypeInterface $type, DefinitionsInterface $defin
return $data;
} elseif ($type instanceof ArrayTypeInterface) {
$data = $type->toArray();
$data['type'] = 'array';

if (isset($data['schema']) && $data['schema'] instanceof TypeInterface) {
$data['items'] = $this->generateType($data['schema'], $definitions, $template);
Expand Down
14 changes: 7 additions & 7 deletions tests/Generator/resource/jsonschema/jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
}
},
"Meta": {
"type": "map",
"type": "object",
"additionalProperties": {
"type": "string"
}
Expand All @@ -56,19 +56,19 @@
"$ref": "#/definitions/Meta"
},
"inlineConfig": {
"type": "map",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"mapTags": {
"type": "map",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"mapReceiver": {
"type": "map",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/Author"
}
Expand Down Expand Up @@ -139,19 +139,19 @@
"$ref": "#/definitions/Meta"
},
"inlineConfig": {
"type": "map",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"mapTags": {
"type": "map",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"mapReceiver": {
"type": "map",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/Author"
}
Expand Down
14 changes: 7 additions & 7 deletions tests/Generator/resource/jsonschema/jsonschema_complex.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,14 @@
"properties": {
"import": {
"description": "",
"type": "map",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"definitions": {
"description": "",
"type": "map",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/DefinitionType"
}
Expand Down Expand Up @@ -383,7 +383,7 @@
},
"properties": {
"description": "",
"type": "map",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/PropertyType"
}
Expand All @@ -394,14 +394,14 @@
},
"mapping": {
"description": "In case a discriminator property was set it is possible to specify a mapping. The key is the type name and the value the concrete value which is mapped to the type",
"type": "map",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"template": {
"description": "In case the parent type contains generics it is possible to set a concrete type for each generic type",
"type": "map",
"type": "object",
"additionalProperties": {
"type": "string"
}
Expand All @@ -416,14 +416,14 @@
"properties": {
"import": {
"description": "",
"type": "map",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"definitions": {
"description": "",
"type": "map",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/DefinitionType"
}
Expand Down

0 comments on commit c90334e

Please sign in to comment.