Giter VIP home page Giter VIP logo

Comments (5)

uderline avatar uderline commented on July 18, 2024

Hi !

RefProperty is only used for responses. I had something in mind like:

#[Property(["field1.subfield1" => "string", "field1.subfield2" => "int])]

But now I'm thinking of automatically generating the RequestBody ref directly from the Request object (in your case CalculationRequest). Basically this means you would declare your schema in your request file and in your controller, just the POST and Response.

Maybe this would include implementing an interface to "find" the request body or just any class inheriting symphony's Request object.

What do you think ?

Obviously I'm open to PRs but if needed I can do it

from openapi-php-attributes.

zaneevat avatar zaneevat commented on July 18, 2024

The variant with the Request object looks very interesting. But in general, this will not solve my problem, it would be great to explicitly specify child schemas. In my example, it would look something like this:

#[
    Schema(name: CalculationRequest::class),
    Property(PropertyType::STRING, "service"),
    Property(PropertyType::REF, "shippingAddress"),
    PropertyRef(Address::class),
    Property(PropertyType::REF, "deliveryAddress"),
    PropertyRef(Address::class),
]
class CalculationRequest extends JsonRequest implements ValidateRequestInterface
{
    private string $service;
    private Address $shippingAddress;
    private Address $deliveryAddress;
}
#[
    Schema(name: Address::class),
    Property(PropertyType::STRING, "region"),
    Property(PropertyType::STRING, "city"),
    Property(PropertyType::STRING, "address"),
    Property(PropertyType::STRING, "fullAddress"),
    Property(PropertyType::BOOLEAN, "isTerminal"),
]
class Address
{
    public string $region;
    public string $city;
    public string $address;
    public string $fullAddress;
    public bool $isTerminal;
}

How do you think?

I think I can implement this in a separate PR.

from openapi-php-attributes.

uderline avatar uderline commented on July 18, 2024

That looks good !

Maybe the syntax should be like the Response attribute where you can put a reference in the attributes.

You could then have:

#[
    Schema,
    Property(name: "shippingAddress", ref: Address::class)
]
class CalculationRequest {
}

Though, this could just be a shortcut ...

from openapi-php-attributes.

uderline avatar uderline commented on July 18, 2024

Published in version 1.2 and 1.3

from openapi-php-attributes.

zaneevat avatar zaneevat commented on July 18, 2024

Thank you @uderline 🙏

from openapi-php-attributes.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.