Idiomatic generated code
Ruby should be indented with two spaces, not four.
Python should have two blank lines between the imports and the class declaration.
Other languages like C#, Kotlin, Java, Go, PHP, Rust, etc should have a blank line between the usings/imports and the class declaration.
Hi @vanillajonathan thanks for the feedback, I have adjusted the ruby generator to use two spaces s. https://github.com/apioo/psx-schema/commit/076a77b476c4374980da3b33bf5a4b915ccecf88
Regarding Python, it looks like we already generate the fitting two new lines s. https://github.com/apioo/psx-schema/blob/master/tests/Generator/resource/python/python.py
The following snippets are taken from the website.
C#
Looks like:
using System.Text.Json.Serialization;
public class Student
{
[JsonPropertyName("firstName")]
public string FirstName { get; set; }
[JsonPropertyName("lastName")]
public string LastName { get; set; }
[JsonPropertyName("age")]
public int Age { get; set; }
}
Should look like:
using System.Text.Json.Serialization;
public class Student
{
[JsonPropertyName("firstName")]
public string FirstName { get; set; }
[JsonPropertyName("lastName")]
public string LastName { get; set; }
[JsonPropertyName("age")]
public int Age { get; set; }
}
Java
Looks like:
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonSetter;
public class Student {
private String firstName;
private String lastName;
private int age;
@JsonSetter("firstName")
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@JsonGetter("firstName")
public String getFirstName() {
return this.firstName;
}
@JsonSetter("lastName")
public void setLastName(String lastName) {
this.lastName = lastName;
}
@JsonGetter("lastName")
public String getLastName() {
return this.lastName;
}
@JsonSetter("age")
public void setAge(int age) {
this.age = age;
}
@JsonGetter("age")
public int getAge() {
return this.age;
}
}
should look like:
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonSetter;
public class Student {
private String firstName;
private String lastName;
private int age;
@JsonSetter("firstName")
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@JsonGetter("firstName")
public String getFirstName() {
return this.firstName;
}
@JsonSetter("lastName")
public void setLastName(String lastName) {
this.lastName = lastName;
}
@JsonGetter("lastName")
public String getLastName() {
return this.lastName;
}
@JsonSetter("age")
public void setAge(int age) {
this.age = age;
}
@JsonGetter("age")
public int getAge() {
return this.age;
}
}
PHP
Looks like:
class Student implements \JsonSerializable, \PSX\Record\RecordableInterface
{
protected ?string $firstName = null;
protected ?string $lastName = null;
protected ?int $age = null;
public function setFirstName(?string $firstName) : void
{
$this->firstName = $firstName;
}
public function getFirstName() : ?string
{
return $this->firstName;
}
public function setLastName(?string $lastName) : void
{
$this->lastName = $lastName;
}
public function getLastName() : ?string
{
return $this->lastName;
}
public function setAge(?int $age) : void
{
$this->age = $age;
}
public function getAge() : ?int
{
return $this->age;
}
public function toRecord() : \PSX\Record\RecordInterface
{
/** @var \PSX\Record\Record<mixed> $record */
$record = new \PSX\Record\Record();
$record->put('firstName', $this->firstName);
$record->put('lastName', $this->lastName);
$record->put('age', $this->age);
return $record;
}
public function jsonSerialize() : object
{
return (object) $this->toRecord()->getAll();
}
}
should look like:
class Student implements \JsonSerializable, \PSX\Record\RecordableInterface
{
protected ?string $firstName = null;
protected ?string $lastName = null;
protected ?int $age = null;
public function setFirstName(?string $firstName) : void
{
$this->firstName = $firstName;
}
public function getFirstName() : ?string
{
return $this->firstName;
}
public function setLastName(?string $lastName) : void
{
$this->lastName = $lastName;
}
public function getLastName() : ?string
{
return $this->lastName;
}
public function setAge(?int $age) : void
{
$this->age = $age;
}
public function getAge() : ?int
{
return $this->age;
}
public function toRecord() : \PSX\Record\RecordInterface
{
/** @var \PSX\Record\Record<mixed> $record */
$record = new \PSX\Record\Record();
$record->put('firstName', $this->firstName);
$record->put('lastName', $this->lastName);
$record->put('age', $this->age);
return $record;
}
public function jsonSerialize() : object
{
return (object) $this->toRecord()->getAll();
}
}
Python
Looks like:
from dataclasses import dataclass
from dataclasses_json import dataclass_json
@dataclass_json
@dataclass
class Student:
first_name: str
last_name: str
age: int
should look like:
from dataclasses import dataclass
from dataclasses_json import dataclass_json
@dataclass_json
@dataclass
class Student:
first_name: str
last_name: str
age: int
Rust
Looks like:
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
pub struct Student {
#[serde(rename = "firstName")]
first_name: Option<String>,
#[serde(rename = "lastName")]
last_name: Option<String>,
#[serde(rename = "age")]
age: Option<u64>,
}
should look like:
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
pub struct Student {
#[serde(rename = "firstName")]
first_name: Option<String>,
#[serde(rename = "lastName")]
last_name: Option<String>,
#[serde(rename = "age")]
age: Option<u64>,
}
Visual Basic
Looks like:
Imports System.Text.Json.Serialization
Public Class Student
<JsonPropertyName("firstName")>
Public Property FirstName As String
<JsonPropertyName("lastName")>
Public Property LastName As String
<JsonPropertyName("age")>
Public Property Age As Integer
End Class
Should look like:
Imports System.Text.Json.Serialization
Public Class Student
<JsonPropertyName("firstName")>
Public Property FirstName As String
<JsonPropertyName("lastName")>
Public Property LastName As String
<JsonPropertyName("age")>
Public Property Age As Integer
End Class