Skip to content

Commit

Permalink
start typeschema next migration
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Oct 12, 2024
1 parent ffd2875 commit c3e40cf
Show file tree
Hide file tree
Showing 27 changed files with 992 additions and 613 deletions.
355 changes: 177 additions & 178 deletions www/composer.lock

Large diffs are not rendered by default.

37 changes: 21 additions & 16 deletions www/resources/examples/discriminator.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"definitions": {
"Human": {
"type": "object",
"type": "struct",
"properties": {
"firstName": {
"type": "string"
Expand All @@ -10,38 +10,43 @@
"type": "string"
},
"location": {
"oneOf": [{
"$ref": "Web"
}, {
"$ref": "World"
}],
"discriminator": {
"propertyName": "type"
}
"type": "reference",
"target": "Location"
}
}
},
"Location": {
"type": "object",
"type": "struct",
"base": true,
"properties": {
"type": {
"type": "string"
}
},
"required": ["type"]
"discriminator": "type",
"mapping": {
"Web": "web",
"World": "world"
}
},
"Web": {
"$extends": "Location",
"type": "object",
"parent": {
"type": "reference",
"target": "Location"
},
"type": "struct",
"properties": {
"url": {
"type": "string"
}
}
},
"World": {
"$extends": "Location",
"type": "object",
"parent": {
"type": "reference",
"target": "Location"
},
"type": "struct",
"properties": {
"lat": {
"type": "string"
Expand All @@ -52,5 +57,5 @@
}
}
},
"$ref": "Human"
"root": "Human"
}
17 changes: 11 additions & 6 deletions www/resources/examples/generic.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
}
},
"StudentMap": {
"$ref": "Map",
"$template": {
"T": "Student"
"type": "struct",
"parent": {
"type": "reference",
"target": "Map",
"template": {
"T": "Student"
}
}
},
"Map": {
Expand All @@ -22,12 +26,13 @@
},
"entries": {
"type": "array",
"items": {
"$generic": "T"
"schema": {
"type": "generic",
"name": "T"
}
}
}
}
},
"$ref": "StudentMap"
"root": "StudentMap"
}
9 changes: 5 additions & 4 deletions www/resources/examples/import.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$import": {
"import": {
"my_ns": "file:///generic.json"
},
"definitions": {
Expand All @@ -11,12 +11,13 @@
},
"students": {
"type": "array",
"items": {
"$ref": "my_ns:StudentMap"
"schema": {
"type": "reference",
"target": "my_ns:StudentMap"
}
}
}
}
},
"$ref": "Faculty"
"root": "Faculty"
}
11 changes: 7 additions & 4 deletions www/resources/examples/inheritance.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"definitions": {
"Human": {
"type": "object",
"type": "struct",
"properties": {
"firstName": {
"type": "string"
Expand All @@ -15,14 +15,17 @@
}
},
"Student": {
"$extends": "Human",
"type": "object",
"parent": {
"type": "reference",
"target": "Human"
},
"type": "struct",
"properties": {
"studentId": {
"type": "string"
}
}
}
},
"$ref": "Student"
"root": "Student"
}
11 changes: 6 additions & 5 deletions www/resources/examples/map.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"definitions": {
"Student": {
"type": "object",
"type": "struct",
"properties": {
"firstName": {
"type": "string"
Expand All @@ -13,16 +13,17 @@
"type": "integer"
},
"properties": {
"$ref": "Student_Properties"
"type": "reference",
"target": "Student_Properties"
}
}
},
"Student_Properties": {
"type": "object",
"additionalProperties": {
"type": "struct",
"schema": {
"type": "string"
}
}
},
"$ref": "Student"
"root": "Student"
}
8 changes: 4 additions & 4 deletions www/resources/examples/map_inline.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"definitions": {
"Student": {
"type": "object",
"type": "struct",
"properties": {
"firstName": {
"type": "string"
Expand All @@ -13,13 +13,13 @@
"type": "integer"
},
"properties": {
"type": "object",
"additionalProperties": {
"type": "map",
"schema": {
"type": "string"
}
}
}
}
},
"$ref": "Student"
"root": "Student"
}
10 changes: 6 additions & 4 deletions www/resources/examples/reference.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"definitions": {
"Student": {
"type": "object",
"description": "A student struct with an assigned faculty",
"type": "struct",
"properties": {
"firstName": {
"type": "string"
Expand All @@ -13,18 +14,19 @@
"type": "integer"
},
"faculty": {
"$ref": "Faculty"
"type": "reference",
"target": "Faculty"
}
}
},
"Faculty": {
"type": "object",
"type": "struct",
"properties": {
"name": {
"type": "string"
}
}
}
},
"$ref": "Student"
"root": "Student"
}
5 changes: 3 additions & 2 deletions www/resources/examples/simple.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"definitions": {
"Student": {
"type": "object",
"description": "A simple student struct",
"type": "struct",
"properties": {
"firstName": {
"type": "string"
Expand All @@ -15,5 +16,5 @@
}
}
},
"$ref": "Student"
"root": "Student"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<?php include __DIR__ . '/../inc/header.php'; ?>
<?php include __DIR__ . '/inc/header.php'; ?>

<nav aria-label="breadcrumb">
<ol class="breadcrumb">
Expand Down Expand Up @@ -49,4 +49,4 @@
</div>
</div>

<?php include __DIR__ . '/../inc/footer.php'; ?>
<?php include __DIR__ . '/inc/footer.php'; ?>
49 changes: 49 additions & 0 deletions www/resources/template/example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

<?php include __DIR__ . '/inc/header.php'; ?>

<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item active" aria-current="page"><a href="<?php echo $url; ?>">TypeSchema</a> / <?php echo $type; ?></li>
</ol>
</nav>

<div class="container">
<h1 class="display-4"><?php echo $type; ?> examples</h1>
<?php foreach($examples as $key => $example): ?>
<div class="row">
<div class="col-md-6">
<div class="psx-object">
<h1><?php echo $example->title; ?></h1>
<div class="psx-object-description"><?php echo $example->description; ?></div>
<div class="example-box"><pre><code class="json"><?php echo $example->schema; ?></code></pre></div>
</div>
</div>
<div class="col-md-6">
<?php foreach ($example->types as $type => $code): ?>
<?php if ($code instanceof stdClass): ?>
<?php foreach ($code as $fileName => $chunk): ?>
<div class="psx-object">
<h1><?php echo $fileName; ?></h1>
<div class="example-box"><pre><code class="<?php echo $type; ?>"><?php echo htmlspecialchars($chunk); ?></code></pre></div>
</div>
<?php endforeach; ?>
<?php else: ?>
<div class="psx-object">
<h1>Output</h1>
<div class="example-box"><pre><code class="<?php echo $type; ?>"><?php echo htmlspecialchars($code); ?></code></pre></div>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
</div>
<hr>
<?php endforeach; ?>

<div class="typeschema-edit">
<a href="https://github.com/apioo/typeschema/blob/master/www/resources/template/<?php echo pathinfo(__FILE__, PATHINFO_BASENAME); ?>"><i class="bi bi-pencil"></i> Edit this page</a>
</div>
</div>

<script>window.addEventListener('load', function() { hljs.highlightAll() });</script>

<?php include __DIR__ . '/inc/footer.php'; ?>
33 changes: 33 additions & 0 deletions www/resources/template/generator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

<?php include __DIR__ . '/inc/header.php'; ?>

<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item active" aria-current="page"><a href="<?php echo $url; ?>">TypeSchema</a> / <a href="<?php echo $router->getAbsolutePath([\App\Controller\Generator::class, 'show']); ?>">Generator</a> / <?php echo $typeName; ?></li>
</ol>
</nav>

<div class="container-fluid">
<h1 class="display-4"><?php echo $typeName; ?> DTO Generator</h1>
<div class="row">
<div class="col-6">
<form method="post" action="<?php echo $router->getAbsolutePath([\App\Controller\Generator::class, 'generate'], ['type' => $type]); ?>">
<div class="form-group">
<input id="namespace" name="namespace" placeholder="Optional a namespace" value="<?php echo htmlspecialchars($namespace ?? ''); ?>" class="form-control">
</div>
<div class="form-group">
<textarea id="schema" name="schema" rows="24" class="form-control"><?php echo htmlspecialchars($schema); ?></textarea>
</div>
<input type="submit" value="Generate" class="btn btn-primary">
<input type="submit" value="Download" class="btn btn-secondary">
</form>
</div>
<div class="col-6">
<div><pre><code class="<?php echo $type ?? ''; ?>"><?php echo isset($output) ? htmlspecialchars($output) : ''; ?></code></pre></div>
</div>
</div>
</div>

<script>window.addEventListener('load', function() { hljs.highlightAll() });</script>

<?php include __DIR__ . '/inc/footer.php'; ?>
Loading

0 comments on commit c3e40cf

Please sign in to comment.