Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Feb 15, 2024
1 parent 349cd47 commit b9a00eb
Show file tree
Hide file tree
Showing 29 changed files with 1,421 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms
github: chriskapp
patreon: fusio
custom: https://www.paypal.me/fusioapi
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI
on:
- pull_request
- push
jobs:
psalm:
name: Psalm
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none
- name: Composer install
run: composer install --no-interaction --no-ansi --no-progress
- name: Run Psalm
run: vendor/bin/psalm --no-progress --shepherd --show-info=false --stats
14 changes: 14 additions & 0 deletions .github/workflows/sdkgen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: SDKgen
on:
- workflow_dispatch
permissions:
contents: 'write'
jobs:
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: apioo/sdkgen-generator-action@v0.1.4
with:
client_id: '${{ secrets.SDKGEN_CLIENT_ID }}'
client_secret: '${{ secrets.SDKGEN_CLIENT_SECRET }}'
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Apioo
Copyright (c) 2024 Christoph Kappestein

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

# About

This library contains the official models to represent a [TypeAPI](https://typeapi.org/) or [TypeSchema](https://typeschema.org/) specification.
It can be used to build i.e. code generators or other tools which need to
interact with a TypeAPI or TypeSchema specification.
21 changes: 21 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "typeapi/model",
"description": "This library contains models to represent a TypeAPI or TypeSchema specification",
"homepage": "https://typeapi.org/",
"license": "MIT",
"authors": [
{
"name": "Christoph Kappestein",
"email": "christoph.kappestein@gmail.com",
"homepage": "https://chrisk.app/"
}
],
"require-dev": {
"vimeo/psalm": "^5.0"
},
"autoload": {
"psr-4": {
"TypeAPI\\Model\\": "src/"
}
}
}
15 changes: 15 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="2"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
13 changes: 13 additions & 0 deletions sdkgen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type": "model-php",
"require": {
"typehub/typeapi": {
"target": "./src",
"namespace": "TypeAPI\\Model"
},
"typehub/typeschema": {
"target": "./src",
"namespace": "TypeAPI\\Model"
}
}
}
34 changes: 34 additions & 0 deletions src/AnyType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types = 1);

namespace TypeAPI\Model;

use PSX\Schema\Attribute\Description;

#[Description('Represents an any type')]
class AnyType extends CommonType implements \JsonSerializable, \PSX\Record\RecordableInterface

Check failure on line 10 in src/AnyType.php

View workflow job for this annotation

GitHub Actions / Psalm

MissingDependency

src/AnyType.php:10:23: MissingDependency: TypeAPI\Model\CommonType depends on class or interface psx\record\recordableinterface that does not exist (see https://psalm.dev/157)

Check failure on line 10 in src/AnyType.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedClass

src/AnyType.php:10:64: UndefinedClass: Class, interface or enum named PSX\Record\RecordableInterface does not exist (see https://psalm.dev/019)
{
#[Description('')]
protected ?string $type = null;
public function setType(?string $type) : void
{
$this->type = $type;
}
public function getType() : ?string
{
return $this->type;
}
public function toRecord() : \PSX\Record\RecordInterface
{
/** @var \PSX\Record\Record<mixed> $record */
$record = parent::toRecord();
$record->put('type', $this->type);
return $record;
}
public function jsonSerialize() : object
{
return (object) $this->toRecord()->getAll();
}
}

56 changes: 56 additions & 0 deletions src/Argument.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types = 1);

namespace TypeAPI\Model;

use PSX\Schema\Attribute\Description;

#[Description('')]
class Argument implements \JsonSerializable, \PSX\Record\RecordableInterface

Check failure on line 10 in src/Argument.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedClass

src/Argument.php:10:46: UndefinedClass: Class, interface or enum named PSX\Record\RecordableInterface does not exist (see https://psalm.dev/019)
{
#[Description('The location where the value can be found either in the path, query, header or body. If you choose path, then your path must have a fitting variable path fragment')]
protected ?string $in = null;
#[Description('')]
protected BooleanType|NumberType|IntegerType|StringType|ReferenceType|null $schema = null;
#[Description('Optional the actual path, query or header name. If not provided the key of the argument map is used')]
protected ?string $name = null;
public function setIn(?string $in) : void
{
$this->in = $in;
}
public function getIn() : ?string
{
return $this->in;
}
public function setSchema(BooleanType|NumberType|IntegerType|StringType|ReferenceType|null $schema) : void
{
$this->schema = $schema;
}
public function getSchema() : BooleanType|NumberType|IntegerType|StringType|ReferenceType|null
{
return $this->schema;
}
public function setName(?string $name) : void
{
$this->name = $name;
}
public function getName() : ?string
{
return $this->name;
}
public function toRecord() : \PSX\Record\RecordInterface
{
/** @var \PSX\Record\Record<mixed> $record */
$record = new \PSX\Record\Record();
$record->put('in', $this->in);
$record->put('schema', $this->schema);
$record->put('name', $this->name);
return $record;
}
public function jsonSerialize() : object
{
return (object) $this->toRecord()->getAll();
}
}

67 changes: 67 additions & 0 deletions src/ArrayType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types = 1);

namespace TypeAPI\Model;

use PSX\Schema\Attribute\Description;

#[Description('Represents an array type. An array type contains an ordered list of a specific type')]
class ArrayType extends CommonType implements \JsonSerializable, \PSX\Record\RecordableInterface

Check failure on line 10 in src/ArrayType.php

View workflow job for this annotation

GitHub Actions / Psalm

MissingDependency

src/ArrayType.php:10:25: MissingDependency: TypeAPI\Model\CommonType depends on class or interface psx\record\recordableinterface that does not exist (see https://psalm.dev/157)

Check failure on line 10 in src/ArrayType.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedClass

src/ArrayType.php:10:66: UndefinedClass: Class, interface or enum named PSX\Record\RecordableInterface does not exist (see https://psalm.dev/019)
{
#[Description('')]
protected ?string $type = null;
#[Description('')]
protected BooleanType|NumberType|IntegerType|StringType|AnyType|ReferenceType|GenericType|null $items = null;
#[Description('Positive integer value')]
protected ?int $maxItems = null;
#[Description('Positive integer value')]
protected ?int $minItems = null;
public function setType(?string $type) : void
{
$this->type = $type;
}
public function getType() : ?string
{
return $this->type;
}
public function setItems(BooleanType|NumberType|IntegerType|StringType|AnyType|ReferenceType|GenericType|null $items) : void
{
$this->items = $items;
}
public function getItems() : BooleanType|NumberType|IntegerType|StringType|AnyType|ReferenceType|GenericType|null
{
return $this->items;
}
public function setMaxItems(?int $maxItems) : void
{
$this->maxItems = $maxItems;
}
public function getMaxItems() : ?int
{
return $this->maxItems;
}
public function setMinItems(?int $minItems) : void
{
$this->minItems = $minItems;
}
public function getMinItems() : ?int
{
return $this->minItems;
}
public function toRecord() : \PSX\Record\RecordInterface
{
/** @var \PSX\Record\Record<mixed> $record */
$record = parent::toRecord();
$record->put('type', $this->type);
$record->put('items', $this->items);
$record->put('maxItems', $this->maxItems);
$record->put('minItems', $this->minItems);
return $record;
}
public function jsonSerialize() : object
{
return (object) $this->toRecord()->getAll();
}
}

34 changes: 34 additions & 0 deletions src/BooleanType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types = 1);

namespace TypeAPI\Model;

use PSX\Schema\Attribute\Description;

#[Description('Represents a boolean type')]
class BooleanType extends ScalarType implements \JsonSerializable, \PSX\Record\RecordableInterface

Check failure on line 10 in src/BooleanType.php

View workflow job for this annotation

GitHub Actions / Psalm

MissingDependency

src/BooleanType.php:10:27: MissingDependency: TypeAPI\Model\ScalarType depends on class or interface psx\record\recordableinterface that does not exist (see https://psalm.dev/157)

Check failure on line 10 in src/BooleanType.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedClass

src/BooleanType.php:10:68: UndefinedClass: Class, interface or enum named PSX\Record\RecordableInterface does not exist (see https://psalm.dev/019)
{
#[Description('')]
protected ?string $type = null;
public function setType(?string $type) : void
{
$this->type = $type;
}
public function getType() : ?string
{
return $this->type;
}
public function toRecord() : \PSX\Record\RecordInterface
{
/** @var \PSX\Record\Record<mixed> $record */
$record = parent::toRecord();
$record->put('type', $this->type);
return $record;
}
public function jsonSerialize() : object
{
return (object) $this->toRecord()->getAll();
}
}

78 changes: 78 additions & 0 deletions src/CommonType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types = 1);

namespace TypeAPI\Model;

use PSX\Schema\Attribute\Description;

#[Description('Represents a base type. Every type extends from this common type and shares the defined properties')]
class CommonType implements \JsonSerializable, \PSX\Record\RecordableInterface

Check failure on line 10 in src/CommonType.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedClass

src/CommonType.php:10:48: UndefinedClass: Class, interface or enum named PSX\Record\RecordableInterface does not exist (see https://psalm.dev/019)
{
#[Description('General description of this type, should not contain any new lines.')]
protected ?string $description = null;
#[Description('Type of the property')]
protected ?string $type = null;
#[Description('Indicates whether it is possible to use a null value')]
protected ?bool $nullable = null;
#[Description('Indicates whether this type is deprecated')]
protected ?bool $deprecated = null;
#[Description('Indicates whether this type is readonly')]
protected ?bool $readonly = null;
public function setDescription(?string $description) : void
{
$this->description = $description;
}
public function getDescription() : ?string
{
return $this->description;
}
public function setType(?string $type) : void
{
$this->type = $type;
}
public function getType() : ?string
{
return $this->type;
}
public function setNullable(?bool $nullable) : void
{
$this->nullable = $nullable;
}
public function getNullable() : ?bool
{
return $this->nullable;
}
public function setDeprecated(?bool $deprecated) : void
{
$this->deprecated = $deprecated;
}
public function getDeprecated() : ?bool
{
return $this->deprecated;
}
public function setReadonly(?bool $readonly) : void
{
$this->readonly = $readonly;
}
public function getReadonly() : ?bool
{
return $this->readonly;
}
public function toRecord() : \PSX\Record\RecordInterface
{
/** @var \PSX\Record\Record<mixed> $record */
$record = new \PSX\Record\Record();
$record->put('description', $this->description);
$record->put('type', $this->type);
$record->put('nullable', $this->nullable);
$record->put('deprecated', $this->deprecated);
$record->put('readonly', $this->readonly);
return $record;
}
public function jsonSerialize() : object
{
return (object) $this->toRecord()->getAll();
}
}

Loading

0 comments on commit b9a00eb

Please sign in to comment.