Skip to content

Commit 183f0c8

Browse files
committed
generating swagger schema
1 parent 6e81df1 commit 183f0c8

29 files changed

+2173
-6369
lines changed

src/Schema.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ class Schema extends ObjectItem
2626
{
2727
const SCHEMA_DRAFT_04_URL = 'http://json-schema.org/draft-04/schema';
2828

29-
public $fromRef;
30-
public $originPath;
31-
3229
/*
3330
public $__seqId;
3431
public static $seq = 0;
@@ -371,8 +368,8 @@ public function process($data, ProcessingOptions $options, $path = '#', $result
371368
}
372369
}
373370

374-
if ($result instanceof Schema) {
375-
$result->originPath = $path;
371+
if ($result instanceof ObjectItem) {
372+
$result->__documentPath = $path;
376373
}
377374
}
378375
}
@@ -396,8 +393,8 @@ public function process($data, ProcessingOptions $options, $path = '#', $result
396393
return $refResult;
397394
}
398395
$data = $ref->getData();
399-
if ($result instanceof Schema) {
400-
$result->fromRef = $refString;
396+
if ($result instanceof ObjectItem) {
397+
$result->__fromRef = $refString;
401398
}
402399
$ref->setImported($result);
403400
$refResult = $this->process($data, $options, $path . '->ref:' . $refString, $result);

src/Structure/ObjectItem.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class ObjectItem extends MagicMap
99
{
1010
/** @var ObjectItem[] */
1111
protected $__nestedObjects;
12+
protected $__documentPath;
13+
protected $__fromRef;
1214

1315
public function setNestedProperty($propertyName, $value, Egg $nestedEgg)
1416
{
@@ -74,5 +76,19 @@ public function jsonSerialize()
7476
}
7577
}
7678

79+
/**
80+
* @return string
81+
*/
82+
public function getDocumentPath()
83+
{
84+
return $this->__documentPath;
85+
}
7786

87+
/**
88+
* @return string
89+
*/
90+
public function getFromRef()
91+
{
92+
return $this->__fromRef;
93+
}
7894
}

src/SwaggerSchema/ApiKeySecurity.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* @file ATTENTION!!! The code below was carefully crafted by a mean machine.
4+
* Please consider to NOT put any emotional human-generated modifications as AI will throw them away with no mercy.
5+
*/
6+
7+
namespace Swaggest\JsonSchema\SwaggerSchema;
8+
9+
use Swaggest\JsonSchema\Constraint\Properties;
10+
use Swaggest\JsonSchema\Schema;
11+
use Swaggest\JsonSchema\Structure\ClassStructure;
12+
13+
14+
class ApiKeySecurity extends ClassStructure {
15+
/** @var string */
16+
public $type;
17+
18+
/** @var string */
19+
public $name;
20+
21+
/** @var string */
22+
public $in;
23+
24+
/** @var string */
25+
public $description;
26+
27+
/**
28+
* @param Properties|static $properties
29+
* @param Schema $ownerSchema
30+
*/
31+
public static function setUpProperties($properties, Schema $ownerSchema)
32+
{
33+
$properties->type = Schema::string();
34+
$properties->type->enum = array (
35+
0 => 'apiKey',
36+
);
37+
$properties->name = Schema::string();
38+
$properties->in = Schema::string();
39+
$properties->in->enum = array (
40+
0 => 'header',
41+
1 => 'query',
42+
);
43+
$properties->description = Schema::string();
44+
$ownerSchema->type = 'object';
45+
$ownerSchema->additionalProperties = false;
46+
$ownerSchema->patternProperties['^x-'] = new Schema();
47+
$ownerSchema->patternProperties['^x-']->description = 'Any property starting with x- is valid.';
48+
$ownerSchema->required = array (
49+
0 => 'type',
50+
1 => 'name',
51+
2 => 'in',
52+
);
53+
}
54+
}
55+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* @file ATTENTION!!! The code below was carefully crafted by a mean machine.
4+
* Please consider to NOT put any emotional human-generated modifications as AI will throw them away with no mercy.
5+
*/
6+
7+
namespace Swaggest\JsonSchema\SwaggerSchema;
8+
9+
use Swaggest\JsonSchema\Constraint\Properties;
10+
use Swaggest\JsonSchema\Schema;
11+
use Swaggest\JsonSchema\Structure\ClassStructure;
12+
13+
14+
class BasicAuthenticationSecurity extends ClassStructure {
15+
/** @var string */
16+
public $type;
17+
18+
/** @var string */
19+
public $description;
20+
21+
/**
22+
* @param Properties|static $properties
23+
* @param Schema $ownerSchema
24+
*/
25+
public static function setUpProperties($properties, Schema $ownerSchema)
26+
{
27+
$properties->type = Schema::string();
28+
$properties->type->enum = array (
29+
0 => 'basic',
30+
);
31+
$properties->description = Schema::string();
32+
$ownerSchema->type = 'object';
33+
$ownerSchema->additionalProperties = false;
34+
$ownerSchema->patternProperties['^x-'] = new Schema();
35+
$ownerSchema->patternProperties['^x-']->description = 'Any property starting with x- is valid.';
36+
$ownerSchema->required = array (
37+
0 => 'type',
38+
);
39+
}
40+
}
41+

src/SwaggerSchema/BodyParameter.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* @file ATTENTION!!! The code below was carefully crafted by a mean machine.
4+
* Please consider to NOT put any emotional human-generated modifications as AI will throw them away with no mercy.
5+
*/
6+
7+
namespace Swaggest\JsonSchema\SwaggerSchema;
8+
9+
use Swaggest\JsonSchema\Constraint\Properties;
10+
use Swaggest\JsonSchema\Schema as Schema1;
11+
use Swaggest\JsonSchema\Structure\ClassStructure;
12+
13+
14+
class BodyParameter extends ClassStructure {
15+
/** @var string A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed. */
16+
public $description;
17+
18+
/** @var string The name of the parameter. */
19+
public $name;
20+
21+
/** @var string Determines the location of the parameter. */
22+
public $in;
23+
24+
/** @var bool Determines whether or not this parameter is required or optional. */
25+
public $required;
26+
27+
/** @var Schema A deterministic version of a JSON Schema object. */
28+
public $schema;
29+
30+
/**
31+
* @param Properties|static $properties
32+
* @param Schema1 $ownerSchema
33+
*/
34+
public static function setUpProperties($properties, Schema1 $ownerSchema)
35+
{
36+
$properties->description = Schema1::string();
37+
$properties->description->description = 'A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed.';
38+
$properties->name = Schema1::string();
39+
$properties->name->description = 'The name of the parameter.';
40+
$properties->in = Schema1::string();
41+
$properties->in->description = 'Determines the location of the parameter.';
42+
$properties->in->enum = array (
43+
0 => 'body',
44+
);
45+
$properties->required = Schema1::boolean();
46+
$properties->required->description = 'Determines whether or not this parameter is required or optional.';
47+
$properties->required->default = false;
48+
$properties->schema = Schema::schema();
49+
$ownerSchema->type = 'object';
50+
$ownerSchema->additionalProperties = false;
51+
$ownerSchema->patternProperties['^x-'] = new Schema1();
52+
$ownerSchema->patternProperties['^x-']->description = 'Any property starting with x- is valid.';
53+
$ownerSchema->required = array (
54+
0 => 'name',
55+
1 => 'in',
56+
2 => 'schema',
57+
);
58+
}
59+
}
60+

src/SwaggerSchema/Contact.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* @file ATTENTION!!! The code below was carefully crafted by a mean machine.
4+
* Please consider to NOT put any emotional human-generated modifications as AI will throw them away with no mercy.
5+
*/
6+
7+
namespace Swaggest\JsonSchema\SwaggerSchema;
8+
9+
use Swaggest\JsonSchema\Constraint\Properties;
10+
use Swaggest\JsonSchema\Schema;
11+
use Swaggest\JsonSchema\Structure\ClassStructure;
12+
13+
14+
class Contact extends ClassStructure {
15+
/** @var string The identifying name of the contact person/organization. */
16+
public $name;
17+
18+
/** @var string The URL pointing to the contact information. */
19+
public $url;
20+
21+
/** @var string The email address of the contact person/organization. */
22+
public $email;
23+
24+
/**
25+
* @param Properties|static $properties
26+
* @param Schema $ownerSchema
27+
*/
28+
public static function setUpProperties($properties, Schema $ownerSchema)
29+
{
30+
$properties->name = Schema::string();
31+
$properties->name->description = 'The identifying name of the contact person/organization.';
32+
$properties->url = Schema::string();
33+
$properties->url->description = 'The URL pointing to the contact information.';
34+
$properties->url->format = 'uri';
35+
$properties->email = Schema::string();
36+
$properties->email->description = 'The email address of the contact person/organization.';
37+
$properties->email->format = 'email';
38+
$ownerSchema->type = 'object';
39+
$ownerSchema->additionalProperties = false;
40+
$ownerSchema->patternProperties['^x-'] = new Schema();
41+
$ownerSchema->patternProperties['^x-']->description = 'Any property starting with x- is valid.';
42+
$ownerSchema->description = 'Contact information for the owners of the API.';
43+
}
44+
}
45+

src/SwaggerSchema/ExternalDocs.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* @file ATTENTION!!! The code below was carefully crafted by a mean machine.
4+
* Please consider to NOT put any emotional human-generated modifications as AI will throw them away with no mercy.
5+
*/
6+
7+
namespace Swaggest\JsonSchema\SwaggerSchema;
8+
9+
use Swaggest\JsonSchema\Constraint\Properties;
10+
use Swaggest\JsonSchema\Schema;
11+
use Swaggest\JsonSchema\Structure\ClassStructure;
12+
13+
14+
class ExternalDocs extends ClassStructure {
15+
/** @var string */
16+
public $description;
17+
18+
/** @var string */
19+
public $url;
20+
21+
/**
22+
* @param Properties|static $properties
23+
* @param Schema $ownerSchema
24+
*/
25+
public static function setUpProperties($properties, Schema $ownerSchema)
26+
{
27+
$properties->description = Schema::string();
28+
$properties->url = Schema::string();
29+
$properties->url->format = 'uri';
30+
$ownerSchema->type = 'object';
31+
$ownerSchema->additionalProperties = false;
32+
$ownerSchema->patternProperties['^x-'] = new Schema();
33+
$ownerSchema->patternProperties['^x-']->description = 'Any property starting with x- is valid.';
34+
$ownerSchema->description = 'information about external documentation';
35+
$ownerSchema->required = array (
36+
0 => 'url',
37+
);
38+
}
39+
}
40+

src/SwaggerSchema/FileSchema.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* @file ATTENTION!!! The code below was carefully crafted by a mean machine.
4+
* Please consider to NOT put any emotional human-generated modifications as AI will throw them away with no mercy.
5+
*/
6+
7+
namespace Swaggest\JsonSchema\SwaggerSchema;
8+
9+
use Swaggest\JsonSchema\Constraint\Properties;
10+
use Swaggest\JsonSchema\Schema;
11+
use Swaggest\JsonSchema\Structure\ClassStructure;
12+
13+
14+
class FileSchema extends ClassStructure {
15+
/** @var string */
16+
public $format;
17+
18+
/** @var string */
19+
public $title;
20+
21+
/** @var string */
22+
public $description;
23+
24+
public $default;
25+
26+
/** @var string[]|array */
27+
public $required;
28+
29+
/** @var string */
30+
public $type;
31+
32+
/** @var bool */
33+
public $readOnly;
34+
35+
/** @var ExternalDocs information about external documentation */
36+
public $externalDocs;
37+
38+
public $example;
39+
40+
/**
41+
* @param Properties|static $properties
42+
* @param Schema $ownerSchema
43+
*/
44+
public static function setUpProperties($properties, Schema $ownerSchema)
45+
{
46+
$properties->format = Schema::string();
47+
$properties->title = Schema::string();
48+
$properties->description = Schema::string();
49+
$properties->default = new Schema();
50+
$properties->required = Schema::arr();
51+
$properties->required->items = Schema::string();
52+
$properties->required->minItems = 1;
53+
$properties->required->uniqueItems = true;
54+
$properties->type = Schema::string();
55+
$properties->type->enum = array (
56+
0 => 'file',
57+
);
58+
$properties->readOnly = Schema::boolean();
59+
$properties->readOnly->default = false;
60+
$properties->externalDocs = ExternalDocs::schema();
61+
$properties->example = new Schema();
62+
$ownerSchema->type = 'object';
63+
$ownerSchema->additionalProperties = false;
64+
$ownerSchema->patternProperties['^x-'] = new Schema();
65+
$ownerSchema->patternProperties['^x-']->description = 'Any property starting with x- is valid.';
66+
$ownerSchema->description = 'A deterministic version of a JSON Schema object.';
67+
$ownerSchema->required = array (
68+
0 => 'type',
69+
);
70+
}
71+
}
72+

0 commit comments

Comments
 (0)